-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.c
57 lines (55 loc) · 1.47 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
52
53
54
55
56
57
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include "./options.h"
void read_options(
int argc,
char* argv[],
struct opts* opts
) {
opts->valid = false;
opts->input = DEFAULT;
opts->output = NONE;
int c;
while ((c = getopt(argc, argv, ":i:o:")) != -1) {
switch(c) {
case 'i':
if (strcmp("rdrand", optarg) == 0) {
opts->input = RDRAND;
} else if (strcmp("mrand48_r", optarg) == 0) {
opts->input = MRAND48_R;
} else if ('/' == optarg[0]) {
opts->input = SLASH_F;
opts->r_src = optarg;
} else {
break;
}
opts->valid = true;
break;
case 'o':
if (strcmp("stdout", optarg) == 0) {
opts->output = STDOUT;
} else {
opts->output = NUM;
opts->block_size = (atoi(optarg)) * 1024;
}
opts->valid = true;
break;
case ':':
break;
case '?':
break;
}
}
if (optind >= argc) {
return;
}
opts->nbytes = atol(argv[optind]);
if (opts->nbytes >= 0) {
opts->valid = true;
if (opts->output == NONE) {
opts->block_size = opts->nbytes;
}
}
}