struct/dstr-putf.c: Remove apparently redundant inclusion of <math.h>.
[mLib] / trace / trace.h
CommitLineData
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
45typedef 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
3832000d
MW
64extern void PRINTF_LIKE(2, 3)
65 trace(unsigned /*l*/, const char */*f*/, ...);
0875b58f 66
67/* --- @trace_block@ --- *
68 *
de3ceebe 69 * Arguments: @unsigned l@ = trace level for output
0875b58f 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
de3ceebe 79extern void trace_block(unsigned /*l*/, const char */*s*/,
0875b58f 80 const void */*b*/, size_t /*sz*/);
81
82/* --- @trace_on@ --- *
83 *
84 * Arguments: @FILE *fp@ = a file to trace on
de3ceebe 85 * @unsigned l@ = trace level to set
0875b58f 86 *
87 * Returns: ---
88 *
89 * Use: Enables tracing to a file.
90 */
91
de3ceebe 92extern void trace_on(FILE */*fp*/, unsigned /*l*/);
0875b58f 93
e4452aaa 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
105extern void trace_custom(void (*/*func*/)(const char */*buf*/,
106 size_t /*sz*/, void */*v*/),
107 void */*v*/);
108
de3ceebe 109/* --- @trace_level@ --- *
0875b58f 110 *
de3ceebe 111 * Arguments: @unsigned l@ = trace level to set
0875b58f 112 *
113 * Returns: ---
114 *
115 * Use: Sets the tracing level.
116 */
117
de3ceebe 118extern void trace_level(unsigned /*l*/);
0875b58f 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
de3ceebe 129extern unsigned tracing(void);
130
131/* --- @traceopt@ --- *
132 *
e4452aaa 133 * Arguments: @const trace_opt *t@ = pointer to trace options table
de3ceebe 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
e4452aaa 145extern unsigned traceopt(const trace_opt */*t*/, const char */*p*/,
de3ceebe 146 unsigned /*f*/, unsigned /*bad*/);
0875b58f 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