te.c (1069B)
1 /* te.c: error message control, input line count */ 2 # include "t.h" 3 4 void 5 error(char *s) 6 { 7 fprint(2, "\n%s:%d: %s\n", ifile, iline, s); 8 fprint(2, "tbl quits\n"); 9 exits(s); 10 } 11 12 13 char * 14 gets1(char *s, int size) 15 { 16 char *p, *ns; 17 int nbl; 18 19 iline++; 20 ns = s; 21 p = Brdline(tabin, '\n'); 22 while (p == 0) { 23 if (swapin() == 0) 24 return(0); 25 p = Brdline(tabin, '\n'); 26 } 27 nbl = Blinelen(tabin)-1; 28 if(nbl >= size) 29 error("input buffer too small"); 30 p[nbl] = 0; 31 strcpy(s, p); 32 s += nbl; 33 for (nbl = 0; *s == '\\' && s > ns; s--) 34 nbl++; 35 if (linstart && nbl % 2) /* fold escaped nl if in table */ 36 gets1(s + 1, size - (s-ns)); 37 38 return(p); 39 } 40 41 42 # define BACKMAX 500 43 char backup[BACKMAX]; 44 char *backp = backup; 45 46 void 47 un1getc(int c) 48 { 49 if (c == '\n') 50 iline--; 51 *backp++ = c; 52 if (backp >= backup + BACKMAX) 53 error("too much backup"); 54 } 55 56 57 int 58 get1char(void) 59 { 60 int c; 61 if (backp > backup) 62 c = *--backp; 63 else 64 c = Bgetc(tabin); 65 if (c == 0) /* EOF */ { 66 if (swapin() == 0) 67 error("unexpected EOF"); 68 c = Bgetc(tabin); 69 } 70 if (c == '\n') 71 iline++; 72 return(c); 73 }