00001
00008 #ifndef __HELPER__
00009 #define __HELPER__
00010
00011 #include <stdio.h>
00012 #include <unistd.h>
00013 #include <sys/types.h>
00014 #include "config.h"
00015
00028 extern int verbose;
00029
00030 #ifdef USE_UNICODE
00031 #define CHAR int64_t
00032 #define STRLEN(a) ustrlen(a);
00033 #define U8_LENGTH(a) ( ( (*(char*)(a)) & 0b10000000 ) ? \
00034 ( ( (*(char*)(a)) & 0b01000000 ) ? \
00035 ( ( (*(char*)(a)) & 0b00100000 ) ? \
00036 ( ( (*(char*)(a)) & 0b00010000 ) ? \
00037 ( ( (*(char*)(a)) & 0b00001000 ) ? \
00038 ( ( (*(char*)(a)) & 0b00000100 ) ? \
00039 6 : 5 ) \
00040 : 4 ) \
00041 : 3 ) \
00042 : 2 ) \
00043 :-1 ) \
00044 : 1 )
00045 #else
00046 #define U8_LENGTH(a) 1
00047 #define CHAR char
00048 #define STRLEN(a) strlen(a);
00049 #endif
00050
00051 #ifdef DEBUG
00052 #define FLUSH fflush(NULL); usleep(10000);
00053 #else
00054 #define FLUSH
00055 #endif
00056
00065 #define VPRINTF(...) if(0<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)
00066
00075 #define WPRINTF(...) if(1<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)
00076
00085 #define VWPRINTF(...) if(2<verbose) do { printf(__VA_ARGS__); FLUSH } while(false)
00086
00096 #ifdef USE_PTHREADS
00097 char *getword(FILE * input, int slot, unsigned int* occurrences=NULL);
00098 #else
00099 char *getword(FILE * input, unsigned int* occurrences=NULL);
00100 #endif
00101
00109 #ifdef USE_UNICODE
00110 int ustrlen(const char* arg);
00111 int sgetch(CHAR* where, const char* from);
00112 #else
00113 #define sgetch(where,from) ((*where)=from[0],1)
00114 #endif
00115
00117 #define CHECK_PTR(a) if(NULL==(a)) { fprintf(stderr,"LOW MEMORY!!!\n"); exit(5); }
00118
00119 #endif