📄 werr.cpp
字号:
// $common\werr.cpp 1.5 milbo$ like err.cpp but for windows// Warning: this is raw research code -- expect it to be quite messy.// milbo durban dec05#include <windows.h>#include <io.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <signal.h>#include <float.h>#include <math.h>#include <new.h>#include <direct.h>#include <sys/stat.h>#include <fstream.h>#include <iostream.h>#include "mcommon.hpp"#include "util.hpp"#include "err.hpp" // use err.hpp for err.cpp and werr.cppbool fgErr; // Err or SysErr was invoked, needed under Windows because can't call exit()extern const char *sgProgramName;//-----------------------------------------------------------------------------// Print an warning message with standard "Warning" prefix// Using a standard format allows easy post processing of log file: grep for "Warning:"// This puts a \n on the msg so you shouldn't.void __cdecl Warn (const char *pArgs, ...) // args like printf{va_list pArg;char *s = (char *)malloc(CONF_nMaxPrintfLen);va_start(pArg, pArgs);vsprintf(s, pArgs, pArg);va_end(pArg);lprintf("Warning: %s\n", s);free(s);}//-----------------------------------------------------------------------------// Print an error message and set global flag fgErr.//// Actually we would like to exit right here but that's not so easy under Windows,// so we do the next best thing: set the global flag fgErr so we check for it later//// This puts a \n on the msg so you shouldn't.void __cdecl Err (const char *pArgs, ...) // args like printf{static bool fInHere;va_list pArg;if (fInHere) // if already in here then just exit printf("\nRecursive call to Err\n");else { fInHere = true; char *s = (char *)malloc(CONF_nMaxPrintfLen); va_start(pArg, pArgs); vsprintf(s, pArgs, pArg); va_end(pArg); printf("\n%s\n", s); fflush(stdout); // unneeded under Win98 but needed under WinXP logprintf("\nErr: %s\n", s); // allows easy post processing of log file: grep for "Err:" char sHeader[256]; sprintf(sHeader, "%s error", sgProgramName); MessageBox(NULL, s, sHeader, MB_OK);#if _DEBUG if (CONF_fAbortOnErr) EnterDebugger;#endif free(s); }fgErr = true; // can't call exit here under Windows so set global err flag instead.}//-----------------------------------------------------------------------------// Like Err but prepends SysErr: and is msg for that aren't directly caused// by the user i.e. for errors that should "never happen".// This puts a \n on the msg so you shouldn't.void __cdecl SysErr (const char *pArgs, ...) // args like printf{static bool fInHere;va_list pArg;if (fInHere) // if already in here then just exit printf("\nRecursive call to SysErr\n");else { fInHere = true; char *s = (char *)malloc(CONF_nMaxPrintfLen); va_start(pArg, pArgs); vsprintf(s, pArgs, pArg); va_end(pArg); lprintf("\nSysErr: %s\n", s); fflush(stdout); // unneeded under Win98 but needed under WinXP char sHeader[256]; sprintf(sHeader, "%s SysError", sgProgramName); MessageBox(NULL, s, sHeader, MB_OK);#if _DEBUG if (CONF_fAbortOnErr) EnterDebugger;#endif free(s); }fgErr = true; // can't call exit here under Windows so set global err flag instead.}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -