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