xref: /netbsd-src/external/bsd/nvi/dist/common/trace.c (revision 75219f3a016dfaad1cb304eb017f9787b1de8292)
1 /*	$NetBSD: trace.c,v 1.2 2013/11/22 15:52:05 christos Exp $	*/
2 /*-
3  * Copyright (c) 1996
4  *	Rob Zimmermann.  All rights reserved.
5  * Copyright (c) 1996
6  *	Keith Bostic.  All rights reserved.
7  *
8  * See the LICENSE file for redistribution information.
9  */
10 
11 #include "config.h"
12 
13 #ifndef lint
14 static const char sccsid[] = "Id: trace.c,v 8.4 1997/08/03 15:04:23 bostic Exp  (Berkeley) Date: 1997/08/03 15:04:23 ";
15 #endif /* not lint */
16 
17 #include <sys/queue.h>
18 
19 #include <bitstring.h>
20 #include <stdio.h>
21 
22 #ifdef __STDC__
23 #include <stdarg.h>
24 #else
25 #include <varargs.h>
26 #endif
27 
28 #include "common.h"
29 
30 #ifdef TRACE
31 
32 static FILE *tfp;
33 
34 /*
35  * vtrace_end --
36  *	End tracing.
37  *
38  * PUBLIC: void vtrace_end __P((void));
39  */
40 void
41 vtrace_end()
42 {
43 	if (tfp != NULL && tfp != stderr)
44 		(void)fclose(tfp);
45 }
46 
47 /*
48  * vtrace_init --
49  *	Initialize tracing.
50  *
51  * PUBLIC: void vtrace_init __P((char *));
52  */
53 void
54 vtrace_init(name)
55 	char *name;
56 {
57 	if (name == NULL || (tfp = fopen(name, "w")) == NULL)
58 		tfp = stderr;
59 	vtrace("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\nTRACE\n");
60 }
61 
62 /*
63  * vtrace --
64  *	Debugging trace routine.
65  *
66  * PUBLIC: void vtrace __P((const char *, ...));
67  */
68 void
69 #ifdef __STDC__
70 vtrace(const char *fmt, ...)
71 #else
72 vtrace(fmt, va_alist)
73 	char *fmt;
74 	va_dcl
75 #endif
76 {
77 	va_list ap;
78 
79 	if (tfp == NULL)
80 		vtrace_init(NULL);
81 
82 #ifdef __STDC__
83 	va_start(ap, fmt);
84 #else
85 	va_start(ap);
86 #endif
87 	(void)vfprintf(tfp, fmt, ap);
88 	va_end(ap);
89 
90 	(void)fflush(tfp);
91 }
92 #endif
93