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