Skip to main content

The message.cpp File Reference

Included Headers

#include <cstdio> #include <cstdlib> #include <mutex> #include <atomic> #include <unordered_set> #include "config.h" #include "debug.h" #include "portable.h" #include "message.h" #include "doxygen.h" #include "fileinfo.h" #include "dir.h" #include "md5.h"

Functions Index

static boolcheckWarnMessage (QCString result)
static voidformat_warn (const QCString &file, int line, const QCString &text)
static voidhandle_warn_as_error ()
static voiddo_warn (const QCString &file, int line, const char *prefix, fmt::string_view fmt, fmt::format_args args)
voidmsg_ (fmt::string_view fmt, fmt::format_args args)
voidwarn_ (WarningType type, const QCString &file, int line, fmt::string_view fmt, fmt::format_args args)
voidwarn_uncond_ (fmt::string_view fmt, fmt::format_args args)
voiderr_ (fmt::string_view fmt, fmt::format_args args)
voiderr_full_ (const QCString &file, int line, fmt::string_view fmt, fmt::format_args args)
voidterm_ (fmt::string_view fmt, fmt::format_args args)
QCStringwarn_line (const QCString &file, int line)
voidwarn_flush ()
voidinitWarningFormat ()
voidfinishWarnExit ()

Variables Index

static QCStringg_warnFormat
static QCStringg_warnLineFormat
static const char *g_warningStr = "warning: "
static const char *g_errorStr = "error: "
static FILE *g_warnFile = stderr
static WARN_AS_ERROR_tg_warnBehavior = WARN_AS_ERROR_t::NO
static QCStringg_warnlogFile
static boolg_warnlogTemp = false
static std::atomic_boolg_warnStat = false
static std::mutexg_mutex
static std::unordered_set< std::string >g_warnHash

Functions

checkWarnMessage()

bool checkWarnMessage (QCString result)
static

Definition at line 46 of file message.cpp.

46static bool checkWarnMessage(QCString result)
47{
48 uint8_t md5_sig[16];
49 char sigStr[33];
50 MD5Buffer(result.data(),result.length(),md5_sig);
51 MD5SigToString(md5_sig,sigStr);
52
53 return g_warnHash.insert(sigStr).second;
54}

References QCString::data, g_warnHash and QCString::length.

Referenced by err_, format_warn, term_ and warn_uncond_.

do_warn()

void do_warn (const QCString & file, int line, const char * prefix, fmt::string_view fmt, fmt::format_args args)
static

Definition at line 122 of file message.cpp.

122static void do_warn(const QCString &file, int line, const char *prefix, fmt::string_view fmt, fmt::format_args args)
123{
124 format_warn(file,line,QCString(prefix+fmt::vformat(fmt,args)));
126}

References format_warn, handle_warn_as_error and prefix.

Referenced by warn_.

err_()

void err_ (fmt::string_view fmt, fmt::format_args args)

Definition at line 175 of file message.cpp.

175void err_(fmt::string_view fmt, fmt::format_args args)
176{
177 {
178 std::unique_lock<std::mutex> lock(g_mutex);
179 if (checkWarnMessage(g_errorStr+fmt::vformat(fmt,args))) fmt::print(g_warnFile,"{}{}",g_errorStr,fmt::vformat(fmt,args));
180 }
182}

References checkWarnMessage, g_errorStr, g_mutex, g_warnFile and handle_warn_as_error.

Referenced by err_fmt.

err_full_()

void err_full_ (const QCString & file, int line, fmt::string_view fmt, fmt::format_args args)

Definition at line 186 of file message.cpp.

186void err_full_(const QCString &file, int line, fmt::string_view fmt, fmt::format_args args)
187{
188 format_warn(file,line,QCString(g_errorStr+fmt::vformat(fmt,args)));
189}

References format_warn and g_errorStr.

Referenced by err_full_fmt.

finishWarnExit()

void finishWarnExit ()

Definition at line 295 of file message.cpp.

