Ignore:
Timestamp:
07/20/11 10:27:17 (13 years ago)
Author:
tbretz
Message:
Added a registry for wildcarded options to detect unaccessed options; for this EvalConfiguration(const Configuration&) has been changed to EvalOptions(Configuration&)
File:
1 edited

Legend:

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

    r11481 r11483  
    528528        ("print-unknown",       "Print unrecognized options.")
    529529        ("print-options",       "Print options as passed to program.")
     530        ("print-wildcards",     "Print all options registered with wildcards.")
    530531        ("dont-check",          "Do not check validity of options from files and database.")
    531532        ("dont-check-files",    "Do not check validity of options from files.")
     
    591592        //for (int j=0; j<options[i].value.size(); j++)
    592593        //    cout << "\t = " << options[i].value[j];
    593 
    594         //cout << "/" << options[i].position_key;
    595594        //cout << "/" << options[i].original_tokens[0];
    596         //cout << "/" << options[i].unregistered << endl;
     595
     596        ostringstream com;
     597
     598        if (opt.position_key>=0)
     599            com << " [position=" << opt.position_key << "]";
    597600        if (opt.unregistered)
    598             cout << "   # option unknown";
     601            com << " [unregistered]";
     602
     603        if (!com.str().empty())
     604            cout << "  # " << com.str();
     605
    599606        cout << endl;
    600607    }
     
    963970//!         options from the default configuration-file and options
    964971//!         from the environment.
    965 //!  - (15) Finally all options which were found and flagged as unrecognized,
     972//!  - (15) Find all options which were found and flagged as unrecognized,
    966973//!         because they are not in the user-defined list of described
    967974//!         options, are collected and stored in the corresponding
    968975//!         data-members.
    969 //!  - (16) Before the function returns it check for \b --print-options
     976//!  - (16) Find all options which where registered with wildcards and
     977//!         store the list in fWildcardOptions.
     978//!  - (17) Before the function returns it check for \b --print-options
    970979//!         and \b --print-unknown and performs the corresponding actions.
    971980//!
     
    10581067    const string globalfile = path.parent_path().string()+"/fact++.rc";
    10591068
    1060     cerr << "Reading options from '" << globalfile << "'." << endl;
     1069    cerr << "Reading global  options from '" << globalfile << "'." << endl;
    10611070
    10621071    ifstream gfile(globalfile.c_str());
     
    10731082    {
    10741083        fDefaultFile = getfiles["default"].as<string>();
    1075         cerr << "Reading options from '" << fDefaultFile << "'." << endl;
     1084        cerr << "Reading default options from '" << fDefaultFile << "'." << endl;
    10761085    }
    10771086
     
    11091118    {
    11101119        fPriorityFile = getfiles["config"].as<string>();
    1111         cerr << "Reading options from '" << fPriorityFile << "'." << endl;
     1120        cerr << "Reading config options from '" << fPriorityFile << "'." << endl;
    11121121    }
    11131122
     
    12081217    // ------------------------ (16) -------------------------
    12091218
     1219    CreateWildcardOptions();
     1220
     1221    // ------------------------ (17) -------------------------
     1222
    12101223    if (result.count("print-options"))
    12111224        PrintOptions();
    12121225
     1226    if (result.count("print-wildcards"))
     1227        PrintWildcardOptions();
     1228
    12131229    if (result.count("print-unknown"))
    12141230        PrintUnknown();
    12151231
    12161232    return fVariables;
     1233}
     1234
     1235// --------------------------------------------------------------------------
     1236//
     1237//! Create a list of all options which were registered using wildcards
     1238//!
     1239void Configuration::CreateWildcardOptions()
     1240{
     1241    po::options_description opts;
     1242
     1243    for (int i=0; i<2; i++)
     1244    {
     1245        opts.add(fOptionsCommandline[i]);
     1246        opts.add(fOptionsConfigfile[i]);
     1247        opts.add(fOptionsEnvironment[i]);
     1248        opts.add(fOptionsDatabase[i]);
     1249    }
     1250
     1251    fWildcardOptions.clear();
     1252
     1253    typedef map<string,po::variable_value> Vars;
     1254    typedef vector<boost::shared_ptr<po::option_description>> Descs;
     1255
     1256    const Descs &desc = opts.options();
     1257
     1258    for (Vars::const_iterator io=fVariables.begin(); io!=fVariables.end(); io++)
     1259    {
     1260        for (Descs::const_iterator id=desc.begin(); id!=desc.end(); id++)
     1261            if ((*id)->match(io->first, false, false, false)==po::option_description::approximate_match)
     1262                fWildcardOptions[io->first] = (*id)->long_name();
     1263    }
     1264}
     1265
     1266// --------------------------------------------------------------------------
     1267//
     1268//! Print a list of all options which were registered using wildcards and
     1269//! have not be registered subsequently by access.
     1270//!
     1271void Configuration::PrintWildcardOptions() const
     1272{
     1273    cout << "Options registered with wildcards and not yet accessed:" << endl;
     1274
     1275    size_t max = 0;
     1276    for (map<string,string>::const_iterator it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
     1277        if (it->second.length()>max)
     1278            max = it->second.length();
     1279
     1280    cout.setf(ios_base::left);
     1281    for (map<string,string>::const_iterator it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
     1282        cout << setw(max+1) << it->second << " : " << it->first <<endl;
    12171283}
    12181284
Note: See TracChangeset for help on using the changeset viewer.