17c478bd9Sstevel@tonic-gate /* 2*b5514887Smuffin * Copyright 1998 Sun Microsystems, Inc. All rights reserved. 3*b5514887Smuffin * 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 15*b5514887Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 16*b5514887Smuffin 177c478bd9Sstevel@tonic-gate /* t7.c: control to write table entries */ 187c478bd9Sstevel@tonic-gate # include "t..c" 197c478bd9Sstevel@tonic-gate # define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol) 20*b5514887Smuffin 21*b5514887Smuffin void need(void); 22*b5514887Smuffin void deftail(void); 23*b5514887Smuffin 24*b5514887Smuffin void 25*b5514887Smuffin runout(void) 267c478bd9Sstevel@tonic-gate { 277c478bd9Sstevel@tonic-gate int i; 287c478bd9Sstevel@tonic-gate if (boxflg || allflg || dboxflg) need(); 297c478bd9Sstevel@tonic-gate if (ctrflg) 307c478bd9Sstevel@tonic-gate { 317c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr #I \\n(.i\n"); 327c478bd9Sstevel@tonic-gate fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n"); 337c478bd9Sstevel@tonic-gate } 347c478bd9Sstevel@tonic-gate fprintf(tabout, ".fc %c %c\n", F1, F2); 357c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr #T 0-1\n"); 367c478bd9Sstevel@tonic-gate deftail(); 377c478bd9Sstevel@tonic-gate for(i=0; i<nlin; i++) 387c478bd9Sstevel@tonic-gate putline(i,i); 397c478bd9Sstevel@tonic-gate if (leftover) 407c478bd9Sstevel@tonic-gate yetmore(); 417c478bd9Sstevel@tonic-gate fprintf(tabout, ".fc\n"); 427c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr T. 1\n"); 437c478bd9Sstevel@tonic-gate fprintf(tabout, ".T# 1\n"); 447c478bd9Sstevel@tonic-gate if (ctrflg) 457c478bd9Sstevel@tonic-gate fprintf(tabout, ".in \\n(#Iu\n"); 467c478bd9Sstevel@tonic-gate } 47*b5514887Smuffin 48*b5514887Smuffin void 49*b5514887Smuffin runtabs(int lform, int ldata) 507c478bd9Sstevel@tonic-gate { 517c478bd9Sstevel@tonic-gate int c, ct, vforml, lf; 527c478bd9Sstevel@tonic-gate fprintf(tabout, ".ta "); 537c478bd9Sstevel@tonic-gate for(c=0; c<ncol; c++) 547c478bd9Sstevel@tonic-gate { 557c478bd9Sstevel@tonic-gate vforml=lform; 567c478bd9Sstevel@tonic-gate for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf)) 577c478bd9Sstevel@tonic-gate vforml=lf; 587c478bd9Sstevel@tonic-gate if (fspan(vforml,c)) 597c478bd9Sstevel@tonic-gate continue; 607c478bd9Sstevel@tonic-gate switch(ct=ctype(vforml,c)) 617c478bd9Sstevel@tonic-gate { 627c478bd9Sstevel@tonic-gate case 'n': 637c478bd9Sstevel@tonic-gate case 'a': 647c478bd9Sstevel@tonic-gate if (table[ldata][c].rcol) 657c478bd9Sstevel@tonic-gate if (lused[c]) /*Zero field width*/ 667c478bd9Sstevel@tonic-gate fprintf(tabout, "\\n(%du ",c+CMID); 677c478bd9Sstevel@tonic-gate case 'c': 687c478bd9Sstevel@tonic-gate case 'l': 697c478bd9Sstevel@tonic-gate case 'r': 707c478bd9Sstevel@tonic-gate if (realsplit? rused[c]: (used[c]+lused[c])) 717c478bd9Sstevel@tonic-gate fprintf(tabout, "\\n(%du ",c+CRIGHT); 727c478bd9Sstevel@tonic-gate continue; 737c478bd9Sstevel@tonic-gate case 's': 747c478bd9Sstevel@tonic-gate if (lspan(lform, c)) 757c478bd9Sstevel@tonic-gate fprintf(tabout, "\\n(%du ", c+CRIGHT); 767c478bd9Sstevel@tonic-gate continue; 777c478bd9Sstevel@tonic-gate } 787c478bd9Sstevel@tonic-gate } 797c478bd9Sstevel@tonic-gate fprintf(tabout, "\n"); 807c478bd9Sstevel@tonic-gate } 81*b5514887Smuffin 82*b5514887Smuffin int 83*b5514887Smuffin ifline(char *s) 847c478bd9Sstevel@tonic-gate { 857c478bd9Sstevel@tonic-gate if (!point(s)) return(0); 867c478bd9Sstevel@tonic-gate if (s[0] == '\\') s++; 877c478bd9Sstevel@tonic-gate if (s[1] ) return(0); 887c478bd9Sstevel@tonic-gate if (s[0] == '_') return('-'); 897c478bd9Sstevel@tonic-gate if (s[0] == '=') return('='); 907c478bd9Sstevel@tonic-gate return(0); 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 93*b5514887Smuffin void 94*b5514887Smuffin need(void) 957c478bd9Sstevel@tonic-gate { 967c478bd9Sstevel@tonic-gate int texlin, horlin, i; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate for(texlin = horlin = i = 0; i < nlin; i++) { 997c478bd9Sstevel@tonic-gate if (allh(i)) 1007c478bd9Sstevel@tonic-gate horlin++; 1017c478bd9Sstevel@tonic-gate else if (instead[i] != 0) 1027c478bd9Sstevel@tonic-gate continue; 1037c478bd9Sstevel@tonic-gate else 1047c478bd9Sstevel@tonic-gate texlin++; 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate (void) fprintf(tabout, ".ne %dv+%dp\n", texlin, 2 * horlin); 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * For nroff runs, we need to reserve space for the full height of the 1097c478bd9Sstevel@tonic-gate * horizontal rules. If we don't reserve sufficient height, we'll have 1107c478bd9Sstevel@tonic-gate * problems trying to draw the vertical lines across the page boundary. 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate (void) fprintf(tabout, ".if n .ne %dv\n", 2 * texlin + 2 * horlin + 2); 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate 115*b5514887Smuffin void 116*b5514887Smuffin deftail(void) 1177c478bd9Sstevel@tonic-gate { 1187c478bd9Sstevel@tonic-gate int i, c, lf, lwid; 1197c478bd9Sstevel@tonic-gate for(i=0; i<MAXHEAD; i++) 1207c478bd9Sstevel@tonic-gate if (linestop[i]) 1217c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1); 1227c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr #a 0-1\n"); 1237c478bd9Sstevel@tonic-gate fprintf(tabout, ".eo\n"); 1247c478bd9Sstevel@tonic-gate fprintf(tabout, ".de T#\n"); 1257c478bd9Sstevel@tonic-gate fprintf(tabout, ".ds #d .d\n"); 1267c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n"); 1277c478bd9Sstevel@tonic-gate fprintf(tabout, ".mk ##\n"); 1287c478bd9Sstevel@tonic-gate fprintf(tabout, ".nr ## -1v\n"); 1297c478bd9Sstevel@tonic-gate fprintf(tabout, ".ls 1\n"); 1307c478bd9Sstevel@tonic-gate for(i=0; i<MAXHEAD; i++) 1317c478bd9Sstevel@tonic-gate if (linestop[i]) 1327c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1); 1337c478bd9Sstevel@tonic-gate if (boxflg || allflg || dboxflg) { /* bottom of table line */ 1347c478bd9Sstevel@tonic-gate if (!pr1403) 1357c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n"); 1367c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\n(T. "); 1377c478bd9Sstevel@tonic-gate drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0); 1387c478bd9Sstevel@tonic-gate fprintf(tabout, "\n.if \\n(T. .vs\n"); 1397c478bd9Sstevel@tonic-gate /* T. is really an argument to a macro but because of 1407c478bd9Sstevel@tonic-gate eqn we don't dare pass it as an argument and reference by $1 */ 1417c478bd9Sstevel@tonic-gate } 1427c478bd9Sstevel@tonic-gate for(c=0; c<ncol; c++) 1437c478bd9Sstevel@tonic-gate { 1447c478bd9Sstevel@tonic-gate if ((lf=left(nlin-1,c, &lwid))>=0) 1457c478bd9Sstevel@tonic-gate { 1467c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1); 1477c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1); 1487c478bd9Sstevel@tonic-gate tohcol(c); 1497c478bd9Sstevel@tonic-gate drawvert(lf, nlin-1, c, lwid); 1507c478bd9Sstevel@tonic-gate fprintf(tabout, "\\h'|\\n(TWu'\n"); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate if (boxflg || allflg || dboxflg) /* right hand line */ 1547c478bd9Sstevel@tonic-gate { 1557c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\n(#a>=0 .sp -1\n"); 1567c478bd9Sstevel@tonic-gate fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'"); 1577c478bd9Sstevel@tonic-gate drawvert (0, nlin-1, ncol, dboxflg? 2 : 1); 1587c478bd9Sstevel@tonic-gate fprintf(tabout, "\n"); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate fprintf(tabout, ".ls\n"); 1617c478bd9Sstevel@tonic-gate fprintf(tabout, "..\n"); 1627c478bd9Sstevel@tonic-gate fprintf(tabout, ".ec\n"); 1637c478bd9Sstevel@tonic-gate } 164