xref: /csrg-svn/old/roff/nroff/n10.c (revision 37897)
17065Srrh #ifndef lint
2*37897Sbostic static char sccsid[] = "@(#)n10.c	4.5 05/11/89";
37065Srrh #endif lint
47065Srrh 
57065Srrh #include "tdef.h"
67065Srrh #include <sgtty.h>
77065Srrh extern
87065Srrh #include "d.h"
97065Srrh extern
107065Srrh #include "v.h"
117065Srrh extern
127065Srrh #include "tw.h"
13*37897Sbostic #include "pathnames.h"
147065Srrh /*
157065Srrh nroff10.c
167065Srrh 
177065Srrh Device interfaces
187065Srrh */
197065Srrh 
207065Srrh extern int lss;
217065Srrh extern char obuf[];
227065Srrh extern char *obufp;
237065Srrh extern int xfont;
247065Srrh extern int esc;
257065Srrh extern int lead;
267065Srrh extern int oline[];
277065Srrh extern int *olinep;
287065Srrh extern int ulfont;
297065Srrh extern int esct;
307065Srrh extern int sps;
317065Srrh extern int ics;
327065Srrh extern int ttysave;
337065Srrh extern struct sgttyb ttys;
347065Srrh extern char termtab[];
357065Srrh extern int ptid;
367065Srrh extern int waitf;
377065Srrh extern int pipeflg;
387065Srrh extern int eqflg;
397065Srrh extern int hflg;
407065Srrh extern int tabtab[];
417065Srrh extern int ascii;
427065Srrh extern int xxx;
437065Srrh int dtab;
447065Srrh int bdmode;
457065Srrh int plotmode;
467065Srrh 
477065Srrh ptinit(){
487065Srrh 	register i, j;
497065Srrh 	register char **p;
507065Srrh 	char *q;
517065Srrh 	int x[8];
527065Srrh 	extern char *setbrk();
537065Srrh 
54*37897Sbostic 	if(((i=open(termtab,0)) < 0) && (i=open(_PATH_TERM,0)) < 0){
557065Srrh 		prstr("Cannot open ");
567065Srrh 		prstr(termtab);
577065Srrh 		prstr("\n");
587065Srrh 		exit(-1);
597065Srrh 	}
607065Srrh 	read(i,(char *)x,8*sizeof(int));
6135270Sbostic 	/* Calc size of table, not counting zzz */
6235270Sbostic 	j = ((int) &t.zzz - (int) &t.bset);
6335270Sbostic 	read(i, (char *)&t.bset, j);
647065Srrh 	x[2] -= j;
657065Srrh 	q = setbrk(x[2]);
667065Srrh 	lseek(i,(long)t.twinit+8*sizeof(int),0);
677065Srrh 	i = read(i,q,x[2]);
687065Srrh 	j = q - t.twinit;
697065Srrh 	for(p = &t.twinit; p < &t.zzz; p++){
707065Srrh 		if(*p)*p += j;else *p = "";
717065Srrh 	}
727065Srrh 	sps = EM;
737065Srrh 	ics = EM*2;
747065Srrh 	dtab = 8 * t.Em;
757065Srrh 	for(i=0; i<16; i++)tabtab[i] = dtab * (i+1);
767065Srrh 	if(eqflg)t.Adj = t.Hor;
777065Srrh }
787065Srrh twdone(){
797065Srrh 	obufp = obuf;
807065Srrh 	oputs(t.twrest);
817065Srrh 	flusho();
827065Srrh 	if(pipeflg){
837065Srrh 		close(ptid);
847065Srrh 		wait(&waitf);
857065Srrh 	}
867065Srrh 	if(ttysave != -1) {
877065Srrh 		ttys.sg_flags = ttysave;
887065Srrh 		stty(1, &ttys);
897065Srrh 	}
907065Srrh }
917065Srrh ptout(i)
927065Srrh int i;
937065Srrh {
947065Srrh 	*olinep++ = i;
957065Srrh 	if(olinep >= &oline[LNSIZE])olinep--;
967065Srrh 	if((i&CMASK) != '\n')return;
977065Srrh 	olinep--;
987065Srrh 	lead += dip->blss + lss - t.Newline;
997065Srrh 	dip->blss = 0;
1007065Srrh 	esct = esc = 0;
1017065Srrh 	if(olinep>oline){
1027065Srrh 		move();
1037065Srrh 		ptout1();
1047065Srrh 		oputs(t.twnl);
1057065Srrh 	}else{
1067065Srrh 		lead += t.Newline;
1077065Srrh 		move();
1087065Srrh 	}
1097065Srrh 	lead += dip->alss;
1107065Srrh 	dip->alss = 0;
1117065Srrh 	olinep = oline;
1127065Srrh }
1137065Srrh ptout1()
1147065Srrh {
1157065Srrh 	register i, k;
1167065Srrh 	register char *codep;
1177065Srrh 	extern char *plot();
1187065Srrh 	int *q, w, j, phyw;
1197065Srrh 
1207065Srrh 	for(q=oline; q<olinep; q++){
1217065Srrh 	if((i = *q) & MOT){
1227065Srrh 		j = i & ~MOTV;
1237065Srrh 		if(i & NMOT)j = -j;
1247065Srrh 		if(i & VMOT)lead += j;
1257065Srrh 		else esc += j;
1267065Srrh 		continue;
1277065Srrh 	}
1287065Srrh 	if((k = (i & CMASK)) <= 040){
1297065Srrh 		switch(k){
1307065Srrh 			case ' ': /*space*/
1317065Srrh 				esc += t.Char;
1327065Srrh 				break;
1337065Srrh 		}
1347065Srrh 		continue;
1357065Srrh 	}
1367065Srrh 	codep = t.codetab[k-32];
1377065Srrh 	w = t.Char * (*codep++ & 0177);
1387065Srrh 	phyw = w;
1397065Srrh 	if(i&ZBIT)w = 0;
1407065Srrh 	if(*codep && (esc || lead))move();
1417065Srrh 	esct += w;
1427065Srrh 	if(i&074000)xfont = (i>>9) & 03;
1437065Srrh 	if(*t.bdon & 0377){
1447065Srrh 		if(!bdmode && (xfont == 2)){
1457065Srrh 			oputs(t.bdon);
1467065Srrh 			bdmode++;
1477065Srrh 		}
1487065Srrh 		if(bdmode && (xfont != 2)){
1497065Srrh 			oputs(t.bdoff);
1507065Srrh 			bdmode = 0;
1517065Srrh 		}
1527065Srrh 	}
15334113Smarc 
1547065Srrh 	if(xfont == ulfont){
1557065Srrh 		for(k=w/t.Char;k>0;k--)oput('_');
1567065Srrh 		for(k=w/t.Char;k>0;k--)oput('\b');
1577065Srrh 	}
1587065Srrh 	while(*codep != 0){
1597065Srrh 		if(*codep & 0200){
1607065Srrh 			codep = plot(codep);
1617065Srrh 			oputs(t.plotoff);
1627065Srrh 			oput(' ');
1637065Srrh 		}else{
1647065Srrh 			if(plotmode)oputs(t.plotoff);
16534113Smarc 			/*
16634113Smarc 			 * simulate bold font as overstrike if no t.bdon
16734113Smarc 			 */
16834113Smarc 			if (xfont == 2 && !(*t.bdon & 0377)) {
16934113Smarc 				oput(*codep);
17034113Smarc 				oput('\b');
17134113Smarc 			}
1727065Srrh 			*obufp++ = *codep++;
1737065Srrh 			if(obufp == (obuf + OBUFSZ + ascii - 1))flusho();
1747065Srrh /*			oput(*codep++);*/
1757065Srrh 		}
1767065Srrh 	}
1777065Srrh 	if(!w)for(k=phyw/t.Char;k>0;k--)oput('\b');
1787065Srrh 	}
1797065Srrh }
1807065Srrh char *plot(x)
1817065Srrh char *x;
1827065Srrh {
1837065Srrh 	register int i;
1847065Srrh 	register char *j, *k;
1857065Srrh 
1867065Srrh 	if(!plotmode)oputs(t.ploton);
1877065Srrh 	k = x;
1887065Srrh 	if((*k & 0377) == 0200)k++;
1897065Srrh 	for(; *k; k++){
1907065Srrh 		if(*k & 0200){
1917065Srrh 			if(*k & 0100){
1927065Srrh 				if(*k & 040)j = t.up; else j = t.down;
1937065Srrh 			}else{
1947065Srrh 				if(*k & 040)j = t.left; else j = t.right;
1957065Srrh 			}
1967065Srrh 			if(!(i = *k & 037))return(++k);
1977065Srrh 			while(i--)oputs(j);
1987065Srrh 		}else oput(*k);
1997065Srrh 	}
2007065Srrh 	return(k);
2017065Srrh }
2027065Srrh move(){
2037065Srrh 	register k;
2047065Srrh 	register char *i, *j;
2057065Srrh 	char *p, *q;
2067065Srrh 	int iesct, dt;
2077065Srrh 
2087065Srrh 	iesct = esct;
2097065Srrh 	if(esct += esc)i = "\0"; else i = "\n\0";
2107065Srrh 	j = t.hlf;
2117065Srrh 	p = t.right;
2127065Srrh 	q = t.down;
2137065Srrh 	if(lead){
2147065Srrh 		if(lead < 0){
2157065Srrh 			lead = -lead;
2167065Srrh 			i = t.flr;
2177065Srrh 		/*	if(!esct)i = t.flr; else i = "\0";*/
2187065Srrh 			j = t.hlr;
2197065Srrh 			q = t.up;
2207065Srrh 		}
2217065Srrh 		if(*i & 0377){
2227065Srrh 			k = lead/t.Newline;
2237065Srrh 			lead = lead%t.Newline;
2247065Srrh 			while(k--)oputs(i);
2257065Srrh 		}
2267065Srrh 		if(*j & 0377){
2277065Srrh 			k = lead/t.Halfline;
2287065Srrh 			lead = lead%t.Halfline;
2297065Srrh 			while(k--)oputs(j);
2307065Srrh 		}
2317065Srrh 		else { /* no half-line forward, not at line begining */
2327065Srrh 			k = lead/t.Newline;
2337065Srrh 			lead = lead%t.Newline;
2347065Srrh 			if (k>0) esc=esct;
2357065Srrh 			i = "\n";
2367065Srrh 			while (k--) oputs(i);
2377065Srrh 		}
2387065Srrh 	}
2397065Srrh 	if(esc){
2407065Srrh 		if(esc < 0){
2417065Srrh 			esc = -esc;
2427065Srrh 			j = "\b";
2437065Srrh 			p = t.left;
2447065Srrh 		}else{
2457065Srrh 			j = " ";
2467065Srrh 			if(hflg)while((dt = dtab - (iesct%dtab)) <= esc){
24718653Skarels 				if(dt%t.Em || dt==t.Em)break;
2487065Srrh 				oput(TAB);
2497065Srrh 				esc -= dt;
2507065Srrh 				iesct += dt;
2517065Srrh 			}
2527065Srrh 		}
2537065Srrh 		k = esc/t.Em;
2547065Srrh 		esc = esc%t.Em;
2557065Srrh 		while(k--)oputs(j);
2567065Srrh 	}
2577065Srrh 	if((*t.ploton & 0377) && (esc || lead)){
2587065Srrh 		if(!plotmode)oputs(t.ploton);
2597065Srrh 		esc /= t.Hor;
2607065Srrh 		lead /= t.Vert;
2617065Srrh 		while(esc--)oputs(p);
2627065Srrh 		while(lead--)oputs(q);
2637065Srrh 		oputs(t.plotoff);
2647065Srrh 	}
2657065Srrh 	esc = lead = 0;
2667065Srrh }
2677065Srrh ptlead(){move();}
2687065Srrh dostop(){
2697065Srrh 	char junk;
2707065Srrh 
2717065Srrh 	flusho();
2727065Srrh 	read(2,&junk,1);
2737065Srrh }
274