forked from samunders-core/le_disasm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.h
102 lines (84 loc) · 3.28 KB
/
options.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef LE_DISASM_OPTIONS_H_
#define LE_DISASM_OPTIONS_H_
#include <getopt.h>
#include <string>
class Options {
int verbose;
int version;
int help;
std::string binary_image_file;
std::string map_file;
std::string executable_file;
enum { DUMP_IMAGE = 4, MAP_FILE = 5 };
public:
Options(int argc, char **argv) {
verbose = 0;
version = 0;
help = 0;
binary_image_file = "";
map_file = "";
executable_file = "";
struct option long_options[] = {/* long options */
{"verbose", no_argument, &verbose, 1},
{"brief", no_argument, &verbose, 0},
{"version", no_argument, &version, 1},
{"help", no_argument, &help, 1},
{"dump-image", required_argument, 0, 'd'},
{"map-file", required_argument, 0, 'm'},
{0, 0, 0, 0}};
{
int c;
for (;;) {
int option_index = 0;
c = getopt_long(argc, argv, "vbhd:m:", long_options, &option_index);
if (c == -1) break;
switch (c) {
case 0:
/* If this option set a flag, do nothing else now. */
if (long_options[option_index].flag != 0) break;
switch (option_index) {
case DUMP_IMAGE:
binary_image_file = optarg ? std::string(optarg) : "";
break;
case MAP_FILE:
map_file = optarg ? std::string(optarg) : "";
break;
}
break;
case 'v':
version = 1;
break;
case 'b':
version = 0;
break;
case 'c':
help = 1;
break;
case 'd':
binary_image_file = optarg ? std::string(optarg) : "";
break;
case 'm':
map_file = optarg ? std::string(optarg) : "";
break;
case '?':
/* getopt_long already printed an error message. */
break;
default:
/* skip unknown options */
break;
}
}
if (optind < argc) {
/* only take one input file */
executable_file = std::string(argv[optind++]);
}
}
}
bool is_verbose() { return verbose ? true : false; }
bool is_help() { return help ? true : false; }
bool is_version() { return version ? true : false; }
std::string &get_map_file() { return map_file; }
std::string &get_binary_image_file() { return binary_image_file; }
std::string &get_executable_file() { return executable_file; }
};
#endif /* LE_DISASM_OPTIONS_H_ */