Fixed wrealloc() to be consistent with the wmalloc() behaviour when it cannot
[wmaker-crm.git] / src / L.h
blob3777b1fd396a9e05bc1ccb331c8ab5f74a8e415d
1 /*
2 * L.h - support for logging (printf...) style debugging.
4 * Copyright (c) 1997 Phil Maker
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 * Id: L.h,v 1.2 1998/01/17 10:57:03 pjm Exp
32 #ifndef _L_h_
33 #define _L_h_ 1
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
39 #ifndef WITHOUT_NANA
42 * nana-config.h - the system wide configuration file; we put the ifndef
43 * around it to avoid the file 5 million times during a compile.
46 #ifndef _nana_config_h_
47 #include <nana-config.h>
48 #endif
50 /*
51 * L_LEVEL sets the level of logging analogously to NDEBUG in assert.h
53 * L_LEVEL == 2: always print.
54 * L_LEVEL == 1: print iff the guard is true.
55 * L_LEVEL == 0: never print.
58 #ifndef L_LEVEL /* define DEFAULT for L_LEVEL */
59 #define L_LEVEL 1
60 #endif
62 /*
63 * L_DEFAULT_HANDLER - the default print handler; by default we just
64 * use fprintf.
67 #ifndef L_DEFAULT_HANDLER /* define default handler */
68 #define L_DEFAULT_HANDLER fprintf
69 #endif /* L_DEFAULT_HANDLER */
72 * L_DEFAULT_GUARD - the default guard expression; a message is printed
73 * iff the guard is true. By default its always true.
76 #ifndef L_DEFAULT_GUARD
77 #define L_DEFAULT_GUARD (1)
78 #endif
81 * L_DEFAULT_PARAMS - the default value to be passed as the second argument
82 * to the handler macro when an invariant fails.
86 #ifndef L_DEFAULT_PARAMS
87 #define L_DEFAULT_PARAMS stderr
88 #endif
90 /*
91 * L_SHOW_TIME_FORMAT - the format string for printing the time.
94 #ifndef L_SHOW_TIME_FORMAT
95 #define L_SHOW_TIME_FORMAT "%.6f:\t"
96 #endif
99 * L_SHOW_TIME_NOW - the function to measure the time.
102 #ifndef L_SHOW_TIME_NOW
103 #include <now.h>
104 #define L_SHOW_TIME_NOW now()
105 #endif
108 * L_SHOW_TIME - if it is defined then we will put time stamps at the
109 * beginning of each message using L_SHOW_TIME_FORMAT and L_SHOW_TIME_NOW.
112 #ifdef L_SHOW_TIME
113 #define _L_SHOWTIME(h,p) h (p, L_SHOW_TIME_FORMAT, L_SHOW_TIME_NOW)
114 #else
115 #define _L_SHOWTIME(h,p) /* nothing */
116 #endif /* L_SHOWTIME */
119 * LGHP(g,h,p, f...) - print a log message.
121 * g - the guard; print the message iff this is true
122 * h - the handler function that does the actual printing
123 * p - a parameter for the handler function; e.g. a file descriptor.
124 * f - printf style format string; we put this at the end since we
125 * we need to be able have 1 or more arguments (e.g. L("x") and
126 * L("%d",10); we use GNU cccp preprocessor varargs extension
127 * to handle multiple arguments.
130 #ifndef __GNUC__
131 error you need gcc for this stuff to work properly
132 #endif
134 #if L_LEVEL == 2 /* always log the message */
135 #define LGHP(g,h,p,f...) \
136 do { \
137 _L_SHOWTIME(h,p); \
138 h (p, ##f); \
139 } while(0)
141 #elif L_LEVEL == 1 /* log it iff the guard is true */
142 #define LGHP(g,h,p,f...) \
143 do { \
144 if(g) { \
145 _L_SHOWTIME(h,p); \
146 h (p, ##f); \
148 } while(0)
149 #elif L_LEVEL == 0 /* no logging so ignore them */
150 #define LGHP(g,h,p,f...) /* nothing */
151 #endif /* L_LEVEL */
154 * User routines.
157 #define L(f...) \
158 LGHP(L_DEFAULT_GUARD,L_DEFAULT_HANDLER,L_DEFAULT_PARAMS,##f)
159 #define LG(g,f...) \
160 LGHP(g,L_DEFAULT_HANDLER,L_DEFAULT_PARAMS,##f)
161 #define LH(h,f...) \
162 LGHP(L_DEFAULT_GUARD,h,L_DEFAULT_PARAMS,##f)
163 #define LP(p,f...) \
164 LGHP(L_DEFAULT_GUARD,L_DEFAULT_HANDLER,p,##f)
165 #define LGP(g,p,f...) \
166 LGHP(g,L_DEFAULT_HANDLER,p,##f)
167 #define LHP(h,p,f...) \
168 LGHP(L_DEFAULT_GUARD,h,p,##f)
171 * V* - since the L* macros take a variable numbers of arguments we
172 * have problems compiling calls to L with C preprocessors other
173 * than GNU cccp. The V* macros are called using a bracketed
174 * argument list, e.g. VL((f,x,s));
176 * if we are compiling with GNU C then they simpily call the normal
177 * varargs macro. if we are not using GNU CC then they map to empty.
180 #define VL(a) L a
181 #define VLG(a) LG a
182 #define VLH(a) LH a
183 #define VLP(a) LP a
184 #define VLGP(a) LGP a
185 #define VLHP(a) LHP a
186 #define VLGHP(a) LGHP a
188 #else /* defined(WITHOUT_NANA) */
190 #define VL(a) /* empty */
191 #define VLG(a) /* empty */
192 #define VLH(a) /* empty */
193 #define VLP(a) /* empty */
194 #define VLGP(a) /* empty */
195 #define VLHP(a) /* empty */
196 #define VLGHP(a) /* empty */
198 #endif /* !defined(WITHOUT_NANA) */
200 #ifdef __cplusplus
202 #endif
204 #endif /* _L_h_ */