51 #elif defined (NCBI_OS_DARWIN)
52 # include <crt_externs.h>
53 # define environ (*_NSGetEnviron())
55 extern char** environ;
59 #define NCBI_USE_ERRCODE_X Corelib_Env
97 for ( ; *envp; envp++) {
98 const char* s = *envp;
99 const char*
eq = strchr(s,
'=');
101 ERR_POST_X(3,
"CNcbiEnvironment: bad string '" << s <<
"'");
118 if (
i->second.ptr ==
NULL &&
i->second.value.empty()) {
123 return i->second.value;
126 string loaded_value =
Load(name, *found);
128 const string& s =
m_Cache[name].value;
140 if ( !it->second.value.empty() || it->second.ptr ==
kEmptyXCStr) {
142 names.push_back(it->first);
163 "failed to set environment variable " + name);
180 #elif defined(NCBI_OS_IRIX)
182 char* p = getenv(name.c_str());
185 _ASSERT( !memcmp(p - name.size() - 1, name.data(), name.size()) );
236 if (
value.empty() ) {
266 const char* p = va_arg(ap,
const char*);
284 #elif defined(NCBI_OS_IRIX)
285 char* p = getenv(name.c_str());
288 _ASSERT( !memcmp(p - name.size() - 1, name.data(), name.size()) );
305 const string& program_name,
306 const string& real_name)
308 Reset(argc, argv, program_name, real_name);
319 : m_ProgramName(args.m_ProgramName),
321 m_ResolvedName(args.m_ResolvedName)
340 const string& program_name,
const string& real_name)
345 "Negative number of command-line arguments");
348 if ((argc == 0) != (argv == 0)) {
351 "Command-line arguments are absent");
354 "CNcbiArguments(): zero \"argc\", non-zero \"argv\"");
359 for (
int i = 0;
i < argc;
i++) {
362 "CNcbiArguments() -- NULL cmd.-line arg #" <<
i);
388 }
else if (
m_Args.size() ) {
392 kDefProgramName->assign(
"ncbi");
393 return kDefProgramName.
Get();
401 SIZE_TYPE base_pos = name.find_last_of(
"/\\:");
402 if (base_pos ==
NPOS)
404 return name.substr(base_pos + 1);
411 SIZE_TYPE base_pos = name.find_last_of(
"/\\:");
412 if (base_pos ==
NPOS)
414 return name.substr(0, base_pos + 1);
419 const string& real_name)
445 case eNoArgs:
return "eNoArgs";
T & Get(void)
Create the variable if not created yet, return the reference.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
container_type::const_iterator const_iterator
container_type::iterator iterator
const_iterator end() const
const_iterator lower_bound(const key_type &key) const
const_iterator find(const key_type &key) const
static const struct name_t names[]
static const char * str(char *buf, int n)
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
CNcbiEnvironment & SetEnvironment(void)
Get a non-const copy of the application's cached environment.
static CNcbiApplicationGuard InstanceGuard(void)
Singleton method.
EFollowLinks
Whether to follow symbolic links (also known as shortcuts or aliases)
@ eIgnoreLinks
Do not follow symbolic links.
@ eTakeOwnership
An object can take ownership of another.
@ eNoOwnership
No ownership is assumed.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
void Shift(int n=1)
Delete arguments from 1 to n.
string m_PrevValue
Previous value of the environment variable manipulated.
deque< string > m_Args
Queue of arguments.
string m_ProgramName
Program name if different from the default m_Args[0].
void Reset(int argc, const char *const *argv, const string &program_name=kEmptyStr, const string &real_name=kEmptyStr)
Reset arguments.
CAutoEnvironmentVariable(const CTempString &var_name, const CTempString &value="1", CNcbiEnvironment *env=NULL)
Initializes the environment variable passed as an argument to the corresponding value ("1" by default...
virtual string Load(const string &name, bool &found) const
Load value of specified environment variable.
string GetProgramDirname(EFollowLinks follow_links=eIgnoreLinks) const
Get program directory name.
CEnvironmentCleaner(const char *s=NULL,...)
Immediately clean some settings, to be passed in as a NULL-terminated sequence of C strings.
void Set(const string &name, const string &value)
Set an environment variable by name.
CNcbiArguments & operator=(const CNcbiArguments &args)
Assignment operator.
const string & Get(const string &name, bool *found=NULL) const
Get environment value by name.
void Unset(const string &name)
Delete an environment variable by name.
CFastMutex m_ResolvedNameMutex
void SetProgramName(const string &program_name, const string &real_name=kEmptyStr)
Set program name.
bool m_WasSet
Was the variable originally set at all?
void Add(const string &arg)
Add a new argument.
string GetProgramBasename(EFollowLinks follow_links=eIgnoreLinks) const
Get program base name.
void Reset(const char *const *envp=0)
Reset environment.
CNcbiEnvironment(void)
Constructor.
virtual ~CNcbiEnvironment(void)
Destructor.
void Clean(const string &name)
Clean the specified setting.
void Enumerate(list< string > &names, const string &prefix=kEmptyStr) const
Find all variable names starting with an optional prefix.
~CAutoEnvironmentVariable()
Destructor which restores the modifications made in the environment by this class.
virtual ~CNcbiArguments(void)
Destructor.
CNcbiArguments(int argc, const char *const *argv, const string &program_name=kEmptyStr, const string &real_name=kEmptyStr)
Constructor.
string m_VariableName
Name of the environment variable manipulated.
AutoPtr< CNcbiEnvironment > m_Env
Affected CNcbiEnvironment instance.
const string & GetProgramName(EFollowLinks follow_links=eIgnoreLinks) const
Get program name.
@ eNegativeArgc
Negative argc value.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Warning(CExceptionArgs_Base &args)
TErrCode GetErrCode(void) const
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
void Info(CExceptionArgs_Base &args)
static string NormalizePath(const string &path, EFollowLinks follow_links=eIgnoreLinks)
Normalize a path.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
NCBI_NS_STD::string::size_type SIZE_TYPE
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition of all error codes used in corelib (xncbi.lib).
const GenericPointer< typename T::ValueType > T2 value
Static variables safety - create on demand, destroy on application termination.
Common macro to detect used sanitizers and suppress memory leaks if run under LeakSanitizer.
#define NCBI_LSAN_DISABLE_GUARD
Defines unified interface to application:
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
bool eq(T x_, T y_, T round_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Cached environment <name,value> pair.