1 /******************************************************************************
3 * Copyright (C) 1997-2014 by Dimitri van Heesch.
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
17 #include <qdatetime.h>
26 static QCString outputFormat;
27 static const char *warning_str = "warning: ";
28 static const char *error_str = "error: ";
29 //static int warnFormatOrder; // 1 = $file,$line,$text
30 // // 2 = $text,$line,$file
31 // // 3 = $line,$text,$file
32 // // 4 = $file,$text,$line
33 // // 5 = $text,$file,$line
34 // // 6 = $line,$file,$text
36 static FILE *warnFile = stderr;
38 void initWarningFormat()
40 // int filePos = Config_getString("WARN_FORMAT").find("$file");
41 // int linePos = Config_getString("WARN_FORMAT").find("$line");
42 // int textPos = Config_getString("WARN_FORMAT").find("$text");
44 // // sort items on position (there are 6 cases)
45 // warnFormatOrder = 1;
46 // if (filePos>linePos && filePos>textPos)
48 // if (linePos>textPos) // $text,$line,$file
50 // warnFormatOrder = 2;
52 // else // $line,$text,$file
54 // warnFormatOrder = 3;
57 // else if (filePos<linePos && filePos<textPos)
59 // if (linePos>textPos) // $file,$text,$line
61 // warnFormatOrder = 4;
64 // else if (filePos<linePos && filePos>textPos) // $text,$file,$line
66 // warnFormatOrder = 5;
68 // else // $line,$file,$text
70 // warnFormatOrder = 6;
76 // Config_getString("WARN_FORMAT"),
84 // replace(QRegExp("\\$file"),"%s").
85 // replace(QRegExp("\\$text"),"%s").
86 // replace(QRegExp("\\$line"),"%d")+
89 outputFormat = Config_getString("WARN_FORMAT");
91 if (!Config_getString("WARN_LOGFILE").isEmpty())
93 warnFile = portable_fopen(Config_getString("WARN_LOGFILE"),"w");
95 if (!warnFile) // point it to something valid, because warn() relies on it
102 void msg(const char *fmt, ...)
104 if (!Config_getBool("QUIET"))
106 if (Debug::isFlagSet(Debug::Time))
108 printf("%.3f sec: ",((double)Doxygen::runningTime.elapsed())/1000.0);
112 vfprintf(stdout, fmt, args);
117 static void format_warn(const char *file,int line,const char *text)
119 QCString fileSubst = file==0 ? "<unknown>" : file;
120 QCString lineSubst; lineSubst.setNum(line);
121 QCString textSubst = text;
122 QCString versionSubst;
123 if (file) // get version from file name
126 FileDef *fd=findFileDef(Doxygen::inputNameDict,file,ambig);
129 versionSubst = fd->getVersion();
132 // substitute markers by actual values
145 "$version",versionSubst
148 // print resulting message
149 fwrite(msgText.data(),1,msgText.length(),warnFile);
152 static void do_warn(const char *tag, const char *file, int line, const char *prefix, const char *fmt, va_list args)
154 if (!Config_getBool(tag)) return; // warning type disabled
162 vsnprintf(text+l, 4096-l, fmt, args);
164 format_warn(file,line,text);
167 void warn(const char *file,int line,const char *fmt, ...)
171 do_warn("WARNINGS", file, line, warning_str, fmt, args);
175 void va_warn(const char *file,int line,const char *fmt,va_list args)
177 do_warn("WARNINGS", file, line, warning_str, fmt, args);
180 void warn_simple(const char *file,int line,const char *text)
182 if (!Config_getBool("WARNINGS")) return; // warning type disabled
183 format_warn(file,line,QCString(warning_str) + text);
186 void warn_undoc(const char *file,int line,const char *fmt, ...)
190 do_warn("WARN_IF_UNDOCUMENTED", file, line, warning_str, fmt, args);
194 void warn_doc_error(const char *file,int line,const char *fmt, ...)
198 do_warn("WARN_IF_DOC_ERROR", file, line, warning_str, fmt, args);
202 void warn_uncond(const char *fmt, ...)
206 vfprintf(warnFile, (QCString(warning_str) + fmt).data(), args);
210 void err(const char *fmt, ...)
214 vfprintf(warnFile, (QCString(error_str) + fmt).data(), args);
218 void printlex(int dbg, bool enter, const char *lexName, const char *fileName)
220 const char *enter_txt = "entering";
221 const char *enter_txt_uc = "Entering";
225 enter_txt = "finished";
226 enter_txt_uc = "Finished";
232 fprintf(stderr,"--%s lexical analyzer: %s (for: %s)\n",enter_txt, lexName, fileName);
234 fprintf(stderr,"--%s lexical analyzer: %s\n",enter_txt, lexName);
239 Debug::print(Debug::Lex,0,"%s lexical analyzer: %s (for: %s)\n",enter_txt_uc, lexName, fileName);
241 Debug::print(Debug::Lex,0,"%s lexical analyzer: %s\n",enter_txt_uc, lexName);