vlogfile.h

Go to the documentation of this file.
00001 
00002 
00003 #ifndef VLOGFILE_H
00004 #define VLOGFILE_H
00005 
00009 
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 
00013 #ifdef __cplusplus
00014 extern "C" {
00015 #endif /* __cplusplus */
00016 
00017 
00018 typedef struct {
00019     const char * name;
00020     unsigned long n_lines;
00021     unsigned long n_chars;
00022     FILE * lines;
00023     FILE * dir;
00024     void *(*malloc) (size_t);
00025     void (*free) (void*);
00026 } vlogfile_t;
00027 
00028 
00029 vlogfile_t* new_vlogfile(
00030     const char * log_file_name,
00031     void *(*vlogfile_malloc) (size_t),
00032     void (*vlogfile_free) (void *));
00033 
00034 void delete_vlogfile( 
00035     vlogfile_t* vlogfile); 
00036 
00037 void vlogfile_add_line( 
00038     vlogfile_t* vlogfile, 
00039     const char * line,
00040     size_t line_length);
00041 
00042 const char * vlogfile_get_line(
00043     vlogfile_t* vlogfile,
00044     unsigned long line_number,
00045     unsigned long * line_length);
00046 
00047 void vlogfile_free_line(
00048     vlogfile_t* vlogfile,
00049     const char * line);
00050 
00051 void vlogfile_clear_log(
00052     vlogfile_t* v);
00053 
00054 FILE * vlogfile_open_snapshot(
00055     vlogfile_t* v,
00056     const char * filename);
00057 
00058 void vlogfile_dump_snapshot(
00059     vlogfile_t* v,
00060     FILE * snapshot_file);
00061 
00062 void vlogfile_close_snapshot(
00063     vlogfile_t* v,
00064     FILE * snapshot_file);
00065 
00066 
00067 /*DEBUG LOG*/
00068 
00069 extern FILE * debug_log_file_handle;
00070 extern char * debug_log_current_time;
00071 
00072 #define FPRINTF_HEX_BUFFER(file_handle,data,length) { \
00073     unsigned int iiiii; \
00074     for(iiiii=0;iiiii<(length);iiiii++) { \
00075         const char * HEX = "0123456789ABCDEF"; \
00076         char t[16]; \
00077         unsigned char c = (data)[iiiii]; \
00078         sprintf(t,"<%c%c>", HEX[(((unsigned char)c)>>4)], HEX[(((unsigned char)c)&0x000F)]); \
00079         fprintf(file_handle, "%s", t); \
00080         fflush(file_handle); \
00081     } \
00082 }
00083 
00084 #if defined(DEBUG_PRINTS)
00085 
00086 #define DEBUG_LOG_PRINT_HEX_BUFFER(data,length) { \
00087     unsigned int iiiii; \
00088     for(iiiii=0;iiiii<(length);iiiii++) { \
00089         const char * HEX = "0123456789ABCDEF"; \
00090         char t[16]; \
00091         unsigned char c = (data)[iiiii]; \
00092         if(c==0x0D || c==0x0A){ \
00093             sprintf(t,"%c", c); \
00094         }else \
00095         if(c<=0x1F){ \
00096             sprintf(t,"<%c%c>", HEX[(((unsigned char)c)>>4)], HEX[(((unsigned char)c)&0x000F)]); \
00097         }else \
00098         if(c>=0x7F){ \
00099             sprintf(t,"<%c%c>", HEX[(((unsigned char)c)>>4)], HEX[(((unsigned char)c)&0x000F)]); \
00100         }else \
00101             sprintf(t,"%c", c); \
00102         DEBUG_LOG_PRINT_NOTIME(t); \
00103     } \
00104 }
00105 
00106 #define DEBUG_LOG_PRINT_1(item) do { \
00107     if(debug_log_file_handle != NULL) { \
00108         fprintf(debug_log_file_handle, "%s ", debug_log_current_time); \
00109         fprintf(debug_log_file_handle, (item)); \
00110         fflush(debug_log_file_handle); \
00111     } \
00112 } while (0)
00113 
00114 #define DEBUG_LOG_PRINT_2(format, item) do { \
00115     if(debug_log_file_handle != NULL) { \
00116         fprintf(debug_log_file_handle, "%s ", debug_log_current_time); \
00117         fprintf(debug_log_file_handle, (format), (item)); \
00118         fflush(debug_log_file_handle); \
00119     } \
00120 } while (0)
00121 
00122 #define DEBUG_LOG_PRINT_3(format, item1, item2) do { \
00123     if(debug_log_file_handle != NULL) { \
00124         fprintf(debug_log_file_handle, "%s ", debug_log_current_time); \
00125         fprintf(debug_log_file_handle, (format), (item1), (item2)); \
00126         fflush(debug_log_file_handle); \
00127     } \
00128 } while (0)
00129 
00130 #define DEBUG_LOG_PRINT_4(format, item1, item2, item3) do { \
00131     if(debug_log_file_handle != NULL) { \
00132         fprintf(debug_log_file_handle, "%s ", debug_log_current_time); \
00133         fprintf(debug_log_file_handle, (format), (item1), (item2), (item3)); \
00134         fflush(debug_log_file_handle); \
00135     } \
00136 } while (0)
00137 
00138 #define DEBUG_LOG_PRINT_5(format, item1, item2, item3, item4) do { \
00139     if(debug_log_file_handle != NULL) { \
00140         fprintf(debug_log_file_handle, "%s ", debug_log_current_time); \
00141         fprintf(debug_log_file_handle, (format), (item1), (item2), (item3), (item4)); \
00142         fflush(debug_log_file_handle); \
00143     } \
00144 } while (0)
00145 
00146 #define DEBUG_LOG_PRINT_6(format, item1, item2, item3, item4, item5) do { \
00147     if(debug_log_file_handle != NULL) { \
00148         fprintf(debug_log_file_handle, "%s ", debug_log_current_time); \
00149         fprintf(debug_log_file_handle, (format), (item1), (item2), (item3), (item4), (item5)); \
00150         fflush(debug_log_file_handle); \
00151     } \
00152 } while (0)
00153 
00154 #define DEBUG_LOG_PRINT_TODO(item) do { \
00155     if(debug_log_file_handle != NULL) { \
00156         fprintf(debug_log_file_handle, "%s ", debug_log_current_time); \
00157         fprintf(debug_log_file_handle, "TODO %s %d : %s\n", __FILE__, __LINE__, (item)); \
00158         fflush(debug_log_file_handle); \
00159     } \
00160 } while (0)
00161 
00162 #define DEBUG_LOG_PRINT_HCS_BUFFER(message, prefix) do { \
00163     if(debug_log_file_handle != NULL) { \
00164         fprintf(debug_log_file_handle, "%s %s", debug_log_current_time, prefix); \
00165         hcs_apro_fprint_hcs_buffer(debug_log_file_handle, message); \
00166         fflush(debug_log_file_handle); \
00167     } \
00168 } while (0)
00169 
00170 #define DEBUG_LOG_PRINT_NOTIME(item) do { \
00171     if(debug_log_file_handle != NULL) { \
00172         fprintf(debug_log_file_handle, "%s",(item)); \
00173         fflush(debug_log_file_handle); \
00174     } \
00175 } while (0)
00176 
00177 #define UPDATE_DEBUG_LOG_TIME() do { \
00178     time_t tmp_time; \
00179     time(&tmp_time); \
00180     strcpy(debug_log_current_time,ctime((const time_t*)&tmp_time)); \
00181     debug_log_current_time[strlen(debug_log_current_time)-strlen("\n")] = '\0'; \
00182 } while (0)
00183 
00184 #else 
00185 
00186 #define DEBUG_LOG_PRINT_HEX_BUFFER(data,length) do { (void)(data); (void)(length); } while (0);
00187 #define DEBUG_LOG_PRINT_1(item) do { ((void)(item)); } while (0)
00188 #define DEBUG_LOG_PRINT_2(format, item) do { ((void)(format)); ((void)(item));} while (0)
00189 #define DEBUG_LOG_PRINT_3(format, item1, item2) do { ((void)(format)); ((void)(item1)); ((void)(item2));} while (0)
00190 #define DEBUG_LOG_PRINT_4(format, item1, item2, item3) do { ((void)(format)); ((void)(item1)); ((void)(item2)); ((void)(item3));} while (0)
00191 #define DEBUG_LOG_PRINT_5(format, item1, item2, item3, item4) do { ((void)(format)); ((void)(item1)); ((void)(item2)); ((void)(item3)); ((void)(item4)); } while (0)
00192 #define DEBUG_LOG_PRINT_6(format, item1, item2, item3, item4, item5) do { ((void)(format)); ((void)(item1)); ((void)(item2)); ((void)(item3)); ((void)(item4)); ((void)(item5)); } while (0)
00193 #define DEBUG_LOG_PRINT_TODO(item) do { void item } while (0)
00194 #define DEBUG_LOG_PRINT_HCS_BUFFER(item, prefix) do { ((void)(item));((void)(prefix));} while (0)
00195 #define DEBUG_LOG_PRINT_NOTIME(item) do { ((void)(item)); } while (0)
00196 
00197 #define UPDATE_DEBUG_LOG_TIME() do { ; } while (0);
00198 
00199 #endif
00200 
00201 
00202 
00203 #ifdef __cplusplus
00204 } /* extern "C" */
00205 #endif /* __cplusplus */
00206 
00207 #endif /*VLOGFILE_H*/
00208 
00209 

Generated on Tue Jan 6 22:41:37 2009 for Autodesk DWF 3D Toolkit by  doxygen 1.4.5