lib/verbose.c

Go to the documentation of this file.
00001 /* verbose.c - write out status messages according to the
00002  * current verbosity level.  These messages go to stderr. */
00003 
00004 #include "common.h"
00005 #include "verbose.h"
00006 
00007 static char const rcsid[] = "$Id: verbose.c,v 1.5 2005/10/17 15:46:41 markd Exp $";
00008 
00009 static int logVerbosity = 1;    /* The level of log verbosity.  0 is silent. */
00010 static FILE *logFile;   /* File to log to. */
00011 
00012 static boolean checkedDotsEnabled = FALSE;  /* have we check for dot output
00013                                              * being enabled? */
00014 static boolean dotsEnabled = FALSE;         /* is dot output enabled? */
00015 
00016 void verboseVa(int verbosity, char *format, va_list args)
00017 /* Log with at given verbosity vprintf formatted args. */
00018 {
00019 if (verbosity <= logVerbosity)
00020     {
00021     if (logFile == NULL)
00022         logFile = stderr;
00023     vfprintf(logFile, format, args);
00024     fflush(logFile);
00025     }
00026 }
00027 
00028 void verbose(int verbosity, char *format, ...)
00029 /* Write printf formatted message to log (which by
00030  * default is stderr) if global verbose variable
00031  * is set to verbosity or higher. */
00032 {
00033 va_list args;
00034 va_start(args, format);
00035 verboseVa(verbosity, format, args);
00036 va_end(args);
00037 }
00038 
00039 boolean verboseDotsEnabled()
00040 /* check if outputting of happy dots are enabled.  They will be enabled if the
00041  * verbosity is > 0, stderr is a tty and we don't appear to be running an
00042  * emacs shell. */
00043 {
00044 if (!checkedDotsEnabled)
00045     {
00046     if (logFile == NULL)
00047         logFile = stderr;
00048     dotsEnabled = (logVerbosity > 0) && isatty(fileno(logFile));
00049     if (dotsEnabled)
00050         {
00051         /* check for an possible emacs shell */
00052         char *emacs = getenv("emacs");
00053         char *term = getenv("TERM");
00054         if ((emacs != NULL) && (emacs[0] == 't'))
00055             dotsEnabled = FALSE;
00056         else if ((term != NULL) && sameString(term, "dumb"))
00057             dotsEnabled = FALSE;
00058         }
00059     checkedDotsEnabled = TRUE;
00060     }
00061 return dotsEnabled;
00062 }
00063 
00064 void verboseDot()
00065 /* Write I'm alive dot (at verbosity level 1) */
00066 {
00067 if (verboseDotsEnabled())
00068     verbose(1, ".");
00069 }
00070 
00071 void verboseSetLevel(int verbosity)
00072 /* Set verbosity level in log.  0 for no logging,
00073  * higher number for increasing verbosity. */
00074 {
00075 logVerbosity = verbosity;
00076 checkedDotsEnabled = FALSE; /* force rechecking of dots enabled */
00077 }
00078 
00079 int verboseLevel(void)
00080 /* Get verbosity level. */
00081 {
00082 return logVerbosity;
00083 }
00084 
00085 void verboseSetLogFile(char *name)
00086 /* Set logFile for verbose messages overrides stderr. */
00087 {
00088 if (sameString(name, "stdout"))
00089     logFile = stdout;
00090 else if (sameString(name, "stderr"))
00091     logFile = stderr;
00092 else
00093     logFile = mustOpen(name, "w");
00094 }
00095 
00096 FILE *verboseLogFile()
00097 /* Get the verbose log file. */
00098 {
00099 if (logFile == NULL)
00100     logFile = stderr;
00101 return logFile;
00102 }

Generated on Tue Dec 25 18:39:32 2007 for blat by  doxygen 1.5.2