xref: /freebsd/contrib/sendmail/src/trace.c (revision c68159a6d8eede11766cf13896d0f7670dbd51aa)
1 /*
2  * Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
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.
7  *
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.
11  *
12  */
13 
14 #ifndef lint
15 static char id[] = "@(#)$Id: trace.c,v 8.20.22.2 2000/09/17 17:04:27 gshapiro Exp $";
16 #endif /* ! lint */
17 
18 #include <sendmail.h>
19 
20 /*
21 **  TtSETUP -- set up for trace package.
22 **
23 **	Parameters:
24 **		vect -- pointer to trace vector.
25 **		size -- number of flags in trace vector.
26 **		defflags -- flags to set if no value given.
27 **
28 **	Returns:
29 **		none
30 **
31 **	Side Effects:
32 **		environment is set up.
33 */
34 
35 static u_char	*tTvect;
36 static int	tTsize;
37 static char	*DefFlags;
38 
39 void
40 tTsetup(vect, size, defflags)
41 	u_char *vect;
42 	int size;
43 	char *defflags;
44 {
45 	tTvect = vect;
46 	tTsize = size;
47 	DefFlags = defflags;
48 }
49 /*
50 **  TtFLAG -- process an external trace flag description.
51 **
52 **	Parameters:
53 **		s -- the trace flag.
54 **
55 **	Returns:
56 **		none.
57 **
58 **	Side Effects:
59 **		sets/clears trace flags.
60 */
61 
62 void
63 tTflag(s)
64 	register char *s;
65 {
66 	int first, last;
67 	register unsigned int i;
68 
69 	if (*s == '\0')
70 		s = DefFlags;
71 
72 	for (;;)
73 	{
74 		/* find first flag to set */
75 		i = 0;
76 		while (isascii(*s) && isdigit(*s))
77 			i = i * 10 + (*s++ - '0');
78 		first = i;
79 
80 		/* find last flag to set */
81 		if (*s == '-')
82 		{
83 			i = 0;
84 			while (isascii(*++s) && isdigit(*s))
85 				i = i * 10 + (*s - '0');
86 		}
87 		last = i;
88 
89 		/* find the level to set it to */
90 		i = 1;
91 		if (*s == '.')
92 		{
93 			i = 0;
94 			while (isascii(*++s) && isdigit(*s))
95 				i = i * 10 + (*s - '0');
96 		}
97 
98 		/* clean up args */
99 		if (first >= tTsize)
100 			first = tTsize - 1;
101 		if (last >= tTsize)
102 			last = tTsize - 1;
103 
104 		/* set the flags */
105 		while (first <= last)
106 			tTvect[first++] = i;
107 
108 		/* more arguments? */
109 		if (*s++ == '\0')
110 			return;
111 	}
112 }
113