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

Generated on Thu Feb 26 13:40:06 2009 for 'LibPst' by  doxygen 1.3.9.1