-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
85 lines (65 loc) · 1.7 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* main.cpp
* Entry point
* Created on: 10-Dec-2017 12:18
* Original author: skyfox69
*/
#include "util/xmlfile.h"
#include "util/codegenerator.h"
#include <iostream>
#include "unistd.h"
std::string classToParse;
std::string inputFileName;
std::string outputPathName;
/*---------------------------------------------------------------------------*/
void usage() {
std::cout << "usage: niflib_gen [options] <XML-fileName> <target-directory>" << std::endl
<< "Copyright (c) 2018 by Skyfox69" << std::endl << std::endl
<< " options:" << std::endl
<< " -c<name>\tgenerate class <name>" << std::endl
<< " -h\t\tshow help (this text)" << std::endl
<< std::endl;
}
/*---------------------------------------------------------------------------*/
bool decodeParameters(int argc, char** argv) {
int params(argc);
int c(0);
if (argc < 3) {
return false;
}
outputPathName = argv[argc - 1];
inputFileName = argv[argc - 2];
argc -= 2;
while ((c = getopt(argc, argv, "c:h")) != -1) {
switch (c) {
case 'c':
if (*optarg == 0) {
return false;
}
classToParse = optarg;
--params;
break;
case 'h':
default:
return false;
}
}
return true;
}
/*---------------------------------------------------------------------------*/
int main(int argc, char** argv) {
if (!decodeParameters(argc, argv)) {
usage();
return -1;
}
// read XML file
niflib_gen::XMLFile xmlFile;
if (!xmlFile.readFile(inputFileName)) {
std::cout << "error reading XML file '" << inputFileName << "'" << std::endl;
return -1;
}
// generate code
niflib_gen::CodeGenerator codeGenerator(outputPathName);
codeGenerator.generateFromXmlFile(&xmlFile, classToParse);
return 0;
}