-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.c
52 lines (47 loc) · 1.06 KB
/
options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "options.h"
options_t options_parse(int argc, char *argv[]) {
assert(argc > 1);
options_t opts;
opts.outfile = NULL;
opts.errfile = NULL;
opts.target = NULL;
opts.json = 0;
opts.child_args = NULL;
int i;
for (i = 1; i < argc; i++) {
switch((int)argv[i][0]) {
case '-':
switch((int)argv[i][1]) {
case 'o':
if (argv[i + 1][0] != '-') {
opts.outfile = &argv[i + 1][0];
}
break;
case 'e':
if (argv[i + 1][0] != '-') {
opts.errfile = &argv[i + 1][0];
}
break;
case 'j':
opts.json = 1;
break;
case '-':
if (argv[i + 1] != NULL) {
opts.target = &argv[i + 1][0];
opts.child_args = &argv[i + 1];
return opts;
}
break;
default:
break;
}
break;
default:
break;
}
}
return opts;
}