-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessor.c
More file actions
56 lines (47 loc) · 1.2 KB
/
Copy pathpreprocessor.c
File metadata and controls
56 lines (47 loc) · 1.2 KB
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
#include <stdio.h>
void preprocess(char *input, char *output)
{
FILE *fp1 = fopen(input, "r");
FILE *fp2 = fopen(output, "w");
char ch, next;
int in_comment = 0;
while ((ch = fgetc(fp1)) != EOF)
{
/* Remove preprocessor lines */
if (ch == '#')
{
while ((ch = fgetc(fp1)) != '\n');
continue;
}
/* Remove comments */
if (ch == '/')
{
next = fgetc(fp1);
/* single-line comment */
if (next == '/')
{
while ((ch = fgetc(fp1)) != '\n');
continue;
}
/* multi-line comment */
if (next == '*')
{
while (1)
{
ch = fgetc(fp1);
next = fgetc(fp1);
if (ch == '*' && next == '/')
break;
}
continue;
}
/* not a comment */
fputc(ch, fp2);
fputc(next, fp2);
continue;
}
fputc(ch, fp2);
}
fclose(fp1);
fclose(fp2);
}