-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdline.cpp
72 lines (56 loc) · 1.62 KB
/
cmdline.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
// this file contains the commandline parser for phantom
//
// (C) Markus Dittrich, 2015
#include <getopt.h>
#include <iostream>
#include "cmdline.hpp"
#include "util.hpp"
// long_options for getopt_long command line parsing
static struct option long_options[] = {
{"num_threads", required_argument, NULL, 'n'},
{"compare", required_argument, NULL, 'c'},
{"digest", required_argument, NULL, 'd'},
{"collect_stats", no_argument, NULL, 's'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
// parse_cmdline parses any provided command line arguments and uses this
// information to populate a CmdLinOpts struct.
struct CmdLineOpts parse_cmdline(int argc, char** argv) {
struct CmdLineOpts cmdOpts;
int c;
long nthreads;
while ((c = getopt_long (argc, argv, "n:c:d:sh", long_options, NULL)) != -1) {
switch(c) {
case 'n':
nthreads = strtol(optarg, NULL, 10);
if (nthreads == 0) {
error("incorrect number of threads specified on command line");
}
cmdOpts.numThreads = nthreads;
break;
case 'c':
cmdOpts.compareToRef = true;
cmdOpts.referenceFilePath = optarg;
break;
case 's':
cmdOpts.collectStats = true;
break;
case 'd':
cmdOpts.hashMethod = optarg;
if (cmdOpts.hashMethod != "md5" && cmdOpts.hashMethod != "sha1"
&& cmdOpts.hashMethod != "ripemd160") {
error("unknown hash method.");
}
break;
case 'h':
default :
usage();
}
}
if (argc == optind) {
usage();
}
cmdOpts.rootPath = argv[optind];
return cmdOpts;
}