xref: /illumos-gate/usr/src/cmd/troff/troff.d/t10.c (revision e0dcd577)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280d1a34abSToomas Soome /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include "tdef.h"
417c478bd9Sstevel@tonic-gate #include <ctype.h>
427c478bd9Sstevel@tonic-gate #include "ext.h"
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * troff10.c
452a8bcb4eSToomas Soome  *
467c478bd9Sstevel@tonic-gate  * typesetter interface
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate int	vpos	 = 0;	/* absolute vertical position on page */
507c478bd9Sstevel@tonic-gate int	hpos	 = 0;	/* ditto horizontal */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate short	*chtab;
537c478bd9Sstevel@tonic-gate char	*chname;
547c478bd9Sstevel@tonic-gate char	*fontab[NFONT+1];
557c478bd9Sstevel@tonic-gate char	*kerntab[NFONT+1];
567c478bd9Sstevel@tonic-gate char	*fitab[NFONT+1];
577c478bd9Sstevel@tonic-gate char	*codetab[NFONT+1];
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate int	Inch;
607c478bd9Sstevel@tonic-gate int	Hor;
617c478bd9Sstevel@tonic-gate int	Vert;
627c478bd9Sstevel@tonic-gate int	Unitwidth;
637c478bd9Sstevel@tonic-gate int	nfonts;
647c478bd9Sstevel@tonic-gate int	nsizes;
657c478bd9Sstevel@tonic-gate int	nchtab;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /* these characters are used as various signals or values
687c478bd9Sstevel@tonic-gate  * in miscellaneous places.
697c478bd9Sstevel@tonic-gate  * values are set in specnames in t10.c
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate int	c_hyphen;
737c478bd9Sstevel@tonic-gate int	c_emdash;
747c478bd9Sstevel@tonic-gate int	c_rule;
757c478bd9Sstevel@tonic-gate int	c_minus;
767c478bd9Sstevel@tonic-gate int	c_fi;
777c478bd9Sstevel@tonic-gate int	c_fl;
787c478bd9Sstevel@tonic-gate int	c_ff;
797c478bd9Sstevel@tonic-gate int	c_ffi;
807c478bd9Sstevel@tonic-gate int	c_ffl;
817c478bd9Sstevel@tonic-gate int	c_acute;
827c478bd9Sstevel@tonic-gate int	c_grave;
837c478bd9Sstevel@tonic-gate int	c_under;
847c478bd9Sstevel@tonic-gate int	c_rooten;
857c478bd9Sstevel@tonic-gate int	c_boxrule;
867c478bd9Sstevel@tonic-gate int	c_lefthand;
877c478bd9Sstevel@tonic-gate int	c_dagger;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #include "dev.h"
907c478bd9Sstevel@tonic-gate struct dev dev;
917c478bd9Sstevel@tonic-gate struct Font *fontbase[NFONT+1];
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate tchar *ptout0();
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 
96e5190c10Smuffin int
ptinit()977c478bd9Sstevel@tonic-gate ptinit()
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate 	int	i, fin, nw;
1007c478bd9Sstevel@tonic-gate 	char	*setbrk(), *filebase, *p;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	/* open table for device,
1037c478bd9Sstevel@tonic-gate 	 * read in resolution, size info, font info, etc.
1047c478bd9Sstevel@tonic-gate 	 * and set params
1057c478bd9Sstevel@tonic-gate 	 */
1067c478bd9Sstevel@tonic-gate 	strcat(termtab, "/dev");
1077c478bd9Sstevel@tonic-gate 	strcat(termtab, devname);
1087c478bd9Sstevel@tonic-gate 	strcat(termtab, "/DESC.out");	/* makes "..../devXXX/DESC.out" */
1097c478bd9Sstevel@tonic-gate 	if ((fin = open(termtab, 0)) < 0) {
1107c478bd9Sstevel@tonic-gate 		errprint(gettext("can't open tables for %s"), termtab);
1117c478bd9Sstevel@tonic-gate 		done3(1);
1127c478bd9Sstevel@tonic-gate 	}
1137c478bd9Sstevel@tonic-gate 	read(fin, (char *) &dev, sizeof(struct dev ));
1147c478bd9Sstevel@tonic-gate 	Inch = dev.res;
1157c478bd9Sstevel@tonic-gate 	Hor = dev.hor;
1167c478bd9Sstevel@tonic-gate 	Vert = dev.vert;
1177c478bd9Sstevel@tonic-gate 	Unitwidth = dev.unitwidth;
1187c478bd9Sstevel@tonic-gate 	nfonts = dev.nfonts;
1197c478bd9Sstevel@tonic-gate 	nsizes = dev.nsizes;
1207c478bd9Sstevel@tonic-gate 	nchtab = dev.nchtab;
1217c478bd9Sstevel@tonic-gate 	if (nchtab >= NCHARS - 128) {
1227c478bd9Sstevel@tonic-gate 		errprint(gettext("too many special characters in file %s"),
1237c478bd9Sstevel@tonic-gate 			termtab);
1247c478bd9Sstevel@tonic-gate 		done3(1);
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 	filebase = setbrk(dev.filesize + 2*EXTRAFONT);	/* enough room for whole file */
1277c478bd9Sstevel@tonic-gate 	read(fin, filebase, dev.filesize);	/* all at once */
1287c478bd9Sstevel@tonic-gate 	pstab = (short *) filebase;
1297c478bd9Sstevel@tonic-gate 	chtab = pstab + nsizes + 1;
1307c478bd9Sstevel@tonic-gate 	chname = (char *) (chtab + dev.nchtab);
1317c478bd9Sstevel@tonic-gate 	p = chname + dev.lchname;
1327c478bd9Sstevel@tonic-gate 	for (i = 1; i <= nfonts; i++) {
1337c478bd9Sstevel@tonic-gate 		fontbase[i] = (struct Font *) p;
1347c478bd9Sstevel@tonic-gate 		nw = *p & BYTEMASK;	/* 1st thing is width count */
1357c478bd9Sstevel@tonic-gate 		fontlab[i] = PAIR(fontbase[i]->namefont[0], fontbase[i]->namefont[1]);
1367c478bd9Sstevel@tonic-gate 		/* for now, still 2 char names */
1377c478bd9Sstevel@tonic-gate 		if (smnt == 0 && fontbase[i]->specfont == 1)
1387c478bd9Sstevel@tonic-gate 			smnt = i;	/* first special font */
1397c478bd9Sstevel@tonic-gate 		p += sizeof(struct Font);	/* that's what's on the beginning */
1407c478bd9Sstevel@tonic-gate 		fontab[i] = p;
1417c478bd9Sstevel@tonic-gate 		kerntab[i] = p + nw;
1427c478bd9Sstevel@tonic-gate 		codetab[i] = p + 2 * nw;
1437c478bd9Sstevel@tonic-gate 		fitab[i] = p + 3 * nw;	/* skip width, kern, code */
1447c478bd9Sstevel@tonic-gate 		p += 3 * nw + dev.nchtab + 128 - 32;
1457c478bd9Sstevel@tonic-gate 	}
1467c478bd9Sstevel@tonic-gate 	fontbase[0] = (struct Font *) p;	/* the last shall be first */
1477c478bd9Sstevel@tonic-gate 	fontbase[0]->nwfont = EXTRAFONT - dev.nchtab - (128-32) - sizeof (struct Font);
1487c478bd9Sstevel@tonic-gate 	fontab[0] = p + sizeof (struct Font);
1497c478bd9Sstevel@tonic-gate 	close(fin);
1507c478bd9Sstevel@tonic-gate 	/* there are a lot of things that used to be constant
1517c478bd9Sstevel@tonic-gate 	 * that now require code to be executed.
1527c478bd9Sstevel@tonic-gate 	 */
1537c478bd9Sstevel@tonic-gate 	sps = SPS;
1547c478bd9Sstevel@tonic-gate 	ics = ICS;
1557c478bd9Sstevel@tonic-gate 	for (i = 0; i < 16; i++)
1567c478bd9Sstevel@tonic-gate 		tabtab[i] = DTAB * (i + 1);
1577c478bd9Sstevel@tonic-gate 	pl = 11 * INCH;
1587c478bd9Sstevel@tonic-gate 	po = PO;
1597c478bd9Sstevel@tonic-gate 	spacesz = SS;
1607c478bd9Sstevel@tonic-gate 	lss = lss1 = VS;
1617c478bd9Sstevel@tonic-gate 	ll = ll1 = lt = lt1 = LL;
1627c478bd9Sstevel@tonic-gate 	specnames();	/* install names like "hyphen", etc. */
1637c478bd9Sstevel@tonic-gate 	if (ascii)
164e5190c10Smuffin 		return (0);
1657c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x T %s\n", devname);
1667c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x res %d %d %d\n", Inch, Hor, Vert);
1677c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x init\n");	/* do initialization for particular device */
1687c478bd9Sstevel@tonic-gate   /*
1697c478bd9Sstevel@tonic-gate 	for (i = 1; i <= nfonts; i++)
1707c478bd9Sstevel@tonic-gate 		fdprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont);
1717c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x xxx fonts=%d sizes=%d unit=%d\n", nfonts, nsizes, Unitwidth);
1727c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x xxx nchtab=%d lchname=%d nfitab=%d\n",
1737c478bd9Sstevel@tonic-gate 		dev.nchtab, dev.lchname, dev.nchtab+128-32);
1747c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x xxx sizes:\nx xxx ");
1757c478bd9Sstevel@tonic-gate 	for (i = 0; i < nsizes; i++)
1767c478bd9Sstevel@tonic-gate 		fdprintf(ptid, " %d", pstab[i]);
1777c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "\nx xxx chars:\nx xxx ");
1787c478bd9Sstevel@tonic-gate 	for (i = 0; i < dev.nchtab; i++)
1797c478bd9Sstevel@tonic-gate 		fdprintf(ptid, " %s", &chname[chtab[i]]);
1807c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "\nx xxx\n");
1817c478bd9Sstevel@tonic-gate   */
182e5190c10Smuffin 
183e5190c10Smuffin 	return (0);
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate 
186e5190c10Smuffin int
specnames()1877c478bd9Sstevel@tonic-gate specnames()
1887c478bd9Sstevel@tonic-gate {
1897c478bd9Sstevel@tonic-gate 	static struct {
1907c478bd9Sstevel@tonic-gate 		int	*n;
1917c478bd9Sstevel@tonic-gate 		char	*v;
1927c478bd9Sstevel@tonic-gate 	} spnames[] = {
1937c478bd9Sstevel@tonic-gate 		&c_hyphen, "hy",
1947c478bd9Sstevel@tonic-gate 		&c_emdash, "em",
1957c478bd9Sstevel@tonic-gate 		&c_rule, "ru",
1967c478bd9Sstevel@tonic-gate 		&c_minus, "\\-",
1977c478bd9Sstevel@tonic-gate 		&c_fi, "fi",
1987c478bd9Sstevel@tonic-gate 		&c_fl, "fl",
1997c478bd9Sstevel@tonic-gate 		&c_ff, "ff",
2007c478bd9Sstevel@tonic-gate 		&c_ffi, "Fi",
2017c478bd9Sstevel@tonic-gate 		&c_ffl, "Fl",
2027c478bd9Sstevel@tonic-gate 		&c_acute, "aa",
2037c478bd9Sstevel@tonic-gate 		&c_grave, "ga",
2047c478bd9Sstevel@tonic-gate 		&c_under, "ul",
2057c478bd9Sstevel@tonic-gate 		&c_rooten, "rn",
2067c478bd9Sstevel@tonic-gate 		&c_boxrule, "br",
2077c478bd9Sstevel@tonic-gate 		&c_lefthand, "lh",
2087c478bd9Sstevel@tonic-gate 		&c_dagger, "dg",
2097c478bd9Sstevel@tonic-gate 		0, 0
2107c478bd9Sstevel@tonic-gate 	};
2117c478bd9Sstevel@tonic-gate 	int	i;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	for (i = 0; spnames[i].n; i++)
2147c478bd9Sstevel@tonic-gate 		*spnames[i].n = findch(spnames[i].v);
215e5190c10Smuffin 
216e5190c10Smuffin 	return (0);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate 
219e5190c10Smuffin int
findch(s)2207c478bd9Sstevel@tonic-gate findch(s)	/* find char s in chname */
221e5190c10Smuffin char	*s;
2227c478bd9Sstevel@tonic-gate {
223e5190c10Smuffin 	int	i;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	for (i = 0; i < nchtab; i++)
2267c478bd9Sstevel@tonic-gate 		if (strcmp(s, &chname[chtab[i]]) == 0)
2277c478bd9Sstevel@tonic-gate 			return(i + 128);
2287c478bd9Sstevel@tonic-gate 	return(0);
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate 
231e5190c10Smuffin int
ptout(i)2327c478bd9Sstevel@tonic-gate ptout(i)
233e5190c10Smuffin tchar	i;
2347c478bd9Sstevel@tonic-gate {
235e5190c10Smuffin 	int	dv;
236e5190c10Smuffin 	tchar	*k;
2377c478bd9Sstevel@tonic-gate 	int temp, a, b;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	if (cbits(i) != '\n') {
2407c478bd9Sstevel@tonic-gate 		*olinep++ = i;
241e5190c10Smuffin 		return (0);
2427c478bd9Sstevel@tonic-gate 	}
2437c478bd9Sstevel@tonic-gate 	if (olinep == oline) {
2447c478bd9Sstevel@tonic-gate 		lead += lss;
245e5190c10Smuffin 		return (0);
2467c478bd9Sstevel@tonic-gate 	}
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	hpos = po;	/* ??? */
2497c478bd9Sstevel@tonic-gate 	esc = 0;	/* ??? */
2507c478bd9Sstevel@tonic-gate 	ptesc();	/* the problem is to get back to the left end of the line */
2517c478bd9Sstevel@tonic-gate 	dv = 0;
2527c478bd9Sstevel@tonic-gate 	for (k = oline; k < olinep; k++) {
2537c478bd9Sstevel@tonic-gate 		if (ismot(*k) && isvmot(*k)) {
2547c478bd9Sstevel@tonic-gate 			temp = absmot(*k);
2557c478bd9Sstevel@tonic-gate 			if (isnmot(*k))
2567c478bd9Sstevel@tonic-gate 				temp = -temp;
2577c478bd9Sstevel@tonic-gate 			dv += temp;
2587c478bd9Sstevel@tonic-gate 		}
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 	if (dv) {
2617c478bd9Sstevel@tonic-gate 		vflag++;
2627c478bd9Sstevel@tonic-gate 		*olinep++ = makem(-dv);
2637c478bd9Sstevel@tonic-gate 		vflag = 0;
2647c478bd9Sstevel@tonic-gate 	}
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	b = dip->blss + lss;
2677c478bd9Sstevel@tonic-gate 	lead += dip->blss + lss;
2687c478bd9Sstevel@tonic-gate 	dip->blss = 0;
2697c478bd9Sstevel@tonic-gate 	for (k = oline; k < olinep; )
2707c478bd9Sstevel@tonic-gate 		k = ptout0(k);	/* now passing a pointer! */
2717c478bd9Sstevel@tonic-gate 	olinep = oline;
2727c478bd9Sstevel@tonic-gate 	lead += dip->alss;
2737c478bd9Sstevel@tonic-gate 	a = dip->alss;
2747c478bd9Sstevel@tonic-gate 	dip->alss = 0;
2757c478bd9Sstevel@tonic-gate 	/*
2767c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x xxx end of line: hpos=%d, vpos=%d\n", hpos, vpos);
2777c478bd9Sstevel@tonic-gate */
2787c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "n%d %d\n", b, a);	/* be nice to chuck */
279e5190c10Smuffin 
280e5190c10Smuffin 	return (0);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate tchar *
ptout0(pi)2847c478bd9Sstevel@tonic-gate ptout0(pi)
2857c478bd9Sstevel@tonic-gate tchar	*pi;
2867c478bd9Sstevel@tonic-gate {
287e5190c10Smuffin 	short j, k, w;
2887c478bd9Sstevel@tonic-gate 	short	z, dx, dy, dx2, dy2, n;
289e5190c10Smuffin 	tchar	i;
2907c478bd9Sstevel@tonic-gate 	int outsize;	/* size of object being printed */
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	outsize = 1;	/* default */
2937c478bd9Sstevel@tonic-gate 	i = *pi;
2947c478bd9Sstevel@tonic-gate 	k = cbits(i);
2957c478bd9Sstevel@tonic-gate 	if (ismot(i)) {
2967c478bd9Sstevel@tonic-gate 		j = absmot(i);
2977c478bd9Sstevel@tonic-gate 		if (isnmot(i))
2987c478bd9Sstevel@tonic-gate 			j = -j;
2997c478bd9Sstevel@tonic-gate 		if (isvmot(i))
3007c478bd9Sstevel@tonic-gate 			lead += j;
3012a8bcb4eSToomas Soome 		else
3027c478bd9Sstevel@tonic-gate 			esc += j;
3037c478bd9Sstevel@tonic-gate 		return(pi+outsize);
3047c478bd9Sstevel@tonic-gate 	}
3057c478bd9Sstevel@tonic-gate 	if (k == XON) {
3067c478bd9Sstevel@tonic-gate 		if (xfont != mfont)
3077c478bd9Sstevel@tonic-gate 			ptfont();
3087c478bd9Sstevel@tonic-gate 		if (xpts != mpts)
3097c478bd9Sstevel@tonic-gate 			ptps();
3107c478bd9Sstevel@tonic-gate 		if (lead)
3117c478bd9Sstevel@tonic-gate 			ptlead();
3127c478bd9Sstevel@tonic-gate 		fdprintf(ptid, "x X ");
3132a8bcb4eSToomas Soome 		/*
3147c478bd9Sstevel@tonic-gate 	     * not guaranteed of finding a XOFF if a word overflow
3157c478bd9Sstevel@tonic-gate 		 * error occured, so also bound this loop by olinep
3167c478bd9Sstevel@tonic-gate 		 */
3177c478bd9Sstevel@tonic-gate 		pi++;
3187c478bd9Sstevel@tonic-gate 		while( cbits(*pi) != XOFF && pi < olinep )
3197c478bd9Sstevel@tonic-gate 			outascii(*pi++);
3207c478bd9Sstevel@tonic-gate 		oput('\n');
3217c478bd9Sstevel@tonic-gate 		if ( cbits(*pi) == XOFF )
3227c478bd9Sstevel@tonic-gate 			pi++;
3237c478bd9Sstevel@tonic-gate 		return pi;
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 			;
3267c478bd9Sstevel@tonic-gate 	if (k == CHARHT) {
3277c478bd9Sstevel@tonic-gate 		if (xpts != mpts)
3287c478bd9Sstevel@tonic-gate 			ptps();
3297c478bd9Sstevel@tonic-gate 		fdprintf(ptid, "x H %d\n", sbits(i));
3307c478bd9Sstevel@tonic-gate 		return(pi+outsize);
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 	if (k == SLANT) {
3337c478bd9Sstevel@tonic-gate 		fdprintf(ptid, "x S %d\n", sfbits(i)-180);
3347c478bd9Sstevel@tonic-gate 		return(pi+outsize);
3357c478bd9Sstevel@tonic-gate 	}
3367c478bd9Sstevel@tonic-gate 	if (k == WORDSP) {
3377c478bd9Sstevel@tonic-gate 		oput('w');
3387c478bd9Sstevel@tonic-gate 		return(pi+outsize);
3397c478bd9Sstevel@tonic-gate 	}
3407c478bd9Sstevel@tonic-gate 	if (k == FONTPOS) {
3417c478bd9Sstevel@tonic-gate 		char temp[3];
3427c478bd9Sstevel@tonic-gate 		n = i >> 16;
3437c478bd9Sstevel@tonic-gate 		temp[0] = n & BYTEMASK;
3447c478bd9Sstevel@tonic-gate 		temp[1] = n >> BYTE;
3457c478bd9Sstevel@tonic-gate 		temp[2] = 0;
3467c478bd9Sstevel@tonic-gate 		ptfpcmd(0, temp);
3477c478bd9Sstevel@tonic-gate 		return(pi+outsize);
3487c478bd9Sstevel@tonic-gate 	}
3497c478bd9Sstevel@tonic-gate 	if (sfbits(i) == oldbits) {
3507c478bd9Sstevel@tonic-gate 		xfont = pfont;
3517c478bd9Sstevel@tonic-gate 		xpts = ppts;
3522a8bcb4eSToomas Soome 	} else
3537c478bd9Sstevel@tonic-gate 		xbits(i, 2);
3547c478bd9Sstevel@tonic-gate 	if (k < 040 && k != DRAWFCN)
3557c478bd9Sstevel@tonic-gate 		return(pi+outsize);
3567c478bd9Sstevel@tonic-gate 	if (k >= 32) {
3577c478bd9Sstevel@tonic-gate 		if (widcache[k-32].fontpts == (xfont<<8) + xpts  && !setwdf) {
3587c478bd9Sstevel@tonic-gate 			w = widcache[k-32].width;
3597c478bd9Sstevel@tonic-gate 			bd = 0;
3607c478bd9Sstevel@tonic-gate 			cs = 0;
3617c478bd9Sstevel@tonic-gate 		} else
3627c478bd9Sstevel@tonic-gate 			w = getcw(k-32);
3637c478bd9Sstevel@tonic-gate 	}
3647c478bd9Sstevel@tonic-gate 	j = z = 0;
3657c478bd9Sstevel@tonic-gate 	if (k != DRAWFCN) {
3667c478bd9Sstevel@tonic-gate 		if (cs) {
3677c478bd9Sstevel@tonic-gate 			if (bd)
3687c478bd9Sstevel@tonic-gate 				w += (bd - 1) * HOR;
3697c478bd9Sstevel@tonic-gate 			j = (cs - w) / 2;
3707c478bd9Sstevel@tonic-gate 			w = cs - j;
3717c478bd9Sstevel@tonic-gate 			if (bd)
3727c478bd9Sstevel@tonic-gate 				w -= (bd - 1) * HOR;
3737c478bd9Sstevel@tonic-gate 		}
3747c478bd9Sstevel@tonic-gate 		if (iszbit(i)) {
3757c478bd9Sstevel@tonic-gate 			if (cs)
3762a8bcb4eSToomas Soome 				w = -j;
3772a8bcb4eSToomas Soome 			else
3787c478bd9Sstevel@tonic-gate 				w = 0;
3797c478bd9Sstevel@tonic-gate 			z = 1;
3807c478bd9Sstevel@tonic-gate 		}
3817c478bd9Sstevel@tonic-gate 	}
3827c478bd9Sstevel@tonic-gate 	esc += j;
3837c478bd9Sstevel@tonic-gate 	if (xfont != mfont)
3847c478bd9Sstevel@tonic-gate 		ptfont();
3857c478bd9Sstevel@tonic-gate 	if (xpts != mpts)
3867c478bd9Sstevel@tonic-gate 		ptps();
3877c478bd9Sstevel@tonic-gate 	if (lead)
3887c478bd9Sstevel@tonic-gate 		ptlead();
3897c478bd9Sstevel@tonic-gate 	/* put out the real character here */
3907c478bd9Sstevel@tonic-gate 	if (k == DRAWFCN) {
3917c478bd9Sstevel@tonic-gate 		if (esc)
3927c478bd9Sstevel@tonic-gate 			ptesc();
3937c478bd9Sstevel@tonic-gate 		dx = absmot(pi[3]);
3947c478bd9Sstevel@tonic-gate 		if (isnmot(pi[3]))
3957c478bd9Sstevel@tonic-gate 			dx = -dx;
3967c478bd9Sstevel@tonic-gate 		dy = absmot(pi[4]);
3977c478bd9Sstevel@tonic-gate 		if (isnmot(pi[4]))
3987c478bd9Sstevel@tonic-gate 			dy = -dy;
3997c478bd9Sstevel@tonic-gate 		switch (cbits(pi[1])) {
4007c478bd9Sstevel@tonic-gate 		case DRAWCIRCLE:	/* circle */
4017c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "D%c %d\n", DRAWCIRCLE, dx);	/* dx is diameter */
4027c478bd9Sstevel@tonic-gate 			w = 0;
4037c478bd9Sstevel@tonic-gate 			hpos += dx;
4047c478bd9Sstevel@tonic-gate 			break;
4057c478bd9Sstevel@tonic-gate 		case DRAWELLIPSE:
4067c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "D%c %d %d\n", DRAWELLIPSE, dx, dy);
4077c478bd9Sstevel@tonic-gate 			w = 0;
4087c478bd9Sstevel@tonic-gate 			hpos += dx;
4097c478bd9Sstevel@tonic-gate 			break;
4107c478bd9Sstevel@tonic-gate 		case DRAWLINE:	/* line */
4117c478bd9Sstevel@tonic-gate 			k = cbits(pi[2]);
4127c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "D%c %d %d ", DRAWLINE, dx, dy);
4137c478bd9Sstevel@tonic-gate 			if (k < 128)
4147c478bd9Sstevel@tonic-gate 				fdprintf(ptid, "%c\n", k);
4157c478bd9Sstevel@tonic-gate 			else
4167c478bd9Sstevel@tonic-gate 				fdprintf(ptid, "%s\n", &chname[chtab[k - 128]]);
4177c478bd9Sstevel@tonic-gate 			w = 0;
4187c478bd9Sstevel@tonic-gate 			hpos += dx;
4197c478bd9Sstevel@tonic-gate 			vpos += dy;
4207c478bd9Sstevel@tonic-gate 			break;
4217c478bd9Sstevel@tonic-gate 		case DRAWARC:	/* arc */
4227c478bd9Sstevel@tonic-gate 			dx2 = absmot(pi[5]);
4237c478bd9Sstevel@tonic-gate 			if (isnmot(pi[5]))
4247c478bd9Sstevel@tonic-gate 				dx2 = -dx2;
4257c478bd9Sstevel@tonic-gate 			dy2 = absmot(pi[6]);
4267c478bd9Sstevel@tonic-gate 			if (isnmot(pi[6]))
4277c478bd9Sstevel@tonic-gate 				dy2 = -dy2;
4287c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "D%c %d %d %d %d\n", DRAWARC,
4297c478bd9Sstevel@tonic-gate 				dx, dy, dx2, dy2);
4307c478bd9Sstevel@tonic-gate 			w = 0;
4317c478bd9Sstevel@tonic-gate 			hpos += dx + dx2;
4327c478bd9Sstevel@tonic-gate 			vpos += dy + dy2;
4337c478bd9Sstevel@tonic-gate 			break;
4347c478bd9Sstevel@tonic-gate 		case DRAWSPLINE:	/* spline */
4357c478bd9Sstevel@tonic-gate 		default:	/* something else; copy it like spline */
4367c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "D%c %d %d", cbits(pi[1]), dx, dy);
4377c478bd9Sstevel@tonic-gate 			w = 0;
4387c478bd9Sstevel@tonic-gate 			hpos += dx;
4397c478bd9Sstevel@tonic-gate 			vpos += dy;
4407c478bd9Sstevel@tonic-gate 			if (cbits(pi[3]) == DRAWFCN || cbits(pi[4]) == DRAWFCN) {
4417c478bd9Sstevel@tonic-gate 				/* it was somehow defective */
4427c478bd9Sstevel@tonic-gate 				fdprintf(ptid, "\n");
4437c478bd9Sstevel@tonic-gate 				break;
4447c478bd9Sstevel@tonic-gate 			}
4457c478bd9Sstevel@tonic-gate 			for (n = 5; cbits(pi[n]) != DRAWFCN; n += 2) {
4467c478bd9Sstevel@tonic-gate 				dx = absmot(pi[n]);
4477c478bd9Sstevel@tonic-gate 				if (isnmot(pi[n]))
4487c478bd9Sstevel@tonic-gate 					dx = -dx;
4497c478bd9Sstevel@tonic-gate 				dy = absmot(pi[n+1]);
4507c478bd9Sstevel@tonic-gate 				if (isnmot(pi[n+1]))
4517c478bd9Sstevel@tonic-gate 					dy = -dy;
4527c478bd9Sstevel@tonic-gate 				fdprintf(ptid, " %d %d", dx, dy);
4537c478bd9Sstevel@tonic-gate 				hpos += dx;
4547c478bd9Sstevel@tonic-gate 				vpos += dy;
4557c478bd9Sstevel@tonic-gate 			}
4567c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "\n");
4577c478bd9Sstevel@tonic-gate 			break;
4587c478bd9Sstevel@tonic-gate 		}
4597c478bd9Sstevel@tonic-gate 		for (n = 3; cbits(pi[n]) != DRAWFCN; n++)
4607c478bd9Sstevel@tonic-gate 			;
4617c478bd9Sstevel@tonic-gate 		outsize = n + 1;
4627c478bd9Sstevel@tonic-gate 	} else if (k < 128) {
4637c478bd9Sstevel@tonic-gate 		/* try to go faster and compress output */
4647c478bd9Sstevel@tonic-gate 		/* by printing nnc for small positive motion followed by c */
4657c478bd9Sstevel@tonic-gate 		/* kludgery; have to make sure set all the vars too */
4667c478bd9Sstevel@tonic-gate 		if (esc > 0 && esc < 100) {
4677c478bd9Sstevel@tonic-gate 			oput(esc / 10 + '0');
4687c478bd9Sstevel@tonic-gate 			oput(esc % 10 + '0');
4697c478bd9Sstevel@tonic-gate 			oput(k);
4707c478bd9Sstevel@tonic-gate 			hpos += esc;
4717c478bd9Sstevel@tonic-gate 			esc = 0;
4727c478bd9Sstevel@tonic-gate 		} else {
4737c478bd9Sstevel@tonic-gate 			if (esc)
4747c478bd9Sstevel@tonic-gate 				ptesc();
4757c478bd9Sstevel@tonic-gate 			oput('c');
4767c478bd9Sstevel@tonic-gate 			oput(k);
4777c478bd9Sstevel@tonic-gate 			oput('\n');
4787c478bd9Sstevel@tonic-gate 		}
4797c478bd9Sstevel@tonic-gate 	} else {
4807c478bd9Sstevel@tonic-gate 		if (esc)
4817c478bd9Sstevel@tonic-gate 			ptesc();
4827c478bd9Sstevel@tonic-gate 		if (k >= nchtab + 128)
4837c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "N%d\n", k - (nchtab+128));
4847c478bd9Sstevel@tonic-gate 		else
4857c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "C%s\n", &chname[chtab[k - 128]]);
4867c478bd9Sstevel@tonic-gate 	}
4877c478bd9Sstevel@tonic-gate 	if (bd) {
4887c478bd9Sstevel@tonic-gate 		bd -= HOR;
4897c478bd9Sstevel@tonic-gate 		if (esc += bd)
4907c478bd9Sstevel@tonic-gate 			ptesc();
4917c478bd9Sstevel@tonic-gate 		if (k < 128) {
4927c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "c%c\n", k);
4937c478bd9Sstevel@tonic-gate 		} else if (k >= nchtab + 128) {
4947c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "N%d\n", k - (nchtab+128));
4957c478bd9Sstevel@tonic-gate 		} else
4967c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "C%s\n", &chname[chtab[k - 128]]);
4977c478bd9Sstevel@tonic-gate 		if (z)
4987c478bd9Sstevel@tonic-gate 			esc -= bd;
4997c478bd9Sstevel@tonic-gate 	}
5007c478bd9Sstevel@tonic-gate 	esc += w;
5017c478bd9Sstevel@tonic-gate 	return(pi+outsize);
5027c478bd9Sstevel@tonic-gate }
5037c478bd9Sstevel@tonic-gate 
504e5190c10Smuffin int
ptps()5057c478bd9Sstevel@tonic-gate ptps()
5067c478bd9Sstevel@tonic-gate {
507e5190c10Smuffin 	int	i, j, k;
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate 	i = xpts;
5107c478bd9Sstevel@tonic-gate 	for (j = 0; i > (k = pstab[j]); j++)
5117c478bd9Sstevel@tonic-gate 		if (!k) {
5127c478bd9Sstevel@tonic-gate 			k = pstab[--j];
5137c478bd9Sstevel@tonic-gate 			break;
5147c478bd9Sstevel@tonic-gate 		}
5157c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "s%d\n", k);	/* really should put out string rep of size */
5167c478bd9Sstevel@tonic-gate 	mpts = i;
517e5190c10Smuffin 
518e5190c10Smuffin 	return (0);
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate 
521e5190c10Smuffin int
ptfont()5227c478bd9Sstevel@tonic-gate ptfont()
5237c478bd9Sstevel@tonic-gate {
5247c478bd9Sstevel@tonic-gate 	mfont = xfont;
5257c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "f%d\n", xfont);
526e5190c10Smuffin 
527e5190c10Smuffin 	return (0);
5287c478bd9Sstevel@tonic-gate }
5297c478bd9Sstevel@tonic-gate 
530e5190c10Smuffin int
ptfpcmd(f,s)5317c478bd9Sstevel@tonic-gate ptfpcmd(f, s)
5327c478bd9Sstevel@tonic-gate int	f;
5337c478bd9Sstevel@tonic-gate char	*s;
5347c478bd9Sstevel@tonic-gate {
5357c478bd9Sstevel@tonic-gate 	if (ascii)
536e5190c10Smuffin 		return (0);
5377c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x font %d %s\n", f, s);
5387c478bd9Sstevel@tonic-gate 	ptfont();	/* make sure that it gets noticed */
539e5190c10Smuffin 
540e5190c10Smuffin 	return (0);
5417c478bd9Sstevel@tonic-gate }
5427c478bd9Sstevel@tonic-gate 
543e5190c10Smuffin int
ptlead()5447c478bd9Sstevel@tonic-gate ptlead()
5457c478bd9Sstevel@tonic-gate {
5467c478bd9Sstevel@tonic-gate 	vpos += lead;
5477c478bd9Sstevel@tonic-gate 	if (!ascii)
5487c478bd9Sstevel@tonic-gate 		fdprintf(ptid, "V%d\n", vpos);
5497c478bd9Sstevel@tonic-gate 	lead = 0;
550e5190c10Smuffin 
551e5190c10Smuffin 	return (0);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate 
554e5190c10Smuffin 
555e5190c10Smuffin int
ptesc(void)556*e0dcd577SToomas Soome ptesc(void)
5577c478bd9Sstevel@tonic-gate {
5587c478bd9Sstevel@tonic-gate 	hpos += esc;
5597c478bd9Sstevel@tonic-gate 	if (esc > 0) {
5607c478bd9Sstevel@tonic-gate 		oput('h');
5617c478bd9Sstevel@tonic-gate 		if (esc>=10 && esc<100) {
5627c478bd9Sstevel@tonic-gate 			oput(esc/10 + '0');
5637c478bd9Sstevel@tonic-gate 			oput(esc%10 + '0');
5647c478bd9Sstevel@tonic-gate 		} else
5657c478bd9Sstevel@tonic-gate 			fdprintf(ptid, "%d", esc);
5667c478bd9Sstevel@tonic-gate 	} else
5677c478bd9Sstevel@tonic-gate 		fdprintf(ptid, "H%d\n", hpos);
5687c478bd9Sstevel@tonic-gate 	esc = 0;
569e5190c10Smuffin 
570e5190c10Smuffin 	return (0);
5717c478bd9Sstevel@tonic-gate }
5727c478bd9Sstevel@tonic-gate 
573e5190c10Smuffin 
574e5190c10Smuffin int
newpage(int n)575*e0dcd577SToomas Soome newpage(int n)	/* called at end of each output page (we hope) */
5767c478bd9Sstevel@tonic-gate {
5777c478bd9Sstevel@tonic-gate 	int i;
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 	ptlead();
5807c478bd9Sstevel@tonic-gate 	vpos = 0;
5817c478bd9Sstevel@tonic-gate 	if (ascii)
582e5190c10Smuffin 		return (0);
5837c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "p%d\n", n);	/* new page */
5847c478bd9Sstevel@tonic-gate 	for (i = 0; i <= nfonts; i++)
5850d1a34abSToomas Soome 		if (fontbase[i]->namefont[0] != '\0')
5860d1a34abSToomas Soome 			fdprintf(ptid, "x font %d %s\n", i,
5870d1a34abSToomas Soome 			    fontbase[i]->namefont);
5887c478bd9Sstevel@tonic-gate 	ptps();
5897c478bd9Sstevel@tonic-gate 	ptfont();
590e5190c10Smuffin 
591e5190c10Smuffin 	return (0);
5927c478bd9Sstevel@tonic-gate }
5937c478bd9Sstevel@tonic-gate 
594e5190c10Smuffin int
pttrailer(void)595*e0dcd577SToomas Soome pttrailer(void)
5967c478bd9Sstevel@tonic-gate {
5977c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x trailer\n");
598e5190c10Smuffin 
599e5190c10Smuffin 	return (0);
6007c478bd9Sstevel@tonic-gate }
6017c478bd9Sstevel@tonic-gate 
602e5190c10Smuffin int
ptstop(void)603*e0dcd577SToomas Soome ptstop(void)
6047c478bd9Sstevel@tonic-gate {
6057c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x stop\n");
606e5190c10Smuffin 
607e5190c10Smuffin 	return (0);
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate 
610e5190c10Smuffin int
dostop(void)611*e0dcd577SToomas Soome dostop(void)
6127c478bd9Sstevel@tonic-gate {
6137c478bd9Sstevel@tonic-gate 	if (ascii)
614e5190c10Smuffin 		return (0);
6157c478bd9Sstevel@tonic-gate 	ptlead();
6167c478bd9Sstevel@tonic-gate 	vpos = 0;
6177c478bd9Sstevel@tonic-gate 	/* fdprintf(ptid, "x xxx end of page\n");*/
6187c478bd9Sstevel@tonic-gate 	if (!nofeed)
6197c478bd9Sstevel@tonic-gate 		pttrailer();
6207c478bd9Sstevel@tonic-gate 	ptlead();
6217c478bd9Sstevel@tonic-gate 	fdprintf(ptid, "x pause\n");
6227c478bd9Sstevel@tonic-gate 	flusho();
6237c478bd9Sstevel@tonic-gate 	mpts = mfont = 0;
6247c478bd9Sstevel@tonic-gate 	ptesc();
6257c478bd9Sstevel@tonic-gate 	esc = po;
6267c478bd9Sstevel@tonic-gate 	hpos = vpos = 0;	/* probably in wrong place */
627e5190c10Smuffin 
628e5190c10Smuffin 	return (0);
6297c478bd9Sstevel@tonic-gate }
630