@@ -27,13 +27,16 @@ int main(int ac, char* av[])
27
27
{
28
28
try {
29
29
int opt;
30
+ string config_file;
30
31
31
32
// Declare a group of options that will be
32
33
// allowed only on command line
33
34
po::options_description generic (" Generic options" );
34
35
generic.add_options ()
35
36
(" version,v" , " print version string" )
36
- (" help" , " produce help message" )
37
+ (" help" , " produce help message" )
38
+ (" config,c" , po::value<string>(&config_file)->default_value (" multiple_sources.cfg" ),
39
+ " name of a file of a configuration." )
37
40
;
38
41
39
42
// Declare a group of options that will be
@@ -71,10 +74,19 @@ int main(int ac, char* av[])
71
74
po::variables_map vm;
72
75
store (po::command_line_parser (ac, av).
73
76
options (cmdline_options).positional (p).run (), vm);
74
-
75
- ifstream ifs (" multiple_sources.cfg" );
76
- store (parse_config_file (ifs, config_file_options), vm);
77
77
notify (vm);
78
+
79
+ ifstream ifs (config_file.c_str ());
80
+ if (!ifs)
81
+ {
82
+ cout << " can not open config file: " << config_file << " \n " ;
83
+ return 0 ;
84
+ }
85
+ else
86
+ {
87
+ store (parse_config_file (ifs, config_file_options), vm);
88
+ notify (vm);
89
+ }
78
90
79
91
if (vm.count (" help" )) {
80
92
cout << visible << " \n " ;
0 commit comments