296{
297 fflush(stdout);
298 if (g_warnBehavior == WARN_AS_ERROR_t::FAIL_ON_WARNINGS_PRINT && g_warnlogFile != "-")
299 {
301 g_warnFile = nullptr;
302 }
303 if (g_warnStat && g_warnBehavior == WARN_AS_ERROR_t::FAIL_ON_WARNINGS_PRINT && g_warnlogFile != "-")
304 {
305
306 std::ifstream warnFile = Portable::openInputStream(g_warnlogFile);
307 if (!warnFile.is_open())
308 {
309 g_warnFile = stderr;
310 err("Cannot open warnings file '{}' for reading\n",g_warnlogFile);
311 }
312 else
313 {
314 std::string line;
315 while (getline(warnFile,line))
316 {
317 fmt::print(stderr,"{}\n",line);
318 }
319 warnFile.close();
320 }
321 }
322
324
325 if (g_warnStat && (g_warnBehavior == WARN_AS_ERROR_t::FAIL_ON_WARNINGS ||
326 g_warnBehavior == WARN_AS_ERROR_t::FAIL_ON_WARNINGS_PRINT))
327 {
328 exit(1);
329 }
330}

References err, Portable::fclose, g_warnBehavior, g_warnFile, g_warnlogFile, g_warnlogTemp, g_warnStat, Portable::openInputStream and Portable::unlink.

Referenced by generateOutput.

format_warn()

void format_warn (const QCString & file, int line, const QCString & text)
static

Definition at line 56 of file message.cpp.

56static void format_warn(const QCString &file,int line,const QCString &text)
57{
58 QCString fileSubst = file.isEmpty() ? "<unknown>" : file;
59 QCString lineSubst; lineSubst.setNum(line);
60 QCString textSubst = text;
61 QCString versionSubst;
62 // substitute markers by actual values
63 QCString msgText =
69 "$file",fileSubst
70 ),
71 "$line",lineSubst
72 ),
73 "$version",versionSubst
74 ),
75 "$text",textSubst
76 );
77 if (g_warnBehavior == WARN_AS_ERROR_t::YES)
78 {
79 msgText += " (warning treated as error, aborting now)";
80 }
81 msgText += '\n';
82
83 {
84 std::unique_lock<std::mutex> lock(g_mutex);
85 // print resulting message
86 if (checkWarnMessage(msgText)) fwrite(msgText.data(),1,msgText.length(),g_warnFile);
87 }
88 if (g_warnBehavior == WARN_AS_ERROR_t::YES)
89 {
90 if (g_warnFile != stderr && !Config_getBool(QUIET))
91 {
92 msg("See '{}' for the reason of termination.\n",g_warnlogFile);
93 }
94 exit(1);
95 }
96 g_warnStat = true;
97}

References checkWarnMessage, Config_getBool, QCString::data, g_mutex, g_warnBehavior, g_warnFile, g_warnFormat, g_warnlogFile, g_warnStat, QCString::isEmpty, QCString::length, msg, QCString::setNum and substitute.

Referenced by do_warn and err_full_.

handle_warn_as_error()

void handle_warn_as_error ()
static

Definition at line 101 of file message.cpp.

102{
103 if (g_warnBehavior == WARN_AS_ERROR_t::YES)
104 {
105 {
106 std::unique_lock<std::mutex> lock(g_mutex);
107 QCString msgText = " (warning treated as error, aborting now)\n";
108 fwrite(msgText.data(),1,msgText.length(),g_warnFile);
109 if (g_warnFile != stderr && !Config_getBool(QUIET))
110 {
111 // cannot use `msg` due to the mutex
112 fprintf(stdout,"See '%s' for the reason of termination.\n",qPrint(g_warnlogFile));
113 }
114 }
115 exit(1);
116 }
117 g_warnStat = true;
118}

References Config_getBool, QCString::data, g_mutex, g_warnBehavior, g_warnFile, g_warnlogFile, g_warnStat, QCString::length and qPrint.

Referenced by do_warn, err_ and warn_uncond_.

initWarningFormat()

void initWarningFormat ()

Definition at line 237 of file message.cpp.

