Main Page | Alphabetical List | Class List | File List | Class Members | File Members

utility.cc

Go to the documentation of this file.
00001 // utility.cc 00002 // Debugging routines. Allows users to control whether to 00003 // print DEBUG statements, based on a command line argument. 00004 // 00005 // Copyright (c) 1992-1993 The Regents of the University of California. 00006 // All rights reserved. See copyright.h for copyright notice and limitation 00007 // of liability and disclaimer of warranty provisions. 00008 00009 #include "copyright.h" 00010 #include "utility.h" 00011 00012 // this seems to be dependent on how the compiler is configured. 00013 // if you have problems with va_start, try both of these alternatives 00014 #ifdef HOST_SNAKE 00015 #include <stdarg.h> 00016 #else 00017 #ifdef HOST_SPARC 00018 #include <stdarg.h> 00019 #else 00020 #include <stdarg.h> 00021 //#include "/usr/include/stdarg.h" 00022 #endif 00023 #endif 00024 00025 static char *enableFlags = NULL; // controls which DEBUG messages are printed 00026 00027 //---------------------------------------------------------------------- 00028 // DebugInit 00029 // Initialize so that only DEBUG messages with a flag in flagList 00030 // will be printed. 00031 // 00032 // If the flag is "+", we enable all DEBUG messages. 00033 // 00034 // "flagList" is a string of characters for whose DEBUG messages are 00035 // to be enabled. 00036 //---------------------------------------------------------------------- 00037 00038 void 00039 DebugInit(char *flagList) 00040 { 00041 enableFlags = flagList; 00042 } 00043 00044 //---------------------------------------------------------------------- 00045 // DebugIsEnabled 00046 // Return TRUE if DEBUG messages with "flag" are to be printed. 00047 //---------------------------------------------------------------------- 00048 00049 bool 00050 DebugIsEnabled(char flag) 00051 { 00052 if (enableFlags != NULL) 00053 return (strchr(enableFlags, flag) != 0) 00054 || (strchr(enableFlags, '+') != 0); 00055 else 00056 return FALSE; 00057 } 00058 00059 //---------------------------------------------------------------------- 00060 // DEBUG 00061 // Print a debug message, if flag is enabled. Like printf, 00062 // only with an extra argument on the front. 00063 //---------------------------------------------------------------------- 00064 00065 void 00066 DEBUG(char flag, char *format, ...) 00067 { 00068 if (DebugIsEnabled(flag)) { 00069 va_list ap; 00070 // You will get an unused variable message here -- ignore it. 00071 va_start(ap, format); 00072 vfprintf(stdout, format, ap); 00073 va_end(ap); 00074 fflush(stdout); 00075 } 00076 }

Generated on Thu Sep 16 12:33:46 2004 for NachOS by doxygen 1.3.8