-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.cc
65 lines (56 loc) · 1.84 KB
/
utility.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// utility.cc
// Debugging routines. Allows users to control whether to
// print DEBUG statements, based on a command line argument.
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved. See copyright.h for copyright notice and limitation
// of liability and disclaimer of warranty provisions.
#include "copyright.h"
#include "utility.h"
#include <stdarg.h>
static char *enableFlags = NULL; // controls which DEBUG messages are printed
//----------------------------------------------------------------------
// DebugInit
// Initialize so that only DEBUG messages with a flag in flagList
// will be printed.
//
// If the flag is "+", we enable all DEBUG messages.
//
// "flagList" is a string of characters for whose DEBUG messages are
// to be enabled.
//----------------------------------------------------------------------
void
DebugInit(char *flagList)
{
enableFlags = flagList;
}
//----------------------------------------------------------------------
// DebugIsEnabled
// Return TRUE if DEBUG messages with "flag" are to be printed.
//----------------------------------------------------------------------
bool
DebugIsEnabled(char flag)
{
if (enableFlags != NULL)
return (strchr(enableFlags, flag) != 0)
|| (strchr(enableFlags, '+') != 0);
else
return FALSE;
}
//----------------------------------------------------------------------
// DEBUG
// Print a debug message, if flag is enabled. Like printf,
// only with an extra argument on the front.
//----------------------------------------------------------------------
void
DEBUG(char flag, char *format, ...)
{
if (DebugIsEnabled(flag)) {
va_list ap;
// You will get an unused variable message here -- ignore it.
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
fflush(stdout);
}
}