151160Scael #ifndef lint
251160Scael static char sccsid[]="@(#)n6.c 1.1 (CWI) 86/08/14";
351160Scael #endif
451160Scael
551160Scael #include "tdef.h"
651160Scael #include "tw.h"
751160Scael #include "ext.h"
851160Scael #include <ctype.h>
951160Scael
1051160Scael /*
1151160Scael * n6.c -- width functions, sizes and fonts
1251160Scael */
1351160Scael
1451160Scael int bdtab[NFONT+1] ={ 0, 0, 0, 3, 3, 0, };
1551160Scael int sbold = 0;
1651160Scael int fontlab[NFONT+1] = { 0, 'R', 'I', 'B', PAIR('B','I'), 'S', 0 };
1751160Scael
width(j)1851160Scael width(j)
1951160Scael register tchar j;
2051160Scael {
2151160Scael register i, k;
2251160Scael
2351160Scael if (j & (ZBIT|MOT)) {
2451160Scael if (iszbit(j))
2551160Scael return(0);
2651160Scael if (isvmot(j))
2751160Scael return(0);
2851160Scael k = absmot(j);
2951160Scael if (isnmot(j))
3051160Scael k = -k;
3151160Scael return(k);
3251160Scael }
3351160Scael i = cbits(j);
3451160Scael if (i < ' ') {
3551160Scael if (i == '\b')
3651160Scael return(-widthp);
3751160Scael if (i == PRESC)
3851160Scael i = eschar;
3951160Scael else if (iscontrol(i))
4051160Scael return(0);
4151160Scael }
4251160Scael if (i==ohc)
4351160Scael return(0);
4451160Scael i = trtab[i];
4551160Scael if (i < 32)
4651160Scael return(0);
4751160Scael k = t.width[i] * t.Char;
4851160Scael widthp = k;
4951160Scael return(k);
5051160Scael }
5151160Scael
5251160Scael
setch()5351160Scael tchar setch()
5451160Scael {
5551160Scael register j;
5651160Scael char temp[10];
5751160Scael register char *s;
5851160Scael
5951160Scael s = temp;
6051160Scael if ((*s++ = getach()) == 0 || (*s++ = getach()) == 0)
6151160Scael return(0);
6251160Scael *s = '\0';
6351160Scael if ((j = findch(temp)) > 0)
6451160Scael return j | chbits;
6551160Scael else
6651160Scael return 0;
6751160Scael }
6851160Scael
setabs()6951160Scael tchar setabs() /* set absolute char from \C'...' */
7051160Scael { /* for now, a no-op */
7151160Scael int i, n, nf;
7251160Scael
7351160Scael getch();
7451160Scael n = 0;
7551160Scael n = inumb(&n);
7651160Scael getch();
7751160Scael return ' ';
7851160Scael }
7951160Scael
findft(i)8051160Scael findft(i)
8151160Scael register int i;
8251160Scael {
8351160Scael register k;
8451160Scael
8551160Scael if ((k = i - '0') >= 0 && k <= nfonts && k < smnt)
8651160Scael return(k);
8751160Scael for (k = 0; fontlab[k] != i; k++)
8851160Scael if (k > nfonts)
8951160Scael return(-1);
9051160Scael return(k);
9151160Scael }
9251160Scael
9351160Scael
caseps()9451160Scael caseps()
9551160Scael {
9651160Scael }
9751160Scael
9851160Scael
mchbits()9951160Scael mchbits()
10051160Scael {
10151160Scael chbits = 0;
10251160Scael setfbits(chbits, font);
10351160Scael sps = width(' ' | chbits);
10451160Scael }
10551160Scael
10651160Scael
setps()10751160Scael setps()
10851160Scael {
10951160Scael register i, j;
11051160Scael
11151160Scael i = cbits(getch());
11251160Scael if (isdigit(i)) { /* \sd or \sdd */
11351160Scael i -= '0';
11451160Scael if (i == 0) /* \s0 */
11551160Scael ;
11651160Scael else if (i <= 3 && isdigit(j = cbits(ch=getch()))) { /* \sdd */
11751160Scael ch = 0;
11851160Scael }
11951160Scael } else if (i == '(') { /* \s(dd */
12051160Scael getch();
12151160Scael getch();
12251160Scael } else if (i == '+' || i == '-') { /* \s+, \s- */
12351160Scael j = cbits(getch());
12451160Scael if (isdigit(j)) { /* \s+d, \s-d */
12551160Scael ;
12651160Scael } else if (j == '(') { /* \s+(dd, \s-(dd */
12751160Scael getch();
12851160Scael getch();
12951160Scael }
13051160Scael }
13151160Scael }
13251160Scael
13351160Scael
oldsetps()13451160Scael oldsetps()
13551160Scael {
13651160Scael int i, j, k;
13751160Scael
13851160Scael if (((i = cbits(getch())) == '+' || i == '-') && (j = cbits(ch = getch()) - '0') >= 0 && j <= 9) {
13951160Scael if (i == '-')
14051160Scael j = -j;
14151160Scael ch = 0;
14251160Scael return;
14351160Scael }
14451160Scael if ((i -= '0') == 0) {
14551160Scael return;
14651160Scael }
14751160Scael if (i > 0 && i <= 9) {
14851160Scael /* removed if (i <= 3 && */
14951160Scael /* didn't work!!!! */
15051160Scael if (i <= 3 && (j = cbits(ch = getch()) - '0') >= 0 && j <= 9) {
15151160Scael i = 10 * i + j;
15251160Scael ch = 0;
15351160Scael }
15451160Scael }
15551160Scael }
15651160Scael
15751160Scael
setht()15851160Scael tchar setht() /* set character height from \H'...' */
15951160Scael {
16051160Scael int n;
16151160Scael tchar c;
16251160Scael
16351160Scael getch();
16451160Scael n = inumb(&apts);
16551160Scael getch();
16651160Scael return(0);
16751160Scael }
16851160Scael
16951160Scael
setslant()17051160Scael tchar setslant() /* set slant from \S'...' */
17151160Scael {
17251160Scael int n;
17351160Scael tchar c;
17451160Scael
17551160Scael getch();
17651160Scael n = 0;
17751160Scael n = inumb(&n);
17851160Scael getch();
17951160Scael return(0);
18051160Scael }
18151160Scael
18251160Scael
caseft()18351160Scael caseft()
18451160Scael {
18551160Scael skip();
18651160Scael setfont(1);
18751160Scael }
18851160Scael
18951160Scael
setfont(a)19051160Scael setfont(a)
19151160Scael int a;
19251160Scael {
19351160Scael register i, j;
19451160Scael
19551160Scael if (a)
19651160Scael i = getrq();
19751160Scael else
19851160Scael i = getsn();
19951160Scael if (!i || i == 'P') {
20051160Scael j = font1;
20151160Scael goto s0;
20251160Scael }
20351160Scael if (i == 'S' || i == '0')
20451160Scael return;
20551160Scael if ((j = findft(i, fontlab)) == -1)
20651160Scael return;
20751160Scael s0:
20851160Scael font1 = font;
20951160Scael font = j;
21051160Scael mchbits();
21151160Scael }
21251160Scael
21351160Scael
setwd()21451160Scael setwd()
21551160Scael {
21651160Scael register base, wid;
21751160Scael register tchar i;
21851160Scael int delim, emsz, k;
21951160Scael int savhp, savapts, savapts1, savfont, savfont1, savpts, savpts1;
22051160Scael
22151160Scael base = numtab[ST].val = numtab[ST].val = wid = numtab[CT].val = 0;
22251160Scael if (ismot(i = getch()))
22351160Scael return;
22451160Scael delim = cbits(i);
22551160Scael savhp = numtab[HP].val;
22651160Scael numtab[HP].val = 0;
22751160Scael savapts = apts;
22851160Scael savapts1 = apts1;
22951160Scael savfont = font;
23051160Scael savfont1 = font1;
23151160Scael savpts = pts;
23251160Scael savpts1 = pts1;
23351160Scael setwdf++;
23451160Scael while (cbits(i = getch()) != delim && !nlflg) {
23551160Scael k = width(i);
23651160Scael wid += k;
23751160Scael numtab[HP].val += k;
23851160Scael if (!ismot(i)) {
23951160Scael emsz = (INCH * pts + 36) / 72;
24051160Scael } else if (isvmot(i)) {
24151160Scael k = absmot(i);
24251160Scael if (isnmot(i))
24351160Scael k = -k;
24451160Scael base -= k;
24551160Scael emsz = 0;
24651160Scael } else
24751160Scael continue;
24851160Scael if (base < numtab[SB].val)
24951160Scael numtab[SB].val = base;
25051160Scael if ((k = base + emsz) > numtab[ST].val)
25151160Scael numtab[ST].val = k;
25251160Scael }
25351160Scael setn1(wid, 0, (tchar) 0);
25451160Scael numtab[HP].val = savhp;
25551160Scael apts = savapts;
25651160Scael apts1 = savapts1;
25751160Scael font = savfont;
25851160Scael font1 = savfont1;
25951160Scael pts = savpts;
26051160Scael pts1 = savpts1;
26151160Scael mchbits();
26251160Scael setwdf = 0;
26351160Scael }
26451160Scael
26551160Scael
vmot()26651160Scael tchar vmot()
26751160Scael {
26851160Scael dfact = lss;
26951160Scael vflag++;
27051160Scael return(mot());
27151160Scael }
27251160Scael
27351160Scael
hmot()27451160Scael tchar hmot()
27551160Scael {
27651160Scael dfact = EM;
27751160Scael return(mot());
27851160Scael }
27951160Scael
28051160Scael
mot()28151160Scael tchar mot()
28251160Scael {
28351160Scael register int j, n;
28451160Scael register tchar i;
28551160Scael
28651160Scael j = HOR;
28751160Scael getch(); /*eat delim*/
288*54111Scael if (n = (int)atoi0()) {
28951160Scael if (vflag)
29051160Scael j = VERT;
29151160Scael i = makem(quant(n, j));
29251160Scael } else
29351160Scael i = 0;
29451160Scael getch();
29551160Scael vflag = 0;
29651160Scael dfact = 1;
29751160Scael return(i);
29851160Scael }
29951160Scael
30051160Scael
sethl(k)30151160Scael tchar sethl(k)
30251160Scael int k;
30351160Scael {
30451160Scael register j;
30551160Scael tchar i;
30651160Scael
30751160Scael j = t.Halfline;
30851160Scael if (k == 'u')
30951160Scael j = -j;
31051160Scael else if (k == 'r')
31151160Scael j = -2 * j;
31251160Scael vflag++;
31351160Scael i = makem(j);
31451160Scael vflag = 0;
31551160Scael return(i);
31651160Scael }
31751160Scael
31851160Scael
makem(i)31951160Scael tchar makem(i)
32051160Scael int i;
32151160Scael {
32251160Scael register tchar j;
32351160Scael
32451160Scael if ((j = i) < 0)
32551160Scael j = -j;
32651160Scael j |= MOT;
32751160Scael if (i < 0)
32851160Scael j |= NMOT;
32951160Scael if (vflag)
33051160Scael j |= VMOT;
33151160Scael return(j);
33251160Scael }
33351160Scael
33451160Scael
getlg(i)33551160Scael tchar getlg(i)
33651160Scael tchar i;
33751160Scael {
33851160Scael return(i);
33951160Scael }
34051160Scael
34151160Scael
caselg()34251160Scael caselg()
34351160Scael {
34451160Scael }
34551160Scael
34651160Scael
casefp()34751160Scael casefp()
34851160Scael {
34951160Scael register i, j;
35051160Scael
35151160Scael skip();
35251160Scael if ((i = cbits(getch()) - '0') < 0 || i > nfonts)
35351160Scael return;
35451160Scael if (skip() || !(j = getrq()))
35551160Scael return;
35651160Scael fontlab[i] = j;
35751160Scael }
35851160Scael
35951160Scael
casecs()36051160Scael casecs()
36151160Scael {
36251160Scael }
36351160Scael
36451160Scael
casebd()36551160Scael casebd()
36651160Scael {
36751160Scael register i, j, k;
36851160Scael
36951160Scael k = 0;
37051160Scael bd0:
37151160Scael if (skip() || !(i = getrq()) || (j = findft(i)) == -1) {
37251160Scael if (k)
37351160Scael goto bd1;
37451160Scael else
37551160Scael return;
37651160Scael }
37751160Scael if (j == smnt) {
37851160Scael k = smnt;
37951160Scael goto bd0;
38051160Scael }
38151160Scael if (k) {
38251160Scael sbold = j;
38351160Scael j = k;
38451160Scael }
38551160Scael bd1:
38651160Scael skip();
38751160Scael noscale++;
388*54111Scael bdtab[j] = (int)atoi0();
38951160Scael noscale = 0;
39051160Scael }
39151160Scael
39251160Scael
casevs()39351160Scael casevs()
39451160Scael {
39551160Scael register i;
39651160Scael
39751160Scael skip();
39851160Scael vflag++;
39951160Scael dfact = INCH; /*default scaling is points!*/
40051160Scael dfactd = 72;
40151160Scael res = VERT;
40251160Scael i = inumb(&lss);
40351160Scael if (nonumb)
40451160Scael i = lss1;
40551160Scael if (i < VERT)
40651160Scael i = 0; /* was VERT */
40751160Scael lss1 = lss;
40851160Scael lss = i;
40951160Scael }
41051160Scael
41151160Scael
41251160Scael
41351160Scael
casess()41451160Scael casess()
41551160Scael {
41651160Scael }
41751160Scael
41851160Scael
xlss()41951160Scael tchar xlss()
42051160Scael {
42151160Scael /* stores \x'...' into
42251160Scael /* two successive tchars.
42351160Scael /* the first contains HX, the second the value,
42451160Scael /* encoded as a vertical motion.
42551160Scael /* decoding is done in n2.c by pchar().
42651160Scael */
42751160Scael int i;
42851160Scael
42951160Scael getch();
43051160Scael dfact = lss;
431*54111Scael i = quant((int)atoi0(), VERT);
43251160Scael dfact = 1;
43351160Scael getch();
43451160Scael if (i >= 0)
43551160Scael *pbp++ = MOT | VMOT | i;
43651160Scael else
43751160Scael *pbp++ = MOT | VMOT | NMOT | -i;
43851160Scael return(HX);
43951160Scael }
440