Blob
1 /* te.c: error message control, input line count */2 # include "t.h"4 void5 error(char *s)6 {7 fprintf(stderr, "\n%s:%d: %s\n", ifile, iline, s);8 fprintf(stderr, "tbl quits\n");9 exit(1);10 }13 char *14 gets1(char *s, int size)15 {16 char *p, *ns;17 int nbl;19 iline++;20 ns = s;21 p = fgetln(tabin, &nbl);22 while (p == 0) {23 if (swapin() == 0)24 return(0);25 p = fgetln(tabin, &nbl);26 }27 if(p != 0 && p[nbl-1] == '\n')28 nbl--;29 if(nbl >= size)30 error("input buffer too small");31 p[nbl] = 0;32 strcpy(s, p);33 s += nbl;34 for (nbl = 0; *s == '\\' && s > ns; s--)35 nbl++;36 if (linstart && nbl % 2) /* fold escaped nl if in table */37 gets1(s + 1, size - (s-ns));39 return(p);40 }43 # define BACKMAX 50044 char backup[BACKMAX];45 char *backp = backup;47 void48 un1getc(int c)49 {50 if (c == '\n')51 iline--;52 *backp++ = c;53 if (backp >= backup + BACKMAX)54 error("too much backup");55 }58 int59 get1char(void)60 {61 int c;62 if (backp > backup)63 c = *--backp;64 else65 c = fgetc(tabin);66 if (c == 0) /* EOF */ {67 if (swapin() == 0)68 error("unexpected EOF");69 c = fgetc(tabin);70 }71 if (c == '\n')72 iline++;73 return(c);74 }