-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.cpp
111 lines (99 loc) · 2.19 KB
/
options.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
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
103
104
105
106
107
108
109
110
111
#include <string>
#include <iostream>
#include "kabilookup.h"
#include "options.h"
using namespace std;
options::options()
{
kb_flags = 0;
longopts[OPT_NODUPS] = "no-dups";
longopts[OPT_ARGS] = "args";
}
bool options::parse_long_opt(char *argstr)
{
unsigned i;
for (i = 0; i < OPT_COUNT; ++i)
if(string(++argstr) == longopts[i])
break;
switch (i) {
case OPT_NODUPS :
kb_flags |= KB_NODUPS;
break;
case OPT_ARGS :
kb_flags |= KB_ARGS;
break;
default :
return false;
}
return true;
}
int options::get_options(int *idx, char **argv,
string &declstr, string &datafile,
string &maskstr, string &pathstr)
{
int index = 0;
char *argstr;
for (index = 0; *argv[0] == '-'; ++index) {
int i;
// Point to the first character of the actual option
argstr = &(*argv++)[1];
if (*argstr == '-')
if(parse_long_opt(argstr))
continue;
for (i = 0; argstr[i]; ++i)
if (!parse_opt(argstr[i], &argv, declstr,
datafile, maskstr, pathstr))
return -1;
if (!*argv)
break;
}
*idx = index;
return kb_flags;
}
bool options::parse_opt(char opt, char ***argv,
string &declstr, string &datafile,
string& maskstr, std::string &pathstr)
{
switch (opt) {
case 'f' : datafile = *((*argv)++);
break;
case 'c' : kb_flags |= KB_COUNT;
declstr = *((*argv)++);
break;
case 'd' : kb_flags |= KB_DECL;
declstr = *((*argv)++);
break;
case 'e' : kb_flags |= KB_EXPORTS;
declstr = *((*argv)++);
break;
case 'l' : kb_flags |= KB_WHITE_LIST;
break;
case 'm' : kb_flags |= KB_MASKSTR;
maskstr = *((*argv)++);
break;
case 'p' : kb_flags |= KB_PATHSTR;
pathstr = *((*argv)++);
break;
case 'q' : kb_flags |= KB_QUIET;
kb_flags &= ~KB_VERBOSE;
bump_qietlvl();
break;
case 's' : kb_flags |= KB_STRUCT;
declstr = *((*argv)++);
break;
case 'v' : kb_flags |= KB_VERBOSE;
kb_flags &= ~KB_QUIET;
break;
case 'w' : kb_flags |= KB_WHOLE_WORD;
break;
case 'h' : cout << lookup::get_version();
cout << lookup::get_helptext();
exit(0);
case 'V' : cout << lookup::get_version();
exit(0);
case '1' : kb_flags |= KB_JUSTONE;
break;
default : return false;
}
return true;
}