| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: trace.h,v 1.5 1999/12/10 23:42:04 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 | /*----- Revision history --------------------------------------------------* |
| 31 | * |
| 32 | * $Log: trace.h,v $ |
| 33 | * Revision 1.5 1999/12/10 23:42:04 mdw |
| 34 | * Change header file guard names. |
| 35 | * |
| 36 | * Revision 1.4 1999/10/22 22:39:52 mdw |
| 37 | * New documented interface for tracing. |
| 38 | * |
| 39 | * Revision 1.3 1999/05/06 19:51:35 mdw |
| 40 | * Reformatted the LGPL notice a little bit. |
| 41 | * |
| 42 | * Revision 1.2 1999/05/05 18:50:31 mdw |
| 43 | * Change licensing conditions to LGPL. |
| 44 | * |
| 45 | * Revision 1.1.1.1 1998/06/17 23:44:42 mdw |
| 46 | * Initial version of mLib |
| 47 | * |
| 48 | */ |
| 49 | |
| 50 | #ifndef MLIB_TRACE_H |
| 51 | #define MLIB_TRACE_H |
| 52 | |
| 53 | #ifdef __cplusplus |
| 54 | extern "C" { |
| 55 | #endif |
| 56 | |
| 57 | /*----- Header files ------------------------------------------------------*/ |
| 58 | |
| 59 | #include <stdio.h> |
| 60 | |
| 61 | /*----- Data structures ---------------------------------------------------*/ |
| 62 | |
| 63 | typedef struct trace_opt { |
| 64 | char ch; |
| 65 | unsigned f; |
| 66 | const char *help; |
| 67 | } trace_opt; |
| 68 | |
| 69 | /*----- Functions provided ------------------------------------------------*/ |
| 70 | |
| 71 | /* --- @trace@ --- * |
| 72 | * |
| 73 | * Arguments: @unsigned l@ = trace level for output |
| 74 | * @const char *f@ = a @printf@-style format string |
| 75 | * @...@ = other arguments |
| 76 | * |
| 77 | * Returns: --- |
| 78 | * |
| 79 | * Use: Reports a message to the trace output. |
| 80 | */ |
| 81 | |
| 82 | extern void trace(unsigned /*l*/, const char */*f*/, ...); |
| 83 | |
| 84 | /* --- @trace_block@ --- * |
| 85 | * |
| 86 | * Arguments: @unsigned l@ = trace level for output |
| 87 | * @const char *s@ = some header string to write |
| 88 | * @const void *b@ = pointer to a block of memory to dump |
| 89 | * @size_t sz@ = size of the block of memory |
| 90 | * |
| 91 | * Returns: --- |
| 92 | * |
| 93 | * Use: Dumps the contents of a block to the trace output. |
| 94 | */ |
| 95 | |
| 96 | extern void trace_block(unsigned /*l*/, const char */*s*/, |
| 97 | const void */*b*/, size_t /*sz*/); |
| 98 | |
| 99 | /* --- @trace_on@ --- * |
| 100 | * |
| 101 | * Arguments: @FILE *fp@ = a file to trace on |
| 102 | * @unsigned l@ = trace level to set |
| 103 | * |
| 104 | * Returns: --- |
| 105 | * |
| 106 | * Use: Enables tracing to a file. |
| 107 | */ |
| 108 | |
| 109 | extern void trace_on(FILE */*fp*/, unsigned /*l*/); |
| 110 | |
| 111 | /* --- @trace_level@ --- * |
| 112 | * |
| 113 | * Arguments: @unsigned l@ = trace level to set |
| 114 | * |
| 115 | * Returns: --- |
| 116 | * |
| 117 | * Use: Sets the tracing level. |
| 118 | */ |
| 119 | |
| 120 | extern void trace_level(unsigned /*l*/); |
| 121 | |
| 122 | /* --- @tracing@ --- * |
| 123 | * |
| 124 | * Arguments: --- |
| 125 | * |
| 126 | * Returns: Zero if not tracing, tracing level if tracing. |
| 127 | * |
| 128 | * Use: Informs the caller whether tracing is enabled. |
| 129 | */ |
| 130 | |
| 131 | extern unsigned tracing(void); |
| 132 | |
| 133 | /* --- @traceopt@ --- * |
| 134 | * |
| 135 | * Arguments: @trace_opt *t@ = pointer to trace options table |
| 136 | * @const char *p@ = option string supplied by user |
| 137 | * @unsigned f@ = initial tracing flags |
| 138 | * @unsigned bad@ = forbidden tracing flags |
| 139 | * |
| 140 | * Returns: Trace flags as set by user. |
| 141 | * |
| 142 | * Use: Parses an option string from the user and sets the |
| 143 | * appropriate trace flags. If the argument is null or a single |
| 144 | * `?' character, a help message is displayed. |
| 145 | */ |
| 146 | |
| 147 | extern unsigned traceopt(trace_opt */*t*/, const char */*p*/, |
| 148 | unsigned /*f*/, unsigned /*bad*/); |
| 149 | |
| 150 | /*----- Tracing macros ----------------------------------------------------*/ |
| 151 | |
| 152 | #ifndef NTRACE |
| 153 | # define T(x) x |
| 154 | # define IF_TRACING(l, x) if ((l) & tracing()) x |
| 155 | #else |
| 156 | # define T(x) |
| 157 | # define IF_TRACING(l, x) |
| 158 | #endif |
| 159 | |
| 160 | /*----- That's all, folks -------------------------------------------------*/ |
| 161 | |
| 162 | #ifdef __cplusplus |
| 163 | } |
| 164 | #endif |
| 165 | |
| 166 | #endif |