1 /******************************************************************************
3 * $Id: message.cpp,v 1.9 2001/03/19 19:27:41 root Exp $
5 * Copyright (C) 1997-2012 by Dimitri van Heesch.
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.
13 * Documents produced by Doxygen are derivative works derived from the
14 * input used in their production; they are not affected by this license.
20 #include <qdatetime.h>
27 static QCString outputFormat;
28 //static int warnFormatOrder; // 1 = $file,$line,$text
29 // // 2 = $text,$line,$file
30 // // 3 = $line,$text,$file
31 // // 4 = $file,$text,$line
32 // // 5 = $text,$file,$line
33 // // 6 = $line,$file,$text
35 static FILE *warnFile = stderr;
37 void initWarningFormat()
39 // int filePos = Config_getString("WARN_FORMAT").find("$file");
40 // int linePos = Config_getString("WARN_FORMAT").find("$line");
41 // int textPos = Config_getString("WARN_FORMAT").find("$text");
43 // // sort items on position (there are 6 cases)
44 // warnFormatOrder = 1;
45 // if (filePos>linePos && filePos>textPos)
47 // if (linePos>textPos) // $text,$line,$file
49 // warnFormatOrder = 2;
51 // else // $line,$text,$file
53 // warnFormatOrder = 3;
56 // else if (filePos<linePos && filePos<textPos)
58 // if (linePos>textPos) // $file,$text,$line
60 // warnFormatOrder = 4;
63 // else if (filePos<linePos && filePos>textPos) // $text,$file,$line
65 // warnFormatOrder = 5;
67 // else // $line,$file,$text
69 // warnFormatOrder = 6;
75 // Config_getString("WARN_FORMAT"),
83 // replace(QRegExp("\\$file"),"%s").
84 // replace(QRegExp("\\$text"),"%s").
85 // replace(QRegExp("\\$line"),"%d")+
88 outputFormat = Config_getString("WARN_FORMAT");
90 if (!Config_getString("WARN_LOGFILE").isEmpty())
92 warnFile = portable_fopen(Config_getString("WARN_LOGFILE"),"w");
94 if (!warnFile) // point it to something valid, because warn() relies on it
101 void msg(const char *fmt, ...)
103 if (!Config_getBool("QUIET"))
105 if (Debug::isFlagSet(Debug::Time))
107 printf("%.3f sec: ",((double)Doxygen::runningTime.elapsed())/1000.0);
111 vfprintf(stdout, fmt, args);
116 static void format_warn(const char *file,int line,const char *text)
118 QCString fileSubst = file==0 ? "<unknown>" : file;
119 QCString lineSubst; lineSubst.setNum(line);
120 QCString textSubst = text;
121 QCString versionSubst;
122 if (file) // get version from file name
125 FileDef *fd=findFileDef(Doxygen::inputNameDict,file,ambig);
128 versionSubst = fd->getVersion();
131 // substitute markers by actual values
144 "$version",versionSubst
147 // print resulting message
148 fwrite(msgText.data(),1,msgText.length(),warnFile);
151 static void do_warn(const char *tag, const char *file, int line, const char *fmt, va_list args)
153 if (!Config_getBool(tag)) return; // warning type disabled
155 vsnprintf(text, 4096, fmt, args);
157 format_warn(file,line,text);
160 void warn(const char *file,int line,const char *fmt, ...)
164 do_warn("WARNINGS", file, line, fmt, args);
168 void warn_simple(const char *file,int line,const char *text)
170 if (!Config_getBool("WARNINGS")) return; // warning type disabled
171 format_warn(file,line,text);
174 void warn_undoc(const char *file,int line,const char *fmt, ...)
178 do_warn("WARN_IF_UNDOCUMENTED", file, line, fmt, args);
182 void warn_doc_error(const char *file,int line,const char *fmt, ...)
186 do_warn("WARN_IF_DOC_ERROR", file, line, fmt, args);
190 void err(const char *fmt, ...)
194 vfprintf(warnFile, fmt, args);