struct/dstr-putf.c: Remove apparently redundant inclusion of <math.h>.
[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 void PRINTF_LIKE(2, 3)
65 trace(unsigned /*l*/, const char */*f*/, ...);
66
67 /* --- @trace_block@ --- *
68 *
69 * Arguments: @unsigned l@ = trace level for output
70 * @const char *s@ = some header string to write
71 * @const void *b@ = pointer to a block of memory to dump
72 * @size_t sz@ = size of the block of memory
73 *
74 * Returns: ---
75 *
76 * Use: Dumps the contents of a block to the trace output.
77 */
78
79 extern void trace_block(unsigned /*l*/, const char */*s*/,
80 const void */*b*/, size_t /*sz*/);
81
82 /* --- @trace_on@ --- *
83 *
84 * Arguments: @FILE *fp@ = a file to trace on
85 * @unsigned l@ = trace level to set
86 *
87 * Returns: ---
88 *
89 * Use: Enables tracing to a file.
90 */
91
92 extern void trace_on(FILE */*fp*/, unsigned /*l*/);
93
94 /* --- @trace_custom@ --- *
95 *
96 * Arguments: @void (*func)(const char *buf, size_t sz, void *v)@ =
97 * output function
98 * @void *v@ = magic handle to give to function
99 *
100 * Returns: ---
101 *
102 * Use: Sets up a custom trace handler.
103 */
104
105 extern void trace_custom(void (*/*func*/)(const char */*buf*/,
106 size_t /*sz*/, void */*v*/),
107 void */*v*/);
108
109 /* --- @trace_level@ --- *
110 *
111 * Arguments: @unsigned l@ = trace level to set
112 *
113 * Returns: ---
114 *
115 * Use: Sets the tracing level.
116 */
117
118 extern void trace_level(unsigned /*l*/);
119
120 /* --- @tracing@ --- *
121 *
122 * Arguments: ---
123 *
124 * Returns: Zero if not tracing, tracing level if tracing.
125 *
126 * Use: Informs the caller whether tracing is enabled.
127 */
128
129 extern unsigned tracing(void);
130
131 /* --- @traceopt@ --- *
132 *
133 * Arguments: @const trace_opt *t@ = pointer to trace options table
134 * @const char *p@ = option string supplied by user
135 * @unsigned f@ = initial tracing flags
136 * @unsigned bad@ = forbidden tracing flags
137 *
138 * Returns: Trace flags as set by user.
139 *
140 * Use: Parses an option string from the user and sets the
141 * appropriate trace flags. If the argument is null or a single
142 * `?' character, a help message is displayed.
143 */
144
145 extern unsigned traceopt(const trace_opt */*t*/, const char */*p*/,
146 unsigned /*f*/, unsigned /*bad*/);
147
148 /*----- Tracing macros ----------------------------------------------------*/
149
150 #ifndef NTRACE
151 # define T(x) x
152 # define IF_TRACING(l, x) if ((l) & tracing()) x
153 #else
154 # define T(x)
155 # define IF_TRACING(l, x)
156 #endif
157
158 /*----- That's all, folks -------------------------------------------------*/
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif