17c478bd9Sstevel@tonic-gate /* 2*b5514887Smuffin * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 77c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate /* 107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 137c478bd9Sstevel@tonic-gate */ 147c478bd9Sstevel@tonic-gate 157c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 167c478bd9Sstevel@tonic-gate 177c478bd9Sstevel@tonic-gate /* t5.c: read data for table */ 187c478bd9Sstevel@tonic-gate # include "t..c" 19*b5514887Smuffin 20*b5514887Smuffin void permute(void); 21*b5514887Smuffin 22*b5514887Smuffin void 23*b5514887Smuffin gettbl(void) 247c478bd9Sstevel@tonic-gate { 257c478bd9Sstevel@tonic-gate int icol, ch; 267c478bd9Sstevel@tonic-gate cstore=cspace= chspace(); 277c478bd9Sstevel@tonic-gate textflg=0; 287c478bd9Sstevel@tonic-gate for (nlin=nslin=0; gets1(cstore, MAXSTR); nlin++) 297c478bd9Sstevel@tonic-gate { 307c478bd9Sstevel@tonic-gate stynum[nlin]=nslin; 317c478bd9Sstevel@tonic-gate if (prefix(".TE", cstore)) 327c478bd9Sstevel@tonic-gate { 337c478bd9Sstevel@tonic-gate leftover=0; 347c478bd9Sstevel@tonic-gate break; 357c478bd9Sstevel@tonic-gate } 367c478bd9Sstevel@tonic-gate if (prefix(".TC", cstore) || prefix(".T&", cstore)) 377c478bd9Sstevel@tonic-gate { 387c478bd9Sstevel@tonic-gate readspec(); 397c478bd9Sstevel@tonic-gate nslin++; 407c478bd9Sstevel@tonic-gate } 417c478bd9Sstevel@tonic-gate if (nlin>=MAXLIN) 427c478bd9Sstevel@tonic-gate { 437c478bd9Sstevel@tonic-gate leftover=cstore; 447c478bd9Sstevel@tonic-gate break; 457c478bd9Sstevel@tonic-gate } 467c478bd9Sstevel@tonic-gate fullbot[nlin]=0; 477c478bd9Sstevel@tonic-gate if (cstore[0] == '.' && !isdigit((unsigned char)cstore[1])) 487c478bd9Sstevel@tonic-gate { 497c478bd9Sstevel@tonic-gate instead[nlin] = cstore; 507c478bd9Sstevel@tonic-gate while (*cstore++); 517c478bd9Sstevel@tonic-gate continue; 527c478bd9Sstevel@tonic-gate } 537c478bd9Sstevel@tonic-gate else instead[nlin] = 0; 547c478bd9Sstevel@tonic-gate if (nodata(nlin)) 557c478bd9Sstevel@tonic-gate { 567c478bd9Sstevel@tonic-gate if (ch = oneh(nlin)) 577c478bd9Sstevel@tonic-gate fullbot[nlin]= ch; 587c478bd9Sstevel@tonic-gate nlin++; 597c478bd9Sstevel@tonic-gate nslin++; 607c478bd9Sstevel@tonic-gate instead[nlin]=(char *)0; 617c478bd9Sstevel@tonic-gate fullbot[nlin]=0; 627c478bd9Sstevel@tonic-gate } 637c478bd9Sstevel@tonic-gate table[nlin] = (struct colstr *) alocv((ncol+2)*sizeof(table[0][0])); 647c478bd9Sstevel@tonic-gate if (cstore[1]==0) 657c478bd9Sstevel@tonic-gate switch(cstore[0]) 667c478bd9Sstevel@tonic-gate { 677c478bd9Sstevel@tonic-gate case '_': fullbot[nlin]= '-'; continue; 687c478bd9Sstevel@tonic-gate case '=': fullbot[nlin]= '='; continue; 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate stynum[nlin] = nslin; 717c478bd9Sstevel@tonic-gate nslin = min(nslin+1, nclin-1); 727c478bd9Sstevel@tonic-gate for (icol = 0; icol <ncol; icol++) 737c478bd9Sstevel@tonic-gate { 747c478bd9Sstevel@tonic-gate table[nlin][icol].col = cstore; 757c478bd9Sstevel@tonic-gate table[nlin][icol].rcol=0; 767c478bd9Sstevel@tonic-gate ch=1; 777c478bd9Sstevel@tonic-gate if (match(cstore, "T{")) /* text follows */ 787c478bd9Sstevel@tonic-gate /* get_text was originally gettext and was renamed */ 797c478bd9Sstevel@tonic-gate table[nlin][icol].col = 807c478bd9Sstevel@tonic-gate (char *)get_text(cstore, nlin, icol, 817c478bd9Sstevel@tonic-gate font[stynum[nlin]][icol], 827c478bd9Sstevel@tonic-gate csize[stynum[nlin]][icol]); 837c478bd9Sstevel@tonic-gate else 847c478bd9Sstevel@tonic-gate { 857c478bd9Sstevel@tonic-gate for(; (ch= *cstore) != '\0' && ch != tab; cstore++) 867c478bd9Sstevel@tonic-gate ; 877c478bd9Sstevel@tonic-gate *cstore++ = '\0'; 887c478bd9Sstevel@tonic-gate switch(ctype(nlin,icol)) /* numerical or alpha, subcol */ 897c478bd9Sstevel@tonic-gate { 907c478bd9Sstevel@tonic-gate case 'n': 917c478bd9Sstevel@tonic-gate table[nlin][icol].rcol = 927c478bd9Sstevel@tonic-gate (char *)maknew(table[nlin][icol].col); 937c478bd9Sstevel@tonic-gate break; 947c478bd9Sstevel@tonic-gate case 'a': 957c478bd9Sstevel@tonic-gate table[nlin][icol].rcol = table[nlin][icol].col; 967c478bd9Sstevel@tonic-gate table[nlin][icol].col = ""; 977c478bd9Sstevel@tonic-gate break; 987c478bd9Sstevel@tonic-gate } 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate while (ctype(nlin,icol+1)== 's') /* spanning */ 1017c478bd9Sstevel@tonic-gate table[nlin][++icol].col = ""; 1027c478bd9Sstevel@tonic-gate if (ch == '\0') break; 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate while (++icol <ncol+2) 1057c478bd9Sstevel@tonic-gate { 1067c478bd9Sstevel@tonic-gate table[nlin][icol].col = ""; 1077c478bd9Sstevel@tonic-gate table [nlin][icol].rcol=0; 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate while (*cstore != '\0') 1107c478bd9Sstevel@tonic-gate cstore++; 1117c478bd9Sstevel@tonic-gate if (cstore-cspace > MAXCHS) 1127c478bd9Sstevel@tonic-gate cstore = cspace = chspace(); 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate last = cstore; 1157c478bd9Sstevel@tonic-gate permute(); 1167c478bd9Sstevel@tonic-gate if (textflg) untext(); 1177c478bd9Sstevel@tonic-gate return; 1187c478bd9Sstevel@tonic-gate } 119*b5514887Smuffin 120*b5514887Smuffin int 121*b5514887Smuffin nodata(int il) 1227c478bd9Sstevel@tonic-gate { 1237c478bd9Sstevel@tonic-gate int c; 1247c478bd9Sstevel@tonic-gate for (c=0; c<ncol;c++) 1257c478bd9Sstevel@tonic-gate { 1267c478bd9Sstevel@tonic-gate switch(ctype(il,c)) 1277c478bd9Sstevel@tonic-gate { 1287c478bd9Sstevel@tonic-gate case 'c': case 'n': case 'r': case 'l': case 's': case 'a': 1297c478bd9Sstevel@tonic-gate return(0); 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate } 1327c478bd9Sstevel@tonic-gate return(1); 1337c478bd9Sstevel@tonic-gate } 134*b5514887Smuffin 135*b5514887Smuffin int 136*b5514887Smuffin oneh(int lin) 1377c478bd9Sstevel@tonic-gate { 1387c478bd9Sstevel@tonic-gate int k, icol; 1397c478bd9Sstevel@tonic-gate k = ctype(lin,0); 1407c478bd9Sstevel@tonic-gate for(icol=1; icol<ncol; icol++) 1417c478bd9Sstevel@tonic-gate { 1427c478bd9Sstevel@tonic-gate if (k != ctype(lin,icol)) 1437c478bd9Sstevel@tonic-gate return(0); 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate return(k); 1467c478bd9Sstevel@tonic-gate } 147*b5514887Smuffin 1487c478bd9Sstevel@tonic-gate # define SPAN "\\^" 149*b5514887Smuffin 150*b5514887Smuffin void 151*b5514887Smuffin permute(void) 1527c478bd9Sstevel@tonic-gate { 1537c478bd9Sstevel@tonic-gate int irow, jcol, is; 1547c478bd9Sstevel@tonic-gate char *start, *strig; 1557c478bd9Sstevel@tonic-gate for(jcol=0; jcol<ncol; jcol++) 1567c478bd9Sstevel@tonic-gate { 1577c478bd9Sstevel@tonic-gate for(irow=1; irow<nlin; irow++) 1587c478bd9Sstevel@tonic-gate { 1597c478bd9Sstevel@tonic-gate if (vspand(irow,jcol,0)) 1607c478bd9Sstevel@tonic-gate { 1617c478bd9Sstevel@tonic-gate is = prev(irow); 1627c478bd9Sstevel@tonic-gate if (is<0) 1637c478bd9Sstevel@tonic-gate error(gettext("Vertical spanning in first row not allowed")); 1647c478bd9Sstevel@tonic-gate start = table[is][jcol].col; 1657c478bd9Sstevel@tonic-gate strig = table[is][jcol].rcol; 1667c478bd9Sstevel@tonic-gate while (irow<nlin &&vspand(irow,jcol,0)) 1677c478bd9Sstevel@tonic-gate irow++; 1687c478bd9Sstevel@tonic-gate table[--irow][jcol].col = start; 1697c478bd9Sstevel@tonic-gate table[irow][jcol].rcol = strig; 1707c478bd9Sstevel@tonic-gate while (is<irow) 1717c478bd9Sstevel@tonic-gate { 1727c478bd9Sstevel@tonic-gate table[is][jcol].rcol =0; 1737c478bd9Sstevel@tonic-gate table[is][jcol].col= SPAN; 1747c478bd9Sstevel@tonic-gate is = next(is); 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate } 180*b5514887Smuffin 181*b5514887Smuffin int 182*b5514887Smuffin vspand(int ir, int ij, int ifform) 1837c478bd9Sstevel@tonic-gate { 1847c478bd9Sstevel@tonic-gate if (ir<0) return(0); 1857c478bd9Sstevel@tonic-gate if (ir>=nlin)return(0); 1867c478bd9Sstevel@tonic-gate if (instead[ir]) return(0); 1877c478bd9Sstevel@tonic-gate if (ifform==0 && ctype(ir,ij)=='^') return(1); 1887c478bd9Sstevel@tonic-gate if (table[ir]==0) return(0); 1897c478bd9Sstevel@tonic-gate if (table[ir][ij].rcol!=0) return(0); 1907c478bd9Sstevel@tonic-gate if (fullbot[ir]) return(0); 1917c478bd9Sstevel@tonic-gate return(vspen(table[ir][ij].col)); 1927c478bd9Sstevel@tonic-gate } 193*b5514887Smuffin 194*b5514887Smuffin int 195*b5514887Smuffin vspen(char *s) 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate if (s==0) return(0); 1987c478bd9Sstevel@tonic-gate if (!point(s)) return(0); 1997c478bd9Sstevel@tonic-gate return(match(s, SPAN)); 2007c478bd9Sstevel@tonic-gate } 201