initial port of plan9 troff to linux
[troff.git] / tbl / te.c
blob77dcaf225eb1649eaba4dfd940646d3bd7f616f0
1 /* te.c: error message control, input line count */
2 #include <string.h>
3 #include "t.h"
5 void error(char *s)
7 fprintf(stderr, "\n%s:%d: %s\n", ifile, iline, s);
8 fprintf(stderr, "tbl quits\n");
9 exit(1);
12 char *gets1(char *s, int size)
14 char *ns;
15 int nbl;
17 iline++;
18 ns = s;
19 if (!fgets(s, size, tabin)) {
20 if (swapin() == 0)
21 return 0;
23 nbl = strlen(s);
24 s[nbl - 1] = '\0'; /* remove the newline */
25 s += nbl - 1;
26 for (nbl = 0; *s == '\\' && s > ns; s--)
27 nbl++;
28 if (linstart && nbl % 2) /* fold escaped nl if in table */
29 gets1(s + 1, size - (s - ns));
31 return s;
35 #define BACKMAX 500
36 char backup[BACKMAX];
37 char *backp = backup;
39 void un1getc(int c)
41 if (c == '\n')
42 iline--;
43 *backp++ = c;
44 if (backp >= backup + BACKMAX)
45 error("too much backup");
49 int get1char(void)
51 int c;
52 if (backp > backup)
53 c = *--backp;
54 else
55 c = fgetc(tabin);
56 if (c == EOF) {
57 if (swapin() == 0)
58 error("unexpected EOF");
59 c = fgetc(tabin);
61 if (c == '\n')
62 iline++;
63 return c;