chiark / gitweb /
Add base32 encoding and decoding.
[mLib] / trace.h
... / ...
CommitLineData
1/* -*-c-*-
2 *
3 * $Id: trace.h,v 1.7 2004/04/08 01:36:13 mdw Exp $
4 *
5 * Tracing functions for debugging
6 *
7 * (c) 1998 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the mLib utilities library.
13 *
14 * mLib is free software; you can redistribute it and/or modify
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 *
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
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
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.
28 */
29
30#ifndef MLIB_TRACE_H
31#define MLIB_TRACE_H
32
33#ifdef __cplusplus
34 extern "C" {
35#endif
36
37/*----- Header files ------------------------------------------------------*/
38
39#include <stdio.h>
40
41/*----- Data structures ---------------------------------------------------*/
42
43typedef struct trace_opt {
44 char ch;
45 unsigned f;
46 const char *help;
47} trace_opt;
48
49/*----- Functions provided ------------------------------------------------*/
50
51/* --- @trace@ --- *
52 *
53 * Arguments: @unsigned l@ = trace level for output
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
62extern void trace(unsigned /*l*/, const char */*f*/, ...);
63
64/* --- @trace_block@ --- *
65 *
66 * Arguments: @unsigned l@ = trace level for output
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
76extern void trace_block(unsigned /*l*/, const char */*s*/,
77 const void */*b*/, size_t /*sz*/);
78
79/* --- @trace_on@ --- *
80 *
81 * Arguments: @FILE *fp@ = a file to trace on
82 * @unsigned l@ = trace level to set
83 *
84 * Returns: ---
85 *
86 * Use: Enables tracing to a file.
87 */
88
89extern void trace_on(FILE */*fp*/, unsigned /*l*/);
90
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
106/* --- @trace_level@ --- *
107 *
108 * Arguments: @unsigned l@ = trace level to set
109 *
110 * Returns: ---
111 *
112 * Use: Sets the tracing level.
113 */
114
115extern void trace_level(unsigned /*l*/);
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
126extern unsigned tracing(void);
127
128/* --- @traceopt@ --- *
129 *
130 * Arguments: @const trace_opt *t@ = pointer to trace options table
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
142extern unsigned traceopt(const trace_opt */*t*/, const char */*p*/,
143 unsigned /*f*/, unsigned /*bad*/);
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