1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 1983-2003 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 7*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 8*7c478bd9Sstevel@tonic-gate 9*7c478bd9Sstevel@tonic-gate 10*7c478bd9Sstevel@tonic-gate /* 11*7c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 12*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 13*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 14*7c478bd9Sstevel@tonic-gate */ 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 17*7c478bd9Sstevel@tonic-gate 18*7c478bd9Sstevel@tonic-gate /* t4.c: read table specification */ 19*7c478bd9Sstevel@tonic-gate # include "t..c" 20*7c478bd9Sstevel@tonic-gate int oncol; 21*7c478bd9Sstevel@tonic-gate getspec() 22*7c478bd9Sstevel@tonic-gate { 23*7c478bd9Sstevel@tonic-gate int icol, i; 24*7c478bd9Sstevel@tonic-gate for(icol=0; icol<MAXCOL; icol++) 25*7c478bd9Sstevel@tonic-gate { 26*7c478bd9Sstevel@tonic-gate sep[icol]= -1; 27*7c478bd9Sstevel@tonic-gate evenup[icol]=0; 28*7c478bd9Sstevel@tonic-gate cll[icol][0]=0; 29*7c478bd9Sstevel@tonic-gate for(i=0; i<MAXHEAD; i++) 30*7c478bd9Sstevel@tonic-gate { 31*7c478bd9Sstevel@tonic-gate csize[i][icol][0]=0; 32*7c478bd9Sstevel@tonic-gate vsize[i][icol][0]=0; 33*7c478bd9Sstevel@tonic-gate font[i][icol][0] = lefline[i][icol] = 0; 34*7c478bd9Sstevel@tonic-gate ctop[i][icol]=0; 35*7c478bd9Sstevel@tonic-gate style[i][icol]= 'l'; 36*7c478bd9Sstevel@tonic-gate } 37*7c478bd9Sstevel@tonic-gate } 38*7c478bd9Sstevel@tonic-gate nclin=ncol=0; 39*7c478bd9Sstevel@tonic-gate oncol =0; 40*7c478bd9Sstevel@tonic-gate left1flg=rightl=0; 41*7c478bd9Sstevel@tonic-gate readspec(); 42*7c478bd9Sstevel@tonic-gate fprintf(tabout, ".rm"); 43*7c478bd9Sstevel@tonic-gate for(i=0; i<ncol; i++) 44*7c478bd9Sstevel@tonic-gate fprintf(tabout, " %02d", 80+i); 45*7c478bd9Sstevel@tonic-gate fprintf(tabout, "\n"); 46*7c478bd9Sstevel@tonic-gate } 47*7c478bd9Sstevel@tonic-gate readspec() 48*7c478bd9Sstevel@tonic-gate { 49*7c478bd9Sstevel@tonic-gate int icol, c, sawchar, stopc, i; 50*7c478bd9Sstevel@tonic-gate char sn[10], *snp, *temp; 51*7c478bd9Sstevel@tonic-gate sawchar=icol=0; 52*7c478bd9Sstevel@tonic-gate while (c=get1char()) 53*7c478bd9Sstevel@tonic-gate { 54*7c478bd9Sstevel@tonic-gate switch(c) 55*7c478bd9Sstevel@tonic-gate { 56*7c478bd9Sstevel@tonic-gate default: 57*7c478bd9Sstevel@tonic-gate if (c != tab) 58*7c478bd9Sstevel@tonic-gate error(gettext("bad table specification character")); 59*7c478bd9Sstevel@tonic-gate case ' ': /* note this is also case tab */ 60*7c478bd9Sstevel@tonic-gate continue; 61*7c478bd9Sstevel@tonic-gate case '\n': 62*7c478bd9Sstevel@tonic-gate if(sawchar==0) continue; 63*7c478bd9Sstevel@tonic-gate case ',': 64*7c478bd9Sstevel@tonic-gate case '.': /* end of table specification */ 65*7c478bd9Sstevel@tonic-gate ncol = max(ncol, icol); 66*7c478bd9Sstevel@tonic-gate if (lefline[nclin][ncol]>0) {ncol++; rightl++;}; 67*7c478bd9Sstevel@tonic-gate if(sawchar) 68*7c478bd9Sstevel@tonic-gate nclin++; 69*7c478bd9Sstevel@tonic-gate if (nclin>=MAXHEAD) 70*7c478bd9Sstevel@tonic-gate error(gettext("too many lines in specification")); 71*7c478bd9Sstevel@tonic-gate icol=0; 72*7c478bd9Sstevel@tonic-gate if (ncol==0 || nclin==0) 73*7c478bd9Sstevel@tonic-gate error(gettext("no specification")); 74*7c478bd9Sstevel@tonic-gate if (c== '.') 75*7c478bd9Sstevel@tonic-gate { 76*7c478bd9Sstevel@tonic-gate while ((c=get1char()) && c != '\n') 77*7c478bd9Sstevel@tonic-gate if (c != ' ' && c != '\t') 78*7c478bd9Sstevel@tonic-gate error(gettext("dot not last character on format line")); 79*7c478bd9Sstevel@tonic-gate /* fix up sep - default is 3 except at edge */ 80*7c478bd9Sstevel@tonic-gate for(icol=0; icol<ncol; icol++) 81*7c478bd9Sstevel@tonic-gate if (sep[icol]<0) 82*7c478bd9Sstevel@tonic-gate sep[icol] = icol+1<ncol ? 3 : 1; 83*7c478bd9Sstevel@tonic-gate if (oncol == 0) 84*7c478bd9Sstevel@tonic-gate oncol = ncol; 85*7c478bd9Sstevel@tonic-gate else if (oncol +2 <ncol) 86*7c478bd9Sstevel@tonic-gate error(gettext("tried to widen table in T&, not allowed")); 87*7c478bd9Sstevel@tonic-gate return; 88*7c478bd9Sstevel@tonic-gate } 89*7c478bd9Sstevel@tonic-gate sawchar=0; 90*7c478bd9Sstevel@tonic-gate continue; 91*7c478bd9Sstevel@tonic-gate case 'C': case 'S': case 'R': case 'N': case 'L': case 'A': 92*7c478bd9Sstevel@tonic-gate c += ('a'-'A'); 93*7c478bd9Sstevel@tonic-gate case '_': if (c=='_') c= '-'; 94*7c478bd9Sstevel@tonic-gate case '=': case '-': 95*7c478bd9Sstevel@tonic-gate case '^': 96*7c478bd9Sstevel@tonic-gate case 'c': case 's': case 'n': case 'r': case 'l': case 'a': 97*7c478bd9Sstevel@tonic-gate style[nclin][icol]=c; 98*7c478bd9Sstevel@tonic-gate if (c== 's' && icol<=0) 99*7c478bd9Sstevel@tonic-gate error(gettext("first column can not be S-type")); 100*7c478bd9Sstevel@tonic-gate if (c=='s' && style[nclin][icol-1] == 'a') 101*7c478bd9Sstevel@tonic-gate { 102*7c478bd9Sstevel@tonic-gate fprintf(tabout, ".tm warning: can't span a-type cols, changed to l\n"); 103*7c478bd9Sstevel@tonic-gate style[nclin][icol-1] = 'l'; 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate if (c=='s' && style[nclin][icol-1] == 'n') 106*7c478bd9Sstevel@tonic-gate { 107*7c478bd9Sstevel@tonic-gate fprintf(tabout, ".tm warning: can't span n-type cols, changed to c\n"); 108*7c478bd9Sstevel@tonic-gate style[nclin][icol-1] = 'c'; 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate icol++; 111*7c478bd9Sstevel@tonic-gate if (c=='^' && nclin<=0) 112*7c478bd9Sstevel@tonic-gate error(gettext("first row can not contain vertical span")); 113*7c478bd9Sstevel@tonic-gate if (icol>=MAXCOL) 114*7c478bd9Sstevel@tonic-gate error(gettext("too many columns in table")); 115*7c478bd9Sstevel@tonic-gate sawchar=1; 116*7c478bd9Sstevel@tonic-gate continue; 117*7c478bd9Sstevel@tonic-gate case 'b': case 'i': 118*7c478bd9Sstevel@tonic-gate c += 'A'-'a'; 119*7c478bd9Sstevel@tonic-gate /* FALLTHRU */ 120*7c478bd9Sstevel@tonic-gate case 'B': case 'I': 121*7c478bd9Sstevel@tonic-gate if (sawchar == 0) 122*7c478bd9Sstevel@tonic-gate continue; 123*7c478bd9Sstevel@tonic-gate if (icol==0) continue; 124*7c478bd9Sstevel@tonic-gate snp=font[nclin][icol-1]; 125*7c478bd9Sstevel@tonic-gate snp[0]= (c=='I' ? '2' : '3'); 126*7c478bd9Sstevel@tonic-gate snp[1]=0; 127*7c478bd9Sstevel@tonic-gate continue; 128*7c478bd9Sstevel@tonic-gate case 't': case 'T': 129*7c478bd9Sstevel@tonic-gate if (sawchar == 0) { 130*7c478bd9Sstevel@tonic-gate continue; 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate if (icol>0) 133*7c478bd9Sstevel@tonic-gate ctop[nclin][icol-1] = 1; 134*7c478bd9Sstevel@tonic-gate continue; 135*7c478bd9Sstevel@tonic-gate case 'd': case 'D': 136*7c478bd9Sstevel@tonic-gate if (sawchar == 0) 137*7c478bd9Sstevel@tonic-gate continue; 138*7c478bd9Sstevel@tonic-gate if (icol>0) 139*7c478bd9Sstevel@tonic-gate ctop[nclin][icol-1] = -1; 140*7c478bd9Sstevel@tonic-gate continue; 141*7c478bd9Sstevel@tonic-gate case 'f': case 'F': 142*7c478bd9Sstevel@tonic-gate if (sawchar == 0) 143*7c478bd9Sstevel@tonic-gate continue; 144*7c478bd9Sstevel@tonic-gate if (icol==0) continue; 145*7c478bd9Sstevel@tonic-gate snp=font[nclin][icol-1]; 146*7c478bd9Sstevel@tonic-gate snp[0]=snp[1]=stopc=0; 147*7c478bd9Sstevel@tonic-gate for(i=0; i<2; i++) 148*7c478bd9Sstevel@tonic-gate { 149*7c478bd9Sstevel@tonic-gate c = get1char(); 150*7c478bd9Sstevel@tonic-gate if (i==0 && c=='(') 151*7c478bd9Sstevel@tonic-gate { 152*7c478bd9Sstevel@tonic-gate stopc=')'; 153*7c478bd9Sstevel@tonic-gate c = get1char(); 154*7c478bd9Sstevel@tonic-gate } 155*7c478bd9Sstevel@tonic-gate if (c==0) break; 156*7c478bd9Sstevel@tonic-gate if (c==stopc) {stopc=0; break;} 157*7c478bd9Sstevel@tonic-gate if (stopc==0) if (c==' ' || c== tab ) break; 158*7c478bd9Sstevel@tonic-gate if (c=='\n'){un1getc(c); break;} 159*7c478bd9Sstevel@tonic-gate snp[i] = c; 160*7c478bd9Sstevel@tonic-gate if (c>= '0' && c<= '9') break; 161*7c478bd9Sstevel@tonic-gate } 162*7c478bd9Sstevel@tonic-gate if (stopc) if (get1char()!=stopc) 163*7c478bd9Sstevel@tonic-gate error(gettext("Nonterminated font name")); 164*7c478bd9Sstevel@tonic-gate continue; 165*7c478bd9Sstevel@tonic-gate case 'P': case 'p': 166*7c478bd9Sstevel@tonic-gate if (sawchar == 0) 167*7c478bd9Sstevel@tonic-gate continue; 168*7c478bd9Sstevel@tonic-gate if (icol<=0) continue; 169*7c478bd9Sstevel@tonic-gate temp = snp = csize[nclin][icol-1]; 170*7c478bd9Sstevel@tonic-gate while (c = get1char()) 171*7c478bd9Sstevel@tonic-gate { 172*7c478bd9Sstevel@tonic-gate if (c== ' ' || c== tab || c=='\n') break; 173*7c478bd9Sstevel@tonic-gate if (c=='-' || c == '+') 174*7c478bd9Sstevel@tonic-gate if (snp>temp) 175*7c478bd9Sstevel@tonic-gate break; 176*7c478bd9Sstevel@tonic-gate else 177*7c478bd9Sstevel@tonic-gate *snp++=c; 178*7c478bd9Sstevel@tonic-gate else 179*7c478bd9Sstevel@tonic-gate if (digit(c)) 180*7c478bd9Sstevel@tonic-gate *snp++ = c; 181*7c478bd9Sstevel@tonic-gate else break; 182*7c478bd9Sstevel@tonic-gate if (snp-temp>4) 183*7c478bd9Sstevel@tonic-gate error(gettext("point size too large")); 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate *snp = 0; 186*7c478bd9Sstevel@tonic-gate if (atoi(temp)>36) 187*7c478bd9Sstevel@tonic-gate error(gettext("point size unreasonable")); 188*7c478bd9Sstevel@tonic-gate un1getc (c); 189*7c478bd9Sstevel@tonic-gate continue; 190*7c478bd9Sstevel@tonic-gate case 'V': case 'v': 191*7c478bd9Sstevel@tonic-gate if (sawchar == 0) 192*7c478bd9Sstevel@tonic-gate continue; 193*7c478bd9Sstevel@tonic-gate if (icol<=0) continue; 194*7c478bd9Sstevel@tonic-gate temp = snp = vsize[nclin][icol-1]; 195*7c478bd9Sstevel@tonic-gate while (c = get1char()) 196*7c478bd9Sstevel@tonic-gate { 197*7c478bd9Sstevel@tonic-gate if (c== ' ' || c== tab || c=='\n') break; 198*7c478bd9Sstevel@tonic-gate if (c=='-' || c == '+') 199*7c478bd9Sstevel@tonic-gate if (snp>temp) 200*7c478bd9Sstevel@tonic-gate break; 201*7c478bd9Sstevel@tonic-gate else 202*7c478bd9Sstevel@tonic-gate *snp++=c; 203*7c478bd9Sstevel@tonic-gate else 204*7c478bd9Sstevel@tonic-gate if (digit(c)) 205*7c478bd9Sstevel@tonic-gate *snp++ = c; 206*7c478bd9Sstevel@tonic-gate else break; 207*7c478bd9Sstevel@tonic-gate if (snp-temp>4) 208*7c478bd9Sstevel@tonic-gate error( 209*7c478bd9Sstevel@tonic-gate gettext("vertical spacing value too large") 210*7c478bd9Sstevel@tonic-gate ); 211*7c478bd9Sstevel@tonic-gate } 212*7c478bd9Sstevel@tonic-gate *snp=0; 213*7c478bd9Sstevel@tonic-gate un1getc(c); 214*7c478bd9Sstevel@tonic-gate continue; 215*7c478bd9Sstevel@tonic-gate case 'w': case 'W': 216*7c478bd9Sstevel@tonic-gate if (sawchar == 0) { 217*7c478bd9Sstevel@tonic-gate /* 218*7c478bd9Sstevel@tonic-gate * This should be an error case. 219*7c478bd9Sstevel@tonic-gate * However, for the backward-compatibility, 220*7c478bd9Sstevel@tonic-gate * treat as if 'c' was specified. 221*7c478bd9Sstevel@tonic-gate */ 222*7c478bd9Sstevel@tonic-gate style[nclin][icol] = 'c'; 223*7c478bd9Sstevel@tonic-gate icol++; 224*7c478bd9Sstevel@tonic-gate if (icol >= MAXCOL) { 225*7c478bd9Sstevel@tonic-gate error(gettext( 226*7c478bd9Sstevel@tonic-gate "too many columns in table")); 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gate sawchar = 1; 229*7c478bd9Sstevel@tonic-gate } 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate snp = cll [icol-1]; 232*7c478bd9Sstevel@tonic-gate /* Dale Smith didn't like this check 233*7c478bd9Sstevel@tonic-gate * possible to have two text blocks 234*7c478bd9Sstevel@tonic-gate * of different widths now .... 235*7c478bd9Sstevel@tonic-gate if (*snp) 236*7c478bd9Sstevel@tonic-gate { 237*7c478bd9Sstevel@tonic-gate fprintf(tabout, 238*7c478bd9Sstevel@tonic-gate gettext("Ignored second width specification")); 239*7c478bd9Sstevel@tonic-gate continue; 240*7c478bd9Sstevel@tonic-gate } 241*7c478bd9Sstevel@tonic-gate * end commented out code ... */ 242*7c478bd9Sstevel@tonic-gate stopc=0; 243*7c478bd9Sstevel@tonic-gate while (c = get1char()) 244*7c478bd9Sstevel@tonic-gate { 245*7c478bd9Sstevel@tonic-gate if (snp==cll[icol-1] && c=='(') 246*7c478bd9Sstevel@tonic-gate { 247*7c478bd9Sstevel@tonic-gate stopc = ')'; 248*7c478bd9Sstevel@tonic-gate continue; 249*7c478bd9Sstevel@tonic-gate } 250*7c478bd9Sstevel@tonic-gate if ( !stopc && (c>'9' || c< '0')) 251*7c478bd9Sstevel@tonic-gate break; 252*7c478bd9Sstevel@tonic-gate if (stopc && c== stopc) 253*7c478bd9Sstevel@tonic-gate break; 254*7c478bd9Sstevel@tonic-gate *snp++ =c; 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate *snp=0; 257*7c478bd9Sstevel@tonic-gate if (snp-cll[icol-1]>CLLEN) 258*7c478bd9Sstevel@tonic-gate error (gettext("column width too long")); 259*7c478bd9Sstevel@tonic-gate if (!stopc) 260*7c478bd9Sstevel@tonic-gate un1getc(c); 261*7c478bd9Sstevel@tonic-gate continue; 262*7c478bd9Sstevel@tonic-gate case 'e': case 'E': 263*7c478bd9Sstevel@tonic-gate if (sawchar == 0) 264*7c478bd9Sstevel@tonic-gate continue; 265*7c478bd9Sstevel@tonic-gate if (icol<1) continue; 266*7c478bd9Sstevel@tonic-gate evenup[icol-1]=1; 267*7c478bd9Sstevel@tonic-gate evenflg=1; 268*7c478bd9Sstevel@tonic-gate continue; 269*7c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4': 270*7c478bd9Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9': 271*7c478bd9Sstevel@tonic-gate sn[0] = c; 272*7c478bd9Sstevel@tonic-gate snp=sn+1; 273*7c478bd9Sstevel@tonic-gate while (digit(*snp++ = c = get1char())) 274*7c478bd9Sstevel@tonic-gate ; 275*7c478bd9Sstevel@tonic-gate un1getc(c); 276*7c478bd9Sstevel@tonic-gate sep[icol-1] = max(sep[icol-1], numb(sn)); 277*7c478bd9Sstevel@tonic-gate continue; 278*7c478bd9Sstevel@tonic-gate case '|': 279*7c478bd9Sstevel@tonic-gate lefline[nclin][icol]++; 280*7c478bd9Sstevel@tonic-gate if (icol==0) left1flg=1; 281*7c478bd9Sstevel@tonic-gate continue; 282*7c478bd9Sstevel@tonic-gate } 283*7c478bd9Sstevel@tonic-gate } 284*7c478bd9Sstevel@tonic-gate error(gettext("EOF reading table specification")); 285*7c478bd9Sstevel@tonic-gate } 286