blob: 5d1d00ca6194c97a606705320965fad06ecde1e5 (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#include "../preproc/preproc.h"
#include "../preproc/pproto.h"
int *first_char;
int *next_char;
int *last_char;
/*
* fill_cbuf - fill the current character buffer.
*/
void fill_cbuf()
{
register int c1, c2, c3;
register int *s;
register int *l;
int c;
int line;
int changes;
struct char_src *cs;
FILE *f;
cs = src_stack->u.cs;
f = cs->f;
s = cs->char_buf;
l = cs->line_buf;
if (next_char == NULL) {
/*
* Initial filling of buffer.
*/
first_char = cs->char_buf;
last_char = first_char + cs->bufsize - 3;
cs->last_char = last_char;
line = 1;
/*
* Get initial read-ahead.
*/
if ((c2 = getc(f)) != EOF)
c3 = getc(f);
}
else if (*next_char == EOF)
return;
else {
/*
* The calling routine needs at least 2 characters, so there is one
* left in the buffer.
*/
*s++= *next_char;
line = cs->line_buf[next_char - first_char];
*l++ = line;
/*
* Retrieve the 2 read-ahead characters that were saved the last
* time the buffer was filled.
*/
c2 = last_char[1];
c3 = last_char[2];
}
next_char = first_char;
/*
* Fill buffer from input file.
*/
while (s <= last_char) {
c1 = c2;
c2 = c3;
c3 = getc(f);
/*
* The first phase of input translation is done here: trigraph
* translation and the deletion of backslash-newline pairs.
*/
changes = 1;
while (changes) {
changes = 0;
/*
* check for trigraphs
*/
if (c1 == '?' && c2 == '?') {
c = ' ';
switch (c3) {
case '=':
c = '#';
break;
case '(':
c = '[';
break;
case '/':
c = '\\';
break;
case ')':
c = ']';
break;
case '\'':
c = '^';
break;
case '<':
c = '{';
break;
case '!':
c = '|';
break;
case '>':
c = '}';
break;
case '-':
c = '~';
break;
}
/*
* If we found a trigraph, use it and refill the 2-character
* read-ahead.
*/
if (c != ' ') {
c1 = c;
if ((c2 = getc(f)) != EOF)
c3 = getc(f);
changes = 1;
}
}
/*
* delete backslash-newline pairs
*/
if (c1 == '\\' && c2 == '\n') {
++line;
if ((c1 = c3) != EOF)
if ((c2 = getc(f)) != EOF)
c3 = getc(f);
changes = 1;
}
}
if (c1 == EOF) {
/*
* If last character in file is not a new-line, insert one.
*/
if (s == first_char || s[-1] != '\n')
*s++ = '\n';
*s = EOF;
last_char = s;
cs->last_char = last_char;
return;
}
if (c1 == '\n')
++line;
*s++ = c1; /* put character in buffer */
*l++ = line;
}
/*
* Save the 2 character read-ahead in the reserved space at the end
* of the buffer.
*/
last_char[1] = c2;
last_char[2] = c3;
}
|