2 * L.h - support for logging (printf...) style debugging.
4 * Copyright (c) 1997 Phil Maker
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
28 * Id: L.h,v 1.2 1998/01/17 10:57:03 pjm Exp
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>
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 */
63 * L_DEFAULT_HANDLER - the default print handler; by default we just
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)
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
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"
99 * L_SHOW_TIME_NOW - the function to measure the time.
102 #ifndef L_SHOW_TIME_NOW
104 #define L_SHOW_TIME_NOW now()
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.
113 #define _L_SHOWTIME(h,p) h (p, L_SHOW_TIME_FORMAT, L_SHOW_TIME_NOW)
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.
131 error you need gcc
for this stuff to work properly
134 #if L_LEVEL == 2 /* always log the message */
135 #define LGHP(g,h,p,f...) \
141 #elif L_LEVEL == 1 /* log it iff the guard is true */
142 #define LGHP(g,h,p,f...) \
149 #elif L_LEVEL == 0 /* no logging so ignore them */
150 #define LGHP(g,h,p,f...) /* nothing */
158 LGHP(L_DEFAULT_GUARD,L_DEFAULT_HANDLER,L_DEFAULT_PARAMS,##f)
160 LGHP(g,L_DEFAULT_HANDLER,L_DEFAULT_PARAMS,##f)
162 LGHP(L_DEFAULT_GUARD,h,L_DEFAULT_PARAMS,##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.
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) */