Commit | Line | Data |
---|---|---|
0875b58f | 1 | /* -*-c-*- |
2 | * | |
0875b58f | 3 | * Tracing functions for debugging |
4 | * | |
5 | * (c) 1998 Straylight/Edgeware | |
6 | */ | |
7 | ||
d4efbcd9 | 8 | /*----- Licensing notice --------------------------------------------------* |
0875b58f | 9 | * |
10 | * This file is part of the mLib utilities library. | |
11 | * | |
12 | * mLib is free software; you can redistribute it and/or modify | |
c846879c | 13 | * it under the terms of the GNU Library General Public License as |
14 | * published by the Free Software Foundation; either version 2 of the | |
15 | * License, or (at your option) any later version. | |
d4efbcd9 | 16 | * |
0875b58f | 17 | * mLib is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
c846879c | 20 | * GNU Library General Public License for more details. |
d4efbcd9 | 21 | * |
c846879c | 22 | * You should have received a copy of the GNU Library General Public |
0bd98442 | 23 | * License along with mLib; if not, write to the Free |
24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
25 | * MA 02111-1307, USA. | |
0875b58f | 26 | */ |
27 | ||
c6e0eaf0 | 28 | #ifndef MLIB_TRACE_H |
29 | #define MLIB_TRACE_H | |
0875b58f | 30 | |
31 | #ifdef __cplusplus | |
32 | extern "C" { | |
33 | #endif | |
34 | ||
de3ceebe | 35 | /*----- Header files ------------------------------------------------------*/ |
36 | ||
0875b58f | 37 | #include <stdio.h> |
38 | ||
3832000d MW |
39 | #ifndef MLIB_MACROS_H |
40 | # include "macros.h" | |
41 | #endif | |
42 | ||
de3ceebe | 43 | /*----- Data structures ---------------------------------------------------*/ |
44 | ||
45 | typedef struct trace_opt { | |
46 | char ch; | |
47 | unsigned f; | |
48 | const char *help; | |
49 | } trace_opt; | |
50 | ||
0875b58f | 51 | /*----- Functions provided ------------------------------------------------*/ |
52 | ||
53 | /* --- @trace@ --- * | |
54 | * | |
de3ceebe | 55 | * Arguments: @unsigned l@ = trace level for output |
0875b58f | 56 | * @const char *f@ = a @printf@-style format string |
57 | * @...@ = other arguments | |
58 | * | |
59 | * Returns: --- | |
60 | * | |
61 | * Use: Reports a message to the trace output. | |
62 | */ | |
63 | ||
31d0247c | 64 | extern PRINTF_LIKE(2, 3) void trace(unsigned /*l*/, const char */*f*/, ...); |
0875b58f | 65 | |
66 | /* --- @trace_block@ --- * | |
67 | * | |
de3ceebe | 68 | * Arguments: @unsigned l@ = trace level for output |
0875b58f | 69 | * @const char *s@ = some header string to write |
70 | * @const void *b@ = pointer to a block of memory to dump | |
71 | * @size_t sz@ = size of the block of memory | |
72 | * | |
73 | * Returns: --- | |
74 | * | |
75 | * Use: Dumps the contents of a block to the trace output. | |
76 | */ | |
77 | ||
de3ceebe | 78 | extern void trace_block(unsigned /*l*/, const char */*s*/, |
0875b58f | 79 | const void */*b*/, size_t /*sz*/); |
80 | ||
81 | /* --- @trace_on@ --- * | |
82 | * | |
83 | * Arguments: @FILE *fp@ = a file to trace on | |
de3ceebe | 84 | * @unsigned l@ = trace level to set |
0875b58f | 85 | * |
86 | * Returns: --- | |
87 | * | |
88 | * Use: Enables tracing to a file. | |
89 | */ | |
90 | ||
de3ceebe | 91 | extern void trace_on(FILE */*fp*/, unsigned /*l*/); |
0875b58f | 92 | |
e4452aaa | 93 | /* --- @trace_custom@ --- * |
94 | * | |
95 | * Arguments: @void (*func)(const char *buf, size_t sz, void *v)@ = | |
96 | * output function | |
97 | * @void *v@ = magic handle to give to function | |
98 | * | |
99 | * Returns: --- | |
100 | * | |
101 | * Use: Sets up a custom trace handler. | |
102 | */ | |
103 | ||
104 | extern void trace_custom(void (*/*func*/)(const char */*buf*/, | |
105 | size_t /*sz*/, void */*v*/), | |
106 | void */*v*/); | |
107 | ||
de3ceebe | 108 | /* --- @trace_level@ --- * |
0875b58f | 109 | * |
de3ceebe | 110 | * Arguments: @unsigned l@ = trace level to set |
0875b58f | 111 | * |
112 | * Returns: --- | |
113 | * | |
114 | * Use: Sets the tracing level. | |
115 | */ | |
116 | ||
de3ceebe | 117 | extern void trace_level(unsigned /*l*/); |
0875b58f | 118 | |
119 | /* --- @tracing@ --- * | |
120 | * | |
121 | * Arguments: --- | |
122 | * | |
123 | * Returns: Zero if not tracing, tracing level if tracing. | |
124 | * | |
125 | * Use: Informs the caller whether tracing is enabled. | |
126 | */ | |
127 | ||
de3ceebe | 128 | extern unsigned tracing(void); |
129 | ||
130 | /* --- @traceopt@ --- * | |
131 | * | |
e4452aaa | 132 | * Arguments: @const trace_opt *t@ = pointer to trace options table |
de3ceebe | 133 | * @const char *p@ = option string supplied by user |
134 | * @unsigned f@ = initial tracing flags | |
135 | * @unsigned bad@ = forbidden tracing flags | |
136 | * | |
137 | * Returns: Trace flags as set by user. | |
138 | * | |
139 | * Use: Parses an option string from the user and sets the | |
140 | * appropriate trace flags. If the argument is null or a single | |
141 | * `?' character, a help message is displayed. | |
142 | */ | |
143 | ||
e4452aaa | 144 | extern unsigned traceopt(const trace_opt */*t*/, const char */*p*/, |
de3ceebe | 145 | unsigned /*f*/, unsigned /*bad*/); |
0875b58f | 146 | |
147 | /*----- Tracing macros ----------------------------------------------------*/ | |
148 | ||
149 | #ifndef NTRACE | |
150 | # define T(x) x | |
151 | # define IF_TRACING(l, x) if ((l) & tracing()) x | |
152 | #else | |
153 | # define T(x) | |
154 | # define IF_TRACING(l, x) | |
155 | #endif | |
156 | ||
157 | /*----- That's all, folks -------------------------------------------------*/ | |
158 | ||
159 | #ifdef __cplusplus | |
160 | } | |
161 | #endif | |
162 | ||
163 | #endif |