chiark / gitweb /
sel/sig.c: Discard return value without provoking other warnings.
[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 /*----- Data structures ---------------------------------------------------*/
40
41 typedef struct trace_opt {
42   char ch;
43   unsigned f;
44   const char *help;
45 } trace_opt;
46
47 /*----- Functions provided ------------------------------------------------*/
48
49 /* --- @trace@ --- *
50  *
51  * Arguments:   @unsigned l@ = trace level for output
52  *              @const char *f@ = a @printf@-style format string
53  *              @...@ = other arguments
54  *
55  * Returns:     ---
56  *
57  * Use:         Reports a message to the trace output.
58  */
59
60 extern void trace(unsigned /*l*/, const char */*f*/, ...);
61
62 /* --- @trace_block@ --- *
63  *
64  * Arguments:   @unsigned l@ = trace level for output
65  *              @const char *s@ = some header string to write
66  *              @const void *b@ = pointer to a block of memory to dump
67  *              @size_t sz@ = size of the block of memory
68  *
69  * Returns:     ---
70  *
71  * Use:         Dumps the contents of a block to the trace output.
72  */
73
74 extern void trace_block(unsigned /*l*/, const char */*s*/,
75                         const void */*b*/, size_t /*sz*/);
76
77 /* --- @trace_on@ --- *
78  *
79  * Arguments:   @FILE *fp@ = a file to trace on
80  *              @unsigned l@ = trace level to set
81  *
82  * Returns:     ---
83  *
84  * Use:         Enables tracing to a file.
85  */
86
87 extern void trace_on(FILE */*fp*/, unsigned /*l*/);
88
89 /* --- @trace_custom@ --- *
90  *
91  * Arguments:   @void (*func)(const char *buf, size_t sz, void *v)@ =
92  *                      output function
93  *              @void *v@ = magic handle to give to function
94  *
95  * Returns:     ---
96  *
97  * Use:         Sets up a custom trace handler.
98  */
99
100 extern void trace_custom(void (*/*func*/)(const char */*buf*/,
101                                           size_t /*sz*/, void */*v*/),
102                          void */*v*/);
103
104 /* --- @trace_level@ --- *
105  *
106  * Arguments:   @unsigned l@ = trace level to set
107  *
108  * Returns:     ---
109  *
110  * Use:         Sets the tracing level.
111  */
112
113 extern void trace_level(unsigned /*l*/);
114
115 /* --- @tracing@ --- *
116  *
117  * Arguments:   ---
118  *
119  * Returns:     Zero if not tracing, tracing level if tracing.
120  *
121  * Use:         Informs the caller whether tracing is enabled.
122  */
123
124 extern unsigned tracing(void);
125
126 /* --- @traceopt@ --- *
127  *
128  * Arguments:   @const trace_opt *t@ = pointer to trace options table
129  *              @const char *p@ = option string supplied by user
130  *              @unsigned f@ = initial tracing flags
131  *              @unsigned bad@ = forbidden tracing flags
132  *
133  * Returns:     Trace flags as set by user.
134  *
135  * Use:         Parses an option string from the user and sets the
136  *              appropriate trace flags.  If the argument is null or a single
137  *              `?' character, a help message is displayed.
138  */
139
140 extern unsigned traceopt(const trace_opt */*t*/, const char */*p*/,
141                          unsigned /*f*/, unsigned /*bad*/);
142
143 /*----- Tracing macros ----------------------------------------------------*/
144
145 #ifndef NTRACE
146 #  define T(x) x
147 #  define IF_TRACING(l, x) if ((l) & tracing()) x
148 #else
149 #  define T(x)
150 #  define IF_TRACING(l, x)
151 #endif
152
153 /*----- That's all, folks -------------------------------------------------*/
154
155 #ifdef __cplusplus
156   }
157 #endif
158
159 #endif