238{
239 g_warnFormat = Config_getString(WARN_FORMAT);
240 g_warnLineFormat = Config_getString(WARN_LINE_FORMAT);
241 g_warnBehavior = Config_getEnum(WARN_AS_ERROR);
242 g_warnlogFile = Config_getString(WARN_LOGFILE);
243 if (g_warnlogFile.isEmpty() && g_warnBehavior == WARN_AS_ERROR_t::FAIL_ON_WARNINGS_PRINT)
244 {
245 uint32_t pid = Portable::pid();
246 g_warnlogFile.sprintf("doxygen_warnings_temp_%d.tmp",pid);
247 g_warnlogTemp = true;
248 }
249
250 if (!g_warnlogFile.isEmpty())
251 {
252 if (g_warnlogFile == "-")
253 {
254 g_warnFile = stdout;
255 }
256 else
257 {
258 FileInfo fi(g_warnlogFile.str());
259 Dir d(fi.dirPath().c_str());
260 if (!d.exists() && !d.mkdir(fi.dirPath().c_str()))
261 {
262 // point it to something valid, because warn() relies on it
263 g_warnFile = stderr;
264 err("Cannot create directory for '{}', redirecting 'WARN_LOGFILE' output to 'stderr'\n",g_warnlogFile);
265 }
266 else if (!(g_warnFile = Portable::fopen(g_warnlogFile,"w")))
267 {
268 // point it to something valid, because warn() relies on it
269 g_warnFile = stderr;
270 err("Cannot open '{}' for writing, redirecting 'WARN_LOGFILE' output to 'stderr'\n",g_warnlogFile);
271 }
272 }
273 }
274 else
275 {
276 g_warnFile = stderr;
277 }
278 if (g_warnBehavior != WARN_AS_ERROR_t::NO)
279 {
281 }
282
283 // make sure the g_warnFile is closed in case we call exit and it is still open
284 std::atexit([](){
285 if (g_warnFile && g_warnFile!=stderr && g_warnFile!=stdout)
286 {
288 g_warnFile = nullptr;
289 }
290 });
291}

References Config_getEnum, Config_getString, FileInfo::dirPath, err, Dir::exists, Portable::fclose, Portable::fopen, g_errorStr, g_warnBehavior, g_warnFile, g_warnFormat, g_warningStr, g_warnLineFormat, g_warnlogFile, g_warnlogTemp, Dir::mkdir and Portable::pid.

Referenced by checkConfiguration.

msg_()

void msg_ (fmt::string_view fmt, fmt::format_args args)

Definition at line 130 of file message.cpp.

130void msg_(fmt::string_view fmt, fmt::format_args args)
131{
132 if (!Config_getBool(QUIET))
133 {
134 std::unique_lock<std::mutex> lock(g_mutex);
136 {
137 fmt::print("{:.3f} sec: ",(static_cast<double>(Debug::elapsedTime())));
138 }
139 fmt::print("{}",fmt::vformat(fmt,args));
140 }
141}

References Config_getBool, Debug::elapsedTime, g_mutex, Debug::isFlagSet and Debug::Time.

Referenced by msg_fmt.

term_()

void term_ (fmt::string_view fmt, fmt::format_args args)

Definition at line 193 of file message.cpp.

193void term_(fmt::string_view fmt, fmt::format_args args)
194{
195 {
196 std::unique_lock<std::mutex> lock(g_mutex);
197 if (checkWarnMessage(g_errorStr+fmt::vformat(fmt,args))) fmt::print(g_warnFile, "{}{}", g_errorStr, fmt::vformat(fmt,args));
198 if (g_warnFile != stderr)
199 {
200 size_t l = strlen(g_errorStr);
201 for (size_t i=0; i<l; i++) fmt::print(g_warnFile, " ");
202 fmt::print(g_warnFile, "{}\n", "Exiting...");
203 if (!Config_getBool(QUIET))
204 {
205 // cannot use `msg` due to the mutex
206 fmt::print("See '{}' for the reason of termination.\n",g_warnlogFile);
207 }
208 }
209 }
210 exit(1);
211}

References checkWarnMessage, Config_getBool, g_errorStr, g_mutex, g_warnFile and g_warnlogFile.

Referenced by term_fmt.

warn_()

void warn_ (WarningType type, const QCString & file, int line, fmt::string_view fmt, fmt::format_args args)

Definition at line 145 of file message.cpp.

145void warn_(WarningType type, const QCString &file, int line, fmt::string_view fmt, fmt::format_args args)
146{
147 bool enabled = false;
148 switch (type)
149 {
150 case WarningType::Generic: enabled = Config_getBool(WARNINGS); break;
151 case WarningType::Undocumented: enabled = Config_getBool(WARN_IF_UNDOCUMENTED); break;
152 case WarningType::IncompleteDoc: enabled = Config_getBool(WARN_IF_INCOMPLETE_DOC); break;
153 case WarningType::DocError: enabled = Config_getBool(WARN_IF_DOC_ERROR); break;
154 case WarningType::Layout: enabled = Config_getBool(WARN_LAYOUT_FILE); break;
155 }
156 if (enabled)
157 {
158 do_warn(file, line, g_warningStr, fmt, args);
159 }
160}

