t5.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* t5.c: read data for table */
  2. # include "t.h"
  3. void
  4. gettbl(void)
  5. {
  6. int icol, ch;
  7. cstore = cspace = chspace();
  8. textflg = 0;
  9. for (nlin = nslin = 0; gets1(cstore, MAXCHS - (cstore - cspace)); nlin++) {
  10. stynum[nlin] = nslin;
  11. if (prefix(".TE", cstore)) {
  12. leftover = 0;
  13. break;
  14. }
  15. if (prefix(".TC", cstore) || prefix(".T&", cstore)) {
  16. readspec();
  17. nslin++;
  18. }
  19. if (nlin >= MAXLIN) {
  20. leftover = cstore;
  21. break;
  22. }
  23. fullbot[nlin] = 0;
  24. if (cstore[0] == '.' && !isdigit(cstore[1])) {
  25. instead[nlin] = cstore;
  26. while (*cstore++)
  27. ;
  28. continue;
  29. } else
  30. instead[nlin] = 0;
  31. if (nodata(nlin)) {
  32. if (ch = oneh(nlin))
  33. fullbot[nlin] = ch;
  34. table[nlin] = (struct colstr *) alocv((ncol + 2) * sizeof(table[0][0]));
  35. for (icol = 0; icol < ncol; icol++) {
  36. table[nlin][icol].rcol = "";
  37. table[nlin][icol].col = "";
  38. }
  39. nlin++;
  40. nslin++;
  41. fullbot[nlin] = 0;
  42. instead[nlin] = (char *) 0;
  43. }
  44. table[nlin] = (struct colstr *) alocv((ncol + 2) * sizeof(table[0][0]));
  45. if (cstore[1] == 0)
  46. switch (cstore[0]) {
  47. case '_':
  48. fullbot[nlin] = '-';
  49. continue;
  50. case '=':
  51. fullbot[nlin] = '=';
  52. continue;
  53. }
  54. stynum[nlin] = nslin;
  55. nslin = min(nslin + 1, nclin - 1);
  56. for (icol = 0; icol < ncol; icol++) {
  57. table[nlin][icol].col = cstore;
  58. table[nlin][icol].rcol = 0;
  59. ch = 1;
  60. if (match(cstore, "T{")) { /* text follows */
  61. table[nlin][icol].col =
  62. (char *)gettext(cstore, nlin, icol,
  63. font[icol][stynum[nlin]],
  64. csize[icol][stynum[nlin]]);
  65. } else
  66. {
  67. for (; (ch = *cstore) != '\0' && ch != tab; cstore++)
  68. ;
  69. *cstore++ = '\0';
  70. switch (ctype(nlin, icol)) /* numerical or alpha, subcol */ {
  71. case 'n':
  72. table[nlin][icol].rcol = maknew(table[nlin][icol].col);
  73. break;
  74. case 'a':
  75. table[nlin][icol].rcol = table[nlin][icol].col;
  76. table[nlin][icol].col = "";
  77. break;
  78. }
  79. }
  80. while (ctype(nlin, icol + 1) == 's') /* spanning */
  81. table[nlin][++icol].col = "";
  82. if (ch == '\0')
  83. break;
  84. }
  85. while (++icol < ncol + 2) {
  86. table[nlin][icol].col = "";
  87. table [nlin][icol].rcol = 0;
  88. }
  89. while (*cstore != '\0')
  90. cstore++;
  91. if (cstore - cspace + MAXLINLEN > MAXCHS)
  92. cstore = cspace = chspace();
  93. }
  94. last = cstore;
  95. permute();
  96. if (textflg)
  97. untext();
  98. return;
  99. }
  100. int
  101. nodata(int il)
  102. {
  103. int c;
  104. for (c = 0; c < ncol; c++) {
  105. switch (ctype(il, c)) {
  106. case 'c':
  107. case 'n':
  108. case 'r':
  109. case 'l':
  110. case 's':
  111. case 'a':
  112. return(0);
  113. }
  114. }
  115. return(1);
  116. }
  117. int
  118. oneh(int lin)
  119. {
  120. int k, icol;
  121. k = ctype(lin, 0);
  122. for (icol = 1; icol < ncol; icol++) {
  123. if (k != ctype(lin, icol))
  124. return(0);
  125. }
  126. return(k);
  127. }
  128. # define SPAN "\\^"
  129. void
  130. permute(void)
  131. {
  132. int irow, jcol, is;
  133. char *start, *strig;
  134. for (jcol = 0; jcol < ncol; jcol++) {
  135. for (irow = 1; irow < nlin; irow++) {
  136. if (vspand(irow, jcol, 0)) {
  137. is = prev(irow);
  138. if (is < 0)
  139. error("Vertical spanning in first row not allowed");
  140. start = table[is][jcol].col;
  141. strig = table[is][jcol].rcol;
  142. while (irow < nlin && vspand(irow, jcol, 0))
  143. irow++;
  144. table[--irow][jcol].col = start;
  145. table[irow][jcol].rcol = strig;
  146. while (is < irow) {
  147. table[is][jcol].rcol = 0;
  148. table[is][jcol].col = SPAN;
  149. is = next(is);
  150. }
  151. }
  152. }
  153. }
  154. }
  155. int
  156. vspand(int ir, int ij, int ifform)
  157. {
  158. if (ir < 0)
  159. return(0);
  160. if (ir >= nlin)
  161. return(0);
  162. if (instead[ir])
  163. return(0);
  164. if (ifform == 0 && ctype(ir, ij) == '^')
  165. return(1);
  166. if (table[ir][ij].rcol != 0)
  167. return(0);
  168. if (fullbot[ir])
  169. return(0);
  170. return(vspen(table[ir][ij].col));
  171. }
  172. int
  173. vspen(char *s)
  174. {
  175. if (s == 0)
  176. return(0);
  177. if (!point(s))
  178. return(0);
  179. return(match(s, SPAN));
  180. }