-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
87 lines (69 loc) · 1.42 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
84
85
#include <stdio.h>
#include "pattern.h"
#include "ruleset.h"
#include "scratchpad.h"
#include "specfile.h"
#include "CSrcExporter.h"
void usage()
{
fprintf(stdout, "Usage: <-i file> <-o file> [-d]\n\n");
fprintf(stdout, " -i input spec file (required)\n");
fprintf(stdout, " -o output src file (required)\n");
fprintf(stdout, " -d output debug files (optional)\n");
}
int main(int argc, const char* argv[])
{
SpecFile specfile;
char input[256];
char output[256];
bool debug = false;
int i;
memset(input, 0, sizeof(input));
memset(output, 0, sizeof(output));
printf("argc = %d\n", argc);
for(i=1; i<argc; i++)
{
const char* arg = argv[i];
if (arg[0]!='-')
continue;
switch(arg[1])
{
case 'i':
if (argc > i+1)
strncpy(input, argv[i+1], sizeof(input)-1);
break;
case 'o':
if (argc > i+1)
strncpy(output, argv[i+1], sizeof(output)-1);
break;
case 'd':
debug = true;
break;
default:
fprintf(stderr, "WARNING: Unknown option \"%s\"\n", arg);
break;
}
}
if (strlen(input) == 0)
{
usage();
fprintf(stderr, "ERROR: No input spec file\n");
return -1;
}
else if (strlen(output) == 0)
{
usage();
fprintf(stderr, "ERROR: No output file\n");
}
else if (false == specfile.Load(input))
{
return -1;
}
if (debug)
{
specfile.SaveDot("tree.dot", true);
specfile.SaveDot("treeraw.dot", false);
}
specfile.Export(output);
return 0;
}