chiark / gitweb /
New array adjustment macros for unsigned arguments.
[mLib] / trace.h
CommitLineData
0875b58f 1/* -*-c-*-
2 *
de3ceebe 3 * $Id: trace.h,v 1.4 1999/10/22 22:39:52 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
30/*----- Revision history --------------------------------------------------*
31 *
32 * $Log: trace.h,v $
de3ceebe 33 * Revision 1.4 1999/10/22 22:39:52 mdw
34 * New documented interface for tracing.
35 *
0bd98442 36 * Revision 1.3 1999/05/06 19:51:35 mdw
37 * Reformatted the LGPL notice a little bit.
38 *
c846879c 39 * Revision 1.2 1999/05/05 18:50:31 mdw
40 * Change licensing conditions to LGPL.
41 *
42 * Revision 1.1.1.1 1998/06/17 23:44:42 mdw
43 * Initial version of mLib
0875b58f 44 *
45 */
46
47#ifndef TRACE_H
48#define TRACE_H
49
50#ifdef __cplusplus
51 extern "C" {
52#endif
53
de3ceebe 54/*----- Header files ------------------------------------------------------*/
55
0875b58f 56#include <stdio.h>
57
de3ceebe 58/*----- Data structures ---------------------------------------------------*/
59
60typedef struct trace_opt {
61 char ch;
62 unsigned f;
63 const char *help;
64} trace_opt;
65
0875b58f 66/*----- Functions provided ------------------------------------------------*/
67
68/* --- @trace@ --- *
69 *
de3ceebe 70 * Arguments: @unsigned l@ = trace level for output
0875b58f 71 * @const char *f@ = a @printf@-style format string
72 * @...@ = other arguments
73 *
74 * Returns: ---
75 *
76 * Use: Reports a message to the trace output.
77 */
78
de3ceebe 79extern void trace(unsigned /*l*/, const char */*f*/, ...);
0875b58f 80
81/* --- @trace_block@ --- *
82 *
de3ceebe 83 * Arguments: @unsigned l@ = trace level for output
0875b58f 84 * @const char *s@ = some header string to write
85 * @const void *b@ = pointer to a block of memory to dump
86 * @size_t sz@ = size of the block of memory
87 *
88 * Returns: ---
89 *
90 * Use: Dumps the contents of a block to the trace output.
91 */
92
de3ceebe 93extern void trace_block(unsigned /*l*/, const char */*s*/,
0875b58f 94 const void */*b*/, size_t /*sz*/);
95
96/* --- @trace_on@ --- *
97 *
98 * Arguments: @FILE *fp@ = a file to trace on
de3ceebe 99 * @unsigned l@ = trace level to set
0875b58f 100 *
101 * Returns: ---
102 *
103 * Use: Enables tracing to a file.
104 */
105
de3ceebe 106extern void trace_on(FILE */*fp*/, unsigned /*l*/);
0875b58f 107
de3ceebe 108/* --- @trace_level@ --- *
0875b58f 109 *
de3ceebe 110 * Arguments: @unsigned l@ = trace level to set
0875b58f 111 *
112 * Returns: ---
113 *
114 * Use: Sets the tracing level.
115 */
116
de3ceebe 117extern void trace_level(unsigned /*l*/);
0875b58f 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
de3ceebe 128extern unsigned tracing(void);
129
130/* --- @traceopt@ --- *
131 *
132 * Arguments: @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
144extern unsigned traceopt(trace_opt */*t*/, const char */*p*/,
145 unsigned /*f*/, unsigned /*bad*/);
0875b58f 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