00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "dconfig.h"
00020 #include "configTable.h"
00021 #include "dSearchPath.h"
00022 #include "executionEnvironment.h"
00023 #include "config_dconfig.h"
00024 #include "pfstream.h"
00025 #include "serialization.h"
00026
00027 #ifdef PENV_PS2
00028
00029 #include <string.h>
00030 #include <sifdev.h>
00031 #include <eekernel.h>
00032
00033 #endif // PENV_PS2
00034
00035
00036
00037 using namespace Config;
00038
00039 ConfigTable* ConfigTable::_instance = (ConfigTable*)0L;
00040
00041 void ConfigTable::CropString(ConfigString& S) {
00042 size_t i = S.find_first_not_of(" \t\r\f\n");
00043 if (i != ConfigString::npos) {
00044 size_t j = S.find_last_not_of(" \t\r\f\n");
00045 if (j != ConfigString::npos)
00046 S = S.substr(i, j-i+1);
00047 else
00048 S = S.substr(i, ConfigString::npos);
00049 } else
00050 S.erase(0, ConfigString::npos);
00051 }
00052
00053 void ConfigTable::DeComment(ConfigString& S) {
00054
00055
00056
00057 size_t i = S.find(configcmt);
00058 while (i != ConfigString::npos) {
00059 if (i + configcmt.length() < S.length() &&
00060 isspace(S[i + configcmt.length()])) {
00061
00062 S.erase(i, ConfigString::npos);
00063 return;
00064 }
00065
00066 i = S.find(configcmt, i + 1);
00067 }
00068 }
00069
00070 bool ConfigTable::IsComment(const ConfigString& S)
00071 {
00072
00073
00074 return (S.substr(0, configcmt.length()) == configcmt);
00075 }
00076
00077 void ConfigTable::UpCase(ConfigString& S)
00078 {
00079 for (ConfigString::iterator i=S.begin(); i!=S.end(); ++i)
00080 (*i) = toupper(*i);
00081 }
00082
00083 ConfigString ConfigTable::NextWord(const ConfigString& S) {
00084 int i(S.find_first_of(" \t\r\f\n"));
00085 return S.substr(0, i);
00086 }
00087
00088 ConfigString ConfigTable::PopNextWord(ConfigString& S) {
00089 int i(S.find_first_of(" \t\r\f\n"));
00090 ConfigString ret(S.substr(0, i));
00091 S.erase(0, i);
00092 CropString(S);
00093 return ret;
00094 }
00095
00096 void ConfigTable::ParseConfigFile(istream& is, const ConfigString& Filename)
00097 {
00098 ConfigString line;
00099
00100 while (!is.eof() && !is.fail()) {
00101 std::getline(is, line);
00102 if (microconfig_cat->is_spam())
00103 microconfig_cat->spam() << "read from " << Filename << ": '" << line
00104 << "'" << endl;
00105 DeComment(line);
00106 CropString(line);
00107 if (microconfig_cat->is_spam())
00108 microconfig_cat->spam() << "cropped line to: '" << line << "'"
00109 << endl;
00110 if (!IsComment(line)) {
00111 ConfigString protosym(PopNextWord(line));
00112 if (microconfig_cat->is_spam())
00113 microconfig_cat->spam() << "protosym is '" << protosym
00114 << "' with value of '" << line << "'"
00115 << endl;
00116 size_t i(protosym.find("."));
00117 if (i == ConfigString::npos) {
00118 if (microconfig_cat->is_spam())
00119 microconfig_cat->spam() << "this is an unqualified symbol"
00120 << endl;
00121 unqualified[protosym].push_back(SymEnt(SymEnt::ConfigFile, line, Filename));
00122 } else {
00123 ConfigString scope(protosym.substr(0, i));
00124 ConfigString sym(protosym.substr(i+1, ConfigString::npos));
00125 if (microconfig_cat->is_spam())
00126 microconfig_cat->spam() << "this is a qualified symbol."
00127 << " scope '" << scope
00128 << "', symbol '" << sym << "'" << endl;
00129 (qualified[scope])[sym].push_back(SymEnt(SymEnt::ConfigFile, line, Filename));
00130 }
00131 } else if (microconfig_cat->is_spam())
00132 microconfig_cat->spam() << "line is detected as a comment" << endl;
00133 }
00134 }
00135
00136 void ConfigTable::ReadConfigFile(void) {
00137
00138
00139
00140
00141
00142 DSearchPath config_search;
00143 while (!configpath.empty()) {
00144 int i = configpath.find_first_of(" ");
00145 ConfigString stmp = configpath.substr(0, i);
00146 if (ExecutionEnvironment::has_environment_variable(stmp)) {
00147 Filename next_path = Filename::from_os_specific(ExecutionEnvironment::get_environment_variable(stmp));
00148 config_search.append_path(next_path);
00149 }
00150 configpath.erase(0, i);
00151 CropString(configpath);
00152 }
00153
00154 if (config_search.is_empty()) {
00155
00156
00157 config_search.append_directory(".");
00158 }
00159
00160 if (microconfig_cat->is_spam()) {
00161 microconfig_cat->spam()
00162 << "search path from configpath is: "
00163 << config_search << endl;
00164 }
00165
00166 DSearchPath::Results config_files;
00167
00168 if (!configsuffix.empty()) {
00169 if (microconfig_cat->is_spam())
00170 microconfig_cat->spam() << "agregate config name is: "
00171 << (configname + configsuffix) << endl;
00172 config_search.find_all_files(configname + configsuffix, config_files);
00173 if (microconfig_cat->is_spam())
00174 microconfig_cat->spam() << "found " << config_files.get_num_files()
00175 << " files" << endl;
00176 } else {
00177 if (microconfig_cat->is_spam())
00178 microconfig_cat->spam() << "searching for '" << configname << "'"
00179 << endl;
00180 config_search.find_all_files(configname, config_files);
00181 if (microconfig_cat->is_spam())
00182 microconfig_cat->spam() << "found " << config_files.get_num_files()
00183 << " files" << endl;
00184 }
00185
00186 if (microconfig_cat->is_spam())
00187 microconfig_cat->spam() << "configpath parsed and searched"
00188 << endl;
00189
00190 int num_config_files = config_files.get_num_files();
00191 for (int i = num_config_files - 1; i >= 0; i--) {
00192 Filename config_file = config_files.get_file(i);
00193
00194 if (microconfig_cat->is_spam())
00195 microconfig_cat->spam() << "examining file '" << config_file << "'"
00196 << endl;
00197
00198 if (!config_file.is_regular_file()) {
00199 if (microconfig_cat->is_spam()) {
00200 microconfig_cat->spam()
00201 << "file is not a regular file, ignoring.\n";
00202 }
00203
00204 } else if (config_file.is_executable()) {
00205 ConfigString line = config_file.to_os_specific() + " " + configargs;
00206 if (microconfig_cat->is_spam())
00207 microconfig_cat->spam() << "file is executable, running '"
00208 << line << "'" << endl;
00209 IPipeStream ifs(line);
00210 ParseConfigFile(ifs, config_file);
00211 } else {
00212 if (microconfig_cat->is_spam())
00213 microconfig_cat->spam()
00214 << "file is not executable, reading normally" << endl;
00215
00216 #ifdef PENV_PS2
00217 ConfigString line = PS2_FILE_PREFIX + convert_pathname(config_file);
00218
00219 int fd = sceOpen((char *) line.c_str(), SCE_RDONLY);
00220 char line_buffer[2048];
00221
00222 memset(line_buffer, 0, 2048);
00223
00224 ConfigString file_buffer;
00225
00226 while (sceRead(fd, line_buffer, 2048) > 0)
00227 {
00228 file_buffer += line_buffer;
00229 memset(line_buffer, 0, 2048);
00230 }
00231
00232 sceClose(fd);
00233
00234 istrstream ifs(file_buffer.c_str());
00235 #else
00236 ifstream ifs(config_file.to_os_specific().c_str());
00237 #endif
00238 ParseConfigFile(ifs, config_file);
00239 }
00240 }
00241 }
00242
00243 void ConfigTable::ParseCommandEnv(ConfigString& S, const ConfigString& sym)
00244 {
00245 if (microconfig_cat->is_spam())
00246 microconfig_cat->spam() << "value of '" << sym << "' is '" << S << "'"
00247 << endl;
00248 while (!S.empty()) {
00249 ConfigString protosym(PopNextWord(S));
00250 bool ok = false;
00251 bool state = false;
00252 if (protosym[0] == '-')
00253 ok = true;
00254 else if (protosym[0] == '+') {
00255 ok = true;
00256 state = true;
00257 }
00258 if (ok) {
00259 protosym.erase(0, 1);
00260 CropString(protosym);
00261 size_t i(protosym.find("."));
00262 if (i == ConfigString::npos) {
00263 unqualified[protosym].push_back(SymEnt(SymEnt::CommandEnv,
00264 NextWord(S), sym, state));
00265 if (microconfig_cat->is_spam())
00266 microconfig_cat->spam() << "unqualified symbol '" << protosym
00267 << "' with value '" << NextWord(S)
00268 << "'" << endl;
00269 } else {
00270 ConfigString scope(protosym.substr(0, i));
00271 ConfigString sym(protosym.substr(i+1, ConfigString::npos));
00272 (qualified[scope])[sym].push_back(SymEnt(SymEnt::CommandEnv,
00273 NextWord(S), sym, state));
00274 if (microconfig_cat->is_spam())
00275 microconfig_cat->spam() << "qualified symbol '" << sym
00276 << "' in scope '" << scope
00277 << "' and value '" << NextWord(S)
00278 << "'" << endl;
00279 }
00280 } else if (microconfig_cat->is_spam())
00281 microconfig_cat->spam() << "'" << protosym
00282 << "' was not recognized as an option"
00283 << endl;
00284 }
00285 }
00286
00287 void ConfigTable::ParseArgs(void)
00288 {
00289 int n = 0;
00290 int num_args = ExecutionEnvironment::get_num_args();
00291
00292 while ( n < num_args) {
00293 bool ok = false;
00294 bool state = false;
00295 ConfigString line(ExecutionEnvironment::get_arg(n));
00296 CropString(line);
00297 if (line[0] == '-')
00298 ok = true;
00299 else if (line[0] == '+') {
00300 ok = true;
00301 state = true;
00302 }
00303 if (ok) {
00304 line.erase(0, 1);
00305 CropString(line);
00306 size_t i(line.find("."));
00307 ConfigString aparam;
00308 if (n + 1 < num_args) {
00309 aparam = ExecutionEnvironment::get_arg(n + 1);
00310 }
00311
00312 if (i == ConfigString::npos) {
00313 unqualified[line].push_back(SymEnt(SymEnt::Commandline,
00314 aparam, "", state));
00315 if (microconfig_cat->is_spam())
00316 microconfig_cat->spam() << "unqualified symbol '" << line
00317 << "' with value '" << aparam
00318 << "'" << endl;
00319 } else {
00320 ConfigString scope(line.substr(0, i));
00321 ConfigString sym(line.substr(i+1, ConfigString::npos));
00322 (qualified[scope])[sym].push_back(SymEnt(SymEnt::Commandline,
00323 aparam, "", state));
00324 if (microconfig_cat->is_spam())
00325 microconfig_cat->spam() << "qualified symbol '" << sym
00326 << "' with scope '" << scope
00327 << "' and value '" << aparam
00328 << "'" << endl;
00329 }
00330 } else if (microconfig_cat->is_spam()) {
00331 microconfig_cat->spam() << "argument #" << n << " ('" << line
00332 << "') is not recognized as an option"
00333 << endl;
00334 }
00335 ++n;
00336 }
00337 }
00338
00339 void ConfigTable::MicroConfig(void)
00340 {
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 microconfig_cat->set_severity(NS_info);
00352
00353
00354 dconfig_cat->set_severity(NS_info);
00355
00356
00357
00358 string cc = ExecutionEnvironment::get_environment_variable("CONFIG_CONFIG");
00359 if (microconfig_cat->is_spam())
00360 microconfig_cat->spam() << "CONFIG_CONFIG = '" << cc << "'" << endl;
00361 bool cdbg = false;
00362 bool psep = false;
00363 bool fsep = false;
00364 bool cname = false;
00365 bool csuff = false;
00366 bool cargs = false;
00367 bool cpath = false;
00368 bool ccmt = false;
00369 bool asuff = false;
00370 bool cstub = false;
00371 bool rdarg = false;
00372 bool rdenv = false;
00373 if (!cc.empty()) {
00374 ConfigString configconfig(cc);
00375 if (configconfig.length() > 1) {
00376 ConfigString assign = "=";
00377 ConfigString sep = configconfig.substr(0, 1);
00378 if (microconfig_cat->is_spam())
00379 microconfig_cat->spam() << "separator character is: '" << sep
00380 << "'" << endl;
00381 typedef std::vector<ConfigString> strvec;
00382 strvec sv;
00383 size_t q = 1;
00384 size_t p = configconfig.find(sep, q);
00385 while (p != ConfigString::npos) {
00386 sv.push_back(configconfig.substr(q, p - q));
00387 q = p + 1;
00388 p = configconfig.find(sep, q);
00389 }
00390 if (q + 1 < configconfig.size()) {
00391 sv.push_back(configconfig.substr(q));
00392 }
00393
00394 if (microconfig_cat->is_spam())
00395 microconfig_cat->spam()
00396 << "extracted vector of microconfig options" << endl;
00397 for (strvec::iterator i=sv.begin(); i!=sv.end(); ++i) {
00398 if (microconfig_cat->is_spam())
00399 microconfig_cat->spam() << "parsing microconfig option '"
00400 << *i << "'" << endl;
00401 if ((*i).length() == 1) {
00402
00403 assign += *i;
00404 continue;
00405 }
00406 size_t j = (*i).find_first_of(assign);
00407 if (j != ConfigString::npos) {
00408 ConfigString tok = (*i).substr(0, j);
00409 ConfigString rest = (*i).substr(j+1, ConfigString::npos);
00410 if (microconfig_cat->is_spam())
00411 microconfig_cat->spam() << "split microconfig option into '"
00412 << tok << "' and '" << rest << "'"
00413 << endl;
00414 if (tok == "pathsep") {
00415 pathsep = rest;
00416 psep = true;
00417 if (microconfig_cat->is_spam())
00418 microconfig_cat->spam()
00419 << "got a microconfig pathsep directive, "
00420 << "setting the path separator to '" << pathsep << "'"
00421 << endl;
00422 } else if (tok == "filesep") {
00423 filesep = rest;
00424 fsep = true;
00425 if (microconfig_cat->is_spam())
00426 microconfig_cat->spam()
00427 << "got a microconfig filesep directive, "
00428 << "setting the file separator to '" << filesep << "'"
00429 << endl;
00430 } else if (tok == "configname") {
00431 configname = rest;
00432 cname = true;
00433 if (microconfig_cat->is_spam())
00434 microconfig_cat->spam()
00435 << "got a microconfig configname directive, "
00436 << "setting the configfile name to '" << configname
00437 << "'" << endl;
00438 } else if (tok == "configsuffix") {
00439 configsuffix = rest;
00440 csuff = true;
00441 if (microconfig_cat->is_spam())
00442 microconfig_cat->spam()
00443 << "got a microconfig configsuffix directive, "
00444 << "setting the config file suffix to '"
00445 << configsuffix << "'"
00446 << endl;
00447 } else if (tok == "configargs") {
00448 configargs = rest;
00449 cargs = true;
00450 if (microconfig_cat->is_spam())
00451 microconfig_cat->spam()
00452 << "got a microconfig configargs directive, "
00453 << "setting the config file args to '"
00454 << configargs << "'"
00455 << endl;
00456 } else if (tok == "configpath") {
00457 if (cpath) {
00458 configpath += " " + rest;
00459 if (microconfig_cat->is_spam())
00460 microconfig_cat->spam()
00461 << "got a microconfig configpath directive, "
00462 << "adding '" << rest << "' to the configpath"
00463 << endl;
00464 } else {
00465 configpath = rest;
00466 if (microconfig_cat->is_spam())
00467 microconfig_cat->spam()
00468 << "got a microconfig configpath directive, "
00469 << "setting the configpath to '" << configpath << "'"
00470 << endl;
00471 }
00472 cpath = true;
00473 } else if (tok == "configcmt") {
00474 configcmt = rest;
00475 ccmt = true;
00476 if (microconfig_cat->is_spam())
00477 microconfig_cat->spam()
00478 << "got a microconfig configcmt directive, "
00479 << "setting the config comment to '" << configcmt
00480 << "'" << endl;
00481 } else if (tok == "argsuffix") {
00482 argsuffix = rest;
00483 asuff = true;
00484 if (microconfig_cat->is_spam())
00485 microconfig_cat->spam()
00486 << "got a microconfig argsuffix directive, "
00487 << "setting the argument environment suffix to '"
00488 << argsuffix << "'" << endl;
00489 } else if (tok == "commandstub") {
00490 commandstub = rest;
00491 cstub = true;
00492 if (microconfig_cat->is_spam())
00493 microconfig_cat->spam()
00494 << "got a microconfig commandstub directive, "
00495 << "setting the command environment stub "
00496 << "to '" << commandstub << "'" << endl;
00497 } else if (tok == "configdbg") {
00498 configdbg = TrueOrFalse(rest);
00499 cdbg = true;
00500 if (configdbg) {
00501 microconfig_cat->set_severity(NS_spam);
00502 dconfig_cat->set_severity(NS_spam);
00503 } else {
00504 microconfig_cat->set_severity(NS_info);
00505 dconfig_cat->set_severity(NS_info);
00506 }
00507 if (microconfig_cat->is_spam())
00508 microconfig_cat->spam()
00509 << "got a microconfig configdbg directive, "
00510 << "setting the config spam state to " << configdbg
00511 << endl;
00512 } else if (tok == "readargs") {
00513 readargs = TrueOrFalse(rest);
00514 rdarg = true;
00515 if (microconfig_cat->is_spam())
00516 microconfig_cat->spam()
00517 << "got a microconfig readargs directive, "
00518 << (readargs?"will":"will not")
00519 << " read from the commandline." << endl;
00520 } else if (tok == "readenv") {
00521 readenvs = TrueOrFalse(rest);
00522 rdenv = true;
00523 if (microconfig_cat->is_spam())
00524 microconfig_cat->spam()
00525 << "got a microconfig readenv directive, "
00526 << (readargs?"will":"will not")
00527 << " read the environment." << endl;
00528 }
00529 } else if (microconfig_cat->is_spam())
00530 microconfig_cat->spam()
00531 << "no '=' in microconfig option, ignoring it" << endl;
00532 }
00533 } else if (microconfig_cat->is_spam())
00534 microconfig_cat->spam()
00535 << "CONFIG_CONFIG contains only a single character" << endl;
00536 } else if (microconfig_cat->is_spam())
00537 microconfig_cat->spam() << "CONFIG_CONFIG is empty" << endl;
00538 if (!cdbg)
00539 ConfigDbgDefault();
00540 if (!psep) {
00541 PathSepDefault();
00542 if (microconfig_cat->is_spam())
00543 microconfig_cat->spam() << "no microconfig for pathsep, "
00544 << "setting to default '" << pathsep << "'"
00545 << endl;
00546 }
00547 if (!fsep) {
00548 FileSepDefault();
00549 if (microconfig_cat->is_spam())
00550 microconfig_cat->spam() << "no microconfig for filesep, "
00551 << "setting to default '" << filesep << "'"
00552 << endl;
00553 }
00554 if (!cname) {
00555 ConfigNameDefault();
00556 if (microconfig_cat->is_spam())
00557 microconfig_cat->spam() << "no microconfig for configname, "
00558 << "setting to default '" << configname
00559 << "'" << endl;
00560 }
00561 if (!csuff) {
00562 ConfigSuffixDefault();
00563 if (microconfig_cat->is_spam())
00564 microconfig_cat->spam() << "no microconfig for configsuffix, "
00565 << "setting to default '" << configsuffix
00566 << "'" << endl;
00567 }
00568 if (!cargs) {
00569 ConfigArgsDefault();
00570 if (microconfig_cat->is_spam())
00571 microconfig_cat->spam() << "no microconfig for configargs, "
00572 << "setting to default '" << configargs
00573 << "'" << endl;
00574 }
00575 if (!cpath) {
00576 ConfigPathDefault();
00577 if (microconfig_cat->is_spam())
00578 microconfig_cat->spam() << "no microconfig for configpath, "
00579 << "setting to default '" << configpath
00580 << "'" << endl;
00581 }
00582 if (!ccmt) {
00583 ConfigCmtDefault();
00584 if (microconfig_cat->is_spam())
00585 microconfig_cat->spam() << "no microconfig for configcmt, "
00586 << "setting to default '" << configcmt
00587 << "'" << endl;
00588 }
00589 if (!asuff) {
00590 ArgSuffixDefault();
00591 if (microconfig_cat->is_spam())
00592 microconfig_cat->spam() << "no microconfig for argsuffix, "
00593 << "setting to default '" << argsuffix
00594 << "'" << endl;
00595 }
00596 if (!cstub) {
00597 CommandStubDefault();
00598 if (microconfig_cat->is_spam())
00599 microconfig_cat->spam() << "no microconfig for commandstub, "
00600 << "setting to default '" << commandstub
00601 << "'" << endl;
00602 }
00603 if (!rdarg) {
00604 ReadArgsDefault();
00605 if (microconfig_cat->is_spam())
00606 microconfig_cat->spam() << "no microconfig for readargs, "
00607 << "setting to default: "
00608 << (readargs?"true":"false") << endl;
00609 }
00610 if (!rdenv) {
00611 ReadEnvsDefault();
00612 if (microconfig_cat->is_spam())
00613 microconfig_cat->spam() << "no microconfig for readenv, "
00614 << "setting to default: "
00615 << (readargs?"true":"false") << endl;
00616 }
00617 }
00618
00619 void ConfigTable::GetData(void) {
00620 MicroConfig();
00621 #ifndef DISABLE_CONFIG
00622 ReadConfigFile();
00623 if (readenvs) {
00624 ConfigString comarg = commandstub + argsuffix;
00625 if (microconfig_cat->is_spam())
00626 microconfig_cat->spam() << "comarg is '" << comarg << "'"
00627 << endl;
00628 if (ExecutionEnvironment::has_environment_variable(comarg)) {
00629 ConfigString env = ExecutionEnvironment::get_environment_variable(comarg);
00630 ParseCommandEnv(env, comarg);
00631 }
00632 ConfigString line = ExecutionEnvironment::get_binary_name() + argsuffix;
00633 UpCase(line);
00634 if (microconfig_cat->is_spam())
00635 microconfig_cat->spam() << "binarg is '" << line << "'"
00636 << endl;
00637 if (ExecutionEnvironment::has_environment_variable(line)) {
00638 ConfigString env = ExecutionEnvironment::get_environment_variable(line);
00639 ParseCommandEnv(env, line);
00640 }
00641 }
00642 if (readargs)
00643 ParseArgs();
00644 #endif // DISABLE_CONFIG
00645 }
00646
00647 ConfigTable* ConfigTable::Instance(void) {
00648 if (_instance == (ConfigTable*)0L) {
00649 _instance = new ConfigTable;
00650 _instance->GetData();
00651 _instance->_initializing = false;
00652 Notify::ptr()->config_initialized();
00653 }
00654 return _instance;
00655 }
00656
00657 bool ConfigTable::AmInitializing(void) {
00658 return _initializing;
00659 }
00660
00661 bool ConfigTable::TrueOrFalse(const ConfigString& in, bool def) {
00662 bool ret = def;
00663 ConfigString S = in;
00664 UpCase(S);
00665 if (S[0] == '#') {
00666 if (S[1] == 'F')
00667 ret = false;
00668 else if (S[1] == 'T')
00669 ret = true;
00670 } else if (S == "0") {
00671 ret = false;
00672 } else if (S == "1") {
00673 ret = true;
00674 } else if (S == "FALSE") {
00675 ret = false;
00676 } else if (S == "TRUE") {
00677 ret = true;
00678 }
00679 return ret;
00680 }
00681
00682 bool ConfigTable::Defined(const ConfigString& sym,
00683 const ConfigString qual) {
00684 #ifdef DISABLE_CONFIG
00685 return false;
00686 #else
00687 if (qual.empty()) {
00688 return (unqualified.count(sym) != 0 ||
00689 ExecutionEnvironment::has_environment_variable(sym));
00690
00691 } else {
00692 TableMap::const_iterator ti;
00693 ti = qualified.find(qual);
00694 if (ti != qualified.end()) {
00695 const SymbolTable &table = (*ti).second;
00696 if (table.count(sym) != 0) {
00697 return true;
00698 }
00699 }
00700
00701 return ExecutionEnvironment::has_environment_variable(qual + "." + sym);
00702 }
00703 #endif // DISABLE_CONFIG
00704 }
00705
00706 ConfigTable::SymEnt ConfigTable::Get(const ConfigString& sym,
00707 const ConfigString qual) {
00708 #ifndef DISABLE_CONFIG
00709 const ConfigTable::Symbol &symbol = GetSym(sym, qual);
00710 if (!symbol.empty()) {
00711 return symbol.back();
00712 }
00713
00714
00715 string envvar = sym;
00716 if (!qual.empty()) {
00717 envvar = qual + "." + sym;
00718 }
00719
00720 if (ExecutionEnvironment::has_environment_variable(sym)) {
00721 string def = ExecutionEnvironment::get_environment_variable(sym);
00722 return ConfigTable::SymEnt(ConfigTable::SymEnt::Environment, def);
00723 }
00724 #endif // DISABLE_CONFIG
00725
00726
00727 return ConfigTable::SymEnt();
00728 }
00729
00730 const ConfigTable::Symbol& ConfigTable::GetSym(const ConfigString& sym,
00731 const ConfigString qual) {
00732 static ConfigTable::Symbol empty_symbol;
00733
00734 #ifndef DISABLE_CONFIG
00735 total_num_get++;
00736 if (qual.empty()) {
00737 SymbolTable::const_iterator si;
00738 si = unqualified.find(sym);
00739 if (si != unqualified.end()) {
00740 return (*si).second;
00741 }
00742
00743 } else {
00744 TableMap::const_iterator ti;
00745 ti = qualified.find(qual);
00746 if (ti != qualified.end()) {
00747 const SymbolTable &table = (*ti).second;
00748 SymbolTable::const_iterator si;
00749 si = table.find(sym);
00750 if (si != table.end()) {
00751 return (*si).second;
00752 }
00753 }
00754 }
00755 #endif // DISABLE_CONFIG
00756
00757 return empty_symbol;
00758 }