1*0a6a1f1dSLionel Sambuc /* $NetBSD: trace.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc * Copyright (c) 1996
484d9c625SLionel Sambuc * Rob Zimmermann. All rights reserved.
584d9c625SLionel Sambuc * Copyright (c) 1996
684d9c625SLionel Sambuc * Keith Bostic. All rights reserved.
784d9c625SLionel Sambuc *
884d9c625SLionel Sambuc * See the LICENSE file for redistribution information.
984d9c625SLionel Sambuc */
1084d9c625SLionel Sambuc
1184d9c625SLionel Sambuc #include "config.h"
1284d9c625SLionel Sambuc
13*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
14*0a6a1f1dSLionel Sambuc #if 0
1584d9c625SLionel Sambuc #ifndef lint
1684d9c625SLionel Sambuc 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 ";
1784d9c625SLionel Sambuc #endif /* not lint */
18*0a6a1f1dSLionel Sambuc #else
19*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: trace.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc
2284d9c625SLionel Sambuc #include <sys/queue.h>
2384d9c625SLionel Sambuc
2484d9c625SLionel Sambuc #include <bitstring.h>
2584d9c625SLionel Sambuc #include <stdio.h>
2684d9c625SLionel Sambuc
2784d9c625SLionel Sambuc #ifdef __STDC__
2884d9c625SLionel Sambuc #include <stdarg.h>
2984d9c625SLionel Sambuc #else
3084d9c625SLionel Sambuc #include <varargs.h>
3184d9c625SLionel Sambuc #endif
3284d9c625SLionel Sambuc
3384d9c625SLionel Sambuc #include "common.h"
3484d9c625SLionel Sambuc
3584d9c625SLionel Sambuc #ifdef TRACE
3684d9c625SLionel Sambuc
3784d9c625SLionel Sambuc static FILE *tfp;
3884d9c625SLionel Sambuc
3984d9c625SLionel Sambuc /*
4084d9c625SLionel Sambuc * vtrace_end --
4184d9c625SLionel Sambuc * End tracing.
4284d9c625SLionel Sambuc *
4384d9c625SLionel Sambuc * PUBLIC: void vtrace_end __P((void));
4484d9c625SLionel Sambuc */
4584d9c625SLionel Sambuc void
vtrace_end(void)4684d9c625SLionel Sambuc vtrace_end(void)
4784d9c625SLionel Sambuc {
4884d9c625SLionel Sambuc if (tfp != NULL && tfp != stderr)
4984d9c625SLionel Sambuc (void)fclose(tfp);
5084d9c625SLionel Sambuc }
5184d9c625SLionel Sambuc
5284d9c625SLionel Sambuc /*
5384d9c625SLionel Sambuc * vtrace_init --
5484d9c625SLionel Sambuc * Initialize tracing.
5584d9c625SLionel Sambuc *
5684d9c625SLionel Sambuc * PUBLIC: void vtrace_init __P((const char *));
5784d9c625SLionel Sambuc */
5884d9c625SLionel Sambuc void
vtrace_init(const char * name)5984d9c625SLionel Sambuc vtrace_init(const char *name)
6084d9c625SLionel Sambuc {
6184d9c625SLionel Sambuc if (name == NULL || (tfp = fopen(name, "w")) == NULL)
6284d9c625SLionel Sambuc tfp = stderr;
6384d9c625SLionel Sambuc vtrace("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\nTRACE\n");
6484d9c625SLionel Sambuc }
6584d9c625SLionel Sambuc
6684d9c625SLionel Sambuc /*
6784d9c625SLionel Sambuc * vtrace --
6884d9c625SLionel Sambuc * Debugging trace routine.
6984d9c625SLionel Sambuc *
7084d9c625SLionel Sambuc * PUBLIC: void vtrace __P((const char *, ...));
7184d9c625SLionel Sambuc */
7284d9c625SLionel Sambuc void
vtrace(const char * fmt,...)7384d9c625SLionel Sambuc vtrace(const char *fmt, ...)
7484d9c625SLionel Sambuc {
7584d9c625SLionel Sambuc va_list ap;
7684d9c625SLionel Sambuc
7784d9c625SLionel Sambuc if (tfp == NULL)
7884d9c625SLionel Sambuc vtrace_init(NULL);
7984d9c625SLionel Sambuc
8084d9c625SLionel Sambuc va_start(ap, fmt);
8184d9c625SLionel Sambuc (void)vfprintf(tfp, fmt, ap);
8284d9c625SLionel Sambuc va_end(ap);
8384d9c625SLionel Sambuc
8484d9c625SLionel Sambuc (void)fflush(tfp);
8584d9c625SLionel Sambuc }
8684d9c625SLionel Sambuc #endif
87