@@@ fltfmt wip
[mLib] / trace / trace.h
1 /* -*-c-*-
2 *
3 * Tracing functions for debugging
4 *
5 * (c) 1998 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of the mLib utilities library.
11 *
12 * mLib is free software; you can redistribute it and/or modify
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.
16 *
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
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
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.
26 */
27
28 #ifndef MLIB_TRACE_H
29 #define MLIB_TRACE_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #include <stdio.h>
38
39 #ifndef MLIB_MACROS_H
40 # include "macros.h"
41 #endif
42
43 /*----- Data structures ---------------------------------------------------*/
44
45 typedef struct trace_opt {
46 char ch;
47 unsigned f;
48 const char *help;
49 } trace_opt;
50
51 /*----- Functions provided ------------------------------------------------*/
52
53 /* --- @trace@ --- *
54 *
55 * Arguments: @unsigned l@ = trace level for output
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
64 extern PRINTF_LIKE(2, 3) void trace(unsigned /*l*/, const char */*f*/, ...);
65
66 /* --- @trace_block@ --- *
67 *
68 * Arguments: @unsigned l@ = trace level for output
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
78 extern void trace_block(unsigned /*l*/, const char */*s*/,
79 const void */*b*/, size_t /*sz*/);
80
81 /* --- @trace_on@ --- *
82 *
83 * Arguments: @FILE *fp@ = a file to trace on
84 * @unsigned l@ = trace level to set
85 *
86 * Returns: ---
87 *
88 * Use: Enables tracing to a file.
89 */
90
91 extern void trace_on(FILE */*fp*/, unsigned /*l*/);
92
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
108 /* --- @trace_level@ --- *
109 *
110 * Arguments: @unsigned l@ = trace level to set
111 *
112 * Returns: ---
113 *
114 * Use: Sets the tracing level.
115 */
116
117 extern void trace_level(unsigned /*l*/);
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
128 extern unsigned tracing(void);
129
130 /* --- @traceopt@ --- *
131 *
132 * Arguments: @const trace_opt *t@ = pointer to trace options table
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
144 extern unsigned traceopt(const trace_opt */*t*/, const char */*p*/,
145 unsigned /*f*/, unsigned /*bad*/);
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