-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.cc
64 lines (54 loc) · 1.99 KB
/
main.cc
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
#include "parser.h"
#include "handler.h"
#include "options.h"
#include <tclap/CmdLine.h>
#include <iostream>
#include <fstream>
#include <sstream>
//----------------------------------------------------------------------------------------------------
void print_usage()
{
std::cout << "Usage: inputFile" << std::endl;
}
//----------------------------------------------------------------------------------------------------
int main(int argc, char** argv)
{
Options options;
std::string inputFile;
try
{
using namespace TCLAP;
CmdLine cmd("Header Parser");
ValueArg<std::string> enumName("e", "enum", "The name of the enum macro", false, "ENUM", "", cmd);
ValueArg<std::string> className("c", "class", "The name of the class macro", false, "CLASS", "", cmd);
MultiArg<std::string> functionName("f", "function", "The name of the function macro", false, "", cmd);
ValueArg<std::string> propertyName("p", "property", "The name of the property macro", false, "PROPERTY", "", cmd);
MultiArg<std::string> customMacro("m", "macro", "Custom macro names to parse", false, "", cmd);
UnlabeledValueArg<std::string> inputFileArg("inputFile", "The file to process", true, "", "", cmd);
cmd.parse(argc, argv);
inputFile = inputFileArg.getValue();
options.classNameMacro = className.getValue();
options.enumNameMacro = enumName.getValue();
options.functionNameMacro = functionName.getValue();
options.customMacros = customMacro.getValue();
options.propertyNameMacro = propertyName.getValue();
}
catch (TCLAP::ArgException& e)
{
std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
return -1;
}
// Open from file
std::ifstream t(inputFile);
if (!t.is_open())
{
std::cerr << "Could not open " << inputFile << std::endl;
return -1;
}
std::stringstream buffer;
buffer << t.rdbuf();
Parser parser(options);
if (parser.Parse(buffer.str().c_str()))
std::cout << parser.result() << std::endl;
return 0;
}