tb.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* tb.c: check which entries exist, also storage allocation */
  2. # include "t.h"
  3. void
  4. checkuse(void)
  5. {
  6. int i, c, k;
  7. for (c = 0; c < ncol; c++) {
  8. used[c] = lused[c] = rused[c] = 0;
  9. for (i = 0; i < nlin; i++) {
  10. if (instead[i] || fullbot[i])
  11. continue;
  12. k = ctype(i, c);
  13. if (k == '-' || k == '=')
  14. continue;
  15. if ((k == 'n' || k == 'a')) {
  16. rused[c] |= real(table[i][c].rcol);
  17. if ( !real(table[i][c].rcol))
  18. used[c] |= real(table[i][c].col);
  19. if (table[i][c].rcol)
  20. lused[c] |= real(table[i][c].col);
  21. } else
  22. used[c] |= real(table[i][c].col);
  23. }
  24. }
  25. }
  26. int
  27. real(char *s)
  28. {
  29. if (s == 0)
  30. return(0);
  31. if (!point(s))
  32. return(1);
  33. if (*s == 0)
  34. return(0);
  35. return(1);
  36. }
  37. int spcount = 0;
  38. # define MAXVEC 20
  39. char *spvecs[MAXVEC];
  40. char *
  41. chspace(void)
  42. {
  43. char *pp;
  44. if (spvecs[spcount])
  45. return(spvecs[spcount++]);
  46. if (spcount >= MAXVEC)
  47. error("Too many characters in table");
  48. spvecs[spcount++] = pp = calloc(MAXCHS + MAXLINLEN, 1);
  49. if (pp == (char *) - 1 || pp == (char *)0)
  50. error("no space for characters");
  51. return(pp);
  52. }
  53. # define MAXPC 50
  54. char *thisvec;
  55. int tpcount = -1;
  56. char *tpvecs[MAXPC];
  57. int *
  58. alocv(int n)
  59. {
  60. int *tp, *q;
  61. if (tpcount < 0 || thisvec + n > tpvecs[tpcount] + MAXCHS) {
  62. tpcount++;
  63. if (tpvecs[tpcount] == 0) {
  64. tpvecs[tpcount] = calloc(MAXCHS, 1);
  65. }
  66. thisvec = tpvecs[tpcount];
  67. if (thisvec == (char *)0)
  68. error("no space for vectors");
  69. }
  70. tp = (int *)thisvec;
  71. thisvec += n;
  72. for (q = tp; q < (int *)thisvec; q++)
  73. *q = 0;
  74. return(tp);
  75. }
  76. void
  77. release(void)
  78. {
  79. /* give back unwanted space in some vectors */
  80. /* this should call free; it does not because
  81. alloc() is so buggy */
  82. spcount = 0;
  83. tpcount = -1;
  84. exstore = 0;
  85. }