1 |
#include <stdio.h>
|
2 |
#include <stdlib.h>
|
3 |
#include <getopt.h>
|
4 |
|
5 |
#include "FOArgs.h"
|
6 |
|
7 |
void parse_foargs( int argc, char** argv, FOFlags &flags ) {
|
8 |
|
9 |
int c;
|
10 |
int digit_optind = 0;
|
11 |
|
12 |
while (1) {
|
13 |
int this_option_optind = optind ? optind : 1;
|
14 |
int option_index = 0;
|
15 |
static struct option long_options[] = {
|
16 |
{"inputfile", 1, 0, 'a'},
|
17 |
{"outputfile", 1, 0, 'b'},
|
18 |
{"outdir", 1, 0, 'c'},
|
19 |
{"mc", 0, 0, 'd'},
|
20 |
{"debug", 0, 0, 'e'},
|
21 |
{"era", 0, 0, 'f'},
|
22 |
{"inputdir", 1, 0, 'g'},
|
23 |
{"mufakedir", 1, 0, 'h'},
|
24 |
{"elefakedir", 1, 0, 'i'},
|
25 |
{"faketype", 1, 0, 'j'},
|
26 |
{"config", 1, 0, 'k'},
|
27 |
{"efftype", 1, 0, 'l'},
|
28 |
{"inputfiles", 1, 0, 'm'},
|
29 |
{0, 0, 0, 0}
|
30 |
};
|
31 |
|
32 |
c = getopt_long (argc, argv, "a:b:",
|
33 |
long_options, &option_index);
|
34 |
if (c == -1)
|
35 |
break;
|
36 |
|
37 |
switch (c) {
|
38 |
case 0:
|
39 |
printf ("option %s", long_options[option_index].name);
|
40 |
if (optarg)
|
41 |
printf (" with arg %s", optarg);
|
42 |
printf ("\n");
|
43 |
break;
|
44 |
|
45 |
case 'a':
|
46 |
flags.inputfile = std::string(optarg);
|
47 |
break;
|
48 |
case 'b':
|
49 |
flags.outputfile = std::string(optarg);
|
50 |
break;
|
51 |
case 'c':
|
52 |
flags.outdir = TString(optarg);
|
53 |
break;
|
54 |
case 'd':
|
55 |
flags.mc = true;
|
56 |
break;
|
57 |
case 'e':
|
58 |
flags.debug = true;
|
59 |
break;
|
60 |
case 'f':
|
61 |
flags.era = atoi(optarg);
|
62 |
break;
|
63 |
case 'g':
|
64 |
flags.inputdir = std::string(optarg);
|
65 |
break;
|
66 |
case 'h':
|
67 |
flags.mufakedir = std::string(optarg);
|
68 |
break;
|
69 |
case 'i':
|
70 |
flags.elefakedir = std::string(optarg);
|
71 |
break;
|
72 |
case 'j':
|
73 |
flags.faketype = std::string(optarg);
|
74 |
break;
|
75 |
case 'k':
|
76 |
flags.config = std::string(optarg);
|
77 |
break;
|
78 |
case 'l':
|
79 |
flags.efftype = std::string(optarg);
|
80 |
break;
|
81 |
case 'm':
|
82 |
flags.inputfiles = std::string(optarg);
|
83 |
break;
|
84 |
case '2':
|
85 |
if (digit_optind != 0 && digit_optind != this_option_optind)
|
86 |
printf ("digits occur in two different argv-elements.\n");
|
87 |
digit_optind = this_option_optind;
|
88 |
printf ("option %c\n", c);
|
89 |
break;
|
90 |
|
91 |
|
92 |
case '?':
|
93 |
break;
|
94 |
|
95 |
default:
|
96 |
printf ("?? getopt returned character code 0%o ??\n", c);
|
97 |
}
|
98 |
}
|
99 |
|
100 |
if (optind < argc) {
|
101 |
printf ("non-option ARGV-elements: ");
|
102 |
while (optind < argc)
|
103 |
printf ("%s ", argv[optind++]);
|
104 |
printf ("\n");
|
105 |
}
|
106 |
|
107 |
|
108 |
}
|