00001
00002
00003
00004 #include "ug_get_options.h"
00005 #include <fstream>
00006
00007 #include <string>
00008 #include <iostream>
00009
00010 namespace ugdiss
00011 {
00012 using namespace std;
00013
00014 void
00015 get_options(int ac, char* av[], progopts& o, posopts& a, optsmap& vm,
00016 char const* cfgFileParam)
00017 {
00018
00019 po::store(po::command_line_parser(ac,av).options(o).run(),vm);
00020
00021 if (cfgFileParam && vm.count(cfgFileParam))
00022 {
00023 string cfgFile = vm[cfgFileParam].as<string>();
00024 if (!cfgFile.empty())
00025 {
00026 if (!access(cfgFile.c_str(),F_OK))
00027 {
00028 ifstream cfg(cfgFile.c_str());
00029 po::store(po::parse_config_file(cfg,o),vm);
00030 }
00031 else
00032 {
00033 cerr << "Error: cannot find config file '"
00034 << cfgFile << "'!" << endl;
00035 exit(1);
00036 }
00037 }
00038 }
00039
00040
00041 if (a.max_total_count())
00042 po::store(po::command_line_parser(ac,av)
00043 .options(o).positional(a).run(),vm);
00044 po::notify(vm);
00045 }
00046 }