-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
72 lines (62 loc) · 1.88 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
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include "parser.h"
void printHelp() {
std::cout
<< "Usage: dboc -o <OUTFILE> <INFILE>" << std::endl
<< "Parameter:" << std::endl
<< " -o <OUTFILE> Specifies the file, where we should output the source code" << std::endl
<< " <INFILE> Specifies the input file" << std::endl;
/**
* accept dboc -d <DIRECTORY> <SOURCE> ...
* DIRECTORY is target directory
* SOURCE is the source file, where each source file will be compiled to `basedir SOURCE`/dbo_`filename SOURCE`.cpp
**/
}
int main (int argc, char **argv)
{
char *outFile = NULL;
char *inFile = NULL;
int index;
int c;
opterr = 0;
while ((c = getopt (argc, argv, "ho:")) != -1)
switch (c)
{
case 'h':
printHelp();
abort();
case 'o':
outFile = optarg;
break;
case '?':
if (optopt == 'c')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
default:
abort ();
}
for (index = optind; index < argc; index++) {
inFile = argv[index];
}
if (inFile == NULL)
std::cerr << "No input file specified" << std::endl;
if (outFile == NULL)
std::cerr << "No output file specified" << std::endl;
try {
Parser parser(inFile);
parser.write(outFile);
} catch(const char * c) {
std::cerr << c << std::endl;
}
return 0;
}