xref: /csrg-svn/local/ditroff/ditroff.van/n5.c (revision 54111)
151159Scael #ifndef lint
251159Scael /*
351159Scael static char sccsid[] = "@(#)n5.c	2.2 (CWI) 87/03/31";
451159Scael */
551159Scael static char sccsid[] = "@(#)n5.c	2.3 (Berkeley) 11/3/90";
651159Scael #endif lint
751159Scael #include "tdef.h"
851159Scael #include <sgtty.h>
951159Scael #include "ext.h"
1051159Scael 
1151159Scael /*
1251159Scael  * troff5.c
1351159Scael  *
1451159Scael  * misc processing requests
1551159Scael  */
1651159Scael 
1751159Scael int	iflist[NIF];
1851159Scael int	ifx;
1951159Scael 
casead()2051159Scael casead()
2151159Scael {
2251159Scael 	register i;
2351159Scael 
2451159Scael 	ad = 1;
2551159Scael 	/*leave admod alone*/
2651159Scael 	if (skip())
2751159Scael 		return;
2851159Scael 	switch (i = cbits(getch())) {
2951159Scael 	case 'r':	/*right adj, left ragged*/
3051159Scael 		admod = 2;
3151159Scael 		break;
3251159Scael 	case 'l':	/*left adj, right ragged*/
3351159Scael 		admod = ad = 0;	/*same as casena*/
3451159Scael 		break;
3551159Scael 	case 'c':	/*centered adj*/
3651159Scael 		admod = 1;
3751159Scael 		break;
3851159Scael 	case 'b':
3951159Scael 	case 'n':
4051159Scael 		admod = 0;
4151159Scael 		break;
4251159Scael 	case '0':
4351159Scael 	case '2':
4451159Scael 	case '4':
4551159Scael 		ad = 0;
4651159Scael 	case '1':
4751159Scael 	case '3':
4851159Scael 	case '5':
4951159Scael 		admod = (i - '0') / 2;
5051159Scael 	}
5151159Scael }
5251159Scael 
5351159Scael 
casena()5451159Scael casena()
5551159Scael {
5651159Scael 	ad = 0;
5751159Scael }
5851159Scael 
5951159Scael 
casefi()6051159Scael casefi()
6151159Scael {
6251159Scael 	tbreak();
6351159Scael 	fi++;
6451159Scael 	pendnf = 0;
6551159Scael 	lnsize = LNSIZE;
6651159Scael }
6751159Scael 
6851159Scael 
casenf()6951159Scael casenf()
7051159Scael {
7151159Scael 	tbreak();
7251159Scael 	fi = 0;
7351159Scael }
7451159Scael 
7551159Scael 
casers()7651159Scael casers()
7751159Scael {
7851159Scael 	dip->nls = 0;
7951159Scael }
8051159Scael 
8151159Scael 
casens()8251159Scael casens()
8351159Scael {
8451159Scael 	dip->nls++;
8551159Scael }
8651159Scael 
8751159Scael 
chget(c)8851159Scael chget(c)
8951159Scael int	c;
9051159Scael {
9151159Scael 	tchar i;
9251159Scael 
9351159Scael 	if (skip() || ismot(i = getch()) || cbits(i) == ' ' || cbits(i) == '\n') {
9451159Scael 		ch = i;
9551159Scael 		return(c);
9651159Scael 	} else
9751159Scael 		return(i & BYTEMASK);
9851159Scael }
9951159Scael 
10051159Scael 
casecc()10151159Scael casecc()
10251159Scael {
10351159Scael 	cc = chget('.');
10451159Scael }
10551159Scael 
10651159Scael 
casec2()10751159Scael casec2()
10851159Scael {
10951159Scael 	c2 = chget('\'');
11051159Scael }
11151159Scael 
11251159Scael 
casehc()11351159Scael casehc()
11451159Scael {
11551159Scael 	ohc = chget(OHC);
11651159Scael }
11751159Scael 
11851159Scael 
casetc()11951159Scael casetc()
12051159Scael {
12151159Scael 	tabc = chget(0);
12251159Scael }
12351159Scael 
12451159Scael 
caselc()12551159Scael caselc()
12651159Scael {
12751159Scael 	dotc = chget(0);
12851159Scael }
12951159Scael 
13051159Scael 
casehy()13151159Scael casehy()
13251159Scael {
13351159Scael 	register i;
13451159Scael 
13551159Scael 	hyf = 1;
13651159Scael 	if (skip())
13751159Scael 		return;
13851159Scael 	noscale++;
139*54111Scael 	i = (int)atoi0();
14051159Scael 	noscale = 0;
14151159Scael 	if (nonumb)
14251159Scael 		return;
14351159Scael 	hyf = max(i, 0);
14451159Scael }
14551159Scael 
14651159Scael 
casenh()14751159Scael casenh()
14851159Scael {
14951159Scael 	hyf = 0;
15051159Scael }
15151159Scael 
15251159Scael 
max(aa,bb)15351159Scael max(aa, bb)
15451159Scael int	aa, bb;
15551159Scael {
15651159Scael 	if (aa > bb)
15751159Scael 		return(aa);
15851159Scael 	else
15951159Scael 		return(bb);
16051159Scael }
16151159Scael 
16251159Scael 
casece()16351159Scael casece()
16451159Scael {
16551159Scael 	register i;
16651159Scael 
16751159Scael 	noscale++;
16851159Scael 	skip();
169*54111Scael 	i = max((int)atoi0(), 0);
17051159Scael 	if (nonumb)
17151159Scael 		i = 1;
17251159Scael 	tbreak();
17351159Scael 	ce = i;
17451159Scael 	noscale = 0;
17551159Scael }
17651159Scael 
17751159Scael 
casein()17851159Scael casein()
17951159Scael {
18051159Scael 	register i;
18151159Scael 
18251159Scael 	if (skip())
18351159Scael 		i = in1;
18451159Scael 	else
18551159Scael 		i = max(hnumb(&in), 0);
18651159Scael 	tbreak();
18751159Scael 	in1 = in;
18851159Scael 	in = i;
18951159Scael 	if (!nc) {
19051159Scael 		un = in;
19151159Scael 		setnel();
19251159Scael 	}
19351159Scael }
19451159Scael 
19551159Scael 
casell()19651159Scael casell()
19751159Scael {
19851159Scael 	register i;
19951159Scael 
20051159Scael 	if (skip())
20151159Scael 		i = ll1;
20251159Scael 	else
20351159Scael 		i = max(hnumb(&ll), INCH / 10);
20451159Scael 	ll1 = ll;
20551159Scael 	ll = i;
20651159Scael 	setnel();
20751159Scael }
20851159Scael 
20951159Scael 
caselt()21051159Scael caselt()
21151159Scael {
21251159Scael 	register i;
21351159Scael 
21451159Scael 	if (skip())
21551159Scael 		i = lt1;
21651159Scael 	else
21751159Scael 		i = max(hnumb(&lt), 0);
21851159Scael 	lt1 = lt;
21951159Scael 	lt = i;
22051159Scael }
22151159Scael 
22251159Scael 
caseti()22351159Scael caseti()
22451159Scael {
22551159Scael 	register i;
22651159Scael 
22751159Scael 	if (skip())
22851159Scael 		return;
22951159Scael 	i = max(hnumb(&in), 0);
23051159Scael 	tbreak();
23151159Scael 	un1 = i;
23251159Scael 	setnel();
23351159Scael }
23451159Scael 
23551159Scael 
casels()23651159Scael casels()
23751159Scael {
23851159Scael 	register i;
23951159Scael 
24051159Scael 	noscale++;
24151159Scael 	if (skip())
24251159Scael 		i = ls1;
24351159Scael 	else
24451159Scael 		i = max(inumb(&ls), 1);
24551159Scael 	ls1 = ls;
24651159Scael 	ls = i;
24751159Scael 	noscale = 0;
24851159Scael }
24951159Scael 
25051159Scael 
casepo()25151159Scael casepo()
25251159Scael {
25351159Scael 	register i;
25451159Scael 
25551159Scael 	if (skip())
25651159Scael 		i = po1;
25751159Scael 	else
25851159Scael 		i = max(hnumb(&po), 0);
25951159Scael 	po1 = po;
26051159Scael 	po = i;
26151159Scael #ifndef NROFF
26251159Scael 	if (!ascii)
26351159Scael 		esc += po - po1;
26451159Scael #endif
26551159Scael }
26651159Scael 
26751159Scael 
casepl()26851159Scael casepl()
26951159Scael {
27051159Scael 	register i;
27151159Scael 
27251159Scael 	skip();
27351159Scael 	if ((i = vnumb(&pl)) == 0)
27451159Scael 		pl = 11 * INCH; /*11in*/
27551159Scael 	else
27651159Scael 		pl = i;
27751159Scael 	if (numtab[NL].val > pl)
27851159Scael 		numtab[NL].val = pl;
27951159Scael }
28051159Scael 
28151159Scael 
casewh()28251159Scael casewh()
28351159Scael {
28451159Scael 	register i, j, k;
28551159Scael 
28651159Scael 	lgf++;
28751159Scael 	skip();
28851159Scael 	i = vnumb((int *)0);
28951159Scael 	if (nonumb)
29051159Scael 		return;
29151159Scael 	skip();
29251159Scael 	j = getrq();
29351159Scael 	if ((k = findn(i)) != NTRAP) {
29451159Scael 		mlist[k] = j;
29551159Scael 		return;
29651159Scael 	}
29751159Scael 	for (k = 0; k < NTRAP; k++)
29851159Scael 		if (mlist[k] == 0)
29951159Scael 			break;
30051159Scael 	if (k == NTRAP) {
30151159Scael 		flusho();
30251159Scael 		errprint("cannot plant trap.");
30351159Scael 		return;
30451159Scael 	}
30551159Scael 	mlist[k] = j;
30651159Scael 	nlist[k] = i;
30751159Scael }
30851159Scael 
30951159Scael 
casech()31051159Scael casech()
31151159Scael {
31251159Scael 	register i, j, k;
31351159Scael 
31451159Scael 	lgf++;
31551159Scael 	skip();
31651159Scael 	if (!(j = getrq()))
31751159Scael 		return;
31851159Scael 	else
31951159Scael 		for (k = 0; k < NTRAP; k++)
32051159Scael 			if (mlist[k] == j)
32151159Scael 				break;
32251159Scael 	if (k == NTRAP)
32351159Scael 		return;
32451159Scael 	skip();
32551159Scael 	i = vnumb((int *)0);
32651159Scael 	if (nonumb)
32751159Scael 		mlist[k] = 0;
32851159Scael 	nlist[k] = i;
32951159Scael }
33051159Scael 
33151159Scael 
findn(i)33251159Scael findn(i)
33351159Scael int	i;
33451159Scael {
33551159Scael 	register k;
33651159Scael 
33751159Scael 	for (k = 0; k < NTRAP; k++)
33851159Scael 		if ((nlist[k] == i) && (mlist[k] != 0))
33951159Scael 			break;
34051159Scael 	return(k);
34151159Scael }
34251159Scael 
34351159Scael 
casepn()34451159Scael casepn()
34551159Scael {
34651159Scael 	register i;
34751159Scael 
34851159Scael 	skip();
34951159Scael 	noscale++;
35051159Scael 	i = max(inumb(&numtab[PN].val), 0);
35151159Scael 	noscale = 0;
35251159Scael 	if (!nonumb) {
35351159Scael 		npn = i;
35451159Scael 		npnflg++;
35551159Scael 	}
35651159Scael }
35751159Scael 
35851159Scael 
casebp()35951159Scael casebp()
36051159Scael {
36151159Scael 	register i;
36251159Scael 	register struct s *savframe;
36351159Scael 
36451159Scael 	if (dip != d)
36551159Scael 		return;
36651159Scael 	savframe = frame;
36751159Scael 	skip();
36851159Scael 	if ((i = inumb(&numtab[PN].val)) < 0)
36951159Scael 		i = 0;
37051159Scael 	tbreak();
37151159Scael 	if (!nonumb) {
37251159Scael 		npn = i;
37351159Scael 		npnflg++;
37451159Scael 	} else if (dip->nls)
37551159Scael 		return;
37651159Scael 	eject(savframe);
37751159Scael }
37851159Scael 
37951159Scael 
casetm(ab)38051159Scael casetm(ab)
38151159Scael 	int ab;
38251159Scael {
38351159Scael 	register i;
38451159Scael 	char	tmbuf[NTM];
38551159Scael 
38651159Scael 	lgf++;
38751159Scael 	copyf++;
38851159Scael 	skip();
38951159Scael 	for (i = 0; i < NTM - 2; )
39051159Scael 		if ((tmbuf[i++] = getch()) == '\n')
39151159Scael 			break;
39251159Scael 	if (i == NTM - 2)
39351159Scael 		tmbuf[i++] = '\n';
39451159Scael 	tmbuf[i] = 0;
39551159Scael 	flusho();
39651159Scael 	fdprintf(stderr, "%s", tmbuf);
39751159Scael 	copyf--;
39851159Scael 	lgf--;
39951159Scael }
40051159Scael 
40151159Scael 
casesp(a)40251159Scael casesp(a)
40351159Scael int	a;
40451159Scael {
40551159Scael 	register i, j, savlss;
40651159Scael 
40751159Scael 	tbreak();
40851159Scael 	if (dip->nls || trap)
40951159Scael 		return;
41051159Scael 	i = findt1();
41151159Scael 	if (!a) {
41251159Scael 		skip();
41351159Scael 		j = vnumb((int *)0);
41451159Scael 		if (nonumb)
41551159Scael 			j = lss;
41651159Scael 	} else
41751159Scael 		j = a;
41851159Scael 	if (j == 0)
41951159Scael 		return;
42051159Scael 	if (i < j)
42151159Scael 		j = i;
42251159Scael 	savlss = lss;
42351159Scael 	if (dip != d)
42451159Scael 		i = dip->dnl;
42551159Scael 	else
42651159Scael 		i = numtab[NL].val;
42751159Scael 	if ((i + j) < 0)
42851159Scael 		j = -i;
42951159Scael 	lss = j;
43051159Scael 	newline(0);
43151159Scael 	lss = savlss;
43251159Scael }
43351159Scael 
43451159Scael 
casert()43551159Scael casert()
43651159Scael {
43751159Scael 	register a, *p;
43851159Scael 
43951159Scael 	skip();
44051159Scael 	if (dip != d)
44151159Scael 		p = &dip->dnl;
44251159Scael 	else
44351159Scael 		p = &numtab[NL].val;
44451159Scael 	a = vnumb(p);
44551159Scael 	if (nonumb)
44651159Scael 		a = dip->mkline;
44751159Scael 	if ((a < 0) || (a >= *p))
44851159Scael 		return;
44951159Scael 	nb++;
45051159Scael 	casesp(a - *p);
45151159Scael }
45251159Scael 
45351159Scael 
caseem()45451159Scael caseem()
45551159Scael {
45651159Scael 	lgf++;
45751159Scael 	skip();
45851159Scael 	em = getrq();
45951159Scael }
46051159Scael 
46151159Scael 
casefl()46251159Scael casefl()
46351159Scael {
46451159Scael 	tbreak();
46551159Scael 	flusho();
46651159Scael }
46751159Scael 
46851159Scael 
caseev()46951159Scael caseev()
47051159Scael {
47151159Scael 	register nxev;
47251159Scael 
47351159Scael 	if (skip()) {
47451159Scael 		if (evi != 0) {
47551159Scael 			ev =  evlist[--evi];
47651159Scael 			env = &env_array[ev];
47751159Scael 		}
47851159Scael 		return;
47951159Scael 	}
48051159Scael 	noscale++;
481*54111Scael 	nxev = (int)atoi0();
48251159Scael 	noscale = 0;
48351159Scael 	if (nonumb) {
48451159Scael 		if (evi != 0) {
48551159Scael 			ev =  evlist[--evi];
48651159Scael 			env = &env_array[ev];
48751159Scael 		}
48851159Scael 		return;
48951159Scael 	}
49051159Scael 	flushi();
49151159Scael 	if ((nxev >= NEV) || (nxev < 0) || (evi >= EVLSZ)) {
49251159Scael 		flusho();
49351159Scael 		errprint("cannot do ev %d. (evi %d)", nxev, evi);
49451159Scael 		if (error)
49551159Scael 			done2(040);
49651159Scael 		else
49751159Scael 			edone(040);
49851159Scael 		return;
49951159Scael 	}
50051159Scael 	evlist[evi++] = ev;
50151159Scael 	ev = nxev;
50251159Scael 	env = &env_array[ev];
50351159Scael }
50451159Scael 
50551159Scael 
caseel()50651159Scael caseel()
50751159Scael {
50851159Scael 	if (--ifx < 0) {
50951159Scael 		ifx = 0;
51051159Scael 		iflist[0] = 0;
51151159Scael 	}
51251159Scael 	caseif(2);
51351159Scael }
51451159Scael 
51551159Scael 
caseie()51651159Scael caseie()
51751159Scael {
51851159Scael 	if (ifx >= NIF) {
51951159Scael 		errprint("if-else overflow.");
52051159Scael 		ifx = 0;
52151159Scael 		edone(040);
52251159Scael 	}
52351159Scael 	caseif(1);
52451159Scael 	ifx++;
52551159Scael }
52651159Scael 
52751159Scael 
caseif(x)52851159Scael caseif(x)
52951159Scael int	x;
53051159Scael {
53151159Scael 	extern int falsef;
53251159Scael 	register notflag, true;
53351159Scael 	tchar i;
53451159Scael 
53551159Scael 	if (x == 2) {
53651159Scael 		notflag = 0;
53751159Scael 		true = iflist[ifx];
53851159Scael 		goto i1;
53951159Scael 	}
54051159Scael 	true = 0;
54151159Scael 	skip();
54251159Scael 	if ((cbits(i = getch())) == '!') {
54351159Scael 		notflag = 1;
54451159Scael 	} else {
54551159Scael 		notflag = 0;
54651159Scael 		ch = i;
54751159Scael 	}
548*54111Scael 	i = (int)atoi0();
54951159Scael 	if (!nonumb) {
55051159Scael 		if (i > 0)
55151159Scael 			true++;
55251159Scael 		goto i1;
55351159Scael 	}
55451159Scael 	i = getch();
55551159Scael 	switch (cbits(i)) {
55651159Scael 	case 'e':
55751159Scael 		if (!(numtab[PN].val & 01))
55851159Scael 			true++;
55951159Scael 		break;
56051159Scael 	case 'o':
56151159Scael 		if (numtab[PN].val & 01)
56251159Scael 			true++;
56351159Scael 		break;
56451159Scael #ifdef NROFF
56551159Scael 	case 'n':
56651159Scael 		true++;
56751159Scael 	case 't':
56851159Scael #endif
56951159Scael #ifndef NROFF
57051159Scael 	case 't':
57151159Scael 		true++;
57251159Scael 	case 'n':
57351159Scael #endif
57451159Scael 	case ' ':
57551159Scael 		break;
57651159Scael 	default:
57751159Scael 		true = cmpstr(i);
57851159Scael 	}
57951159Scael i1:
58051159Scael 	true ^= notflag;
58151159Scael 	if (x == 1)
58251159Scael 		iflist[ifx] = !true;
58351159Scael 	if (true) {
58451159Scael i2:
58551159Scael 		while ((cbits(i = getch())) == ' ')
58651159Scael 			;
58751159Scael 		if (cbits(i) == LEFT)
58851159Scael 			goto i2;
58951159Scael 		ch = i;
59051159Scael 		nflush++;
59151159Scael 	} else {
59251159Scael 		copyf++;
59351159Scael 		falsef++;
59451159Scael 		eatblk(0);
59551159Scael 		copyf--;
59651159Scael 		falsef--;
59751159Scael 	}
59851159Scael }
59951159Scael 
eatblk(inblk)60051159Scael eatblk(inblk)
60151159Scael int inblk;
60251159Scael {	register int cnt, i;
60351159Scael 
60451159Scael 	cnt = 0;
60551159Scael 	do {
60651159Scael 		if (ch)	{
60751159Scael 			i = cbits(ch);
60851159Scael 			ch = 0;
60951159Scael 		} else
61051159Scael 			i = cbits(getch0());
61151159Scael 		if (i == ESC)
61251159Scael 			cnt++;
61351159Scael 		else {
61451159Scael 			if (cnt == 1)
61551159Scael 				switch (i) {
61651159Scael 				case '{':  i = LEFT; break;
61751159Scael 				case '}':  i = RIGHT; break;
61851159Scael 				case '\n': i = 'x'; break;
61951159Scael 				}
62051159Scael 			cnt = 0;
62151159Scael 		}
62251159Scael 		if (i == LEFT) eatblk(1);
62351159Scael 	} while ((!inblk && (i != '\n')) || (inblk && (i != RIGHT)));
62451159Scael 	if (i == '\n')
62551159Scael 		nlflg++;
62651159Scael }
62751159Scael 
62851159Scael 
cmpstr(c)62951159Scael cmpstr(c)
63051159Scael tchar c;
63151159Scael {
63251159Scael 	register j, delim;
63351159Scael 	register tchar i;
63451159Scael 	register val;
63551159Scael 	int savapts, savapts1, savfont, savfont1, savpts, savpts1;
63651159Scael 	tchar string[1280];
63751159Scael 	register tchar *sp;
63851159Scael 
63951159Scael 	if (ismot(c))
64051159Scael 		return(0);
64151159Scael 	delim = cbits(c);
64251159Scael 	savapts = apts;
64351159Scael 	savapts1 = apts1;
64451159Scael 	savfont = font;
64551159Scael 	savfont1 = font1;
64651159Scael 	savpts = pts;
64751159Scael 	savpts1 = pts1;
64851159Scael 	sp = string;
64951159Scael 	while ((j = cbits(i = getch()))!=delim && j!='\n' && sp<&string[1280-1])
65051159Scael 		*sp++ = i;
65151159Scael 	if (sp >= string + 1280) {
65251159Scael 		errprint("too-long string compare.");
65351159Scael 		edone(0100);
65451159Scael 	}
65551159Scael 	if (nlflg) {
65651159Scael 		val = sp==string;
65751159Scael 		goto rtn;
65851159Scael 	}
65951159Scael 	*sp++ = 0;
66051159Scael 	apts = savapts;
66151159Scael 	apts1 = savapts1;
66251159Scael 	font = savfont;
66351159Scael 	font1 = savfont1;
66451159Scael 	pts = savpts;
66551159Scael 	pts1 = savpts1;
66651159Scael 	mchbits();
66751159Scael 	val = 1;
66851159Scael 	sp = string;
66951159Scael 	while ((j = cbits(i = getch())) != delim && j != '\n') {
67051159Scael 		if (*sp != i) {
67151159Scael 			eat(delim);
67251159Scael 			val = 0;
67351159Scael 			goto rtn;
67451159Scael 		}
67551159Scael 		sp++;
67651159Scael 	}
67751159Scael 	if (*sp)
67851159Scael 		val = 0;
67951159Scael rtn:
68051159Scael 	apts = savapts;
68151159Scael 	apts1 = savapts1;
68251159Scael 	font = savfont;
68351159Scael 	font1 = savfont1;
68451159Scael 	pts = savpts;
68551159Scael 	pts1 = savpts1;
68651159Scael 	mchbits();
68751159Scael 	return(val);
68851159Scael }
68951159Scael 
69051159Scael 
caserd()69151159Scael caserd()
69251159Scael {
69351159Scael 
69451159Scael 	lgf++;
69551159Scael 	skip();
69651159Scael 	getname();
69751159Scael 	if (!iflg) {
69851159Scael 		if (quiet) {
69951159Scael 			ttys.sg_flags &= ~ECHO;
70051159Scael 			stty(0, &ttys);
70151159Scael 			flusho();
70251159Scael 			fdprintf(stderr, "\007"); /*bell*/
70351159Scael 		} else {
70451159Scael 			if (nextf[0]) {
70551159Scael 				fdprintf(stderr, "%s:", nextf);
70651159Scael 			} else {
70751159Scael 				fdprintf(stderr, "\007"); /*bell*/
70851159Scael 			}
70951159Scael 		}
71051159Scael 	}
71151159Scael 	collect();
71251159Scael 	tty++;
71351159Scael 	pushi(NBLIST*BLK, PAIR('r','d'));
71451159Scael }
71551159Scael 
71651159Scael 
rdtty()71751159Scael rdtty()
71851159Scael {
71951159Scael 	char	onechar;
72051159Scael 
72151159Scael 	onechar = 0;
72251159Scael 	if (read(0, &onechar, 1) == 1) {
72351159Scael 		if (onechar == '\n')
72451159Scael 			tty++;
72551159Scael 		else
72651159Scael 			tty = 1;
72751159Scael 		if (tty != 3)
72851159Scael 			return(onechar);
72951159Scael 	}
73051159Scael 	popi();
73151159Scael 	tty = 0;
73251159Scael 	if (quiet) {
73351159Scael 		ttys.sg_flags |= ECHO;
73451159Scael 		stty(0, &ttys);
73551159Scael 	}
73651159Scael 	return(0);
73751159Scael }
73851159Scael 
73951159Scael 
caseec()74051159Scael caseec()
74151159Scael {
74251159Scael 	eschar = chget('\\');
74351159Scael }
74451159Scael 
74551159Scael 
caseeo()74651159Scael caseeo()
74751159Scael {
74851159Scael 	eschar = 0;
74951159Scael }
75051159Scael 
75151159Scael 
caseta()75251159Scael caseta()
75351159Scael {
75451159Scael 	register i;
75551159Scael 
75651159Scael 	tabtab[0] = nonumb = 0;
75751159Scael 	for (i = 0; ((i < (NTAB - 1)) && !nonumb); i++) {
75851159Scael 		if (skip())
75951159Scael 			break;
76051159Scael 		tabtab[i] = max(hnumb(&tabtab[max(i-1,0)]), 0) & TABMASK;
76151159Scael 		if (!nonumb)
76251159Scael 			switch (cbits(ch)) {
76351159Scael 			case 'C':
76451159Scael 				tabtab[i] |= CTAB;
76551159Scael 				break;
76651159Scael 			case 'R':
76751159Scael 				tabtab[i] |= RTAB;
76851159Scael 				break;
76951159Scael 			default: /*includes L*/
77051159Scael 				break;
77151159Scael 			}
77251159Scael 		nonumb = ch = 0;
77351159Scael 	}
77451159Scael 	tabtab[i] = 0;
77551159Scael }
77651159Scael 
77751159Scael 
casene()77851159Scael casene()
77951159Scael {
78051159Scael 	register i, j;
78151159Scael 
78251159Scael 	skip();
78351159Scael 	i = vnumb((int *)0);
78451159Scael 	if (nonumb)
78551159Scael 		i = lss;
78651159Scael 	if (i > (j = findt1())) {
78751159Scael 		i = lss;
78851159Scael 		lss = j;
78951159Scael 		dip->nls = 0;
79051159Scael 		newline(0);
79151159Scael 		lss = i;
79251159Scael 	}
79351159Scael }
79451159Scael 
79551159Scael 
casetr()79651159Scael casetr()
79751159Scael {
79851159Scael 	register i, j;
79951159Scael 	tchar k;
80051159Scael 
80151159Scael 	lgf++;
80251159Scael 	skip();
80351159Scael 	while ((i = cbits(k=getch())) != '\n') {
80451159Scael 		if (ismot(k))
80551159Scael 			return;
80651159Scael 		if (ismot(k = getch()))
80751159Scael 			return;
80851159Scael 		if ((j = cbits(k)) == '\n')
80951159Scael 			j = ' ';
81051159Scael 		trtab[i] = j;
81151159Scael 	}
81251159Scael }
81351159Scael 
81451159Scael 
casecu()81551159Scael casecu()
81651159Scael {
81751159Scael 	cu++;
81851159Scael 	caseul();
81951159Scael }
82051159Scael 
82151159Scael 
caseul()82251159Scael caseul()
82351159Scael {
82451159Scael 	register i;
82551159Scael 
82651159Scael 	noscale++;
82751159Scael 	if (skip())
82851159Scael 		i = 1;
82951159Scael 	else
830*54111Scael 		i = (int)atoi0();
83151159Scael 	if (ul && (i == 0)) {
83251159Scael 		font = sfont;
83351159Scael 		ul = cu = 0;
83451159Scael 	}
83551159Scael 	if (i) {
83651159Scael 		if (!ul) {
83751159Scael 			sfont = font;
83851159Scael 			font = ulfont;
83951159Scael 		}
84051159Scael 		ul = i;
84151159Scael 	}
84251159Scael 	noscale = 0;
84351159Scael 	mchbits();
84451159Scael }
84551159Scael 
84651159Scael 
caseuf()84751159Scael caseuf()
84851159Scael {
84951159Scael 	register i, j;
85051159Scael 
85151159Scael 	if (skip() || !(i = getrq()) || i == 'S' ||  (j = findft(i))  == -1)
85251159Scael 		ulfont = ULFONT; /*default underline position*/
85351159Scael 	else
85451159Scael 		ulfont = j;
85551159Scael #ifdef NROFF
85651159Scael 	if (ulfont == FT)
85751159Scael 		ulfont = ULFONT;
85851159Scael #endif
85951159Scael }
86051159Scael 
86151159Scael 
caseit()86251159Scael caseit()
86351159Scael {
86451159Scael 	register i;
86551159Scael 
86651159Scael 	lgf++;
86751159Scael 	it = itmac = 0;
86851159Scael 	noscale++;
86951159Scael 	skip();
870*54111Scael 	i = (int)atoi0();
87151159Scael 	skip();
87251159Scael 	if (!nonumb && (itmac = getrq()))
87351159Scael 		it = i;
87451159Scael 	noscale = 0;
87551159Scael }
87651159Scael 
87751159Scael 
casemc()87851159Scael casemc()
87951159Scael {
88051159Scael 	register i;
88151159Scael 
88251159Scael 	if (icf > 1)
88351159Scael 		ic = 0;
88451159Scael 	icf = 0;
88551159Scael 	if (skip())
88651159Scael 		return;
88751159Scael 	ic = getch();
88851159Scael 	icf = 1;
88951159Scael 	skip();
89051159Scael 	i = max(hnumb((int *)0), 0);
89151159Scael 	if (!nonumb)
89251159Scael 		ics = i;
89351159Scael }
89451159Scael 
89551159Scael 
casemk()89651159Scael casemk()
89751159Scael {
89851159Scael 	register i, j;
89951159Scael 
90051159Scael 	if (dip != d)
90151159Scael 		j = dip->dnl;
90251159Scael 	else
90351159Scael 		j = numtab[NL].val;
90451159Scael 	if (skip()) {
90551159Scael 		dip->mkline = j;
90651159Scael 		return;
90751159Scael 	}
90851159Scael 	if ((i = getrq()) == 0)
90951159Scael 		return;
91051159Scael 	numtab[findr(i)].val = j;
91151159Scael }
91251159Scael 
91351159Scael 
casesv()91451159Scael casesv()
91551159Scael {
91651159Scael 	register i;
91751159Scael 
91851159Scael 	skip();
91951159Scael 	if ((i = vnumb((int *)0)) < 0)
92051159Scael 		return;
92151159Scael 	if (nonumb)
92251159Scael 		i = 1;
92351159Scael 	sv += i;
92451159Scael 	caseos();
92551159Scael }
92651159Scael 
92751159Scael 
caseos()92851159Scael caseos()
92951159Scael {
93051159Scael 	register savlss;
93151159Scael 
93251159Scael 	if (sv <= findt1()) {
93351159Scael 		savlss = lss;
93451159Scael 		lss = sv;
93551159Scael 		newline(0);
93651159Scael 		lss = savlss;
93751159Scael 		sv = 0;
93851159Scael 	}
93951159Scael }
94051159Scael 
94151159Scael 
casenm()94251159Scael casenm()
94351159Scael {
94451159Scael 	register i;
94551159Scael 
94651159Scael 	lnmod = nn = 0;
94751159Scael 	if (skip())
94851159Scael 		return;
94951159Scael 	lnmod++;
95051159Scael 	noscale++;
95151159Scael 	i = inumb(&numtab[LN].val);
95251159Scael 	if (!nonumb)
95351159Scael 		numtab[LN].val = max(i, 0);
95451159Scael 	getnm(&ndf, 1);
95551159Scael 	getnm(&nms, 0);
95651159Scael 	getnm(&ni, 0);
95751159Scael 	noscale = 0;
95851159Scael 	nmbits = chbits;
95951159Scael }
96051159Scael 
96151159Scael 
getnm(p,min)96251159Scael getnm(p, min)
96351159Scael int	*p, min;
96451159Scael {
96551159Scael 	register i;
96651159Scael 
96751159Scael 	eat(' ');
96851159Scael 	if (skip())
96951159Scael 		return;
970*54111Scael 	i = (int)atoi0();
97151159Scael 	if (nonumb)
97251159Scael 		return;
97351159Scael 	*p = max(i, min);
97451159Scael }
97551159Scael 
97651159Scael 
casenn()97751159Scael casenn()
97851159Scael {
97951159Scael 	noscale++;
98051159Scael 	skip();
981*54111Scael 	nn = max((int)atoi0(), 1);
98251159Scael 	noscale = 0;
98351159Scael }
98451159Scael 
98551159Scael 
caseab()98651159Scael caseab()
98751159Scael {
98851159Scael 	casetm(1);
98951159Scael 	done3(0);
99051159Scael }
991