10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate * The Regents of the University of California
330Sstevel@tonic-gate * All Rights Reserved
340Sstevel@tonic-gate *
350Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate * contributors.
380Sstevel@tonic-gate */
390Sstevel@tonic-gate
40*217Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
41*217Smuffin
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate * troff3.c
440Sstevel@tonic-gate *
450Sstevel@tonic-gate * macro and string routines, storage allocation
460Sstevel@tonic-gate */
470Sstevel@tonic-gate
480Sstevel@tonic-gate
490Sstevel@tonic-gate #include "tdef.h"
500Sstevel@tonic-gate #ifdef NROFF
510Sstevel@tonic-gate #include "tw.h"
520Sstevel@tonic-gate #endif
530Sstevel@tonic-gate #include "ext.h"
540Sstevel@tonic-gate
550Sstevel@tonic-gate #define MHASH(x) ((x>>6)^x)&0177
560Sstevel@tonic-gate struct contab *mhash[128]; /* 128 == the 0177 on line above */
570Sstevel@tonic-gate #define blisti(i) (((i)-ENV_BLK*BLK) / BLK)
580Sstevel@tonic-gate filep blist[NBLIST];
590Sstevel@tonic-gate tchar *argtop;
600Sstevel@tonic-gate int pagech = '%';
610Sstevel@tonic-gate int strflg;
620Sstevel@tonic-gate
630Sstevel@tonic-gate #ifdef INCORE
640Sstevel@tonic-gate tchar *wbuf;
650Sstevel@tonic-gate tchar corebuf[(ENV_BLK + NBLIST + 1) * BLK];
660Sstevel@tonic-gate #else
670Sstevel@tonic-gate tchar wbuf[BLK];
680Sstevel@tonic-gate tchar rbuf[BLK];
690Sstevel@tonic-gate #endif
700Sstevel@tonic-gate
71*217Smuffin int
caseig()720Sstevel@tonic-gate caseig()
730Sstevel@tonic-gate {
74*217Smuffin int i;
75*217Smuffin filep oldoff;
760Sstevel@tonic-gate
770Sstevel@tonic-gate oldoff = offset;
780Sstevel@tonic-gate offset = 0;
790Sstevel@tonic-gate i = copyb();
800Sstevel@tonic-gate offset = oldoff;
810Sstevel@tonic-gate if (i != '.')
820Sstevel@tonic-gate control(i, 1);
83*217Smuffin
84*217Smuffin return (0);
850Sstevel@tonic-gate }
860Sstevel@tonic-gate
87*217Smuffin int
casern()880Sstevel@tonic-gate casern()
890Sstevel@tonic-gate {
90*217Smuffin int i, j;
910Sstevel@tonic-gate
920Sstevel@tonic-gate lgf++;
930Sstevel@tonic-gate skip();
940Sstevel@tonic-gate if ((i = getrq()) == 0 || (oldmn = findmn(i)) < 0)
95*217Smuffin return (0);
960Sstevel@tonic-gate skip();
970Sstevel@tonic-gate clrmn(findmn(j = getrq()));
980Sstevel@tonic-gate if (j) {
990Sstevel@tonic-gate munhash(&contab[oldmn]);
1000Sstevel@tonic-gate contab[oldmn].rq = j;
1010Sstevel@tonic-gate maddhash(&contab[oldmn]);
1020Sstevel@tonic-gate }
103*217Smuffin
104*217Smuffin return (0);
1050Sstevel@tonic-gate }
1060Sstevel@tonic-gate
107*217Smuffin int
maddhash(rp)1080Sstevel@tonic-gate maddhash(rp)
109*217Smuffin struct contab *rp;
1100Sstevel@tonic-gate {
111*217Smuffin struct contab **hp;
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate if (rp->rq == 0)
114*217Smuffin return (0);
1150Sstevel@tonic-gate hp = &mhash[MHASH(rp->rq)];
1160Sstevel@tonic-gate rp->link = *hp;
1170Sstevel@tonic-gate *hp = rp;
118*217Smuffin
119*217Smuffin return (0);
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate
122*217Smuffin int
munhash(mp)1230Sstevel@tonic-gate munhash(mp)
124*217Smuffin struct contab *mp;
1250Sstevel@tonic-gate {
126*217Smuffin struct contab *p;
127*217Smuffin struct contab **lp;
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate if (mp->rq == 0)
130*217Smuffin return (0);
1310Sstevel@tonic-gate lp = &mhash[MHASH(mp->rq)];
1320Sstevel@tonic-gate p = *lp;
1330Sstevel@tonic-gate while (p) {
1340Sstevel@tonic-gate if (p == mp) {
1350Sstevel@tonic-gate *lp = p->link;
1360Sstevel@tonic-gate p->link = 0;
137*217Smuffin return (0);
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate lp = &p->link;
1400Sstevel@tonic-gate p = p->link;
1410Sstevel@tonic-gate }
142*217Smuffin
143*217Smuffin return (0);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate
146*217Smuffin int
mrehash()1470Sstevel@tonic-gate mrehash()
1480Sstevel@tonic-gate {
149*217Smuffin struct contab *p;
150*217Smuffin int i;
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate for (i=0; i<128; i++)
1530Sstevel@tonic-gate mhash[i] = 0;
1540Sstevel@tonic-gate for (p=contab; p < &contab[NM]; p++)
1550Sstevel@tonic-gate p->link = 0;
1560Sstevel@tonic-gate for (p=contab; p < &contab[NM]; p++) {
1570Sstevel@tonic-gate if (p->rq == 0)
1580Sstevel@tonic-gate continue;
1590Sstevel@tonic-gate i = MHASH(p->rq);
1600Sstevel@tonic-gate p->link = mhash[i];
1610Sstevel@tonic-gate mhash[i] = p;
1620Sstevel@tonic-gate }
163*217Smuffin
164*217Smuffin return (0);
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate
167*217Smuffin int
caserm()1680Sstevel@tonic-gate caserm()
1690Sstevel@tonic-gate {
1700Sstevel@tonic-gate int j;
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate lgf++;
1730Sstevel@tonic-gate while (!skip() && (j = getrq()) != 0)
1740Sstevel@tonic-gate clrmn(findmn(j));
1750Sstevel@tonic-gate lgf--;
176*217Smuffin
177*217Smuffin return (0);
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate
1800Sstevel@tonic-gate
181*217Smuffin int
caseas()1820Sstevel@tonic-gate caseas()
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate app++;
1850Sstevel@tonic-gate caseds();
186*217Smuffin
187*217Smuffin return (0);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate
191*217Smuffin int
caseds()1920Sstevel@tonic-gate caseds()
1930Sstevel@tonic-gate {
1940Sstevel@tonic-gate ds++;
1950Sstevel@tonic-gate casede();
196*217Smuffin
197*217Smuffin return (0);
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate
201*217Smuffin int
caseam()2020Sstevel@tonic-gate caseam()
2030Sstevel@tonic-gate {
2040Sstevel@tonic-gate app++;
2050Sstevel@tonic-gate casede();
206*217Smuffin
207*217Smuffin return (0);
2080Sstevel@tonic-gate }
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate
211*217Smuffin int
casede()2120Sstevel@tonic-gate casede()
2130Sstevel@tonic-gate {
214*217Smuffin int i, req;
215*217Smuffin filep savoff;
2160Sstevel@tonic-gate extern filep finds();
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate if (dip != d)
2190Sstevel@tonic-gate wbfl();
2200Sstevel@tonic-gate req = '.';
2210Sstevel@tonic-gate lgf++;
2220Sstevel@tonic-gate skip();
2230Sstevel@tonic-gate if ((i = getrq()) == 0)
2240Sstevel@tonic-gate goto de1;
2250Sstevel@tonic-gate if ((offset = finds(i)) == 0)
2260Sstevel@tonic-gate goto de1;
2270Sstevel@tonic-gate if (ds)
2280Sstevel@tonic-gate copys();
2290Sstevel@tonic-gate else
2300Sstevel@tonic-gate req = copyb();
2310Sstevel@tonic-gate wbfl();
2320Sstevel@tonic-gate clrmn(oldmn);
2330Sstevel@tonic-gate if (newmn) {
2340Sstevel@tonic-gate if (contab[newmn].rq)
2350Sstevel@tonic-gate munhash(&contab[newmn]);
2360Sstevel@tonic-gate contab[newmn].rq = i;
2370Sstevel@tonic-gate maddhash(&contab[newmn]);
2380Sstevel@tonic-gate }
2390Sstevel@tonic-gate if (apptr) {
2400Sstevel@tonic-gate savoff = offset;
2410Sstevel@tonic-gate offset = apptr;
2420Sstevel@tonic-gate wbt((tchar) IMP);
2430Sstevel@tonic-gate offset = savoff;
2440Sstevel@tonic-gate }
2450Sstevel@tonic-gate offset = dip->op;
2460Sstevel@tonic-gate if (req != '.')
2470Sstevel@tonic-gate control(req, 1);
2480Sstevel@tonic-gate de1:
2490Sstevel@tonic-gate ds = app = 0;
250*217Smuffin return (0);
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate
254*217Smuffin int
findmn(i)2550Sstevel@tonic-gate findmn(i)
256*217Smuffin int i;
2570Sstevel@tonic-gate {
258*217Smuffin struct contab *p;
2590Sstevel@tonic-gate
2600Sstevel@tonic-gate for (p = mhash[MHASH(i)]; p; p = p->link)
2610Sstevel@tonic-gate if (i == p->rq)
2620Sstevel@tonic-gate return(p - contab);
2630Sstevel@tonic-gate return(-1);
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate
267*217Smuffin int
clrmn(i)2680Sstevel@tonic-gate clrmn(i)
269*217Smuffin int i;
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate if (i >= 0) {
2720Sstevel@tonic-gate if (contab[i].mx)
2730Sstevel@tonic-gate ffree((filep)contab[i].mx);
2740Sstevel@tonic-gate munhash(&contab[i]);
2750Sstevel@tonic-gate contab[i].rq = 0;
2760Sstevel@tonic-gate contab[i].mx = 0;
2770Sstevel@tonic-gate contab[i].f = 0;
2780Sstevel@tonic-gate }
279*217Smuffin
280*217Smuffin return (0);
2810Sstevel@tonic-gate }
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate
finds(mn)2840Sstevel@tonic-gate filep finds(mn)
285*217Smuffin int mn;
2860Sstevel@tonic-gate {
287*217Smuffin int i;
288*217Smuffin filep savip;
2890Sstevel@tonic-gate extern filep alloc();
2900Sstevel@tonic-gate extern filep incoff();
2910Sstevel@tonic-gate
2920Sstevel@tonic-gate oldmn = findmn(mn);
2930Sstevel@tonic-gate newmn = 0;
2940Sstevel@tonic-gate apptr = (filep)0;
2950Sstevel@tonic-gate if (app && oldmn >= 0 && contab[oldmn].mx) {
2960Sstevel@tonic-gate savip = ip;
2970Sstevel@tonic-gate ip = (filep)contab[oldmn].mx;
2980Sstevel@tonic-gate oldmn = -1;
2990Sstevel@tonic-gate while ((i = rbf()) != 0)
3000Sstevel@tonic-gate ;
3010Sstevel@tonic-gate apptr = ip;
3020Sstevel@tonic-gate if (!diflg)
3030Sstevel@tonic-gate ip = incoff(ip);
3040Sstevel@tonic-gate nextb = ip;
3050Sstevel@tonic-gate ip = savip;
3060Sstevel@tonic-gate } else {
3070Sstevel@tonic-gate for (i = 0; i < NM; i++) {
3080Sstevel@tonic-gate if (contab[i].rq == 0)
3090Sstevel@tonic-gate break;
3100Sstevel@tonic-gate }
3110Sstevel@tonic-gate if (i == NM || (nextb = alloc()) == 0) {
3120Sstevel@tonic-gate app = 0;
3130Sstevel@tonic-gate if (macerr++ > 1)
3140Sstevel@tonic-gate done2(02);
3150Sstevel@tonic-gate errprint(gettext("Too many (%d) string/macro names"),
3160Sstevel@tonic-gate NM);
3170Sstevel@tonic-gate edone(04);
3180Sstevel@tonic-gate return(offset = 0);
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate contab[i].mx = (unsigned) nextb;
3210Sstevel@tonic-gate if (!diflg) {
3220Sstevel@tonic-gate newmn = i;
3230Sstevel@tonic-gate if (oldmn == -1)
3240Sstevel@tonic-gate contab[i].rq = -1;
3250Sstevel@tonic-gate } else {
3260Sstevel@tonic-gate contab[i].rq = mn;
3270Sstevel@tonic-gate maddhash(&contab[i]);
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate app = 0;
3310Sstevel@tonic-gate return(offset = nextb);
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate
335*217Smuffin int
skip()3360Sstevel@tonic-gate skip() /*skip over blanks; return nlflg*/
3370Sstevel@tonic-gate {
338*217Smuffin tchar i;
3390Sstevel@tonic-gate
3400Sstevel@tonic-gate while (cbits(i = getch()) == ' ')
3410Sstevel@tonic-gate ;
3420Sstevel@tonic-gate ch = i;
3430Sstevel@tonic-gate return(nlflg);
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate
347*217Smuffin int
copyb()3480Sstevel@tonic-gate copyb()
3490Sstevel@tonic-gate {
350*217Smuffin int i, j, state;
351*217Smuffin tchar ii;
3520Sstevel@tonic-gate int req, k;
3530Sstevel@tonic-gate filep savoff;
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate if (skip() || !(j = getrq()))
3560Sstevel@tonic-gate j = '.';
3570Sstevel@tonic-gate req = j;
3580Sstevel@tonic-gate k = j >> BYTE;
3590Sstevel@tonic-gate j &= BYTEMASK;
3600Sstevel@tonic-gate copyf++;
3610Sstevel@tonic-gate flushi();
3620Sstevel@tonic-gate nlflg = 0;
3630Sstevel@tonic-gate state = 1;
3640Sstevel@tonic-gate
3650Sstevel@tonic-gate /* state 0 eat up
3660Sstevel@tonic-gate * state 1 look for .
3670Sstevel@tonic-gate * state 2 look for first char of end macro
3680Sstevel@tonic-gate * state 3 look for second char of end macro
3690Sstevel@tonic-gate */
3700Sstevel@tonic-gate
3710Sstevel@tonic-gate while (1) {
3720Sstevel@tonic-gate i = cbits(ii = getch());
3730Sstevel@tonic-gate if (state == 3) {
3740Sstevel@tonic-gate if (i == k)
3750Sstevel@tonic-gate break;
3760Sstevel@tonic-gate if (!k) {
3770Sstevel@tonic-gate ch = ii;
3780Sstevel@tonic-gate i = getach();
3790Sstevel@tonic-gate ch = ii;
3800Sstevel@tonic-gate if (!i)
3810Sstevel@tonic-gate break;
3820Sstevel@tonic-gate }
3830Sstevel@tonic-gate state = 0;
3840Sstevel@tonic-gate goto c0;
3850Sstevel@tonic-gate }
3860Sstevel@tonic-gate if (i == '\n') {
3870Sstevel@tonic-gate state = 1;
3880Sstevel@tonic-gate nlflg = 0;
3890Sstevel@tonic-gate goto c0;
3900Sstevel@tonic-gate }
3910Sstevel@tonic-gate if (state == 1 && i == '.') {
3920Sstevel@tonic-gate state++;
3930Sstevel@tonic-gate savoff = offset;
3940Sstevel@tonic-gate goto c0;
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate if ((state == 2) && (i == j)) {
3970Sstevel@tonic-gate state++;
3980Sstevel@tonic-gate goto c0;
3990Sstevel@tonic-gate }
4000Sstevel@tonic-gate state = 0;
4010Sstevel@tonic-gate c0:
4020Sstevel@tonic-gate if (offset)
4030Sstevel@tonic-gate wbf(ii);
4040Sstevel@tonic-gate }
4050Sstevel@tonic-gate if (offset) {
4060Sstevel@tonic-gate wbfl();
4070Sstevel@tonic-gate offset = savoff;
4080Sstevel@tonic-gate wbt((tchar)0);
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate copyf--;
4110Sstevel@tonic-gate return(req);
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate
415*217Smuffin int
copys()4160Sstevel@tonic-gate copys()
4170Sstevel@tonic-gate {
418*217Smuffin tchar i;
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate copyf++;
4210Sstevel@tonic-gate if (skip())
4220Sstevel@tonic-gate goto c0;
4230Sstevel@tonic-gate if (cbits(i = getch()) != '"')
4240Sstevel@tonic-gate wbf(i);
4250Sstevel@tonic-gate while (cbits(i = getch()) != '\n')
4260Sstevel@tonic-gate wbf(i);
4270Sstevel@tonic-gate c0:
4280Sstevel@tonic-gate wbt((tchar)0);
4290Sstevel@tonic-gate copyf--;
430*217Smuffin
431*217Smuffin return (0);
4320Sstevel@tonic-gate }
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate
alloc()4350Sstevel@tonic-gate filep alloc() /*return free blist[] block in nextb*/
4360Sstevel@tonic-gate {
437*217Smuffin int i;
438*217Smuffin filep j;
4390Sstevel@tonic-gate
4400Sstevel@tonic-gate for (i = 0; i < NBLIST; i++) {
4410Sstevel@tonic-gate if (blist[i] == 0)
4420Sstevel@tonic-gate break;
4430Sstevel@tonic-gate }
4440Sstevel@tonic-gate if (i == NBLIST) {
4450Sstevel@tonic-gate j = 0;
4460Sstevel@tonic-gate } else {
4470Sstevel@tonic-gate blist[i] = -1;
4480Sstevel@tonic-gate j = (filep)i * BLK + ENV_BLK * BLK;
4490Sstevel@tonic-gate }
4500Sstevel@tonic-gate #ifdef DEBUG
4510Sstevel@tonic-gate if (debug & DB_ALLC) {
4520Sstevel@tonic-gate char cc1, cc2;
4530Sstevel@tonic-gate fdprintf(stderr, "alloc: ");
4540Sstevel@tonic-gate if (oldmn >= 0 && oldmn < NM) {
4550Sstevel@tonic-gate cc1 = contab[oldmn].rq & 0177;
4560Sstevel@tonic-gate if ((cc2 = (contab[oldmn].rq >> BYTE) & 0177) == 0)
4570Sstevel@tonic-gate cc2 = ' ';
4580Sstevel@tonic-gate fdprintf(stderr, "oldmn %d %c%c, ", oldmn, cc1, cc2);
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate fdprintf(stderr, "newmn %d; nextb was %x, will be %x\n",
4610Sstevel@tonic-gate newmn, nextb, j);
4620Sstevel@tonic-gate }
463*217Smuffin #endif /* DEBUG */
4640Sstevel@tonic-gate return(nextb = j);
4650Sstevel@tonic-gate }
4660Sstevel@tonic-gate
4670Sstevel@tonic-gate
468*217Smuffin int
ffree(i)4690Sstevel@tonic-gate ffree(i) /*free blist[i] and blocks pointed to*/
4700Sstevel@tonic-gate filep i;
4710Sstevel@tonic-gate {
472*217Smuffin int j;
4730Sstevel@tonic-gate
4740Sstevel@tonic-gate while (blist[j = blisti(i)] != (unsigned) ~0) {
4750Sstevel@tonic-gate i = (filep) blist[j];
4760Sstevel@tonic-gate blist[j] = 0;
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate blist[j] = 0;
479*217Smuffin
480*217Smuffin return (0);
4810Sstevel@tonic-gate }
4820Sstevel@tonic-gate
483*217Smuffin int
wbt(i)4840Sstevel@tonic-gate wbt(i)
4850Sstevel@tonic-gate tchar i;
4860Sstevel@tonic-gate {
4870Sstevel@tonic-gate wbf(i);
4880Sstevel@tonic-gate wbfl();
489*217Smuffin
490*217Smuffin return (0);
4910Sstevel@tonic-gate }
4920Sstevel@tonic-gate
4930Sstevel@tonic-gate
494*217Smuffin int
wbf(i)4950Sstevel@tonic-gate wbf(i) /*store i into blist[offset] (?) */
496*217Smuffin tchar i;
4970Sstevel@tonic-gate {
498*217Smuffin int j;
4990Sstevel@tonic-gate
5000Sstevel@tonic-gate if (!offset)
501*217Smuffin return (0);
5020Sstevel@tonic-gate if (!woff) {
5030Sstevel@tonic-gate woff = offset;
5040Sstevel@tonic-gate #ifdef INCORE
5050Sstevel@tonic-gate wbuf = &corebuf[woff]; /* INCORE only */
5060Sstevel@tonic-gate #endif
5070Sstevel@tonic-gate wbfi = 0;
5080Sstevel@tonic-gate }
5090Sstevel@tonic-gate wbuf[wbfi++] = i;
5100Sstevel@tonic-gate if (!((++offset) & (BLK - 1))) {
5110Sstevel@tonic-gate wbfl();
5120Sstevel@tonic-gate j = blisti(--offset);
5130Sstevel@tonic-gate if (j < 0 || j >= NBLIST) {
5140Sstevel@tonic-gate errprint(gettext("Out of temp file space"));
5150Sstevel@tonic-gate done2(01);
5160Sstevel@tonic-gate }
5170Sstevel@tonic-gate if (blist[j] == (unsigned) ~0) {
5180Sstevel@tonic-gate if (alloc() == 0) {
5190Sstevel@tonic-gate errprint(gettext("Out of temp file space"));
5200Sstevel@tonic-gate done2(01);
5210Sstevel@tonic-gate }
5220Sstevel@tonic-gate blist[j] = (unsigned)(nextb);
5230Sstevel@tonic-gate }
5240Sstevel@tonic-gate offset = ((filep)blist[j]);
5250Sstevel@tonic-gate }
5260Sstevel@tonic-gate if (wbfi >= BLK)
5270Sstevel@tonic-gate wbfl();
528*217Smuffin
529*217Smuffin return (0);
5300Sstevel@tonic-gate }
5310Sstevel@tonic-gate
5320Sstevel@tonic-gate
533*217Smuffin int
wbfl()5340Sstevel@tonic-gate wbfl() /*flush current blist[] block*/
5350Sstevel@tonic-gate {
5360Sstevel@tonic-gate if (woff == 0)
537*217Smuffin return (0);
5380Sstevel@tonic-gate #ifndef INCORE
5390Sstevel@tonic-gate lseek(ibf, ((long)woff) * sizeof(tchar), 0);
5400Sstevel@tonic-gate write(ibf, (char *)wbuf, wbfi * sizeof(tchar));
5410Sstevel@tonic-gate #endif
5420Sstevel@tonic-gate if ((woff & (~(BLK - 1))) == (roff & (~(BLK - 1))))
5430Sstevel@tonic-gate roff = -1;
5440Sstevel@tonic-gate woff = 0;
545*217Smuffin
546*217Smuffin return (0);
5470Sstevel@tonic-gate }
5480Sstevel@tonic-gate
5490Sstevel@tonic-gate
rbf()5500Sstevel@tonic-gate tchar rbf() /*return next char from blist[] block*/
5510Sstevel@tonic-gate {
552*217Smuffin tchar i;
553*217Smuffin filep j, p;
5540Sstevel@tonic-gate extern filep incoff();
5550Sstevel@tonic-gate
5560Sstevel@tonic-gate if (ip == NBLIST*BLK) { /* for rdtty */
5570Sstevel@tonic-gate if (j = rdtty())
5580Sstevel@tonic-gate return(j);
5590Sstevel@tonic-gate else
5600Sstevel@tonic-gate return(popi());
5610Sstevel@tonic-gate }
5620Sstevel@tonic-gate /* this is an inline expansion of rbf0: dirty! */
5630Sstevel@tonic-gate #ifndef INCORE
5640Sstevel@tonic-gate j = ip & ~(BLK - 1);
5650Sstevel@tonic-gate if (j != roff) {
5660Sstevel@tonic-gate roff = j;
5670Sstevel@tonic-gate lseek(ibf, (long)j * sizeof(tchar), 0);
5680Sstevel@tonic-gate if (read(ibf, (char *)rbuf, BLK * sizeof(tchar)) <= 0)
5690Sstevel@tonic-gate i = 0;
5700Sstevel@tonic-gate else
5710Sstevel@tonic-gate i = rbuf[ip & (BLK-1)];
5720Sstevel@tonic-gate } else
5730Sstevel@tonic-gate i = rbuf[ip & (BLK-1)];
5740Sstevel@tonic-gate #else
5750Sstevel@tonic-gate i = corebuf[ip];
5760Sstevel@tonic-gate #endif
5770Sstevel@tonic-gate /* end of rbf0 */
5780Sstevel@tonic-gate if (i == 0) {
5790Sstevel@tonic-gate if (!app)
5800Sstevel@tonic-gate i = popi();
5810Sstevel@tonic-gate return(i);
5820Sstevel@tonic-gate }
5830Sstevel@tonic-gate /* this is an inline expansion of incoff: also dirty */
5840Sstevel@tonic-gate p = ++ip;
5850Sstevel@tonic-gate if ((p & (BLK - 1)) == 0) {
5860Sstevel@tonic-gate if ((ip = blist[blisti(p-1)]) == (unsigned) ~0) {
5870Sstevel@tonic-gate errprint(gettext("Bad storage allocation"));
5880Sstevel@tonic-gate ip = 0;
5890Sstevel@tonic-gate done2(-5);
5900Sstevel@tonic-gate }
5910Sstevel@tonic-gate /* this was meant to protect against people removing
5920Sstevel@tonic-gate * the macro they were standing on, but it's too
5930Sstevel@tonic-gate * sensitive to block boundaries.
5940Sstevel@tonic-gate * if (ip == 0) {
5950Sstevel@tonic-gate * errprint(gettext("Block removed while in use"));
5960Sstevel@tonic-gate * done2(-6);
5970Sstevel@tonic-gate * }
5980Sstevel@tonic-gate */
5990Sstevel@tonic-gate }
6000Sstevel@tonic-gate return(i);
6010Sstevel@tonic-gate }
6020Sstevel@tonic-gate
6030Sstevel@tonic-gate
rbf0(p)6040Sstevel@tonic-gate tchar rbf0(p)
605*217Smuffin filep p;
6060Sstevel@tonic-gate {
6070Sstevel@tonic-gate #ifndef INCORE
608*217Smuffin filep i;
6090Sstevel@tonic-gate
6100Sstevel@tonic-gate if ((i = p & ~(BLK - 1)) != roff) {
6110Sstevel@tonic-gate roff = i;
6120Sstevel@tonic-gate lseek(ibf, (long)roff * sizeof(tchar), 0);
6130Sstevel@tonic-gate if (read(ibf, (char *)rbuf, BLK * sizeof(tchar)) == 0)
6140Sstevel@tonic-gate return(0);
6150Sstevel@tonic-gate }
6160Sstevel@tonic-gate return(rbuf[p & (BLK-1)]);
6170Sstevel@tonic-gate #else
6180Sstevel@tonic-gate return(corebuf[p]);
6190Sstevel@tonic-gate #endif
6200Sstevel@tonic-gate }
6210Sstevel@tonic-gate
6220Sstevel@tonic-gate
incoff(p)6230Sstevel@tonic-gate filep incoff(p) /*get next blist[] block*/
624*217Smuffin filep p;
6250Sstevel@tonic-gate {
6260Sstevel@tonic-gate p++;
6270Sstevel@tonic-gate if ((p & (BLK - 1)) == 0) {
6280Sstevel@tonic-gate if ((p = blist[blisti(p-1)]) == (unsigned) ~0) {
6290Sstevel@tonic-gate errprint(gettext("Bad storage allocation"));
6300Sstevel@tonic-gate done2(-5);
6310Sstevel@tonic-gate }
6320Sstevel@tonic-gate }
6330Sstevel@tonic-gate return(p);
6340Sstevel@tonic-gate }
6350Sstevel@tonic-gate
6360Sstevel@tonic-gate
popi()6370Sstevel@tonic-gate tchar popi()
6380Sstevel@tonic-gate {
639*217Smuffin struct s *p;
6400Sstevel@tonic-gate
6410Sstevel@tonic-gate if (frame == stk)
6420Sstevel@tonic-gate return(0);
6430Sstevel@tonic-gate if (strflg)
6440Sstevel@tonic-gate strflg--;
6450Sstevel@tonic-gate p = nxf = frame;
6460Sstevel@tonic-gate p->nargs = 0;
6470Sstevel@tonic-gate frame = p->pframe;
6480Sstevel@tonic-gate ip = p->pip;
6490Sstevel@tonic-gate pendt = p->ppendt;
6500Sstevel@tonic-gate lastpbp = p->lastpbp;
6510Sstevel@tonic-gate return(p->pch);
6520Sstevel@tonic-gate }
6530Sstevel@tonic-gate
6540Sstevel@tonic-gate /*
6550Sstevel@tonic-gate * test that the end of the allocation is above a certain location
6560Sstevel@tonic-gate * in memory
6570Sstevel@tonic-gate */
6580Sstevel@tonic-gate #define SPACETEST(base, size) while ((enda - (size)) <= (char *)(base)){setbrk(DELTA);}
6590Sstevel@tonic-gate
660*217Smuffin int
pushi(newip,mname)6610Sstevel@tonic-gate pushi(newip, mname)
6620Sstevel@tonic-gate filep newip;
6630Sstevel@tonic-gate int mname;
6640Sstevel@tonic-gate {
665*217Smuffin struct s *p;
6660Sstevel@tonic-gate extern char *setbrk();
6670Sstevel@tonic-gate
6680Sstevel@tonic-gate SPACETEST(nxf, sizeof(struct s));
6690Sstevel@tonic-gate p = nxf;
6700Sstevel@tonic-gate p->pframe = frame;
6710Sstevel@tonic-gate p->pip = ip;
6720Sstevel@tonic-gate p->ppendt = pendt;
6730Sstevel@tonic-gate p->pch = ch;
6740Sstevel@tonic-gate p->lastpbp = lastpbp;
6750Sstevel@tonic-gate p->mname = mname;
6760Sstevel@tonic-gate lastpbp = pbp;
6770Sstevel@tonic-gate pendt = ch = 0;
6780Sstevel@tonic-gate frame = nxf;
6790Sstevel@tonic-gate if (nxf->nargs == 0)
6800Sstevel@tonic-gate nxf += 1;
6810Sstevel@tonic-gate else
6820Sstevel@tonic-gate nxf = (struct s *)argtop;
6830Sstevel@tonic-gate return(ip = newip);
6840Sstevel@tonic-gate }
6850Sstevel@tonic-gate
6860Sstevel@tonic-gate
setbrk(x)6870Sstevel@tonic-gate char *setbrk(x)
6880Sstevel@tonic-gate int x;
6890Sstevel@tonic-gate {
690*217Smuffin char *i, *k;
691*217Smuffin int j;
6920Sstevel@tonic-gate char *sbrk();
6930Sstevel@tonic-gate
6940Sstevel@tonic-gate if ((i = sbrk(x)) == (char *) -1) {
6950Sstevel@tonic-gate errprint(gettext("Core limit reached"));
6960Sstevel@tonic-gate edone(0100);
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate if (j = (unsigned)i % sizeof(int)) { /*check alignment for 3B*/
6990Sstevel@tonic-gate j = sizeof(int) - j; /*only init calls should need this*/
7000Sstevel@tonic-gate if ((k = sbrk(j)) == (char *) -1) {
7010Sstevel@tonic-gate errprint("Core limit reached");
7020Sstevel@tonic-gate edone(0100);
7030Sstevel@tonic-gate }
7040Sstevel@tonic-gate if (k != i + x) { /*there must have been an intervening sbrk*/
7050Sstevel@tonic-gate errprint ("internal error in setbrk: i=%x, j=%d, k=%x",
7060Sstevel@tonic-gate i, j, k);
7070Sstevel@tonic-gate edone(0100);
7080Sstevel@tonic-gate }
7090Sstevel@tonic-gate i += j;
7100Sstevel@tonic-gate }
7110Sstevel@tonic-gate enda = i + x;
7120Sstevel@tonic-gate return(i);
7130Sstevel@tonic-gate }
7140Sstevel@tonic-gate
7150Sstevel@tonic-gate
716*217Smuffin int
getsn()7170Sstevel@tonic-gate getsn()
7180Sstevel@tonic-gate {
719*217Smuffin int i;
7200Sstevel@tonic-gate
7210Sstevel@tonic-gate if ((i = getach()) == 0)
7220Sstevel@tonic-gate return(0);
7230Sstevel@tonic-gate if (i == '(')
7240Sstevel@tonic-gate return(getrq());
7250Sstevel@tonic-gate else
7260Sstevel@tonic-gate return(i);
7270Sstevel@tonic-gate }
7280Sstevel@tonic-gate
7290Sstevel@tonic-gate
730*217Smuffin int
setstr()7310Sstevel@tonic-gate setstr()
7320Sstevel@tonic-gate {
733*217Smuffin int i, j;
7340Sstevel@tonic-gate
7350Sstevel@tonic-gate lgf++;
7360Sstevel@tonic-gate if ((i = getsn()) == 0 || (j = findmn(i)) == -1 || !contab[j].mx) {
7370Sstevel@tonic-gate lgf--;
7380Sstevel@tonic-gate return(0);
7390Sstevel@tonic-gate } else {
7400Sstevel@tonic-gate SPACETEST(nxf, sizeof(struct s));
7410Sstevel@tonic-gate nxf->nargs = 0;
7420Sstevel@tonic-gate strflg++;
7430Sstevel@tonic-gate lgf--;
7440Sstevel@tonic-gate return pushi((filep)contab[j].mx, i);
7450Sstevel@tonic-gate }
7460Sstevel@tonic-gate }
7470Sstevel@tonic-gate
7480Sstevel@tonic-gate
749*217Smuffin int
collect()7500Sstevel@tonic-gate collect()
7510Sstevel@tonic-gate {
752*217Smuffin int j;
753*217Smuffin tchar i;
754*217Smuffin tchar *strp;
7550Sstevel@tonic-gate tchar * lim;
7560Sstevel@tonic-gate tchar * *argpp, **argppend;
7570Sstevel@tonic-gate int quote;
7580Sstevel@tonic-gate struct s *savnxf;
7590Sstevel@tonic-gate
7600Sstevel@tonic-gate copyf++;
7610Sstevel@tonic-gate nxf->nargs = 0;
7620Sstevel@tonic-gate savnxf = nxf;
7630Sstevel@tonic-gate if (skip())
7640Sstevel@tonic-gate goto rtn;
7650Sstevel@tonic-gate
7660Sstevel@tonic-gate {
7670Sstevel@tonic-gate char *memp;
7680Sstevel@tonic-gate memp = (char *)savnxf;
7690Sstevel@tonic-gate /*
7700Sstevel@tonic-gate * 1 s structure for the macro descriptor
7710Sstevel@tonic-gate * APERMAC tchar *'s for pointers into the strings
7720Sstevel@tonic-gate * space for the tchar's themselves
7730Sstevel@tonic-gate */
7740Sstevel@tonic-gate memp += sizeof(struct s);
7750Sstevel@tonic-gate /*
7760Sstevel@tonic-gate * CPERMAC (the total # of characters for ALL arguments)
7770Sstevel@tonic-gate * to a macros, has been carefully chosen
7780Sstevel@tonic-gate * so that the distance between stack frames is < DELTA
7790Sstevel@tonic-gate */
7800Sstevel@tonic-gate #define CPERMAC 200
7810Sstevel@tonic-gate #define APERMAC 9
7820Sstevel@tonic-gate memp += APERMAC * sizeof(tchar *);
7830Sstevel@tonic-gate memp += CPERMAC * sizeof(tchar);
7840Sstevel@tonic-gate nxf = (struct s*)memp;
7850Sstevel@tonic-gate }
7860Sstevel@tonic-gate lim = (tchar *)nxf;
7870Sstevel@tonic-gate argpp = (tchar **)(savnxf + 1);
7880Sstevel@tonic-gate argppend = &argpp[APERMAC];
7890Sstevel@tonic-gate SPACETEST(argppend, sizeof(tchar *));
7900Sstevel@tonic-gate strp = (tchar *)argppend;
7910Sstevel@tonic-gate /*
7920Sstevel@tonic-gate * Zero out all the string pointers before filling them in.
7930Sstevel@tonic-gate */
7940Sstevel@tonic-gate for (j = 0; j < APERMAC; j++){
7950Sstevel@tonic-gate argpp[j] = (tchar *)0;
7960Sstevel@tonic-gate }
7970Sstevel@tonic-gate #if 0
7980Sstevel@tonic-gate errprint("savnxf=0x%x,nxf=0x%x,argpp=0x%x,strp=argppend=0x%x,lim=0x%x,enda=0x%x",
7990Sstevel@tonic-gate savnxf, nxf, argpp, strp, lim, enda);
800*217Smuffin #endif
8010Sstevel@tonic-gate strflg = 0;
8020Sstevel@tonic-gate while ((argpp != argppend) && (!skip())) {
8030Sstevel@tonic-gate *argpp++ = strp;
8040Sstevel@tonic-gate quote = 0;
8050Sstevel@tonic-gate if (cbits(i = getch()) == '"')
8060Sstevel@tonic-gate quote++;
8070Sstevel@tonic-gate else
8080Sstevel@tonic-gate ch = i;
8090Sstevel@tonic-gate while (1) {
8100Sstevel@tonic-gate i = getch();
8110Sstevel@tonic-gate if (nlflg || (!quote && cbits(i) == ' '))
8120Sstevel@tonic-gate break;
8130Sstevel@tonic-gate if ( quote
8140Sstevel@tonic-gate && (cbits(i) == '"')
8150Sstevel@tonic-gate && (cbits(i = getch()) != '"')) {
8160Sstevel@tonic-gate ch = i;
8170Sstevel@tonic-gate break;
8180Sstevel@tonic-gate }
8190Sstevel@tonic-gate *strp++ = i;
8200Sstevel@tonic-gate if (strflg && strp >= lim) {
8210Sstevel@tonic-gate #if 0
8220Sstevel@tonic-gate errprint("strp=0x%x, lim = 0x%x",
8230Sstevel@tonic-gate strp, lim);
824*217Smuffin #endif
8250Sstevel@tonic-gate errprint(gettext("Macro argument too long"));
8260Sstevel@tonic-gate copyf--;
8270Sstevel@tonic-gate edone(004);
8280Sstevel@tonic-gate }
8290Sstevel@tonic-gate SPACETEST(strp, 3 * sizeof(tchar));
8300Sstevel@tonic-gate }
8310Sstevel@tonic-gate *strp++ = 0;
8320Sstevel@tonic-gate }
8330Sstevel@tonic-gate nxf = savnxf;
8340Sstevel@tonic-gate nxf->nargs = argpp - (tchar **)(savnxf + 1);
8350Sstevel@tonic-gate argtop = strp;
8360Sstevel@tonic-gate rtn:
8370Sstevel@tonic-gate copyf--;
838*217Smuffin
839*217Smuffin return (0);
8400Sstevel@tonic-gate }
8410Sstevel@tonic-gate
8420Sstevel@tonic-gate
843*217Smuffin int
seta()8440Sstevel@tonic-gate seta()
8450Sstevel@tonic-gate {
846*217Smuffin int i;
8470Sstevel@tonic-gate
8480Sstevel@tonic-gate i = cbits(getch()) - '0';
8490Sstevel@tonic-gate if (i > 0 && i <= APERMAC && i <= frame->nargs)
8500Sstevel@tonic-gate pushback(*(((tchar **)(frame + 1)) + i - 1));
851*217Smuffin
852*217Smuffin return (0);
8530Sstevel@tonic-gate }
8540Sstevel@tonic-gate
8550Sstevel@tonic-gate
856*217Smuffin int
caseda()8570Sstevel@tonic-gate caseda()
8580Sstevel@tonic-gate {
8590Sstevel@tonic-gate app++;
8600Sstevel@tonic-gate casedi();
861*217Smuffin
862*217Smuffin return (0);
8630Sstevel@tonic-gate }
8640Sstevel@tonic-gate
8650Sstevel@tonic-gate
866*217Smuffin int
casedi()8670Sstevel@tonic-gate casedi()
8680Sstevel@tonic-gate {
869*217Smuffin int i, j;
870*217Smuffin int *k;
8710Sstevel@tonic-gate
8720Sstevel@tonic-gate lgf++;
8730Sstevel@tonic-gate if (skip() || (i = getrq()) == 0) {
8740Sstevel@tonic-gate if (dip != d)
8750Sstevel@tonic-gate wbt((tchar)0);
8760Sstevel@tonic-gate if (dilev > 0) {
8770Sstevel@tonic-gate numtab[DN].val = dip->dnl;
8780Sstevel@tonic-gate numtab[DL].val = dip->maxl;
8790Sstevel@tonic-gate dip = &d[--dilev];
8800Sstevel@tonic-gate offset = dip->op;
8810Sstevel@tonic-gate }
8820Sstevel@tonic-gate goto rtn;
8830Sstevel@tonic-gate }
8840Sstevel@tonic-gate if (++dilev == NDI) {
8850Sstevel@tonic-gate --dilev;
8860Sstevel@tonic-gate errprint(gettext("Diversions nested too deep"));
8870Sstevel@tonic-gate edone(02);
8880Sstevel@tonic-gate }
8890Sstevel@tonic-gate if (dip != d)
8900Sstevel@tonic-gate wbt((tchar)0);
8910Sstevel@tonic-gate diflg++;
8920Sstevel@tonic-gate dip = &d[dilev];
8930Sstevel@tonic-gate dip->op = finds(i);
8940Sstevel@tonic-gate dip->curd = i;
8950Sstevel@tonic-gate clrmn(oldmn);
8960Sstevel@tonic-gate k = (int *) & dip->dnl;
8970Sstevel@tonic-gate for (j = 0; j < 10; j++)
8980Sstevel@tonic-gate k[j] = 0; /*not op and curd*/
8990Sstevel@tonic-gate rtn:
9000Sstevel@tonic-gate app = 0;
9010Sstevel@tonic-gate diflg = 0;
902*217Smuffin
903*217Smuffin return (0);
9040Sstevel@tonic-gate }
9050Sstevel@tonic-gate
9060Sstevel@tonic-gate
907*217Smuffin int
casedt()9080Sstevel@tonic-gate casedt()
9090Sstevel@tonic-gate {
9100Sstevel@tonic-gate lgf++;
9110Sstevel@tonic-gate dip->dimac = dip->ditrap = dip->ditf = 0;
9120Sstevel@tonic-gate skip();
9130Sstevel@tonic-gate dip->ditrap = vnumb((int *)0);
9140Sstevel@tonic-gate if (nonumb)
915*217Smuffin return (0);
9160Sstevel@tonic-gate skip();
9170Sstevel@tonic-gate dip->dimac = getrq();
918*217Smuffin
919*217Smuffin return (0);
9200Sstevel@tonic-gate }
9210Sstevel@tonic-gate
9220Sstevel@tonic-gate
923*217Smuffin int
casetl()9240Sstevel@tonic-gate casetl()
9250Sstevel@tonic-gate {
926*217Smuffin int j;
9270Sstevel@tonic-gate int w[3];
9280Sstevel@tonic-gate tchar buf[LNSIZE];
929*217Smuffin tchar *tp;
9300Sstevel@tonic-gate tchar i, delim;
9310Sstevel@tonic-gate
9320Sstevel@tonic-gate dip->nls = 0;
9330Sstevel@tonic-gate skip();
9340Sstevel@tonic-gate if (ismot(delim = getch())) {
9350Sstevel@tonic-gate ch = delim;
9360Sstevel@tonic-gate delim = '\'';
9370Sstevel@tonic-gate } else
9380Sstevel@tonic-gate delim = cbits(delim);
9390Sstevel@tonic-gate tp = buf;
9400Sstevel@tonic-gate numtab[HP].val = 0;
9410Sstevel@tonic-gate w[0] = w[1] = w[2] = 0;
9420Sstevel@tonic-gate j = 0;
9430Sstevel@tonic-gate while (cbits(i = getch()) != '\n') {
9440Sstevel@tonic-gate if (cbits(i) == cbits(delim)) {
9450Sstevel@tonic-gate if (j < 3)
9460Sstevel@tonic-gate w[j] = numtab[HP].val;
9470Sstevel@tonic-gate numtab[HP].val = 0;
9480Sstevel@tonic-gate j++;
9490Sstevel@tonic-gate *tp++ = 0;
9500Sstevel@tonic-gate } else {
9510Sstevel@tonic-gate if (cbits(i) == pagech) {
9520Sstevel@tonic-gate setn1(numtab[PN].val, numtab[findr('%')].fmt,
9530Sstevel@tonic-gate i&SFMASK);
9540Sstevel@tonic-gate continue;
9550Sstevel@tonic-gate }
9560Sstevel@tonic-gate numtab[HP].val += width(i);
9570Sstevel@tonic-gate if (tp < &buf[LNSIZE-10])
9580Sstevel@tonic-gate *tp++ = i;
9590Sstevel@tonic-gate }
9600Sstevel@tonic-gate }
9610Sstevel@tonic-gate if (j<3)
9620Sstevel@tonic-gate w[j] = numtab[HP].val;
9630Sstevel@tonic-gate *tp++ = 0;
9640Sstevel@tonic-gate *tp++ = 0;
9650Sstevel@tonic-gate *tp++ = 0;
9660Sstevel@tonic-gate tp = buf;
9670Sstevel@tonic-gate #ifdef NROFF
9680Sstevel@tonic-gate horiz(po);
9690Sstevel@tonic-gate #endif
9700Sstevel@tonic-gate while (i = *tp++)
9710Sstevel@tonic-gate pchar(i);
9720Sstevel@tonic-gate if (w[1] || w[2])
9730Sstevel@tonic-gate horiz(j = quant((lt - w[1]) / 2 - w[0], HOR));
9740Sstevel@tonic-gate while (i = *tp++)
9750Sstevel@tonic-gate pchar(i);
9760Sstevel@tonic-gate if (w[2]) {
9770Sstevel@tonic-gate horiz(lt - w[0] - w[1] - w[2] - j);
9780Sstevel@tonic-gate while (i = *tp++)
9790Sstevel@tonic-gate pchar(i);
9800Sstevel@tonic-gate }
9810Sstevel@tonic-gate newline(0);
9820Sstevel@tonic-gate if (dip != d) {
9830Sstevel@tonic-gate if (dip->dnl > dip->hnl)
9840Sstevel@tonic-gate dip->hnl = dip->dnl;
9850Sstevel@tonic-gate } else {
9860Sstevel@tonic-gate if (numtab[NL].val > dip->hnl)
9870Sstevel@tonic-gate dip->hnl = numtab[NL].val;
9880Sstevel@tonic-gate }
989*217Smuffin
990*217Smuffin return (0);
9910Sstevel@tonic-gate }
9920Sstevel@tonic-gate
9930Sstevel@tonic-gate
994*217Smuffin int
casepc()9950Sstevel@tonic-gate casepc()
9960Sstevel@tonic-gate {
9970Sstevel@tonic-gate pagech = chget(IMP);
998*217Smuffin
999*217Smuffin return (0);
10000Sstevel@tonic-gate }
10010Sstevel@tonic-gate
10020Sstevel@tonic-gate
1003*217Smuffin int
casepm()10040Sstevel@tonic-gate casepm()
10050Sstevel@tonic-gate {
1006*217Smuffin int i, k;
1007*217Smuffin char *p;
10080Sstevel@tonic-gate int xx, cnt, tcnt, kk, tot;
10090Sstevel@tonic-gate filep j;
10100Sstevel@tonic-gate char pmline[10];
10110Sstevel@tonic-gate
10120Sstevel@tonic-gate kk = cnt = tcnt = 0;
10130Sstevel@tonic-gate tot = !skip();
10140Sstevel@tonic-gate for (i = 0; i < NM; i++) {
10150Sstevel@tonic-gate if ((xx = contab[i].rq) == 0 || contab[i].mx == 0)
10160Sstevel@tonic-gate continue;
10170Sstevel@tonic-gate tcnt++;
10180Sstevel@tonic-gate p = pmline;
10190Sstevel@tonic-gate j = (filep) contab[i].mx;
10200Sstevel@tonic-gate k = 1;
10210Sstevel@tonic-gate while ((j = blist[blisti(j)]) != (unsigned) ~0) {
10220Sstevel@tonic-gate k++;
10230Sstevel@tonic-gate }
10240Sstevel@tonic-gate cnt++;
10250Sstevel@tonic-gate kk += k;
10260Sstevel@tonic-gate if (!tot) {
10270Sstevel@tonic-gate *p++ = xx & 0177;
10280Sstevel@tonic-gate if (!(*p++ = (xx >> BYTE) & 0177))
10290Sstevel@tonic-gate *(p - 1) = ' ';
10300Sstevel@tonic-gate *p++ = 0;
10310Sstevel@tonic-gate fdprintf(stderr, "%s %d\n", pmline, k);
10320Sstevel@tonic-gate }
10330Sstevel@tonic-gate }
10340Sstevel@tonic-gate fdprintf(stderr, "pm: total %d, macros %d, space %d\n", tcnt, cnt, kk);
1035*217Smuffin
1036*217Smuffin return (0);
10370Sstevel@tonic-gate }
10380Sstevel@tonic-gate
1039*217Smuffin int
stackdump()10400Sstevel@tonic-gate stackdump() /* dumps stack of macros in process */
10410Sstevel@tonic-gate {
10420Sstevel@tonic-gate struct s *p;
10430Sstevel@tonic-gate
10440Sstevel@tonic-gate if (frame != stk) {
10450Sstevel@tonic-gate for (p = frame; p != stk; p = p->pframe)
10460Sstevel@tonic-gate fdprintf(stderr, "%c%c ", p->mname&0177, (p->mname>>BYTE)&0177);
10470Sstevel@tonic-gate fdprintf(stderr, "\n");
10480Sstevel@tonic-gate }
1049*217Smuffin
1050*217Smuffin return (0);
10510Sstevel@tonic-gate }
1052