Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

define.h

Go to the documentation of this file.
00001 /***
00002  * define.h
00003  * Part of the LibPST project
00004  * Written by David Smith
00005  *            dave.s@earthcorp.com
00006  */
00007 
00008 #ifndef DEFINEH_H
00009 #define DEFINEH_H
00010 
00011 #ifdef HAVE_CONFIG_H
00012     #include "config.h"
00013 #endif
00014 
00015 #include "libpst.h"
00016 #include "timeconv.h"
00017 #include "libstrfunc.h"
00018 #include "vbuf.h"
00019 
00020 #define DEBUG_MODE_GEN
00021 #define DEBUGPRINT
00022 #define DEBUG_MODE_WARN
00023 #define DEBUG_MODE_READ
00024 #define DEBUG_MODE_EMAIL
00025 #define DEBUG_MODE_MAIN
00026 #define DEBUG_MODE_INDEX
00027 #define DEBUG_MODE_CODE
00028 #define DEBUG_MODE_INFO
00029 #define DEBUG_MODE_HEXDUMP
00030 #define DEBUG_MODE_FUNC
00031 
00032 //number of items to save in memory between writes
00033 #define DEBUG_MAX_ITEMS 0
00034 
00035 #define DEBUG_FILE_NO     1
00036 #define DEBUG_INDEX_NO    2
00037 #define DEBUG_EMAIL_NO    3
00038 #define DEBUG_WARN_NO     4
00039 #define DEBUG_READ_NO     5
00040 #define DEBUG_INFO_NO     6
00041 #define DEBUG_MAIN_NO     7
00042 #define DEBUG_DECRYPT_NO  8
00043 #define DEBUG_FUNCENT_NO  9
00044 #define DEBUG_FUNCRET_NO 10
00045 #define DEBUG_HEXDUMP_NO 11
00046 
00047 #ifdef HAVE_TIME_H
00048     #include <time.h>
00049 #endif
00050 
00051 #ifdef HAVE_STRING_H
00052     #include <string.h>
00053 #endif
00054 
00055 #ifdef HAVE_CTYPE_H
00056     #include <ctype.h>
00057 #endif
00058 
00059 #ifdef HAVE_LIMITS_H
00060     #include <limits.h>
00061 #endif
00062 
00063 #ifdef HAVE_WCHAR_H
00064     #include <wchar.h>
00065 #endif
00066 
00067 #ifdef HAVE_SIGNAL_H
00068     #include <signal.h>
00069 #endif
00070 
00071 #ifdef HAVE_ERRNO_H
00072     #include <errno.h>
00073 #endif
00074 
00075 #ifdef HAVE_ICONV
00076     #include <iconv.h>
00077 #endif
00078 
00079 #ifdef HAVE_REGEX_H
00080     #include <regex.h>
00081 #endif
00082 
00083 #ifdef HAVE_GD_H
00084     #include <gd.h>
00085 #endif
00086 
00087 
00088 #define PERM_DIRS 0777
00089 
00090 #ifdef _WIN32
00091     #include <direct.h>
00092 
00093     #define D_MKDIR(x) mkdir(x)
00094     #define chdir      _chdir
00095     #define strcasecmp _stricmp
00096     #define vsnprintf  _vsnprintf
00097     #define snprintf   _snprintf
00098     #ifdef _MSC_VER
00099         #define ftello     _ftelli64
00100         #define fseeko     _fseeki64
00101     #elif defined (__MINGW32__)
00102         #define ftello     ftello64
00103         #define fseeko     fseeko64
00104     #else
00105         #error Only MSC and mingw supported for Windows
00106     #endif
00107     #ifndef __MINGW32__
00108         #define size_t     __int64
00109     #endif
00110     #ifndef UINT64_MAX
00111         #define UINT64_MAX ((uint64_t)0xffffffffffffffff)
00112     #endif
00113     #define PRIx64 "I64x"
00114     int __cdecl _fseeki64(FILE *, __int64, int);
00115     __int64 __cdecl _ftelli64(FILE *);
00116 
00117     #ifdef __MINGW32__
00118         #include <getopt.h>
00119     #else
00120         #include "XGetopt.h"
00121     #endif
00122 #else
00123     #ifdef HAVE_UNISTD_H
00124         #include <unistd.h>
00125     #else
00126         #include "XGetopt.h"
00127     #endif
00128     #define D_MKDIR(x) mkdir(x, PERM_DIRS)
00129 #endif
00130 
00131 #ifdef HAVE_SYS_STAT_H
00132     #include <sys/stat.h>
00133 #endif
00134 
00135 #ifdef HAVE_SYS_TYPES_H
00136     #include <sys/types.h>
00137 #endif
00138 
00139 #ifdef HAVE_DIRENT_H
00140     #include <dirent.h>
00141 #endif
00142 
00143 
00144 void pst_debug(const char *fmt, ...);
00145 void pst_debug_hexdumper(FILE* out, char* buf, size_t size, int col, int delta);
00146 void pst_debug_hexprint(char *data, int size);
00147 
00148 void pst_debug_init(const char *fname);
00149 void pst_debug_msg_info (int line, const char *file, int type);
00150 void pst_debug_msg_text(const char* fmt, ...);
00151 void pst_debug_hexdump(char *x, size_t y, int cols, int delta);
00152 void pst_debug_func(const char *function);
00153 void pst_debug_func_ret();
00154 void pst_debug_close(void);
00155 void pst_debug_write();
00156 size_t pst_debug_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
00157 
00158 void * xmalloc(size_t size);
00159 
00160 #define MESSAGEPRINT(x,y) {pst_debug_msg_info(__LINE__,__FILE__,y);\
00161                            pst_debug_msg_text x;}
00162 
00163 #define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();}
00164 
00165 #define DIE(x) {\
00166  MESSAGEPRINT(x, 0);\
00167  printf x;\
00168  exit(EXIT_FAILURE);\
00169 }
00170 #define WARN(x) {\
00171  MESSAGEPRINT(x, 0);\
00172  printf x;\
00173 }
00174 
00175 #ifdef DEBUGPRINT
00176 #define DEBUG_PRINT(x) pst_debug x;
00177 #else
00178 #define DEBUG_PRINT(x) {}
00179 #endif
00180 
00181 #ifdef DEBUG_MODE_GEN
00182 #define DEBUG(x) {DEBUG_PRINT(x);}
00183 #else
00184 #define DEBUG(x) {}
00185 #endif
00186 
00187 #ifdef DEBUG_MODE_INDEX
00188 #define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO);
00189 #else
00190 #define DEBUG_INDEX(x) {}
00191 #endif
00192 
00193 #ifdef DEBUG_MODE_EMAIL
00194 #define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO);
00195 #define DEBUG_EMAIL_HEXPRINT(x,y) {pst_debug_msg_info(__LINE__, __FILE__, 11);\
00196                                    pst_debug_hexdump((char*)x, y, 0x10, 0);}
00197 #else
00198 #define DEBUG_EMAIL(x) {}
00199 #define DEBUG_EMAIL_HEXPRINT(x,y) {}
00200 #endif
00201 
00202 #ifdef DEBUG_MODE_WARN
00203 #define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO);
00204 #else
00205 #define DEBUG_WARN(x) {}
00206 #endif
00207 
00208 #ifdef DEBUG_MODE_READ
00209 #define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO);
00210 #else
00211 #define DEBUG_READ(x) {}
00212 #endif
00213 
00214 #ifdef DEBUG_MODE_INFO
00215 #define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO);
00216 #else
00217 #define DEBUG_INFO(x) {}
00218 #endif
00219 
00220 #ifdef DEBUG_MODE_MAIN
00221 #define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO);
00222 #else
00223 #define DEBUG_MAIN(x) {}
00224 #endif
00225 
00226 #ifdef DEBUG_MODE_CODE
00227 #define DEBUG_CODE(x) {x}
00228 #else
00229 #define DEBUG_CODE(x) {}
00230 #endif
00231 
00232 #ifdef DEBUG_MODE_DECRYPT
00233 #define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO);
00234 #else
00235 #define DEBUG_DECRYPT(x) {}
00236 #endif
00237 
00238 #ifdef DEBUG_MODE_HEXDUMP
00239 #define DEBUG_HEXDUMP(x, s)\
00240   {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
00241    pst_debug_hexdump((char*)x, s, 0x10, 0);}
00242 #define DEBUG_HEXDUMPC(x, s, c)\
00243   {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
00244    pst_debug_hexdump((char*)x, s, c, 0);}
00245 #else
00246 #define DEBUG_HEXDUMP(x, s) {}
00247 #define DEBUG_HEXDUMPC(x, s, c) {}
00248 #endif
00249 
00250 #define DEBUG_FILE(x) {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\
00251                        pst_debug_msg_text x;}
00252 
00253 #ifdef DEBUG_MODE_FUNC
00254 # define DEBUG_ENT(x)                                           \
00255     {                                                           \
00256         pst_debug_func(x);                                      \
00257         MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNCENT_NO); \
00258     }
00259 # define DEBUG_RET()                                            \
00260     {                                                           \
00261         MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNCRET_NO);  \
00262         pst_debug_func_ret();                                   \
00263     }
00264 #else
00265 # define DEBUG_ENT(x) {}
00266 # define DEBUG_RET() {}
00267 #endif
00268 
00269 #define DEBUG_INIT(fname) {pst_debug_init(fname);}
00270 #define DEBUG_CLOSE() {pst_debug_close();}
00271 #define DEBUG_REGISTER_CLOSE() {if(atexit(pst_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");}
00272 
00273 #define RET_DERROR(res, ret_val, x)\
00274     if (res) { DIE(x);}
00275 
00276 #define RET_ERROR(res, ret_val)\
00277     if (res) {return ret_val;}
00278 
00279 #define DEBUG_VERSION 1
00280 struct pst_debug_file_rec_m {
00281     unsigned short int funcname;
00282     unsigned short int filename;
00283     unsigned short int text;
00284     unsigned short int end;
00285     unsigned int line;
00286     unsigned int type;
00287 };
00288 
00289 struct pst_debug_file_rec_l {
00290     unsigned int funcname;
00291     unsigned int filename;
00292     unsigned int text;
00293     unsigned int end;
00294     unsigned int line;
00295     unsigned int type;
00296 };
00297 
00298 #if BYTE_ORDER == BIG_ENDIAN
00299 #  define LE64_CPU(x) \
00300   x = ((((x) & UINT64_C(0xff00000000000000)) >> 56) | \
00301        (((x) & UINT64_C(0x00ff000000000000)) >> 40) | \
00302        (((x) & UINT64_C(0x0000ff0000000000)) >> 24) | \
00303        (((x) & UINT64_C(0x000000ff00000000)) >> 8 ) | \
00304        (((x) & UINT64_C(0x00000000ff000000)) << 8 ) | \
00305        (((x) & UINT64_C(0x0000000000ff0000)) << 24) | \
00306        (((x) & UINT64_C(0x000000000000ff00)) << 40) | \
00307        (((x) & UINT64_C(0x00000000000000ff)) << 56));
00308 #  define LE32_CPU(x) \
00309   x = ((((x) & 0xff000000) >> 24) | \
00310        (((x) & 0x00ff0000) >> 8 ) | \
00311        (((x) & 0x0000ff00) << 8 ) | \
00312        (((x) & 0x000000ff) << 24));
00313 #  define LE16_CPU(x) \
00314   x = ((((x) & 0xff00) >> 8) | \
00315        (((x) & 0x00ff) << 8));
00316 #elif BYTE_ORDER == LITTLE_ENDIAN
00317 #  define LE64_CPU(x) {}
00318 #  define LE32_CPU(x) {}
00319 #  define LE16_CPU(x) {}
00320 #else
00321 #  error "Byte order not supported by this library"
00322 #endif // BYTE_ORDER
00323 
00324 
00325 #define PST_LE_GET_UINT64(p) \
00326         (uint64_t)((((uint8_t const *)(p))[0] << 0)  |    \
00327                    (((uint8_t const *)(p))[1] << 8)  |    \
00328                    (((uint8_t const *)(p))[2] << 16) |    \
00329                    (((uint8_t const *)(p))[3] << 24) |    \
00330                    (((uint8_t const *)(p))[4] << 32) |    \
00331                    (((uint8_t const *)(p))[5] << 40) |    \
00332                    (((uint8_t const *)(p))[6] << 48) |    \
00333                    (((uint8_t const *)(p))[7] << 56))
00334 
00335 #define PST_LE_GET_INT64(p) \
00336         (int64_t)((((uint8_t const *)(p))[0] << 0)  |    \
00337                   (((uint8_t const *)(p))[1] << 8)  |    \
00338                   (((uint8_t const *)(p))[2] << 16) |    \
00339                   (((uint8_t const *)(p))[3] << 24) |    \
00340                   (((uint8_t const *)(p))[4] << 32) |    \
00341                   (((uint8_t const *)(p))[5] << 40) |    \
00342                   (((uint8_t const *)(p))[6] << 48) |    \
00343                   (((uint8_t const *)(p))[7] << 56))
00344 
00345 #define PST_LE_GET_UINT32(p) \
00346         (uint32_t)((((uint8_t const *)(p))[0] << 0)  |    \
00347                    (((uint8_t const *)(p))[1] << 8)  |    \
00348                    (((uint8_t const *)(p))[2] << 16) |    \
00349                    (((uint8_t const *)(p))[3] << 24))
00350 
00351 #define PST_LE_GET_INT32(p) \
00352         (int32_t)((((uint8_t const *)(p))[0] << 0)  |    \
00353                   (((uint8_t const *)(p))[1] << 8)  |    \
00354                   (((uint8_t const *)(p))[2] << 16) |    \
00355                   (((uint8_t const *)(p))[3] << 24))
00356 
00357 #define PST_LE_GET_UINT16(p)                  \
00358         (uint16_t)((((uint8_t const *)(p))[0] << 0)  |    \
00359                    (((uint8_t const *)(p))[1] << 8))
00360 
00361 #define PST_LE_GET_INT16(p)               \
00362         (int16_t)((((uint8_t const *)(p))[0] << 0)  |    \
00363                    (((uint8_t const *)(p))[1] << 8))
00364 
00365 #define PST_LE_GET_UINT8(p) (*(uint8_t const *)(p))
00366 
00367 #define PST_LE_GET_INT8(p) (*(int8_t const *)(p))
00368 
00369 
00370 #endif //DEFINEH_H

Generated on Thu Mar 19 16:39:25 2009 for 'LibPst' by  doxygen 1.3.9.1