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