1 |
#include <stdio.h>
|
2 |
#include <stdlib.h>
|
3 |
#include <getopt.h>
|
4 |
|
5 |
#include "ZeeTreeWriterArgs.h"
|
6 |
|
7 |
void parse_zee_tree_writer_args(int argc, char** argv, ZeeTreeWriterFlags &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 |
{"catalogDir", 1, 0, 'a'},
|
17 |
{"book", 1, 0, 'b'},
|
18 |
{"dataset", 1, 0, 'c'},
|
19 |
{"fileset", 1, 0, 'd'},
|
20 |
{"output_filename", 1, 0, 'e'},
|
21 |
{"is_data", 1, 0, 'f'},
|
22 |
{"n_events_to_process", 1, 0, 'g'},
|
23 |
{"rho", 1, 0, 'h'},
|
24 |
{"electron_id", 1, 0, 'i'},
|
25 |
{"json", 1, 0, 'j'},
|
26 |
{"trigger", 1, 0, 'k'},
|
27 |
{0, 0, 0, 0}
|
28 |
};
|
29 |
|
30 |
c = getopt_long (argc, argv, "a:b:",
|
31 |
long_options, &option_index);
|
32 |
if (c == -1)
|
33 |
break;
|
34 |
|
35 |
switch (c) {
|
36 |
case 0:
|
37 |
printf ("option %s", long_options[option_index].name);
|
38 |
if (optarg)
|
39 |
printf (" with arg %s", optarg);
|
40 |
printf ("\n");
|
41 |
break;
|
42 |
|
43 |
case 'a':
|
44 |
flags.catalogDir = string(optarg);
|
45 |
break;
|
46 |
case 'b':
|
47 |
flags.book = string(optarg);
|
48 |
break;
|
49 |
case 'c':
|
50 |
flags.dataset = string(optarg);
|
51 |
break;
|
52 |
case 'd':
|
53 |
flags.fileset = string(optarg);
|
54 |
break;
|
55 |
case 'e':
|
56 |
flags.output_filename = string(optarg);
|
57 |
break;
|
58 |
case 'f':
|
59 |
flags.is_data = atoi(optarg);
|
60 |
break;
|
61 |
case 'g':
|
62 |
flags.n_events_to_process = atoi(optarg);
|
63 |
break;
|
64 |
case 'h':
|
65 |
flags.rho = string(optarg);
|
66 |
break;
|
67 |
case 'i':
|
68 |
flags.electron_id = string(optarg);
|
69 |
break;
|
70 |
case 'j':
|
71 |
flags.json = string(optarg);
|
72 |
break;
|
73 |
case 'k':
|
74 |
flags.trigger = string(optarg);
|
75 |
break;
|
76 |
case '2':
|
77 |
if (digit_optind != 0 && digit_optind != this_option_optind)
|
78 |
printf ("digits occur in two different argv-elements.\n");
|
79 |
digit_optind = this_option_optind;
|
80 |
printf ("option %c\n", c);
|
81 |
break;
|
82 |
|
83 |
|
84 |
case '?':
|
85 |
break;
|
86 |
|
87 |
default:
|
88 |
printf ("?? getopt returned character code 0%o ??\n", c);
|
89 |
}
|
90 |
}
|
91 |
|
92 |
if (optind < argc) {
|
93 |
printf ("non-option ARGV-elements: ");
|
94 |
while (optind < argc)
|
95 |
printf ("%s ", argv[optind++]);
|
96 |
printf ("\n");
|
97 |
}
|
98 |
|
99 |
|
100 |
}
|