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