Changeset 11404
- Timestamp:
- 07/14/11 09:22:46 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Configuration.cc
r11400 r11404 31 31 - (3) Database entries 32 32 - (4) Options from the default configuration-file (given by \b --default, defaults to \b program_name.rc) 33 - (5) Environment variables 33 - (5) Options from the global configuration-file (constrctor path + \b fact++.rc) 34 - (6) Environment variables 34 35 35 36 Which options are accepted is defined by the program. To get a list … … 763 764 if (!var.empty()) 764 765 cout << " = "; 765 cout << va l<< " #" << str.str();766 cout << var << " #" << str.str(); 766 767 767 768 if (v.defaulted()) … … 925 926 //! - (4) Check for \b --print and \b --print-all and perform corresponding 926 927 //! action 927 //! - (5) Read and parse the default configuration file, which is either 928 //! - (5) Read and parse the global configuration file, which is compiled 929 //! from the path corresponding to the argument given in the 930 //! constructor + "/fact++.rc", unrecognized options are always 931 //! allowed. 932 //! - (6) Read and parse the default configuration file, which is either 928 933 //! given by the default name or the \b --default command-line 929 934 //! option. The default name is compiled from the argument … … 933 938 //! the \b --dont-check and \b --dont-check-files options, 934 939 //! unrecognized options in the file throw an exception or not. 935 //! - ( 6) Check for \b --print-default and \b --print-all and perform940 //! - (7) Check for \b --print-default and \b --print-all and perform 936 941 //! corresponding action 937 //! - ( 7) Read and parse the priority configuration file, which must be given942 //! - (8) Read and parse the priority configuration file, which must be given 938 943 //! by the \b --config or \b -C command-line option or a 939 944 //! corresponding entry in the default-configuration file. … … 943 948 //! the \b --dont-check and \b --dont-check-files options, 944 949 //! unrecognized options in the file throw an exception or not. 945 //! - ( 8) Check for \b --print-config and \b --print-all and perform950 //! - (9) Check for \b --print-config and \b --print-all and perform 946 951 //! corresponding action 947 //! - ( 9)Retrieve options from the database according to the952 //! - (10) Retrieve options from the database according to the 948 953 //! options \b --database and \b --no-database. Note that 949 954 //! options given on the command-line have highest priority. … … 951 956 //! The options from the default configuration-file have 952 957 //! lowest priority. 953 //! - (1 0) Check for \b --print-database and \b --print-all and perform958 //! - (11) Check for \b --print-database and \b --print-all and perform 954 959 //! corresponding action 955 //! - (1 1) Parse the environment options.956 //! - (1 2) Check for \b --print-environment and \b --print-all and perform960 //! - (12) Parse the environment options. 961 //! - (13) Check for \b --print-environment and \b --print-all and perform 957 962 //! corresponding action 958 //! - (1 3) Compile the final result. The priority of the options is (in963 //! - (14) Compile the final result. The priority of the options is (in 959 964 //! decreasing order): command-line options, options from the 960 965 //! priority configuration file, options from the database, 961 966 //! options from the default configuration-file and options 962 967 //! from the environment. 963 //! - (1 4) Finally all options which were found and flagged as unrecognized,968 //! - (15) Finally all options which were found and flagged as unrecognized, 964 969 //! because they are not in the user-defined list of described 965 970 //! options, are collected and stored in the corresponding 966 971 //! data-members. 967 //! - (1 5) Before the function returns it check for \b --print-options972 //! - (16) Before the function returns it check for \b --print-options 968 973 //! and \b --print-unknown and performs the corresponding actions. 969 974 //! … … 1053 1058 // ------------------------ (5) -------------------------- 1054 1059 1060 const boost::filesystem::path path(GetName()); 1061 const string globalfile = path.parent_path().string()+"/fact++.rc"; 1062 1063 cerr << "Reading options from '" << globalfile << "'." << endl; 1064 1065 ifstream gfile(globalfile.c_str()); 1066 // ===> FIXME: Proper handling of missing file or wrong file name 1067 const po::parsed_options parsed_globalfile = 1068 !gfile ? 1069 po::parsed_options(&opt_configfile) : 1070 po::parse_config_file<char>(gfile, opt_configfile, false); 1071 1072 // ------------------------ (6) -------------------------- 1073 1055 1074 // Get default file from command line 1056 1075 if (getfiles.count("default")) 1057 1076 { 1058 1077 fDefaultFile = getfiles["default"].as<string>(); 1059 cerr << "Reading configurationfrom '" << fDefaultFile << "'." << endl;1078 cerr << "Reading options from '" << fDefaultFile << "'." << endl; 1060 1079 } 1061 1080 … … 1071 1090 po::parse_config_file<char>(indef, opt_configfile, !checkf); 1072 1091 1073 // ------------------------ ( 6) --------------------------1092 // ------------------------ (7) -------------------------- 1074 1093 1075 1094 if (getfiles.count("print-default") || getfiles.count("print-all")) … … 1087 1106 po::store(parsed_defaultfile, getfiles); 1088 1107 1089 // ------------------------ ( 7) --------------------------1108 // ------------------------ (8) -------------------------- 1090 1109 1091 1110 // Get priority from commandline(1), defaultfile(2) … … 1093 1112 { 1094 1113 fPriorityFile = getfiles["config"].as<string>(); 1095 cerr << "Re trieved optionfrom '" << fPriorityFile << "'." << endl;1114 cerr << "Reading options from '" << fPriorityFile << "'." << endl; 1096 1115 } 1097 1116 … … 1102 1121 po::parse_config_file<char>(inpri, opt_configfile, !checkf); 1103 1122 1104 // ------------------------ ( 8) --------------------------1123 // ------------------------ (9) -------------------------- 1105 1124 1106 1125 if (getfiles.count("print-config") || getfiles.count("print-all")) … … 1116 1135 } 1117 1136 1118 // ------------------------ ( 9) --------------------------1137 // ------------------------ (10) ------------------------- 1119 1138 1120 1139 po::variables_map getdatabase; … … 1122 1141 po::store(parsed_priorityfile, getdatabase); 1123 1142 po::store(parsed_defaultfile, getdatabase); 1143 po::store(parsed_globalfile, getdatabase); 1124 1144 1125 1145 if (getdatabase.count("database") && !getdatabase.count("no-database")) 1126 1146 { 1127 1147 fDatabase = getdatabase["database"].as<string>(); 1128 cerr << "Re trieving configurationfrom '" << fDatabase << "'." << endl;1148 cerr << "Requesting options from '" << fDatabase << "'." << endl; 1129 1149 } 1130 1150 … … 1135 1155 parse_database(fDatabase, opt_database, !checkdb); 1136 1156 1137 // ------------------------ (1 0) -------------------------1157 // ------------------------ (11) ------------------------- 1138 1158 1139 1159 if (getfiles.count("print-database") || getfiles.count("print-all")) … … 1143 1163 else 1144 1164 { 1145 cout << endl << "Options re trieved from '" << fDatabase << "':" << endl;1165 cout << endl << "Options received from '" << fDatabase << "':" << endl; 1146 1166 PrintParsed(parsed_database); 1147 1167 cout << endl; … … 1149 1169 } 1150 1170 1151 // ------------------------ (1 1) -------------------------1171 // ------------------------ (12) ------------------------- 1152 1172 1153 1173 const po::parsed_options parsed_environment = po::parse_environment(opt_environment, fNameMapper); 1154 1174 1155 // ------------------------ (1 2) -------------------------1175 // ------------------------ (13) ------------------------- 1156 1176 1157 1177 if (getfiles.count("print-environment")) … … 1162 1182 } 1163 1183 1164 // ------------------------ (1 3) -------------------------1184 // ------------------------ (14) ------------------------- 1165 1185 po::variables_map result; 1166 1186 po::store(parsed_commandline, result); … … 1168 1188 po::store(parsed_database, result); 1169 1189 po::store(parsed_defaultfile, result); 1190 po::store(parsed_globalfile, result); 1170 1191 po::store(parsed_environment, result); 1171 1192 po::notify(result); … … 1173 1194 fVariables = result; 1174 1195 1175 // ------------------------ (14) ------------------------- 1176 1196 // ------------------------ (15) ------------------------- 1197 1198 const vector<string> unknown0 = collect_unrecognized(parsed_globalfile.options, po::exclude_positional); 1177 1199 const vector<string> unknown1 = collect_unrecognized(parsed_defaultfile.options, po::exclude_positional); 1178 1200 const vector<string> unknown2 = collect_unrecognized(parsed_priorityfile.options, po::exclude_positional); 1179 1201 1180 1202 fUnknownConfigfile.clear(); 1203 fUnknownConfigfile.insert(fUnknownConfigfile.end(), unknown0.begin(), unknown0.end()); 1181 1204 fUnknownConfigfile.insert(fUnknownConfigfile.end(), unknown1.begin(), unknown1.end()); 1182 1205 fUnknownConfigfile.insert(fUnknownConfigfile.end(), unknown2.begin(), unknown2.end()); … … 1186 1209 fUnknownDatabase = collect_unrecognized(parsed_database.options, po::exclude_positional); 1187 1210 1188 // ------------------------ (1 5) -------------------------1211 // ------------------------ (16) ------------------------- 1189 1212 1190 1213 if (result.count("print-options"))
Note:
See TracChangeset
for help on using the changeset viewer.