Orb/Doxygen/src/message.cpp
changeset 0 42188c7ea2d9
child 4 468f4c8d3d5b
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /******************************************************************************
       
     2  *
       
     3  * 
       
     4  *
       
     5  * Copyright (C) 1997-2008 by Dimitri van Heesch.
       
     6  *
       
     7  * Permission to use, copy, modify, and distribute this software and its
       
     8  * documentation under the terms of the GNU General Public License is hereby 
       
     9  * granted. No representations are made about the suitability of this software 
       
    10  * for any purpose. It is provided "as is" without express or implied warranty.
       
    11  * See the GNU General Public License for more details.
       
    12  *
       
    13  * Documents produced by Doxygen are derivative works derived from the
       
    14  * input used in their production; they are not affected by this license.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <stdarg.h>
       
    19 #include <stdio.h>
       
    20 #include <qdatetime.h>
       
    21 #include "config.h"
       
    22 #include "util.h"
       
    23 #include "debug.h"
       
    24 #include "doxygen.h"
       
    25 
       
    26 static QCString outputFormat;
       
    27 //static int warnFormatOrder; // 1 = $file,$line,$text
       
    28 //                            // 2 = $text,$line,$file
       
    29 //                            // 3 = $line,$text,$file
       
    30 //                            // 4 = $file,$text,$line
       
    31 //                            // 5 = $text,$file,$line
       
    32 //                            // 6 = $line,$file,$text
       
    33 
       
    34 static FILE *warnFile = stderr;
       
    35 
       
    36 void initWarningFormat()
       
    37 {
       
    38 //  int filePos = Config_getString("WARN_FORMAT").find("$file");
       
    39 //  int linePos = Config_getString("WARN_FORMAT").find("$line");
       
    40 //  int textPos = Config_getString("WARN_FORMAT").find("$text");
       
    41 //
       
    42 //  // sort items on position (there are 6 cases)
       
    43 //  warnFormatOrder = 1;
       
    44 //  if (filePos>linePos && filePos>textPos)
       
    45 //  {
       
    46 //    if (linePos>textPos) // $text,$line,$file
       
    47 //    {
       
    48 //      warnFormatOrder = 2;
       
    49 //    }
       
    50 //    else                 // $line,$text,$file
       
    51 //    {
       
    52 //      warnFormatOrder = 3;
       
    53 //    }
       
    54 //  }
       
    55 //  else if (filePos<linePos && filePos<textPos)
       
    56 //  {
       
    57 //    if (linePos>textPos) // $file,$text,$line
       
    58 //    {
       
    59 //      warnFormatOrder = 4;
       
    60 //    }
       
    61 //  }
       
    62 //  else if (filePos<linePos && filePos>textPos) // $text,$file,$line
       
    63 //  {
       
    64 //    warnFormatOrder = 5;
       
    65 //  }
       
    66 //  else // $line,$file,$text
       
    67 //  {
       
    68 //    warnFormatOrder = 6;
       
    69 //  }
       
    70 //  outputFormat = 
       
    71 //      substitute(
       
    72 //        substitute(
       
    73 //          substitute( 
       
    74 //            Config_getString("WARN_FORMAT"),
       
    75 //           "$file","%s"
       
    76 //          ),
       
    77 //          "$text","%s"
       
    78 //        ),
       
    79 //        "$line","%d"
       
    80 //      )+'\n';
       
    81 
       
    82   //    replace(QRegExp("\\$file"),"%s").
       
    83   //    replace(QRegExp("\\$text"),"%s").
       
    84   //    replace(QRegExp("\\$line"),"%d")+
       
    85   //    '\n';
       
    86 
       
    87   outputFormat = Config_getString("WARN_FORMAT");
       
    88 
       
    89   if (!Config_getString("WARN_LOGFILE").isEmpty())
       
    90   {
       
    91     warnFile = fopen(Config_getString("WARN_LOGFILE"),"w");
       
    92   }
       
    93   if (!warnFile) // point it to something valid, because warn() relies on it
       
    94   {
       
    95     warnFile = stderr;
       
    96   }
       
    97 }
       
    98 
       
    99 
       
   100 void msg(const char *fmt, ...)
       
   101 {
       
   102   if (!Config_getBool("QUIET"))
       
   103   {
       
   104     if (Debug::isFlagSet(Debug::Time))
       
   105     {
       
   106       printf("%.3f sec: ",((double)Doxygen::runningTime.elapsed())/1000.0);
       
   107     }
       
   108     va_list args;
       
   109     va_start(args, fmt);
       
   110     vfprintf(stdout, fmt, args);
       
   111     va_end(args); 
       
   112   }
       
   113 }
       
   114 
       
   115 static void do_warn(const char *tag, const char *file, int line, const char *fmt, va_list args)
       
   116 {
       
   117   if (!Config_getBool(tag)) return; // warning type disabled
       
   118   char text[40960];
       
   119   vsprintf(text, fmt, args);
       
   120   QCString fileSubst = file==0 ? "<unknown>" : file;
       
   121   QCString lineSubst; lineSubst.setNum(line);
       
   122   QCString textSubst = text;
       
   123   QCString versionSubst;
       
   124   if (file) // get version from file name
       
   125   {
       
   126     bool ambig;
       
   127     FileDef *fd=findFileDef(Doxygen::inputNameDict,file,ambig);
       
   128     if (fd)
       
   129     {
       
   130       versionSubst = fd->getVersion();
       
   131     }
       
   132   }
       
   133   // substitute markers by actual values
       
   134   QCString msgText = 
       
   135     substitute(
       
   136       substitute(
       
   137         substitute(
       
   138           substitute(
       
   139             substitute( 
       
   140               outputFormat,
       
   141               "$file",fileSubst
       
   142             ),
       
   143             "$text",textSubst
       
   144           ),
       
   145           "$line",lineSubst
       
   146         ),
       
   147         "$version",versionSubst
       
   148       ),
       
   149       "%","%%"
       
   150     )+'\n';
       
   151 
       
   152   // print resulting message
       
   153   fprintf(warnFile,"%s",msgText.data());
       
   154 }
       
   155 
       
   156 void warn(const char *file,int line,const char *fmt, ...)
       
   157 {
       
   158   va_list args;
       
   159   va_start(args, fmt);
       
   160   do_warn("WARNINGS", file, line, fmt, args);
       
   161   va_end(args); 
       
   162 }
       
   163 
       
   164 void warn_cont(const char *fmt, ...)
       
   165 {
       
   166   if (!Config_getBool("WARNINGS"))
       
   167     return;
       
   168   va_list args;
       
   169   va_start(args, fmt);
       
   170   vfprintf(warnFile, fmt, args);
       
   171   va_end(args); 
       
   172 }
       
   173   
       
   174 void warn_undoc(const char *file,int line,const char *fmt, ...)
       
   175 {
       
   176   va_list args;
       
   177   va_start(args, fmt);
       
   178   do_warn("WARN_IF_UNDOCUMENTED", file, line, fmt, args);
       
   179   va_end(args);
       
   180 }
       
   181   
       
   182 void warn_doc_error(const char *file,int line,const char *fmt, ...)
       
   183 {
       
   184   va_list args;
       
   185   va_start(args, fmt);
       
   186   do_warn("WARN_IF_DOC_ERROR", file, line, fmt, args);
       
   187   va_end(args);
       
   188 }
       
   189 
       
   190 void err(const char *fmt, ...)
       
   191 {
       
   192   va_list args;
       
   193   va_start(args, fmt);
       
   194   vfprintf(warnFile, fmt, args);
       
   195   va_end(args); 
       
   196 }