-
Notifications
You must be signed in to change notification settings - Fork 0
/
pp.l
80 lines (69 loc) · 2.11 KB
/
pp.l
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
%{
#include <string>
#ifdef GCOMPILE
#define POPEN popen
#define PCLOSE pclose
#else
#define POPEN _popen
#define PCLOSE _pclose
#endif
%}
%option noyywrap
%x GOT_PP
%x GOT_PPS
%%
^!!PP {
BEGIN(GOT_PP);
}
^!!PPS {
BEGIN(GOT_PPS);
}
<GOT_PP>[^\n]* {
/*
we use popen() as output from system()
doesn't turn up where we want it
*/
FILE *pfp = POPEN(yytext, "r");
if (pfp != 0)
{
while (!feof(pfp) && !ferror(pfp))
{
int c = fgetc(pfp);
if (c != EOF)
putchar(c);
}
PCLOSE(pfp);
}
BEGIN(INITIAL);
}
<GOT_PPS>[^\n]* {
/*
we use popen() as output from system()
doesn't turn up where we want it
*/
FILE *pfp = POPEN(yytext, "r");
if (pfp != 0)
{
std::string res;
while (!feof(pfp) && !ferror(pfp))
{
int c = fgetc(pfp);
if (c != EOF)
{
char s[2];
s[0] = (char)c;
s[1] = 0;
res.append(s);
}
}
size_t resLen = res.length();
if (resLen > 0 && res[resLen-1] == '\n')
res = res.substr(0, resLen-1);
fprintf(stdout, "%s", res.c_str());
}
PCLOSE(pfp);
BEGIN(INITIAL);
}
. {
ECHO;
}