-
Notifications
You must be signed in to change notification settings - Fork 0
/
pp.cpp
72 lines (56 loc) · 1.23 KB
/
pp.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 <cstdio>
#include <string>
#pragma warning (disable: 4996)
void usage();
char *progname = 0;
extern FILE *yyin;
int yylex (void);
int main (int argc, char *argv[])
{
progname = argv[0];
bool firstArgIsOption = false;
if (argc == 2)
{
firstArgIsOption = (argv[1][0] == '-');
}
else
{
usage();
return 1;
}
std::string inputFile = argv[1];
if (firstArgIsOption)
{
switch (argv[1][1])
{
case 'h':
default:
usage();
return 1;
}
inputFile = argv[2];
}
FILE *fp = fopen(inputFile.c_str(), "rt");
if (fp == 0)
{
std::string msg = progname;
msg += " error opening ";
msg += argv[1];
perror(msg.c_str());
return 2;
}
yyin = fp;
yylex();
fclose(fp);
return 0;
}
void usage()
{
fprintf(stderr, "%s filename\n", progname);
fprintf(stderr,
"copies filename to stdout, replacing lines \n"
"starting with !!PPcmd with the results of \n"
"running _popen(cmd)\n\n"
"use !!PPS in your input file to supress the \n"
"newline at the end of cmd output.\n");
}