2 * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
16 #include <sm/string.h>
18 SM_RCSID("@(#)$Id: trace.c,v 8.38 2002/12/05 17:28:35 ca Exp $")
20 static char *tTnewflag __P((char *));
21 static char *tToldflag __P((char *));
24 ** TtSETUP -- set up for trace package.
27 ** vect -- pointer to trace vector.
28 ** size -- number of flags in trace vector.
29 ** defflags -- flags to set if no value given.
35 ** environment is set up.
38 static unsigned char *tTvect;
39 static unsigned int tTsize;
40 static char *DefFlags;
43 tTsetup(vect, size, defflags)
54 ** tToldflag -- process an old style trace flag
57 ** s -- points to a [\0, \t] terminated string,
58 ** and the initial character is a digit.
61 ** pointer to terminating [\0, \t] character
71 unsigned int first, last;
72 register unsigned int i;
74 /* find first flag to set */
76 while (isascii(*s) && isdigit(*s) && i < tTsize)
77 i = i * 10 + (*s++ - '0');
80 ** skip over rest of a too large number
81 ** Maybe we should complain if out-of-bounds values are used.
84 while (isascii(*s) && isdigit(*s) && i >= tTsize)
88 /* find last flag to set */
92 while (isascii(*++s) && isdigit(*s) && i < tTsize)
93 i = i * 10 + (*s - '0');
95 /* skip over rest of a too large number */
96 while (isascii(*s) && isdigit(*s) && i >= tTsize)
101 /* find the level to set it to */
106 while (isascii(*++s) && isdigit(*s))
107 i = i * 10 + (*s - '0');
117 while (first <= last)
118 tTvect[first++] = (unsigned char) i;
120 /* skip trailing junk */
121 while (*s != '\0' && *s != ',' && *s != ' ' && *s != '\t')
128 ** tTnewflag -- process a new style trace flag
131 ** s -- Points to a non-empty [\0, \t] terminated string,
132 ** of which the initial character is not a digit.
135 ** pointer to terminating [\0, \t] character
138 ** adds trace flag to libsm debug database
149 while (*s != '\0' && *s != ',' && *s != ' ' && *s != '\t' && *s != '.')
156 while (isascii(*s) && isdigit(*s))
158 level = level * 10 + (*s - '0');
169 sm_debug_addsetting_x(sm_strndup_x(pat, endpat - pat), level);
171 /* skip trailing junk */
172 while (*s != '\0' && *s != ',' && *s != ' ' && *s != '\t')
179 ** TtFLAG -- process an external trace flag list.
182 ** s -- the trace flag.
184 ** The syntax of a trace flag list is as follows:
186 ** <flags> ::= <flag> | <flags> "," <flag>
187 ** <flag> ::= <categories> | <categories> "." <level>
188 ** <categories> ::= <int> | <int> "-" <int> | <pattern>
189 ** <pattern> ::= <an sh glob pattern matching a C identifier>
191 ** White space is ignored before and after a flag.
192 ** However, note that we skip over anything we don't
193 ** understand, rather than report an error.
199 ** sets/clears old-style trace flags.
200 ** registers new-style trace flags with the libsm debug package.
207 if (s == NULL || *s == '\0')
214 if (*s == ',' || *s == ' ' || *s == '\t')
219 if (isascii(*s) && isdigit(*s))