Main Page   Compound List   File List   Compound 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 "/usr/include/stdarg.h"
00021 #endif
00022 #endif
00023 
00024 static char *enableFlags = NULL; // controls which DEBUG messages are printed 
00025 
00026 //----------------------------------------------------------------------
00027 // DebugInit
00028 //      Initialize so that only DEBUG messages with a flag in flagList 
00029 //      will be printed.
00030 //
00031 //      If the flag is "+", we enable all DEBUG messages.
00032 //
00033 //      "flagList" is a string of characters for whose DEBUG messages are 
00034 //              to be enabled.
00035 //----------------------------------------------------------------------
00036 
00037 void
00038 DebugInit(char *flagList)
00039 {
00040     enableFlags = flagList;
00041 }
00042 
00043 //----------------------------------------------------------------------
00044 // DebugIsEnabled
00045 //      Return TRUE if DEBUG messages with "flag" are to be printed.
00046 //----------------------------------------------------------------------
00047 
00048 bool
00049 DebugIsEnabled(char flag)
00050 {
00051     if (enableFlags != NULL)
00052        return (strchr(enableFlags, flag) != 0) 
00053                 || (strchr(enableFlags, '+') != 0);
00054     else
00055       return FALSE;
00056 }
00057 
00058 //----------------------------------------------------------------------
00059 // DEBUG
00060 //      Print a debug message, if flag is enabled.  Like printf,
00061 //      only with an extra argument on the front.
00062 //----------------------------------------------------------------------
00063 
00064 void 
00065 DEBUG(char flag, char *format, ...)
00066 {
00067     if (DebugIsEnabled(flag)) {
00068         va_list ap;
00069         // You will get an unused variable message here -- ignore it.
00070         va_start(ap, format);
00071         vfprintf(stdout, format, ap);
00072         va_end(ap);
00073         fflush(stdout);
00074     }
00075 }

Generated on Mon Feb 10 09:54:48 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees