message.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * $Id: message.cpp,v 1.9 2001/03/19 19:27:41 root Exp $
00004  *
00005  * Copyright (C) 1997-2008 by Dimitri van Heesch.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and its
00008  * documentation under the terms of the GNU General Public License is hereby 
00009  * granted. No representations are made about the suitability of this software 
00010  * for any purpose. It is provided "as is" without express or implied warranty.
00011  * See the GNU General Public License for more details.
00012  *
00013  * Documents produced by Doxygen are derivative works derived from the
00014  * input used in their production; they are not affected by this license.
00015  *
00016  */
00017 
00018 #include <stdarg.h>
00019 #include <stdio.h>
00020 #include <qdatetime.h>
00021 #include "config.h"
00022 #include "util.h"
00023 #include "debug.h"
00024 #include "doxygen.h"
00025 
00026 static QCString outputFormat;
00027 //static int warnFormatOrder; // 1 = $file,$line,$text
00028 //                            // 2 = $text,$line,$file
00029 //                            // 3 = $line,$text,$file
00030 //                            // 4 = $file,$text,$line
00031 //                            // 5 = $text,$file,$line
00032 //                            // 6 = $line,$file,$text
00033 
00034 static FILE *warnFile = stderr;
00035 
00036 void initWarningFormat()
00037 {
00038 //  int filePos = Config_getString("WARN_FORMAT").find("$file");
00039 //  int linePos = Config_getString("WARN_FORMAT").find("$line");
00040 //  int textPos = Config_getString("WARN_FORMAT").find("$text");
00041 //
00042 //  // sort items on position (there are 6 cases)
00043 //  warnFormatOrder = 1;
00044 //  if (filePos>linePos && filePos>textPos)
00045 //  {
00046 //    if (linePos>textPos) // $text,$line,$file
00047 //    {
00048 //      warnFormatOrder = 2;
00049 //    }
00050 //    else                 // $line,$text,$file
00051 //    {
00052 //      warnFormatOrder = 3;
00053 //    }
00054 //  }
00055 //  else if (filePos<linePos && filePos<textPos)
00056 //  {
00057 //    if (linePos>textPos) // $file,$text,$line
00058 //    {
00059 //      warnFormatOrder = 4;
00060 //    }
00061 //  }
00062 //  else if (filePos<linePos && filePos>textPos) // $text,$file,$line
00063 //  {
00064 //    warnFormatOrder = 5;
00065 //  }
00066 //  else // $line,$file,$text
00067 //  {
00068 //    warnFormatOrder = 6;
00069 //  }
00070 //  outputFormat = 
00071 //      substitute(
00072 //        substitute(
00073 //          substitute( 
00074 //            Config_getString("WARN_FORMAT"),
00075 //           "$file","%s"
00076 //          ),
00077 //          "$text","%s"
00078 //        ),
00079 //        "$line","%d"
00080 //      )+'\n';
00081 
00082   //    replace(QRegExp("\\$file"),"%s").
00083   //    replace(QRegExp("\\$text"),"%s").
00084   //    replace(QRegExp("\\$line"),"%d")+
00085   //    '\n';
00086 
00087   outputFormat = Config_getString("WARN_FORMAT");
00088 
00089   if (!Config_getString("WARN_LOGFILE").isEmpty())
00090   {
00091     warnFile = fopen(Config_getString("WARN_LOGFILE"),"w");
00092   }
00093   if (!warnFile) // point it to something valid, because warn() relies on it
00094   {
00095     warnFile = stderr;
00096   }
00097 }
00098 
00099 
00100 void msg(const char *fmt, ...)
00101 {
00102   if (!Config_getBool("QUIET"))
00103   {
00104     if (Debug::isFlagSet(Debug::Time))
00105     {
00106       printf("%.3f sec: ",((double)Doxygen::runningTime.elapsed())/1000.0);
00107     }
00108     va_list args;
00109     va_start(args, fmt);
00110     vfprintf(stdout, fmt, args);
00111     va_end(args); 
00112   }
00113 }
00114 
00115 static void do_warn(const char *tag, const char *file, int line, const char *fmt, va_list args)
00116 {
00117   if (!Config_getBool(tag)) return; // warning type disabled
00118   char text[40960];
00119   vsprintf(text, fmt, args);
00120   QCString fileSubst = file==0 ? "<unknown>" : file;
00121   QCString lineSubst; lineSubst.setNum(line);
00122   QCString textSubst = text;
00123   QCString versionSubst;
00124   if (file) // get version from file name
00125   {
00126     bool ambig;
00127     FileDef *fd=findFileDef(Doxygen::inputNameDict,file,ambig);
00128     if (fd)
00129     {
00130       versionSubst = fd->getVersion();
00131     }
00132   }
00133   // substitute markers by actual values
00134   QCString msgText = 
00135     substitute(
00136       substitute(
00137         substitute(
00138           substitute(
00139             substitute( 
00140               outputFormat,
00141               "$file",fileSubst
00142             ),
00143             "$text",textSubst
00144           ),
00145           "$line",lineSubst
00146         ),
00147         "$version",versionSubst
00148       ),
00149       "%","%%"
00150     )+'\n';
00151 
00152   // print resulting message
00153   fprintf(warnFile,msgText);
00154 }
00155 
00156 void warn(const char *file,int line,const char *fmt, ...)
00157 {
00158   va_list args;
00159   va_start(args, fmt);
00160   do_warn("WARNINGS", file, line, fmt, args);
00161   va_end(args); 
00162 }
00163 
00164 void warn_cont(const char *fmt, ...)
00165 {
00166   if (!Config_getBool("WARNINGS"))
00167     return;
00168   va_list args;
00169   va_start(args, fmt);
00170   vfprintf(warnFile, fmt, args);
00171   va_end(args); 
00172 }
00173   
00174 void warn_undoc(const char *file,int line,const char *fmt, ...)
00175 {
00176   va_list args;
00177   va_start(args, fmt);
00178   do_warn("WARN_IF_UNDOCUMENTED", file, line, fmt, args);
00179   va_end(args);
00180 }
00181   
00182 void warn_doc_error(const char *file,int line,const char *fmt, ...)
00183 {
00184   va_list args;
00185   va_start(args, fmt);
00186   do_warn("WARN_IF_DOC_ERROR", file, line, fmt, args);
00187   va_end(args);
00188 }
00189 
00190 void err(const char *fmt, ...)
00191 {
00192   va_list args;
00193   va_start(args, fmt);
00194   vfprintf(warnFile, fmt, args);
00195   va_end(args); 
00196 }



Generated on Mon Mar 31 10:58:41 2008 by  doxygen 1.5.1