diff options
| author | rsc <devnull@localhost> | 2004-05-15 23:24:00 +0000 |
|---|---|---|
| committer | rsc <devnull@localhost> | 2004-05-15 23:24:00 +0000 |
| commit | 5cedca1b69d020c32466f70843a11767773d7e3b (patch) | |
| tree | a15a3d84e92aa262543b0010763a5e6920c9ba24 /src/cmd/tbl/te.c | |
| parent | 76e6aca867e3e48ea04fbcf7284c45369a69829e (diff) | |
| download | plan9port-5cedca1b69d020c32466f70843a11767773d7e3b.tar.gz plan9port-5cedca1b69d020c32466f70843a11767773d7e3b.zip | |
Let's try this. It's BUGGERED.
Diffstat (limited to 'src/cmd/tbl/te.c')
| -rw-r--r-- | src/cmd/tbl/te.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/cmd/tbl/te.c b/src/cmd/tbl/te.c new file mode 100644 index 00000000..3df8d445 --- /dev/null +++ b/src/cmd/tbl/te.c @@ -0,0 +1,75 @@ +/* te.c: error message control, input line count */ +# include "t.h" + +void +error(char *s) +{ + fprint(2, "\n%s:%d: %s\n", ifile, iline, s); + fprint(2, "tbl quits\n"); + exits(s); +} + + +char * +gets1(char *s, int size) +{ + char *p, *ns; + int nbl; + + iline++; + ns = s; + p = Brdline(tabin, '\n'); + while (p == 0) { + if (swapin() == 0) + return(0); + p = Brdline(tabin, '\n'); + } + nbl = Blinelen(tabin)-1; + if(nbl >= size) + error("input buffer too small"); + p[nbl] = 0; + strcpy(s, p); + s += nbl; + for (nbl = 0; *s == '\\' && s > ns; s--) + nbl++; + if (linstart && nbl % 2) /* fold escaped nl if in table */ + gets1(s + 1, size - (s-ns)); + + return(p); +} + + +# 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 = Bgetc(tabin); + if (c == 0) /* EOF */ { + if (swapin() == 0) + error("unexpected EOF"); + c = Bgetc(tabin); + } + if (c == '\n') + iline++; + return(c); +} + + |
