- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
Latest commit
60 lines (48 loc) · 1.35 KB
/
Copy pathmain.cpp
File metadata and controls
60 lines (48 loc) · 1.35 KB
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
52
53
54
55
56
57
58
59
60
extern"C" {
#include<argp.h>
}
#include<cstdio>
#include<cstdlib>
#include"UserMount.hpp"
error_tparse_arg(int key, char *arg, structargp_state *state) {
Options *output = (Options*)state->input;
switch (key) {
case't':
output->time = atoi(arg);
break;
case'n':
output->net = true;
caseARGP_KEY_ARG:
if (state->arg_num == 0)
output->program = arg;
else
output->args.push_back(arg);
break;
default:
returnARGP_ERR_UNKNOWN;
}
return0;
}
Options processOptions(int argc, char **argv) {
structargp parser;
structargp_option options[3];
Options result = { 0 };
options[0] = {"time", 't', "limit", 0, "Execution time allowed"};
options[1] = {"network", 'n', NULL, 0, "Allow network access"};
options[2] = { 0 };
parser = {options, parse_arg, "command args..."};
argp_parse(&parser, argc, argv, 0, NULL, &result);
return result;
}
voidtest_args(Options *opts) {
printf("Run %s for %u seconds with %i network acess with arguments \n",
opts->program, opts->time, opts->net);
}
intmain(int argc, char **argv) {
Options opts = processOptions(argc, argv);
test_args(&opts);
UserMount um(opts);
um.start();
um.wait();
exit(0);
}