te.c 1.0 KB

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