blob: 8cd091b017a259f2416a9a2ef1afca5f00b76cef (
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
158
159
160
161
162
163
164
165
166
167
168
169
|
/*
*
* debugger
*
*/
#include "defs.h"
#include "fns.h"
Rune line[LINSIZ];
extern int infile;
Rune *lp;
int peekc,lastc = EOR;
int eof;
/* input routines */
int
eol(int c)
{
return(c==EOR || c==';');
}
int
rdc(void)
{
do {
readchar();
} while (lastc==SPC || lastc==TB);
return(lastc);
}
void
reread(void)
{
peekc = lastc;
}
void
clrinp(void)
{
flush();
lp = 0;
peekc = 0;
}
int
readrune(int fd, Rune *r)
{
char buf[UTFmax];
int i;
for(i=0; i<UTFmax && !fullrune(buf, i); i++)
if(read(fd, buf+i, 1) <= 0)
return -1;
chartorune(r, buf);
return 1;
}
int
readchar(void)
{
Rune *p;
if (eof)
lastc=0;
else if (peekc) {
lastc = peekc;
peekc = 0;
}
else {
if (lp==0) {
for (p = line; p < &line[LINSIZ-1]; p++) {
eof = readrune(infile, p) <= 0;
if (mkfault) {
eof = 0;
error(0);
}
if (eof) {
p--;
break;
}
if (*p == EOR) {
if (p <= line)
break;
if (p[-1] != '\\')
break;
p -= 2;
}
}
p[1] = 0;
lp = line;
}
if ((lastc = *lp) != 0)
lp++;
}
return(lastc);
}
int
nextchar(void)
{
if (eol(rdc())) {
reread();
return(0);
}
return(lastc);
}
int
quotchar(void)
{
if (readchar()=='\\')
return(readchar());
else if (lastc=='\'')
return(0);
else
return(lastc);
}
void
getformat(char *deformat)
{
char *fptr;
BOOL quote;
Rune r;
fptr=deformat;
quote=FALSE;
while ((quote ? readchar()!=EOR : !eol(readchar()))){
r = lastc;
fptr += runetochar(fptr, &r);
if (lastc == '"')
quote = ~quote;
}
lp--;
if (fptr!=deformat)
*fptr = '\0';
}
/*
* check if the input line if of the form:
* <filename>:<digits><verb> ...
*
* we handle this case specially because we have to look ahead
* at the token after the colon to decide if it is a file reference
* or a colon-command with a symbol name prefix.
*/
int
isfileref(void)
{
Rune *cp;
for (cp = lp-1; *cp && !strchr(CMD_VERBS, *cp); cp++)
if (*cp == '\\' && cp[1]) /* escape next char */
cp++;
if (*cp && cp > lp-1) {
while (*cp == ' ' || *cp == '\t')
cp++;
if (*cp++ == ':') {
while (*cp == ' ' || *cp == '\t')
cp++;
if (isdigit(*cp))
return 1;
}
}
return 0;
}
|