Ignore:
Timestamp:
07/14/11 09:22:46 (13 years ago)
Author:
tbretz
Message:
Added fact++.rc global configuration file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Configuration.cc

    r11400 r11404  
    3131   - (3) Database entries
    3232   - (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
    3435
    3536Which options are accepted is defined by the program. To get a list
     
    763764        if (!var.empty())
    764765            cout << " = ";
    765         cout << val << "   #" << str.str();
     766        cout << var << "   #" << str.str();
    766767
    767768        if (v.defaulted())
     
    925926//!  - (4)  Check for \b --print and \b --print-all and perform corresponding
    926927//!         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
    928933//!         given by the default name or the \b --default command-line
    929934//!         option. The default name is compiled from the argument
     
    933938//!         the \b --dont-check and \b --dont-check-files options,
    934939//!         unrecognized options in the file throw an exception or not.
    935 //!  - (6)  Check for \b --print-default and \b --print-all and perform
     940//!  - (7)  Check for \b --print-default and \b --print-all and perform
    936941//!         corresponding action
    937 //!  - (7)  Read and parse the priority configuration file, which must be given
     942//!  - (8)  Read and parse the priority configuration file, which must be given
    938943//!         by the \b --config or \b -C command-line option or a
    939944//!         corresponding entry in the default-configuration file.
     
    943948//!         the \b --dont-check and \b --dont-check-files options,
    944949//!         unrecognized options in the file throw an exception or not.
    945 //!  - (8)  Check for \b --print-config and \b --print-all and perform
     950//!  - (9)  Check for \b --print-config and \b --print-all and perform
    946951//!         corresponding action
    947 //!  - (9) Retrieve options from the database according to the
     952//!  - (10) Retrieve options from the database according to the
    948953//!         options \b --database and \b --no-database. Note that
    949954//!         options given on the command-line have highest priority.
     
    951956//!         The options from the default configuration-file have
    952957//!         lowest priority.
    953 //!  - (10) Check for \b --print-database and \b --print-all and perform
     958//!  - (11) Check for \b --print-database and \b --print-all and perform
    954959//!         corresponding action
    955 //!  - (11)  Parse the environment options.
    956 //!  - (12) Check for \b --print-environment and \b --print-all and perform
     960//!  - (12)  Parse the environment options.
     961//!  - (13) Check for \b --print-environment and \b --print-all and perform
    957962//!         corresponding action
    958 //!  - (13) Compile the final result. The priority of the options is (in
     963//!  - (14) Compile the final result. The priority of the options is (in
    959964//!         decreasing order): command-line options, options from the
    960965//!         priority configuration file, options from the database,
    961966//!         options from the default configuration-file and options
    962967//!         from the environment.
    963 //!  - (14) Finally all options which were found and flagged as unrecognized,
     968//!  - (15) Finally all options which were found and flagged as unrecognized,
    964969//!         because they are not in the user-defined list of described
    965970//!         options, are collected and stored in the corresponding
    966971//!         data-members.
    967 //!  - (15) Before the function returns it check for \b --print-options
     972//!  - (16) Before the function returns it check for \b --print-options
    968973//!         and \b --print-unknown and performs the corresponding actions.
    969974//!
     
    10531058    // ------------------------ (5) --------------------------
    10541059
     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
    10551074    // Get default file from command line
    10561075    if (getfiles.count("default"))
    10571076    {
    10581077        fDefaultFile = getfiles["default"].as<string>();
    1059         cerr << "Reading configuration from '" << fDefaultFile << "'." << endl;
     1078        cerr << "Reading options from '" << fDefaultFile << "'." << endl;
    10601079    }
    10611080
     
    10711090        po::parse_config_file<char>(indef, opt_configfile, !checkf);
    10721091
    1073     // ------------------------ (6) --------------------------
     1092    // ------------------------ (7) --------------------------
    10741093
    10751094    if (getfiles.count("print-default") || getfiles.count("print-all"))
     
    10871106    po::store(parsed_defaultfile, getfiles);
    10881107
    1089     // ------------------------ (7) --------------------------
     1108    // ------------------------ (8) --------------------------
    10901109
    10911110    // Get priority from commandline(1), defaultfile(2)
     
    10931112    {
    10941113        fPriorityFile = getfiles["config"].as<string>();
    1095         cerr << "Retrieved option from '" << fPriorityFile << "'." << endl;
     1114        cerr << "Reading options from '" << fPriorityFile << "'." << endl;
    10961115    }
    10971116
     
    11021121        po::parse_config_file<char>(inpri, opt_configfile, !checkf);
    11031122
    1104     // ------------------------ (8) --------------------------
     1123    // ------------------------ (9) --------------------------
    11051124
    11061125    if (getfiles.count("print-config") || getfiles.count("print-all"))
     
    11161135    }
    11171136
    1118     // ------------------------ (9) --------------------------
     1137    // ------------------------ (10) -------------------------
    11191138
    11201139    po::variables_map getdatabase;
     
    11221141    po::store(parsed_priorityfile, getdatabase);
    11231142    po::store(parsed_defaultfile,  getdatabase);
     1143    po::store(parsed_globalfile,   getdatabase);
    11241144
    11251145    if (getdatabase.count("database") && !getdatabase.count("no-database"))
    11261146    {
    11271147        fDatabase = getdatabase["database"].as<string>();
    1128         cerr << "Retrieving configuration from '" << fDatabase << "'." << endl;
     1148        cerr << "Requesting options from '" << fDatabase << "'." << endl;
    11291149    }
    11301150
     
    11351155        parse_database(fDatabase, opt_database, !checkdb);
    11361156
    1137     // ------------------------ (10) -------------------------
     1157    // ------------------------ (11) -------------------------
    11381158
    11391159    if (getfiles.count("print-database") || getfiles.count("print-all"))
     
    11431163        else
    11441164        {
    1145             cout << endl << "Options retrieved from '" << fDatabase << "':" << endl;
     1165            cout << endl << "Options received from '" << fDatabase << "':" << endl;
    11461166            PrintParsed(parsed_database);
    11471167            cout << endl;
     
    11491169    }
    11501170
    1151     // ------------------------ (11) -------------------------
     1171    // ------------------------ (12) -------------------------
    11521172
    11531173    const po::parsed_options parsed_environment = po::parse_environment(opt_environment, fNameMapper);
    11541174
    1155     // ------------------------ (12) -------------------------
     1175    // ------------------------ (13) -------------------------
    11561176
    11571177    if (getfiles.count("print-environment"))
     
    11621182    }
    11631183
    1164     // ------------------------ (13) -------------------------
     1184    // ------------------------ (14) -------------------------
    11651185    po::variables_map result;
    11661186    po::store(parsed_commandline,  result);
     
    11681188    po::store(parsed_database,     result);
    11691189    po::store(parsed_defaultfile,  result);
     1190    po::store(parsed_globalfile,   result);
    11701191    po::store(parsed_environment,  result);
    11711192    po::notify(result);
     
    11731194    fVariables = result;
    11741195
    1175     // ------------------------ (14) -------------------------
    1176 
     1196    // ------------------------ (15) -------------------------
     1197
     1198    const vector<string> unknown0 = collect_unrecognized(parsed_globalfile.options,   po::exclude_positional);
    11771199    const vector<string> unknown1 = collect_unrecognized(parsed_defaultfile.options,  po::exclude_positional);
    11781200    const vector<string> unknown2 = collect_unrecognized(parsed_priorityfile.options, po::exclude_positional);
    11791201
    11801202    fUnknownConfigfile.clear();
     1203    fUnknownConfigfile.insert(fUnknownConfigfile.end(), unknown0.begin(), unknown0.end());
    11811204    fUnknownConfigfile.insert(fUnknownConfigfile.end(), unknown1.begin(), unknown1.end());
    11821205    fUnknownConfigfile.insert(fUnknownConfigfile.end(), unknown2.begin(), unknown2.end());
     
    11861209    fUnknownDatabase    = collect_unrecognized(parsed_database.options, po::exclude_positional);
    11871210
    1188     // ------------------------ (15) -------------------------
     1211    // ------------------------ (16) -------------------------
    11891212
    11901213    if (result.count("print-options"))
Note: See TracChangeset for help on using the changeset viewer.