-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.cpp
66 lines (54 loc) · 1.52 KB
/
main.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
#include "ResourcesParser.h"
#include "ResourcesParserInterpreter.h"
#include <iostream>
#include <sstream>
using namespace std;
int findArgvIndex(const char* argv, char *argvs[], int count);
const char* getArgv(const char* argv, char *argvs[], int count);
void printHelp();
int main(int argc, char *argv[]) {
const char* path = getArgv("-p", argv, argc);
const char* type = getArgv("-t", argv, argc);
const char* id = getArgv("-i", argv, argc);
int all = findArgvIndex("-a", argv, argc);
if(nullptr == path) {
printHelp();
return -1;
} else if(getArgv("-h", argv, argc) != nullptr) {
printHelp();
}
ResourcesParser parser(path);
ResourcesParserInterpreter interpreter(&parser);
if(all >= 0) {
interpreter.parserResource(ResourcesParserInterpreter::ALL_TYPE);
}
if(type) {
interpreter.parserResource(type);
}
if(id) {
interpreter.parserId(id);
}
return 0;
}
int findArgvIndex(const char* argv, char *argvs[], int count) {
for(int i = 0 ; i<count ; i++) {
if(strcmp(argv, argvs[i])==0) {
return i;
}
}
return -1;
}
const char* getArgv(const char* argv, char *argvs[], int count) {
int index = findArgvIndex(argv, argvs, count);
if(index>=0 && index+1 < count) {
return argvs[index+1];
}
return nullptr;
}
void printHelp() {
cout <<"rp -p path [-a] [-t type] [-i id]" <<endl<<endl;
cout <<"-p : set path of resources.arsc" <<endl;
cout <<"-a : show all of resources.arsc" <<endl;
cout <<"-t : select the type in resources.arsc to show" <<endl;
cout <<"-i : select the id of resource to show" <<endl;
}