xref: /original-bsd/old/tbl/te.c (revision bdc0a208)
1 /*-
2  * %sccs.include.proprietary.c%
3  */
4 
5 #ifndef lint
6 static char sccsid[] = "@(#)te.c	4.3 (Berkeley) 04/18/91";
7 #endif /* not lint */
8 
9  /* te.c: error message control, input line count */
10 # include "t..c"
11 error(s)
12 	char *s;
13 {
14 fprintf(stderr, "\n%s: line %d: %s\n", ifile, iline, s);
15 # ifdef unix
16 fprintf(stderr, "tbl quits\n");
17 exit(1);
18 # endif
19 # ifdef gcos
20 fprintf(stderr, "run terminated due to error condition detected by tbl preprocessor\n");
21 exit(0);
22 # endif
23 }
24 gets1(s)
25 	char *s;
26 {
27 char *p;
28 int nbl = 0;
29 iline++;
30 p=fgets(s,BUFSIZ,tabin);
31 while (p==0)
32 	{
33 	if (swapin()==0)
34 		return(0);
35 	p = fgets(s,BUFSIZ,tabin);
36 	}
37 
38 while (*s) s++;
39 s--;
40 if (*s == '\n') *s-- =0;
41 for(nbl=0; *s == '\\' && s>p; s--)
42 	nbl++;
43 if (linstart && nbl % 2) /* fold escaped nl if in table */
44 	gets1(s+1);
45 
46 return(p);
47 }
48 # define BACKMAX 500
49 char backup[BACKMAX];
50 char *backp = backup;
51 un1getc(c)
52 {
53 if (c=='\n')
54 	iline--;
55 *backp++ = c;
56 if (backp >= backup+BACKMAX)
57 	error("too much backup");
58 }
59 get1char()
60 {
61 int c;
62 if (backp>backup)
63 	c = *--backp;
64 else
65 	c=getc(tabin);
66 if (c== EOF) /* EOF */
67 	{
68 	if (swapin() ==0)
69 		error("unexpected EOF");
70 	c = getc(tabin);
71 	}
72 if (c== '\n')
73 	iline++;
74 return(c);
75 }
76