📄 ncbiapp.cpp
字号:
} } } catch (CException) { ; // Just catch an all exceptions from CDll } // This method don't work -- use standard method# endif# if defined(NCBI_OS_LINUX) && 0 // Linux OS: Try more accurate method of detection {{ char buf[FILENAME_MAX + 1]; string procfile = "/proc/" + NStr::IntToString(getpid()) + "/exe"; int ncount = readlink((procfile).c_str(), buf, FILENAME_MAX); if ( ncount != -1 ) { buf[ncount] = 0; return buf; } }} // This method don't work -- use standard method# endif if ( !CDirEntry::IsAbsolutePath(app_path) ) {# if defined(NCBI_OS_MSWIN) // Add default ".exe" extention to the name of executable file // if it running without extension string dir, title, ext; CDirEntry::SplitPath(app_path, &dir, &title, &ext); if ( ext.empty() ) { app_path = CDirEntry::MakePath(dir, title, "exe"); }# endif if ( CFile(app_path).Exists() ) { // Relative path from the the current directory app_path = CDir::GetCwd() + CDirEntry::GetPathSeparator()+app_path; if ( !CFile(app_path).Exists() ) { app_path = kEmptyStr; } } else { // Running from some path from PATH environment variable. // Try to determine that path. string env_path = GetEnvironment().Get("PATH"); list<string> split_path;# if defined(NCBI_OS_MSWIN) NStr::Split(env_path, ";", split_path);# else NStr::Split(env_path, ":", split_path);# endif string base_name = CDirEntry(app_path).GetBase(); ITERATE(list<string>, it, split_path) { app_path = CDirEntry::MakePath(*it, base_name); if ( CFile(app_path).Exists() ) { break; } app_path = kEmptyStr; } } } ret_val = CDirEntry::NormalizePath(app_path.empty() ? argv[0] : app_path);#else // defined (NCBI_OS_MSWIN) || defined(NCBI_OS_UNIX)# error "Platform unrecognized"#endif return ret_val;}void CNcbiApplication::HonorDebugSettings(CNcbiRegistry* reg){ if (reg == 0) { reg = m_Config; if (reg == 0) return; } // Setup the debugging features if ( !reg->Get("DEBUG", DIAG_TRACE).empty() ) { SetDiagTrace(eDT_Enable, eDT_Enable); } if ( !reg->Get("DEBUG", ABORT_ON_THROW).empty() ) { SetThrowTraceAbort(true); } string post_level = reg->Get("DEBUG", DIAG_POST_LEVEL); if ( !post_level.empty() ) { EDiagSev sev; if (CNcbiDiag::StrToSeverityLevel(post_level.c_str(), sev)) { SetDiagFixedPostLevel(sev); } } string msg_file = reg->Get("DEBUG", DIAG_MESSAGE_FILE); if ( !msg_file.empty() ) { CDiagErrCodeInfo* info = new CDiagErrCodeInfo(); if ( !info || !info->Read(msg_file) ) { if ( info ) { delete info; } ERR_POST(Warning << "Applications message file \"" << msg_file << "\" is not found"); } else { SetDiagErrCodeInfo(info); } }}END_NCBI_SCOPE/* * =========================================================================== * $Log: ncbiapp.cpp,v $ * Revision 1000.5 2004/06/03 19:28:14 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.85 * * Revision 1.85 2004/06/02 20:45:27 vakatov * CNcbiApplication::AppMain() not to printout line of '=' before USAGE * * Revision 1.84 2004/05/14 13:59:26 gorelenk * Added include of ncbi_pch.hpp * * Revision 1.83 2004/03/02 15:57:34 ucko * Downgrade severity of missing Mac arguments file to Info, since Darwin * allows actual command lines. * * Revision 1.82 2004/01/06 18:17:49 dicuccio * Added APIs for setting environment variables * * Revision 1.81 2003/12/17 20:25:46 ucko * x_SetupStdio: for the sake of interactive applications, don't buffer * cin if it's a terminal. * * Revision 1.80 2003/11/21 21:03:37 vakatov * Cosmetics * * Revision 1.79 2003/11/21 20:12:20 kuznets * Minor clean-up * * Revision 1.78 2003/11/21 19:53:58 kuznets * Added catch(...) to intercept all exceptions and give compiler * (MSVC) a chance to call destructors even if this exception * will never be handled and causes crash. * * Revision 1.77 2003/11/19 13:54:19 ivanov * FindProgramExecutablePath: Replaced GetEntryPoint with GetEntryPoint_Func * * Revision 1.76 2003/10/10 19:37:13 lavr * Ugly workaround for G++/Solaris C RTL (FILE*) interactions that affect * stdio constructed on pipes (sockets). To be fully investigated later... * * Revision 1.75 2003/10/01 14:32:09 ucko * +EFollowLinks * * Revision 1.74 2003/09/30 21:12:30 ucko * CNcbiApplication::LoadConfig: if run through a symlink and there's no * configuration file for the link's source, try its (ultimate) target. * * Revision 1.73 2003/09/29 20:28:00 vakatov * + LoadConfig(...., reg_flags) * * Revision 1.72 2003/09/25 19:34:51 ucko * FindProgramExecutablePath: disable Linux-specific logic, since it * loses the ability to detect having been run through a symlink. * * Revision 1.71 2003/09/25 13:33:58 rsmith * NCBI_OS_DARWIN and NCBI_OS_UNIX are not mutually exclusive. * * Revision 1.70 2003/09/22 13:43:41 ivanov * Include <corelib/ncbidll.hpp> only on MSWin. + include <corelib/ncbi_os_mswin.hpp> * * Revision 1.69 2003/09/17 21:03:58 ivanov * FindProgramExecutablePath: try more accurate method of detection on MS Windows * * Revision 1.68 2003/09/16 20:55:33 ivanov * FindProgramExecutablePath: try more accurate method of detection on Linux. * * Revision 1.67 2003/09/16 16:35:38 ivanov * FindProgramExecutablePath(): added implementation for UNIX and MS-Windows * * Revision 1.66 2003/08/06 20:27:17 ucko * LoadConfig: take advantage of the latest changes to CMetaRegistry to * reuse reg. * * Revision 1.65 2003/08/06 14:31:55 ucko * LoadConfig: Only replace m_Config if it was empty, and remember to * delete the old object if we owned it. * * Revision 1.64 2003/08/05 20:00:36 ucko * Completely rewrite LoadConfig to use CMetaRegistry; properly handle * only sometimes owning m_Config. * * Revision 1.63 2003/06/26 18:55:40 rsmith * call LoadConfig even if conf is null, child classes might do something * anyway. (gbench). * * Revision 1.62 2003/06/25 15:59:00 rsmith * factor out config file DEBUG settings into HonorDebugSettings * * Revision 1.61 2003/06/23 18:02:31 vakatov * CNcbiApplication::MacArgMunging() moved from header to the source file. * Heed warnings, formally reformat the code and comments. * * Revision 1.60 2003/06/18 20:41:23 ucko * FindProgramExecutablePath: conditionalize the Darwin-specific code on * Metrowerks, since no executable linked against Carbon can run remotely. :-/ * * Revision 1.59 2003/06/16 13:52:27 rsmith * Add ProgramDisplayName member. Program name becomes real executable full * path. Handle Mac special arg handling better. * * Revision 1.58 2003/04/07 21:22:54 gouriano * correct App exit codes when CException was catched * * Revision 1.57 2003/03/19 19:37:10 gouriano * added optional adjustment of stdio streams * * Revision 1.56 2003/03/14 21:01:06 kans * commented out include Processes because Mac OS 10.2 libraries give an * undefined symbol error * * Revision 1.55 2003/03/14 20:35:24 rsmith * Comment out previous changes for Mac OSX since on 10.2 the header files * do not compile properly. * * Revision 1.54 2003/03/13 22:16:11 rsmith * on Metrowerks, Mac OSX, always use ncbi.args as the file name for arguments. * * Revision 1.53 2003/03/13 22:04:27 rsmith * Changes to AppMain so MacOSX can find out the appname and arguments. * * Revision 1.52 2003/02/17 06:30:05 vakatov * Get rid of an unused variable * * Revision 1.51 2002/12/26 17:13:03 ivanov * Added version info and Set/GetVersion functions into CNcbiApplication class * * Revision 1.50 2002/12/18 22:54:48 dicuccio * Shuffled some headers to avoid a potentially serious compiler warning * (deletion of incomplete type in Windows). * * Revision 1.49 2002/08/08 18:36:50 gouriano * added HideStdArgs function * * Revision 1.48 2002/08/08 13:39:06 gouriano * logfile & conffile-related correction * * Revision 1.47 2002/08/02 20:13:06 gouriano * added possibility to disable arg descriptions * * Revision 1.46 2002/08/01 19:02:17 ivanov * Added autoload of the verbose message file specified in the * applications configuration file. * * Revision 1.45 2002/07/31 18:33:44 gouriano * added default argument description, * added info about logfile and conffile optional arguments * * Revision 1.44 2002/07/22 19:33:28 ivanov * Fixed bug with internal processing parameters -conffile and -logfile * * Revision 1.43 2002/07/15 18:17:23 gouriano * renamed CNcbiException and its descendents * * Revision 1.42 2002/07/11 14:18:25 gouriano * exceptions replaced by CNcbiException-type ones * * Revision 1.41 2002/07/10 16:20:13 ivanov * Changes related with renaming * SetDiagFixedStrPostLevel()->SetDiagFixedPostLevel() * * Revision 1.40 2002/07/09 16:36:52 ivanov * s_SetFixedDiagPostLevel() moved to ncbidiag.cpp * and renamed to SetDiagFixedStrPostLevel() * * Revision 1.39 2002/07/02 18:31:38 ivanov * Added assignment the value of diagnostic post level from environment * variable and config file if set. Disable to change it from application * in this case. * * Revision 1.38 2002/06/19 16:57:56 ivanov * Added new default command line parameters "-logfile <file>" and * "-conffile <file>" into CNcbiApplication::AppMain() * * Revision 1.37 2002/04/11 21:08:00 ivanov * CVS log moved to end of the file * * Revision 1.36 2002/01/22 19:28:37 ivanov * Changed ConcatPath() -> ConcatPathEx() in LoadConfig() * * Revision 1.35 2002/01/20 05:53:59 vakatov * Get rid of a GCC warning; formally rearrange some code. * * Revision 1.34 2002/01/10 16:52:20 ivanov * Changed LoadConfig() -- new method to search the config file * * Revision 1.33 2001/08/20 14:58:10 vakatov * Get rid of some compilation warnings * * Revision 1.32 2001/08/10 18:26:07 vakatov * Allow user to throw "CArgException" (and thus force USAGE printout * with user-provided explanation) not from any of Init(), Run() or Exit(). * * Revision 1.31 2001/07/07 01:19:28 juran * Use "ncbi" for app name on Mac OS (if argv[0] is null). * * Revision 1.30 2001/03/26 20:07:40 vakatov * [NCBI_OS_MAC] Use argv[0] (if available) as basename for ".args" * * Revision 1.29 2001/02/02 16:19:27 vasilche * Fixed reading program arguments on Mac * * Revision 1.28 2001/02/01 19:53:26 vasilche * Reading program arguments from file moved to CNcbiApplication::AppMain. * * Revision 1.27 2000/12/23 05:50:53 vakatov * AppMain() -- check m_ArgDesc for NULL * * Revision 1.26 2000/11/29 17:00:25 vakatov * Use LOG_POST instead of ERR_POST to print cmd.-line arg usage * * Revision 1.25 2000/11/24 23:33:12 vakatov * CNcbiApplication:: added SetupArgDescriptions() and GetArgs() to * setup cmd.-line argument description, and then to retrieve their * values, respectively. Also implements internal error handling and * printout of USAGE for the described arguments. * * Revision 1.24 2000/11/01 20:37:15 vasilche * Fixed detection of heap objects. * Removed ECanDelete enum and related constructors. * Disabled sync_with_stdio ad the beginning of AppMain. * * Revision 1.23 2000/06/09 18:41:04 vakatov * FlushDiag() -- check for empty diag.buffer * * Revision 1.22 2000/04/04 22:33:35 vakatov * Auto-set the tracing and the "abort-on-throw" debugging features * basing on the application environment and/or registry * * Revision 1.21 2000/01/20 17:51:18 vakatov * Major redesign and expansion of the "CNcbiApplication" class to * - embed application arguments "CNcbiArguments" * - embed application environment "CNcbiEnvironment" * - allow auto-setup or "by choice" (see enum EAppDiagStream) of diagnostics * - allow memory-resided "per application" temp. diagnostic buffer * - allow one to specify exact name of the config.-file to load, or to * ignore the config.file (via constructor's "conf" arg) * - added detailed comments * * Revision 1.20 1999/12/29 21:20:18 vakatov * More intelligent lookup for the default config.file. -- try to strip off * file extensions if cannot find an exact match; more comments and tracing * * Revision 1.19 1999/11/15 15:54:59 sandomir * Registry support moved from CCgiApplication to CNcbiApplication * * Revision 1.18 1999/06/11 20:30:37 vasilche * We should catch exception by reference, because catching by value * doesn't preserve comment string. * * Revision 1.17 1999/05/04 00:03:12 vakatov * Removed the redundant severity arg from macro ERR_POST() * * Revision 1.16 1999/04/30 19:21:03 vakatov * Added more details and more control on the diagnostics * See #ERR_POST, EDiagPostFlag, and ***DiagPostFlag() * * Revision 1.15 1999/04/27 14:50:06 vasilche * Added FastCGI interface. * CNcbiContext renamed to CCgiContext. * * Revision 1.14 1999/02/22 21:12:38 sandomir * MsgRequest -> NcbiContext * * Revision 1.13 1998/12/28 23:29:06 vakatov * New CVS and development tree structure for the NCBI C++ projects * * Revision 1.12 1998/12/28 15:43:12 sandomir * minor fixed in CgiApp and Resource * * Revision 1.11 1998/12/14 15:30:07 sandomir * minor fixes in CNcbiApplication; command handling fixed * * Revision 1.10 1998/12/09 22:59:35 lewisg * use new cgiapp class * * Revision 1.7 1998/12/09 16:49:56 sandomir * CCgiApplication added * * Revision 1.4 1998/12/03 21:24:23 sandomir * NcbiApplication and CgiApplication updated * * Revision 1.3 1998/12/01 19:12:08 lewisg * added CCgiApplication * * Revision 1.2 1998/11/05 21:45:14 sandomir * std:: deleted * * Revision 1.1 1998/11/02 22:10:13 sandomir * CNcbiApplication added; netest sample updated * * =========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -