Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

epDefs.h

Go to the documentation of this file.
00001 
00016 #ifndef _EPDEFS_H_
00017 #define _EPDEFS_H_
00018 
00019 #include <stdlib.h>
00020 
00021 /* boolean type */
00022 #define boolean_t int
00023 #define _false  (0)
00024 #define _true   (!_false)  /* !! never make this test: if(x == true)
00025                                  make : if(x)  OR  if(x != false)
00026                                  (in C, true=all number different of 0)
00027                            */
00028 #define _sfalse "<false>" 
00029 #define _strue  "<true>"  
00030 #define _BOOL_TO_STRING(bool) (!(bool)?_sfalse:_strue)
00031 
00032 #define ushort   unsigned short
00033 #define uint     unsigned int
00034 #define ulong    unsigned long
00035 
00036 
00037 //#define _VERSION __EPVERSION
00038 
00046 #define _DEBUG(arg...)
00047 #define _DEBUG2(arg...)
00048 #define _DEBUG3(arg...)
00049 #define _DEBUG4(arg...)
00050 #define _ABORT(arg...)  abort()
00051 #define _EXIT(arg...)   exit(-1)
00052 #define _NDEBUG(args...) args
00053 
00054 #ifdef __GNUC__
00055 #  undef _ABORT
00056 #  undef _EXIT
00057 
00058 #ifdef DEBUG
00059 #  undef  _NDEBUG
00060 #  define _NDEBUG(args...)
00061 
00062 #  undef  _DEBUG
00063 #  define _DEBUG(msg, args...) \
00064      fprintf(stdout, "* %-15s::%-15s:: "msg"\n", __FILE__, __FUNCTION__, \
00065              ##args)
00066 
00067 #  if DEBUG > 1
00068 #    undef  _DEBUG2
00069 #    define _DEBUG2(msg, args...)  _DEBUG(msg, args)
00070 #  endif
00071 
00072 #  if DEBUG > 2
00073 #    undef  _DEBUG3
00074 #    define _DEBUG3(msg, args...)  _DEBUG("  "msg, args)
00075 #  endif
00076 
00077 #  if DEBUG > 3
00078 #    undef  _DEBUG4
00079 #    define _DEBUG4(msg, args...)  _DEBUG("    "msg, args)
00080 #  endif
00081 #endif
00082 
00083 #define _ABORT(msg, args...)                                                  \
00084         fprintf(stderr, "*- ABORT -* %-15s::%-15s:: "msg"\n", __FILE__,       \
00085                 __FUNCTION__, ## args);                                       \
00086         abort()
00087 
00088 #define _EXIT(msg, args...)                                                   \
00089         fprintf(stderr, "*- EXIT -* %-15s::%-15s:: "msg"\n", __FILE__,        \
00090                __FUNCTION__, ## args);                                        \
00091         exit(-1)
00092 
00093 
00094 /* erreur fatale 
00095   la raison pour laquelle la macro n'est pas la même en débug ou non,
00096   c'est que la version débug génère un core(fonction abort) qui permet
00097   de tracer le programme
00098 */
00099 #ifdef DEBUG
00100 #  define _FATAL_ERROR(retval, msg, args...)                                  \
00101         fprintf(stderr, "*- FATAL ERROR -* %-15s::%-15s(line #%d):: "msg"\n", \
00102                 __FILE__, __FUNCTION__, __LINE__, ## args);                   \
00103         abort()
00104 #else
00105 #  define _FATAL_ERROR(retval, msg, args...)                                  \
00106         fprintf(stderr, "*- FATAL ERROR -* %-15s::%-15s(line #%d):: "msg"\n", \
00107                 __FILE__, __FUNCTION__, __LINE__, ## args);                   \
00108         exit(retval)
00109 #endif
00110 
00111 #endif /* __GNU_C__ */
00112 
00113 /* retourne avec 1 code d'erreur si un test est vrai
00114    on pourra afficher en debug le message associé au code d'erreur */
00115 #define _IF_TRUE_RETURN(test, errcode, retval) \
00116         if(test)                               \
00117           { return(retval); }
00118 
00119 /* warper à la fonction return(). sera utilisée ultérieurement pour fixer 
00120    le code d'erreur à <none>(gestion des erreurs) */
00121 #define _RETURN(retval) return(retval)
00122 
00123 
00124 
00125 #define _XMALLOC(len)                                                         \
00126    ({                                                                         \
00127        void *__ptr;                                                           \
00128                                                                               \
00129        if((__ptr = malloc(len)) == NULL)                                      \
00130          { _FATAL_ERROR(1, "%s", "Echec d'allocation de mémoire"); }          \
00131                                                                               \
00132        __ptr;                                                                 \
00133    })                                                   
00134 
00135 #define _XDUP(type, value)                                                    \
00136    ({                                                                         \
00137        type *__x =(type *) _XMALLOC(sizeof(type));                            \
00138        (type *) memcpy((void *)__x, (const void *)&(value), sizeof(type));    \
00139    })
00140 
00141 #define _XSTRDUP(value)                                                       \
00142    ({                                                                         \
00143        size_t __len;                                                          \
00144        char *__x;                                                             \
00145                                                                               \
00146        if(value == NULL)                                                      \
00147          { __x = NULL; }                                                      \
00148        else                                                                   \
00149          {                                                                    \
00150             __len = strlen(value)+1;                                          \
00151             __x =(char *) _XMALLOC(__len);                                    \
00152             memcpy((void *)__x, (const void *)(value), __len);                \
00153          };                                                                   \
00154                                                                               \
00155        __x;                                                                   \
00156    })
00157 
00158 #define _XFREE(ptr)                                                           \
00159    ({                                                                         \
00160        if(ptr != NULL)                                                        \
00161          { free(ptr); (ptr) = NULL; }                                         \
00162    })                                                                         \
00163 
00164 
00166 /*#ifdef _USING_STRIP
00167 
00168 char *strip_char;
00169 int  *strip_int;*/
00170 /* Macros _x_STRIP (où x est le type de la variable a "globaliser")
00171 
00172    !! pas de gestion sur erreur de alloc !!! 
00173    !! pas de libération de ressources    !!!
00174 
00175    + Recopie la variable locale src dans une variable globale strip_dst
00176    + Retourne un pointeur sur cette variable
00177 */
00178 /*#define _STRING_STRIP(src)                                           \
00179        (                                                             \
00180         strip_char =(int *) malloc(sizeof(char) * (strlen(src)+1)),  \
00181         strcpy(strip_char, (src))                                    \
00182        )                                                   
00183 
00184 #define _INT_STRIP(src)                                              \
00185        (                                                             \
00186         strip_int =(int *) malloc(sizeof(int)),                      \
00187         *strip_int = src                                             \
00188        )
00189 */
00190 /* utilisation:
00191      _STRING_STRIP("toto sur son vélo")
00192      _INT_STRIP(5)
00193 */
00194 
00195 /*#endif _USING_STRIP */
00196 
00197 #endif  /* _EPDEFS_H_ */
00198 

Generated at Sun Nov 25 14:05:07 2001 for ExtendedPersonnalLibrary by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000