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