blob: 7cc45bab9e76ffa397fa929043523090b3e244b3 (
plain) (
blame)
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
|
/* te.c: error message control, input line count */
#include <string.h>
#include <stdlib.h>
#include "t.h"
void error(char *s)
{
fprintf(stderr, "\n%s:%d: %s\n", ifile, iline, s);
fprintf(stderr, "tbl quits\n");
exit(1);
}
char *gets1(char *s, int size)
{
char *ns;
int nbl;
iline++;
ns = s;
if (!fgets(s, size, tabin)) {
if (swapin() == 0)
return 0;
}
nbl = strlen(s);
if (s[nbl - 1] == '\n')
s[nbl - 1] = '\0'; /* remove the newline */
s += nbl - 2;
for (nbl = 0; s > ns && *s == '\\'; s--)
nbl++;
if (linstart && nbl % 2) /* fold escaped nl if in table */
gets1(s + 1, size - (s - ns));
return s;
}
#define BACKMAX 500
char backup[BACKMAX];
char *backp = backup;
void un1getc(int c)
{
if (c == '\n')
iline--;
*backp++ = c;
if (backp >= backup + BACKMAX)
error("too much backup");
}
int get1char(void)
{
int c;
if (backp > backup)
c = *--backp;
else
c = fgetc(tabin);
if (c == EOF) {
if (swapin() == 0)
error("unexpected EOF");
c = fgetc(tabin);
}
if (c == '\n')
iline++;
return c;
}
|