References Config_getBool, do_warn, DocError, g_warningStr, Generic, IncompleteDoc, Layout and Undocumented.

Referenced by warn_fmt.

warn_flush()

void warn_flush ()

Definition at line 230 of file message.cpp.

231{
232 fflush(g_warnFile);
233}

Reference g_warnFile.

Referenced by Statistics::end.

warn_line()

QCString warn_line (const QCString & file, int line)

Definition at line 215 of file message.cpp.

215QCString warn_line(const QCString &file,int line)
216{
217 QCString fileSubst = file.isEmpty() ? "<unknown>" : file;
218 QCString lineSubst; lineSubst.setNum(line);
219 return substitute(
222 "$file",fileSubst
223 ),
224 "$line",lineSubst
225 );
226}

References g_warnLineFormat, QCString::isEmpty, QCString::setNum and substitute.

Referenced by addMemberFunction, checkPageRelations, computePageRelations and findGlobalMember.

warn_uncond_()

void warn_uncond_ (fmt::string_view fmt, fmt::format_args args)

Definition at line 164 of file message.cpp.

164void warn_uncond_(fmt::string_view fmt, fmt::format_args args)
165{
166 {
167 std::unique_lock<std::mutex> lock(g_mutex);
168 if (checkWarnMessage(g_errorStr+fmt::vformat(fmt,args))) fmt::print(g_warnFile,"{}{}",g_warningStr,vformat(fmt,args));
169 }
171}

References checkWarnMessage, g_errorStr, g_mutex, g_warnFile, g_warningStr and handle_warn_as_error.

Referenced by warn_uncond_fmt.

Variables

g_errorStr

const char* g_errorStr = "error: "
static

Definition at line 35 of file message.cpp.

35static const char * g_errorStr = "error: ";

Referenced by err_, err_full_, initWarningFormat, term_ and warn_uncond_.

g_mutex

std::mutex g_mutex
static

Definition at line 41 of file message.cpp.

41static std::mutex g_mutex;

Referenced by err_, format_warn, handle_warn_as_error, msg_, term_ and warn_uncond_.

g_warnBehavior

WARN_AS_ERROR_t g_warnBehavior = WARN_AS_ERROR_t::NO
static

Definition at line 37 of file message.cpp.

37static WARN_AS_ERROR_t g_warnBehavior = WARN_AS_ERROR_t::NO;

Referenced by finishWarnExit, format_warn, handle_warn_as_error and initWarningFormat.

g_warnFile

FILE* g_warnFile = stderr
static

Definition at line 36 of file message.cpp.

36static FILE * g_warnFile = stderr;

Referenced by err_, finishWarnExit, format_warn, handle_warn_as_error, initWarningFormat, term_, warn_flush and warn_uncond_.

g_warnFormat

QCString g_warnFormat
static

Definition at line 32 of file message.cpp.

Referenced by format_warn and initWarningFormat.

g_warnHash

std::unordered_set<std::string> g_warnHash
static

Definition at line 42 of file message.cpp.

42static std::unordered_set<std::string> g_warnHash;

Referenced by checkWarnMessage.

g_warningStr

const char* g_warningStr = "warning: "
static

Definition at line 34 of file message.cpp.

34static const char * g_warningStr = "warning: ";

Referenced by initWarningFormat, warn_ and warn_uncond_.

g_warnLineFormat

QCString g_warnLineFormat
static

Definition at line 33 of file message.cpp.

Referenced by initWarningFormat and warn_line.

g_warnlogFile

QCString g_warnlogFile
static

Definition at line 38 of file message.cpp.

Referenced by finishWarnExit, format_warn, handle_warn_as_error, initWarningFormat and term_.

g_warnlogTemp

bool g_warnlogTemp = false
static

Definition at line 39 of file message.cpp.

39static bool g_warnlogTemp = false;

Referenced by finishWarnExit and initWarningFormat.

g_warnStat

std::atomic_bool g_warnStat = false
static

Definition at line 40 of file message.cpp.

40static std::atomic_bool g_warnStat = false;

Referenced by finishWarnExit, format_warn and handle_warn_as_error.


Generated via doxygen2docusaurus by Doxygen 1.14.0.