⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncbidiag.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
////////////////////////////////////////////////////////  abort handlerstatic FAbortHandler s_UserAbortHandler = 0;extern void SetAbortHandler(FAbortHandler func){    s_UserAbortHandler = func;}extern void Abort(void){    // If defined user abort handler then call it     if ( s_UserAbortHandler )        s_UserAbortHandler();        // If don't defined handler or application doesn't still terminated    // Check environment variable for silent exit    const char* value = getenv("DIAG_SILENT_ABORT");    if (value  &&  (*value == 'Y'  ||  *value == 'y'  ||  *value == '1')) {        ::exit(255);    }    else if (value  &&  (*value == 'N'  ||  *value == 'n' || *value == '0')) {        ::abort();    }    else {#if defined(_DEBUG)        ::abort();#else        ::exit(255);#endif    }}/////////////////////////////////////////////////////////  CDiagErrCodeInfo:://SDiagErrCodeDescription::SDiagErrCodeDescription(void)        : m_Message(kEmptyStr),          m_Explanation(kEmptyStr),          m_Severity(-1){    return;}bool CDiagErrCodeInfo::Read(const string& file_name){    CNcbiIfstream is(file_name.c_str());    if ( !is.good() ) {        return false;    }    return Read(is);}// Parse string for CDiagErrCodeInfo::Read()bool s_ParseErrCodeInfoStr(string&          str,                           const SIZE_TYPE  line,                           int&             x_code,                           int&             x_severity,                           string&          x_message,                           bool&            x_ready){    list<string> tokens;    // List with line tokens    try {        // Get message text        SIZE_TYPE pos = str.find_first_of(':');        if (pos == NPOS) {            x_message = kEmptyStr;        } else {            x_message = NStr::TruncateSpaces(str.substr(pos+1));            str.erase(pos);        }        // Split string on parts        NStr::Split(str, ",", tokens);        if (tokens.size() < 2) {            ERR_POST("Error message file parsing: Incorrect file format " \                     ", line " + NStr::IntToString(line));            return false;        }        // Mnemonic name (skip)        tokens.pop_front();        // Error code        string token = NStr::TruncateSpaces(tokens.front());        tokens.pop_front();        x_code = NStr::StringToInt(token);        // Severity        if (!tokens.empty()) {             token = NStr::TruncateSpaces(tokens.front());            EDiagSev sev;            if (CNcbiDiag::StrToSeverityLevel(token.c_str(), sev)) {                x_severity = sev;            } else {                ERR_POST(Warning << "Error message file parsing: " \                         "Incorrect severity level in the verbose " \                         "message file, line " + NStr::IntToString(line));            }        } else {            x_severity = -1;        }    }    catch (CException& e) {        ERR_POST(Warning << "Error message file parsing: " << e.GetMsg() <<                 ", line " + NStr::IntToString(line));        return false;    }    x_ready = true;    return true;}  bool CDiagErrCodeInfo::Read(CNcbiIstream& is){    string       str;                      // The line being parsed    SIZE_TYPE    line;                     // # of the line being parsed    bool         err_ready       = false;  // Error data ready flag     int          err_code        = 0;      // First level error code    int          err_subcode     = 0;      // Second level error code    string       err_message;              // Short message    string       err_text;                 // Error explanation    int          err_severity    = -1;     // Use default severity if                                             // has not specified    int          err_subseverity = -1;     // Use parents severity if                                             // has not specified    for (line = 1;  NcbiGetlineEOL(is, str);  line++) {                // This is a comment or empty line        if (!str.length()  ||  NStr::StartsWith(str,"#")) {            continue;        }        // Add error description        if (err_ready  &&  str[0] == '$') {            if (err_subseverity == -1)                err_subseverity = err_severity;            SetDescription(ErrCode(err_code, err_subcode),                 SDiagErrCodeDescription(err_message, err_text,                                        err_subseverity));            // Clean            err_subseverity = -1;            err_text     = kEmptyStr;            err_ready    = false;        }        // Get error code        if (NStr::StartsWith(str,"$$")) {            if (!s_ParseErrCodeInfoStr(str, line, err_code, err_severity,                                        err_message, err_ready))                continue;            err_subcode = 0;                } else if (NStr::StartsWith(str,"$^")) {        // Get error subcode            s_ParseErrCodeInfoStr(str, line, err_subcode, err_subseverity,                                  err_message, err_ready);              } else if (err_ready) {        // Get line of explanation message            if (!err_text.empty()) {                err_text += '\n';            }            err_text += str;        }    }    if (err_ready) {        if (err_subseverity == -1)            err_subseverity = err_severity;        SetDescription(ErrCode(err_code, err_subcode),             SDiagErrCodeDescription(err_message, err_text,                                    err_subseverity));    }    return true;}bool CDiagErrCodeInfo::GetDescription(const ErrCode& err_code,                       SDiagErrCodeDescription* description) const{    // Find entry    TInfo::const_iterator find_entry = m_Info.find(err_code);    if (find_entry == m_Info.end()) {        return false;    }    // Get entry value    const SDiagErrCodeDescription& entry = find_entry->second;    if (description) {        *description = entry;    }    return true;}END_NCBI_SCOPE/* * ========================================================================== * $Log: ncbidiag.cpp,v $ * Revision 1000.4  2004/06/01 19:08:57  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.80 * * Revision 1.80  2004/05/14 13:59:27  gorelenk * Added include of ncbi_pch.hpp * * Revision 1.79  2004/03/18 20:19:20  gouriano * make it possible to convert multi-line diagnostic message into single-line * * Revision 1.78  2003/11/12 20:30:26  ucko * Make extra flags for severity-trace messages tunable. * * Revision 1.77  2003/11/06 21:40:56  vakatov * A somewhat more natural handling of the 'eDPF_Default' flag -- replace * it by the current global flags, then merge these with other flags (if any) * * Revision 1.76  2003/10/31 19:38:53  lavr * No '\0' in exception reporting * * Revision 1.75  2003/09/26 15:54:13  vakatov * CNcbiDiag::DiagAssert() -- print everything (trace-like -- file, line, etc.) * in the message * * Revision 1.74  2003/09/17 15:58:29  vasilche * Allow debug abort when: * CObjectException is thrown - env var NCBI_ABORT_ON_COBJECT_THROW=[Yy1], * CNullPointerException is thrown - env var NCBI_ABORT_ON_NULL=[Yy1]. * Allow quit abort in debug mode and coredump in release mode: * env var DIAG_SILENT_ABORT=[Yy1Nn0]. * * Revision 1.73  2003/05/19 21:12:46  vakatov * CNcbiDiag::DiagValidate() -- get rid of "unused func arg" compilation warning * * Revision 1.72  2003/04/25 20:54:15  lavr * Introduce draft version of IgnoreDiagDieLevel() * * Revision 1.71  2003/03/10 18:57:08  kuznets * iterate->ITERATE * * Revision 1.70  2003/02/21 21:08:57  vakatov * Minor cast to get rid of 64-bit compilation warning * * Revision 1.69  2003/01/13 20:42:50  gouriano * corrected the problem with ostrstream::str(): replaced such calls with * CNcbiOstrstreamToString(os) * * Revision 1.68  2002/09/30 16:35:16  vasilche * Restored mutex lock on fork(). * * Revision 1.67  2002/09/24 18:28:20  vasilche * Fixed behavour of CNcbiDiag::DiagValidate() in release mode * * Revision 1.66  2002/09/19 20:05:42  vasilche * Safe initialization of static mutexes * * Revision 1.65  2002/08/20 19:10:39  gouriano * added DiagWriteFlags into SDiagMessage::Write * * Revision 1.64  2002/08/16 15:02:11  ivanov * Added class CDiagAutoPrefix * * Revision 1.63  2002/08/01 18:47:43  ivanov * Added stuff to store and output error verbose messages for error codes * * Revision 1.62  2002/07/25 15:46:08  ivanov * Rollback R1.60 * * Revision 1.61  2002/07/25 13:35:05  ivanov * Changed exit code of a faild test * * Revision 1.60  2002/07/15 18:17:24  gouriano * renamed CNcbiException and its descendents * * Revision 1.59  2002/07/10 16:19:00  ivanov * Added CNcbiDiag::StrToSeverityLevel(). * Rewrite and rename SetDiagFixedStrPostLevel() -> SetDiagFixedPostLevel() * * Revision 1.58  2002/07/09 16:37:11  ivanov * Added GetSeverityChangeEnabledFirstTime(). * Fix usage forced set severity post level from environment variable * to work without NcbiApplication::AppMain() * * Revision 1.57  2002/07/02 18:26:22  ivanov * Added CDiagBuffer::DisableDiagPostLevelChange() * * Revision 1.56  2002/06/27 18:56:16  gouriano * added "title" parameter to report functions * * Revision 1.55  2002/06/26 18:38:04  gouriano * added CNcbiException class * * Revision 1.54  2002/06/18 17:07:12  lavr * Take advantage of NStr:strftime() * * Revision 1.53  2002/05/14 16:47:27  ucko * Conditionalize usage of pthread_atfork, which doesn't seem to exist at * all on FreeBSD. * * Revision 1.52  2002/05/03 14:29:17  ucko * #include <unistd.h> for pthread_atfork(); the other headers do not * necessarily already include it. * * Revision 1.51  2002/04/25 21:49:05  ucko * Made pthread_atfork callbacks extern "C". * * Revision 1.50  2002/04/25 21:29:39  ucko * At Yan Raytselis's suggestion, use pthread_atfork to avoid * inadvertently holding s_DiagMutex across fork. * * Revision 1.49  2002/04/23 19:57:29  vakatov * Made the whole CNcbiDiag class "mutable" -- it helps eliminate * numerous warnings issued by SUN Forte6U2 compiler. * Do not use #NO_INCLASS_TMPL anymore -- apparently all modern * compilers seem to be supporting in-class template methods. * * Revision 1.48  2002/04/16 18:48:42  ivanov * SuppressDiagPopupMessages() moved to "test/test_assert.h" * * Revision 1.47  2002/04/11 19:58:34  ivanov * Added function SuppressDiagPopupMessages() * * Revision 1.46  2002/04/10 14:45:27  ivanov * Abort() moved from static to extern and added to header file * * Revision 1.45  2002/04/01 22:35:22  ivanov * Added SetAbortHandler() function to set user abort handler. * Used call internal function Abort() vice ::abort(). * * Revision 1.44  2002/02/07 19:45:54  ucko * Optionally transfer ownership in GetDiagHandler. * * Revision 1.43  2002/02/05 22:01:36  lavr * Minor tweak * * Revision 1.42  2002/01/12 22:16:47  lavr * Eliminated GCC warning: "'%D' yields only 2 digits of year" * * Revision 1.41  2001/12/07 15:27:28  ucko * Switch CDiagRecycler over to current form of SetDiagHandler. * * Revision 1.40  2001/12/03 22:06:31  juran * Use 'special environment' flag to indicate that a fatal error * must throw an exception rather than abort.  (Mac only.) * * Revision 1.39  2001/11/14 15:15:00  ucko * Revise diagnostic handling to be more object-oriented. * * Revision 1.38  2001/10/29 15:16:13  ucko * Preserve default CGI diagnostic settings, even if customized by app. * * Revision 1.37  2001/10/16 23:44:07  vakatov * + SetDiagPostAllFlags() * * Revision 1.36  2001/08/24 13:48:01  grichenk * Prevented some memory leaks * * Revision 1.35  2001/08/09 16:26:11  lavr * Added handling for new eDPF_OmitInfoSev format flag * * Revision 1.34  2001/07/30 14:42:10  lavr * eDiag_Trace and eDiag_Fatal always print as much as possible * * Revision 1.33  2001/07/26 21:29:00  lavr * Remove printing DateTime stamp by default * * Revision 1.32  2001/07/25 19:13:55  lavr * Added date/time stamp for message logging * * Revision 1.31  2001/06/13 23:19:38  vakatov * Revamped previous revision (prefix and error codes) * * Revision 1.30  2001/06/13 20:48:28  ivanov * + PushDiagPostPrefix(), PopPushDiagPostPrefix() - stack post prefix messages. * + ERR_POST_EX, LOG_POST_EX - macros for posting with error codes. * + ErrCode(code[,subcode]) - CNcbiDiag error code manipulator. * + eDPF_ErrCode, eDPF_ErrSubCode - new post flags. * * Revision 1.29  2001/06/05 20:58:16  vakatov * ~CDiagBuffer()::  to check for consistency and call "abort()" only * #if (_DEBUG > 1) * * Revision 1.28  2001/05/17 15:04:59  lavr * Typos corrected * * Revision 1.27  2001/03/30 22:49:22  grichenk * KCC freeze() bug workaround * * Revision 1.26  2001/03/26 21:45:54  vakatov * Made MT-safe (with A.Grichenko) * * Revision 1.25  2001/01/23 23:20:42  lavr * MSVS++ -> MSVC++ * * Revision 1.24  2000/11/16 23:52:41  vakatov * Porting to Mac... * * Revision 1.23  2000/10/24 21:51:21  vakatov * [DEBUG] By default, do not print file name and line into the diagnostics * * Revision 1.22  2000/10/24 19:54:46  vakatov * Diagnostics to go to CERR by default (was -- disabled by default) * * Revision 1.21  2000/06/22 22:09:10  vakatov * Fixed:  GetTraceEnabledFirstTime(), sm_TraceDefault * * Revision 1.20  2000/06/11 01:47:28  vakatov * IsDiagSet(0) to return TRUE if the diag stream is unset * * Revision 1.19  2000/06/09 21:22:21  vakatov * IsDiagStream() -- fixed * * Revision 1.18  2000/04/04 22:31:59  vakatov * SetDiagTrace() -- auto-set basing on the application * environment and/or registry * * Revision 1.17  2000/02/18 16:54:07  vakatov * + eDiag_Critical * * Revision 1.16  2000/01/20 16:52:32  vakatov * SDiagMessage::Write() to replace SDiagMessage::Compose() * + operator<<(CNcbiOstream& os, const SDiagMessage& mess) * + IsSetDiagHandler(), IsDiagStream() * * Revision 1.15  1999/12/29 22:30:25  vakatov * Use "exit()" rather than "abort()" in non-#_DEBUG mode * * Revision 1.14  1999/12/29 21:22:30  vakatov * Fixed "delete" to "delete[]" * * Revision 1.13  1999/12/27 19:44:18  vakatov * Fixes for R1.13: * ERR_POST() -- use eDPF_Default rather than eDPF_Trace;  forcibly flush * ("<< Endm") the diag. stream. Get rid of the eDPF_CopyFilename, always * make a copy of the file name. * * Revision 1.12  1999/12/16 17:22:51  vakatov * Fixed "delete" to "delete[]" * * Revision 1.11  1999/09/27 16:23:23  vasilche * Changed implementation of debugging macros (_TRACE, _THROW*, _ASSERT etc), * so that they will be much easier for compilers to eat. * * Revision 1.10  1999/05/27 16:32:26  vakatov * In debug-mode(#_DEBUG), set the default post severity level to * "Warning" (yet, it is "Error" in non-debug mode) * * Revision 1.9  1999/04/30 19:21:04  vakatov * Added more details and more control on the diagnostics * See #ERR_POST, EDiagPostFlag, and ***DiagPostFlag() * * Revision 1.8  1998/12/28 17:56:37  vakatov * New CVS and development tree structure for the NCBI C++ projects * * Revision 1.7  1998/11/06 22:42:41  vakatov * Introduced BEGIN_, END_ and USING_ NCBI_SCOPE macros to put NCBI C++ * API to namespace "ncbi::" and to use it by default, respectively * Introduced THROWS_NONE and THROWS(x) macros for the exception * specifications * Other fixes and rearrangements throughout the most of "corelib" code * * Revision 1.6  1998/11/03 22:57:51  vakatov * Use #define'd manipulators(like "NcbiFlush" instead of "flush") to * make it compile and work with new(templated) version of C++ streams * * Revision 1.4  1998/11/03 22:28:35  vakatov * Renamed Die/Post...Severity() to ...Level() * * Revision 1.3  1998/11/03 20:51:26  vakatov * Adaptation for the SunPro compiler glitchs(see conf. #NO_INCLASS_TMPL) * * Revision 1.2  1998/10/30 20:08:37  vakatov * Fixes to (first-time) compile and test-run on MSVC++ * * ========================================================================== */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -