Serial Port: debug-msg.h Source File
Serial Port 1.0 beta

debug-msg.h

Go to the documentation of this file.
00001 
00022 #ifndef _DEBUG_MSG_H
00023 #define _DEBUG_MSG_H
00024 
00025 #include <stdio.h>      /* perror() */
00026 #include <string.h>     /* strerror() */
00027 #include <errno.h>      /* errno */
00028 
00029 /***
00030  * Print the error msg is one thing
00031  * but print the msg is another!!
00032  */
00033 
00039 #define error_exit(error)       \
00040     do{                                         \
00041         fprintf(stderr, "%s\n", error);         \
00042         exit(0);                                \
00043     } while(0)
00044 
00049 #define error_ret(error)                          \
00050     do{                                           \
00051         fprintf(stderr, "%s\n", error);           \
00052         return -1;                                \
00053     } while(0)
00054 
00060 #define unix_error_exit(error)                  \
00061     do{                                         \
00062         fprintf(stderr, "%s Info[%d]:%s\n",     \
00063                 error, errno, strerror(errno)); \
00064         exit(1);                                \
00065     } while(0)
00066 
00072 #define unix_error_ret(error)                   \
00073     do{                                         \
00074         fprintf(stderr, "%s Info[%d]:%s\n",     \
00075                 error, errno, strerror(errno)); \
00076         return -1;                              \
00077     } while(0)
00078 
00079 /* error handle ,detail version */
00080 /* it can show the file,function and the line */
00089 #define unix_print_error(error)                                 \
00090     do {                                                        \
00091         fprintf(stderr, "Oh God!\nFile:%s Line:%d Function:%s:\n",  \
00092                 __FILE__, __LINE__, __func__);                      \
00093         perror(error);                                              \
00094         exit(0);                                                    \
00095     } while(0)
00096 
00097 /* DEBUG=0  will show nothing */
00098 #ifndef DEBUG
00099 #define DEBUG   1               
00100 #endif
00101 
00107 #if DEBUG > 0
00108 #define debug_msg(fmt, ...)     \
00109     fprintf(stdout, fmt, ##__VA_ARGS__)
00110 #else
00111 #define debug_msg(fmt,...)
00112 #endif   /* DEBUG */
00113 
00114 #ifndef TRACE
00115 #define TRACE   1               
00116 #endif
00117 
00123 #if TRACE > 0
00124 #define debug_trace(trace)      \
00125     fprintf(stdout, "%s File:%s Line:%d Func:%s.\n",   \
00126             trace, __FILE__, __LINE__, __func__)
00127 #else
00128 #define debug_trace(trace)
00129 #endif
00130 
00131 #endif   /* _DEBUG_MSG_H */