1 #ifndef OUTPUT_H_HEADER_INCLUDED 2 #define OUTPUT_H_HEADER_INCLUDED 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #ifndef Bool 9 #define Bool int 10 #endif 11 12 /* This has to manually set in order for output to have meaningfull labels : */ 13 extern char *ApplicationName ; 14 void set_application_name (char *argv0); 15 const char *get_application_name(); 16 17 18 /***********************************************************************************/ 19 /* The following can be used to enable/disable verbose output from AfterStep : */ 20 /***********************************************************************************/ 21 typedef int (*stream_func)(void*, const char*,...); 22 unsigned int set_output_threshold( unsigned int threshold ); 23 unsigned int get_output_threshold(); 24 25 /* 26 * FEW PRESET LEVELS OF OUTPUT : 27 */ 28 #define OUTPUT_LEVEL_INVALID 0 29 #define OUTPUT_LEVEL_PARSE_ERR 1 30 #define OUTPUT_LEVEL_ERROR 1 31 #define OUTPUT_LEVEL_WARNING 4 32 #define OUTPUT_DEFAULT_THRESHOLD 5 33 #define OUTPUT_LEVEL_PROGRESS OUTPUT_DEFAULT_THRESHOLD+1 34 #define OUTPUT_LEVEL_ACTIVITY OUTPUT_DEFAULT_THRESHOLD+2 35 #define OUTPUT_VERBOSE_THRESHOLD OUTPUT_DEFAULT_THRESHOLD+3 36 #define OUTPUT_LEVEL_DEBUG 10 /* anything above it is hardcore debugging */ 37 38 unsigned int set_output_level( unsigned int level ); 39 void restore_output_level(); 40 Bool is_output_level_under_threshold( unsigned int level ); 41 /* 42 * if pfunc is NULL then if threshold >= level - then we use fprintf 43 * otherwise - return False 44 */ 45 Bool pre_print_check( stream_func *pfunc, void** pstream, void *data, const char *msg ); 46 47 /* AfterStep specific error and Warning handlers : */ 48 /* Returns True if something was actually printed */ 49 Bool show_error( const char *error_format, ...); 50 Bool show_system_error( const char *error_format, ...); /* will also execute perror() */ 51 Bool show_warning( const char *warning_format, ...); 52 Bool show_progress( const char *msg_format, ...); 53 Bool show_activity( const char *msg_format, ...); 54 Bool show_debug( const char *file, const char *func, int line, const char *msg_format, ...); 55 #define SHOW_CHECKPOINT show_debug(__FILE__,__FUNCTION__,__LINE__, "*checkpoint*") 56 57 58 void nonGNUC_debugout( const char *format, ...); 59 inline void nonGNUC_debugout_stub( const char *format, ...); 60 /* may be used below in case compilation problems occur. 61 * Please submit a bug report if usage of any of the following generates errors on 62 * your compiler . Thanks!!! */ 63 64 void debugout_print_linestamp(const char *file, const char *func, int line ); 65 66 67 const char *get_caller_func();/* required by below */ 68 69 /* Some usefull debugging macros : */ 70 #ifdef __GNUC__ 71 72 #if (!defined(NO_DEBUG_OUTPUT))&&(defined(LOCAL_DEBUG)||defined(DEBUG)||defined(DEBUG_ALL)) 73 #define DEBUG_OUT(format,args...) \ 74 do{ fprintf( stderr, "%s:%s:%s:%d:>" format "\n", ApplicationName, __FILE__, __FUNCTION__, __LINE__, ## args );}while(0) 75 #else 76 #define DEBUG_OUT(format,args...) 77 #endif /* DEBUG */ 78 79 #if (!defined(NO_DEBUG_OUTPUT))&&(defined(LOCAL_DEBUG)||defined(DEBUG_ALL)) 80 #define LOCAL_DEBUG_OUT(format,args...) \ 81 do{ debugout_print_linestamp(__FILE__,__FUNCTION__,__LINE__); \ 82 fprintf( stderr, format "\n", ## args );}while(0) 83 #define LOCAL_DEBUG_CALLER_OUT(format,args...) \ 84 do{ debugout_print_linestamp(__FILE__,__FUNCTION__,__LINE__); \ 85 fprintf( stderr, "called from [%s] with args(" format ")\n", get_caller_func(), ## args );}while(0) 86 #else 87 #define LOCAL_DEBUG_OUT(format,args...) 88 #define LOCAL_DEBUG_CALLER_OUT(format,args...) 89 #endif /* LOCAL_DEBUG */ 90 91 #elif __STDC_VERSION__ >= 199901 /* C99 standard provides support for this as well : */ 92 93 #if (!defined(NO_DEBUG_OUTPUT))&&(defined(LOCAL_DEBUG)||defined(DEBUG)||defined(DEBUG_ALL)) 94 #define DEBUG_OUT(...) \ 95 do{ fprintf( stderr, "%s:%s:%s:%d:>", ApplicationName, __FILE__, __FUNCTION__, __LINE__ ); \ 96 fprintf( stderr, __VA_ARGS__); \ 97 fprintf( stderr, "\n"); \ 98 }while(0) 99 #else 100 #define DEBUG_OUT(...) 101 #endif /* DEBUG */ 102 103 #if (!defined(NO_DEBUG_OUTPUT))&&(defined(LOCAL_DEBUG)||defined(DEBUG_ALL)) 104 #define LOCAL_DEBUG_OUT(...) \ 105 do{ fprintf( stderr, "%s:%s:%s:%d:>", ApplicationName, __FILE__, __FUNCTION__, __LINE__ ); \ 106 fprintf( stderr, __VA_ARGS__); \ 107 fprintf( stderr, "\n"); \ 108 }while(0) 109 #define LOCAL_DEBUG_CALLER_OUT(...) \ 110 do{ fprintf( stderr, "%s:%s:%s:> called from [%s] with args(", ApplicationName, __FILE__, get_caller_func() ); \ 111 fprintf( stderr, __VA_ARGS__); \ 112 fprintf( stderr, ")\n"); \ 113 }while(0) 114 #else 115 #define LOCAL_DEBUG_OUT(...) 116 #define LOCAL_DEBUG_CALLER_OUT(...) 117 #endif /* LOCAL_DEBUG */ 118 119 #else /* non __GNUC__ or C99 compliant compiler : */ 120 121 #if (!defined(NO_DEBUG_OUTPUT))&&(defined(LOCAL_DEBUG)||defined(DEBUG)||defined(DEBUG_ALL)) 122 #define DEBUG_OUT nonGNUC_debugout 123 #else 124 #define DEBUG_OUT nonGNUC_debugout_stub 125 #endif /* DEBUG */ 126 127 #if (!defined(NO_DEBUG_OUTPUT))&&(defined(LOCAL_DEBUG)||defined(DEBUG_ALL)) 128 #define LOCAL_DEBUG_OUT nonGNUC_debugout 129 #define LOCAL_DEBUG_CALLER_OUT nonGNUC_debugout_stub 130 #else 131 #define LOCAL_DEBUG_OUT nonGNUC_debugout_stub 132 #define LOCAL_DEBUG_CALLER_OUT nonGNUC_debugout_stub 133 #endif /* LOCAL_DEBUG */ 134 135 #endif 136 137 #ifdef DO_CLOCKING 138 #define START_TIME(started) time_t started = clock() 139 #define SHOW_TIME(s,started) fprintf (stderr, "%s %s time (clocks): %lu mlsec\n", __FUNCTION__, s, ((clock () - (started))*100)/CLOCKS_PER_SEC) 140 #else 141 #define START_TIME(started) while(0){}; 142 #define SHOW_TIME(s,started) while(0){}; 143 #endif 144 145 #ifdef __cplusplus 146 } 147 #endif 148 149 #endif 150