📄 ncbi_util.c
字号:
}/* Callback for LOG_Reset_FILE() */static void s_LOG_FileHandler(void* user_data, SLOG_Handler* call_data){ FILE* fp = (FILE*) user_data; assert(call_data); if ( fp ) { char* str = LOG_ComposeMessage(call_data, s_LogFormatFlags); if ( str ) { fprintf(fp, "%s\n", str); fflush(fp); free(str); } }}/* Callback for LOG_Reset_FILE() */static void s_LOG_FileCleanup(void* user_data){ FILE* fp = (FILE*) user_data; if ( fp ) fclose(fp);}extern void LOG_ToFILE(LOG lg, FILE* fp, int/*bool*/ auto_close){ if ( fp ) { if ( auto_close ) { LOG_Reset(lg, fp, s_LOG_FileHandler, s_LOG_FileCleanup); } else { LOG_Reset(lg, fp, s_LOG_FileHandler, 0/*no cleaning up*/); } } else { LOG_Reset(lg, 0/*data*/, 0/*handler*/, 0/*cleanup*/); }}/* Return non-zero value if "*beg" has reached the "end" */static int/*bool*/ s_SafeCopy(const char* src, char** beg, const char* end){ assert(*beg <= end); if ( src ) { for ( ; *src && *beg != end; src++, (*beg)++) { **beg = *src; } } **beg = '\0'; return (*beg == end);}extern char* MessagePlusErrno(const char* message, int x_errno, const char* descr, char* buf, size_t buf_size){ char* beg; char* end; /* Check and init */ if (!buf || !buf_size) return 0; buf[0] = '\0'; if (buf_size < 2) return buf; /* empty */ /* Adjust the description, if necessary and possible */ if (x_errno && !descr) { descr = strerror(x_errno); if ( !descr ) { static const char s_UnknownErrno[] = "Error code is out of range"; descr = s_UnknownErrno; } } /* Check for an empty result, calculate string lengths */ if ((!message || !*message) && !x_errno && (!descr || !*descr)) return buf; /* empty */ /* Compose: <message> {errno=<x_errno>,<descr>} */ beg = buf; end = buf + buf_size - 1; /* <message> */ if ( s_SafeCopy(message, &beg, end) ) return buf; /* {errno=<x_errno>,<descr>} */ if (!x_errno && (!descr || !*descr)) return buf; /* "{errno=" */ if ( s_SafeCopy(" {errno=", &beg, end) ) return buf; /* <x_errno> */ if ( x_errno ) { int/*bool*/ neg; /* calculate length */ size_t len; int mod; if (x_errno < 0) { neg = 1/*true*/; x_errno = -x_errno; } else { neg = 0/*false*/; } for (len = 1, mod = 1; (x_errno / mod) > 9; len++, mod *= 10) continue; if ( neg ) len++; /* ? not enough space */ if (beg + len >= end) { s_SafeCopy("...", &beg, end); return buf; } /* ? add sign */ if (x_errno < 0) { *beg++ = '-'; } /* print error code */ for ( ; mod; mod /= 10) { static const char s_Num[] = "0123456789"; assert(x_errno / mod < 10); *beg++ = s_Num[x_errno / mod]; x_errno %= mod; } /* "," before "<descr>" */ if (descr && *descr && beg != end) *beg++ = ','; } /* "<descr>" */ if ( s_SafeCopy(descr, &beg, end) ) return buf; /* "}\0" */ assert(beg <= end); if (beg != end) *beg++ = '}'; *beg = '\0'; return buf;}/****************************************************************************** * REGISTRY */extern void CORE_SetREG(REG rg){ CORE_LOCK_WRITE; if (g_CORE_Registry && rg != g_CORE_Registry) { REG_Delete(g_CORE_Registry); } g_CORE_Registry = rg; CORE_UNLOCK;}extern REG CORE_GetREG(void){ return g_CORE_Registry;}/****************************************************************************** * MISCELLANEOUS */extern const char* CORE_GetPlatform(void){#ifndef NCBI_CXX_TOOLKIT return Nlm_PlatformName();#else return HOST;#endif /*NCBI_CXX_TOOLKIT*/}/* * --------------------------------------------------------------------------- * $Log: ncbi_util.c,v $ * Revision 1000.1 2003/11/17 22:18:57 gouriano * PRODUCTION: UPGRADED [ORIGINAL] Dev-tree R6.31 * * Revision 6.31 2003/11/14 13:04:38 lavr * Little changes in comments [no code changes] * * Revision 6.30 2003/11/13 19:53:41 rsmith * Took out metrowerks specific #ifdef's (COMP_METRO). Not needed anymore. * * Revision 6.29 2003/09/02 21:05:14 lavr * Proper indentation of compilation conditionals * * Revision 6.28 2003/05/05 20:19:13 lavr * LOG_ComposeMessage() to check raw_size instead of raw_data ptr * * Revision 6.27 2003/05/05 11:41:09 rsmith * added defines and declarations to allow cross compilation Mac->Win32 * using Metrowerks Codewarrior. * * Revision 6.26 2003/01/17 15:55:13 lavr * Fix errno reporting (comma was missing if errno == 0) * * Revision 6.25 2003/01/17 01:23:07 lavr * Always print full message for TRACE log in Debug mode * * Revision 6.24 2002/12/04 21:00:53 lavr * -CORE_LOG[F]_SYS_ERRNO() * * Revision 6.23 2002/12/04 19:51:12 lavr * No change * * Revision 6.22 2002/10/11 19:52:10 lavr * Log moved to end * * Revision 6.21 2002/06/18 17:07:44 lavr * Employ _strdate() & _strtime() if compiled by MSVC * * Revision 6.20 2002/05/07 18:22:10 lavr * Use fLOG_None in LOG_ComposeMessage() * * Revision 6.19 2002/02/11 20:36:44 lavr * Use "ncbi_config.h" * * Revision 6.18 2002/02/05 22:02:17 lavr * Minor tweak * * Revision 6.17 2002/01/28 20:22:39 lavr * Get rid of GCC warning about "'%D' yields only 2 last digits of year" * * Revision 6.16 2001/08/28 17:49:45 thiessen * oops, sorry - incorrect fix; reverted * * Revision 6.15 2001/08/28 17:21:22 thiessen * need ncbiconf.h for NCBI_CXX_TOOLKIT * * Revision 6.14 2001/08/09 16:25:06 lavr * Remove last (unneeded) parameter from LOG_Reset() * Added: fLOG_OmitNoteLevel format flag handling * * Revision 6.13 2001/07/30 14:41:37 lavr * Added: CORE_SetLOGFormatFlags() * * Revision 6.12 2001/07/26 15:13:02 lavr * Always do stream flush after message output (previously was in DEBUG only) * * Revision 6.11 2001/07/25 20:27:23 lavr * Included header files rearranged * * Revision 6.10 2001/07/25 19:12:57 lavr * Added date/time stamp for message logging * * Revision 6.9 2001/04/24 21:24:59 lavr * Make log flush in DEBUG mode * * Revision 6.8 2001/01/23 23:20:14 lavr * Comments added to some "boolean" 1s and 0s * * Revision 6.7 2001/01/12 23:50:38 lavr * "a+" -> "a" as a mode in fopen() for a logfile * * Revision 6.6 2000/08/28 20:05:51 vakatov * CORE_SetLOGFILE() -- typo fixed * * Revision 6.5 2000/06/23 19:34:45 vakatov * Added means to log binary data * * Revision 6.4 2000/05/30 23:23:26 vakatov * + CORE_SetLOGFILE_NAME() * * Revision 6.3 2000/03/31 17:19:11 kans * added continue statement to for loop to suppress missing body warning * * Revision 6.2 2000/03/24 23:12:09 vakatov * Starting the development quasi-branch to implement CONN API. * All development is performed in the NCBI C++ tree only, while * the NCBI C tree still contains "frozen" (see the last revision) code. * * Revision 6.1 2000/02/23 22:36:17 vakatov * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -