blob: f997edfd8b5f02594e84cf816c5d46482ae4b119 (
plain)
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 <stdio.h>
static int was_space = 0;
static int first_char = 1;
static void put_char (int c)
{
if (c == '\n') {
if (!first_char) {
fputs ("\\n\"\n\"", stdout);
first_char = 1;
}
}
else {
first_char = 0;
if (c == '\\')
fputs ("\\\\", stdout);
else if (c == '\"')
fputs ("\\\"", stdout);
else if (!was_space || !(c == ' ' || c == '\t'))
fputc (c, stdout);
was_space = (c == ' ' || c == '\t');
}
}
int main (int argc, char *argv[])
{
int c;
FILE *f;
if (argc == 1)
return 1;
f = fopen (argv[1], "r");
if (f == NULL)
return 1;
fputs ("\n", stdout);
fputs ("/* DO NOT EDIT - THIS FILE IS AUTOMATICALLY GENERATED FROM THE .syn FILE */\n", stdout);
fputs ("\n", stdout);
fputs ("\"", stdout);
c = getc (f);
while (c != EOF) {
if (c == '/') {
int c2 = getc (f);
if (c2 == '*') {
was_space = 0;
c = getc (f);
for (;;) {
if (c == '*') {
c2 = getc (f);
if (c2 == '/')
break;
}
c = getc (f);
}
}
else {
put_char (c);
put_char (c2);
}
}
else {
put_char (c);
}
c = getc (f);
}
fputs ("\"\n", stdout);
fclose (f);
return 0;
}
|