- Timestamp:
- 11/12/18 21:32:33 (6 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Configuration.cc
r19363 r19385 331 331 #include <iostream> 332 332 #include <iomanip> 333 334 #include <boost/filesystem.hpp>335 333 336 334 #ifdef HAVE_SQL … … 492 490 ; 493 491 494 po::options_description def_config;495 def_config.add_options()496 ("default", var<string>(fName+string(".rc")), "Default configuration file.")497 ;498 499 492 po::options_description config("Configuration options"); 500 493 config.add_options() … … 502 495 ("database", var<string>(), "Database link as in\n\t[user[:password]@]server.com[:port]/database[?compress=0|1]\nOverwrites options from the default configuration file.") 503 496 ("no-database", "Suppress any access to the database even if a database URL was set.") 497 ("default", var<string>(fName+string(".rc")), "Default configuration file.") 498 ("prefix", var<string>(), "Path to default configuration file.") 504 499 ; 505 500 506 501 fOptionsCommandline[kVisible].add(generic); 507 502 fOptionsCommandline[kVisible].add(config); 508 fOptionsCommandline[kVisible].add(def_config);509 503 fOptionsConfigfile[kVisible].add(config); 510 504 } … … 981 975 982 976 fPriorityFile = ""; 977 fPrefixPath = ""; 983 978 fDefaultFile = ""; 984 979 fDatabase = ""; … … 1054 1049 const string globalfile = (path.parent_path()/boost::filesystem::path("fact++.rc")).string(); 1055 1050 1056 cerr << "Reading global options from '" << globalfile << "'." << endl; 1051 1052 errno = 0; 1057 1053 1058 1054 ifstream gfile(globalfile.c_str()); 1059 // ===> FIXME: Proper handling of missing file or wrong file name1055 cerr << "Reading global options from '" << globalfile << "' [" << strerror(errno) << "]" << endl; 1060 1056 const po::parsed_options parsed_globalfile = 1061 1057 !gfile ? … … 1068 1064 #endif 1069 1065 1066 po::store(parsed_globalfile, getfiles); 1067 1068 // Get default prefix path from command line 1069 if (getfiles.count("prefix")) 1070 fPrefixPath = getfiles["prefix"].as<string>(); 1071 1070 1072 // Get default file from command line 1071 1073 if (getfiles.count("default")) 1072 {1073 1074 fDefaultFile = getfiles["default"].as<string>(); 1074 cerr << "Reading default options from '" << fDefaultFile << "'." << endl; 1075 }1075 1076 const string default_file = (boost::filesystem::path(fPrefixPath)/boost::filesystem::path(fDefaultFile)).string(); 1076 1077 1077 1078 const bool checkf = !getfiles.count("dont-check-files") && !getfiles.count("dont-check"); … … 1079 1080 //const bool exists = boost::filesystem::exists(fDefaultFile); 1080 1081 1081 ifstream indef(fDefaultFile.c_str()); 1082 // ===> FIXME: Proper handling of missing file or wrong file name 1082 errno = 0; 1083 1084 ifstream indef(default_file); 1085 if (!fDefaultFile.empty()) 1086 cerr << "Reading default options from '" << default_file << "' [" << strerror(errno) << "]" << endl; 1083 1087 const po::parsed_options parsed_defaultfile = 1084 1088 !indef && defaulted ? … … 1114 1118 { 1115 1119 fPriorityFile = getfiles["config"].as<string>(); 1116 cerr << "Reading config options from '" << fPriorityFile << "'." << endl;1120 cerr << "Reading config options from '" << fPriorityFile << "'." << endl; 1117 1121 } 1118 1122 1119 1123 ifstream inpri(fPriorityFile.c_str()); 1124 if (!fPriorityFile.empty() && !inpri) 1125 throw runtime_error("Reading '"+fPriorityFile+"' failed: "+strerror(errno)); 1126 1120 1127 // ===> FIXME: Proper handling of missing file or wrong file name 1121 1128 const po::parsed_options parsed_priorityfile = -
trunk/FACT++/src/Configuration.h
r18997 r19385 4 4 #include <iostream> 5 5 #include <boost/program_options.hpp> 6 #include <boost/filesystem.hpp> 6 7 7 8 namespace po = boost::program_options; … … 36 37 37 38 std::string fPriorityFile; /// File name of the priority configuration file (overwrites option from the databse) 39 std::string fPrefixPath; /// Path to the default configuration file 38 40 std::string fDefaultFile; /// File name of the default configuration file (usually {program}.rc) 39 41 std::string fDatabase; /// URL for database connection (see Configuration::parse_database) … … 204 206 } 205 207 208 const std::string GetPrefixedString(const std::string &var) 209 { 210 const boost::filesystem::path ff(Get<std::string>(var)); 211 const boost::filesystem::path pp(fPrefixPath); 212 return (ff.has_parent_path() ? ff : pp/ff).string(); 213 } 214 206 215 /* 207 216 template<class T> … … 234 243 */ 235 244 const std::string &GetName() const { return fName; } 245 const boost::filesystem::path GetPrefixPath() const { return fPrefixPath; } 236 246 }; 237 247
Note:
See TracChangeset
for help on using the changeset viewer.