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 2003 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 */
28*e0dcd577SToomas 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 /*
412a8bcb4eSToomas Soome * drive hp2621 terminal
427c478bd9Sstevel@tonic-gate * just to see stuff quickly. like troff -a
437c478bd9Sstevel@tonic-gate */
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate output language from troff:
477c478bd9Sstevel@tonic-gate all numbers are character strings
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate sn size in points
507c478bd9Sstevel@tonic-gate fn font as number from 1-n
517c478bd9Sstevel@tonic-gate cx ascii character x
527c478bd9Sstevel@tonic-gate Cxyz funny char xyz. terminated by white space
537c478bd9Sstevel@tonic-gate Hn go to absolute horizontal position n
547c478bd9Sstevel@tonic-gate Vn go to absolute vertical position n (down is positive)
557c478bd9Sstevel@tonic-gate hn go n units horizontally (relative)
567c478bd9Sstevel@tonic-gate vn ditto vertically
577c478bd9Sstevel@tonic-gate nnc move right nn (exactly 2 digits!), then print c
587c478bd9Sstevel@tonic-gate (this wart is an optimization that shrinks output file size
597c478bd9Sstevel@tonic-gate about 35% and run-time about 15% while preserving ascii-ness)
607c478bd9Sstevel@tonic-gate w paddable word space - no action needed
617c478bd9Sstevel@tonic-gate nb a end of line (information only -- no action needed)
627c478bd9Sstevel@tonic-gate b = space before line, a = after
637c478bd9Sstevel@tonic-gate pn begin page n
647c478bd9Sstevel@tonic-gate #...\n comment
657c478bd9Sstevel@tonic-gate Dt ...\n draw operation 't':
667c478bd9Sstevel@tonic-gate Dl x y line from here by x,y
677c478bd9Sstevel@tonic-gate Dc d circle of diameter d with left side here
687c478bd9Sstevel@tonic-gate De x y ellipse of axes x,y with left side here
697c478bd9Sstevel@tonic-gate Da x y u v arc counter-clockwise from here to u,v from center
707c478bd9Sstevel@tonic-gate with center x,y from here
717c478bd9Sstevel@tonic-gate D~ x y x y ... wiggly line by x,y then x,y ...
727c478bd9Sstevel@tonic-gate x ...\n device control functions:
737c478bd9Sstevel@tonic-gate x i init
747c478bd9Sstevel@tonic-gate x T s name of device is s
757c478bd9Sstevel@tonic-gate x r n h v resolution is n/inch
767c478bd9Sstevel@tonic-gate h = min horizontal motion, v = min vert
777c478bd9Sstevel@tonic-gate x p pause (can restart)
787c478bd9Sstevel@tonic-gate x s stop -- done for ever
797c478bd9Sstevel@tonic-gate x t generate trailer
807c478bd9Sstevel@tonic-gate x f n s font position n contains font s
817c478bd9Sstevel@tonic-gate x H n set character height to n
827c478bd9Sstevel@tonic-gate x S n set character slant to n
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate Subcommands like "i" are often spelled out like "init".
857c478bd9Sstevel@tonic-gate */
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate #include <stdio.h>
88*e0dcd577SToomas Soome #include <stdarg.h>
897c478bd9Sstevel@tonic-gate #include <signal.h>
907c478bd9Sstevel@tonic-gate #include <ctype.h>
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate #include "dev.h"
937c478bd9Sstevel@tonic-gate #define NFONT 10
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate int output = 0; /* do we do output at all? */
967c478bd9Sstevel@tonic-gate int nolist = 0; /* output page list if > 0 */
977c478bd9Sstevel@tonic-gate int olist[20]; /* pairs of page numbers */
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate int erase = 1;
1007c478bd9Sstevel@tonic-gate float aspect = 1.5; /* default aspect ratio */
1017c478bd9Sstevel@tonic-gate int wflag = 0; /* wait, looping, for new input if on */
102*e0dcd577SToomas Soome void (*sigint)(int);
103*e0dcd577SToomas Soome void (*sigquit)(int);
104*e0dcd577SToomas Soome void done(void);
105*e0dcd577SToomas Soome int error(int, char *, ...);
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate struct dev dev;
1087c478bd9Sstevel@tonic-gate struct font *fontbase[NFONT];
1097c478bd9Sstevel@tonic-gate short psizes[] ={ 11, 16, 22, 36, 0}; /* approx sizes available */
1107c478bd9Sstevel@tonic-gate short *pstab = psizes;
1117c478bd9Sstevel@tonic-gate int nsizes = 1;
1127c478bd9Sstevel@tonic-gate int nfonts;
1137c478bd9Sstevel@tonic-gate int smnt; /* index of first special font */
1147c478bd9Sstevel@tonic-gate int nchtab;
1157c478bd9Sstevel@tonic-gate char *chname;
1167c478bd9Sstevel@tonic-gate short *chtab;
1177c478bd9Sstevel@tonic-gate char *fitab[NFONT];
1187c478bd9Sstevel@tonic-gate char *widthtab[NFONT]; /* widtab would be a better name */
1197c478bd9Sstevel@tonic-gate char *codetab[NFONT]; /* device codes */
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate #define FATAL 1
1227c478bd9Sstevel@tonic-gate #define BMASK 0377
1237c478bd9Sstevel@tonic-gate int dbg = 0;
1247c478bd9Sstevel@tonic-gate int res = 972; /* input assumed computed according to this resolution */
1257c478bd9Sstevel@tonic-gate /* initial value to avoid 0 divide */
1267c478bd9Sstevel@tonic-gate FILE *tf = stdout; /* output file */
1277c478bd9Sstevel@tonic-gate char *fontdir = "/usr/lib/font";
1287c478bd9Sstevel@tonic-gate extern char devname[];
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate FILE *fp = stdin; /* input file pointer */
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate int nowait = 0; /* 0 => wait at bottom of each page */
1337c478bd9Sstevel@tonic-gate
134e5190c10Smuffin int
main(int argc,char ** argv)135e5190c10Smuffin main(int argc, char **argv)
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate setbuf(stdout, buf);
1407c478bd9Sstevel@tonic-gate while (argc > 1 && argv[1][0] == '-') {
1417c478bd9Sstevel@tonic-gate switch (argv[1][1]) {
1427c478bd9Sstevel@tonic-gate case 'a':
1437c478bd9Sstevel@tonic-gate aspect = atof(&argv[1][2]);
1447c478bd9Sstevel@tonic-gate break;
1457c478bd9Sstevel@tonic-gate case 'e':
1467c478bd9Sstevel@tonic-gate erase = 0;
1477c478bd9Sstevel@tonic-gate break;
1487c478bd9Sstevel@tonic-gate case 'o':
1497c478bd9Sstevel@tonic-gate outlist(&argv[1][2]);
1507c478bd9Sstevel@tonic-gate break;
1517c478bd9Sstevel@tonic-gate case 'd':
1527c478bd9Sstevel@tonic-gate dbg = atoi(&argv[1][2]);
1537c478bd9Sstevel@tonic-gate if (dbg == 0) dbg = 1;
1547c478bd9Sstevel@tonic-gate break;
1557c478bd9Sstevel@tonic-gate case 'w': /* no wait at bottom of page */
1567c478bd9Sstevel@tonic-gate nowait = 1;
1577c478bd9Sstevel@tonic-gate break;
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate argc--;
1607c478bd9Sstevel@tonic-gate argv++;
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate if (argc <= 1)
1647c478bd9Sstevel@tonic-gate conv(stdin);
1657c478bd9Sstevel@tonic-gate else
1667c478bd9Sstevel@tonic-gate while (--argc > 0) {
1677c478bd9Sstevel@tonic-gate if (strcmp(*++argv, "-") == 0)
1687c478bd9Sstevel@tonic-gate fp = stdin;
1697c478bd9Sstevel@tonic-gate else if ((fp = fopen(*argv, "r")) == NULL)
1707c478bd9Sstevel@tonic-gate error(FATAL, "can't open %s", *argv);
1717c478bd9Sstevel@tonic-gate conv(fp);
1727c478bd9Sstevel@tonic-gate fclose(fp);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate done();
175e5190c10Smuffin
176e5190c10Smuffin return (0);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
179e5190c10Smuffin int
outlist(char * s)180*e0dcd577SToomas Soome outlist(char *s) /* process list of page numbers to be printed */
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate int n1, n2, i;
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate nolist = 0;
1857c478bd9Sstevel@tonic-gate while (*s) {
1867c478bd9Sstevel@tonic-gate n1 = 0;
1877c478bd9Sstevel@tonic-gate if (isdigit((unsigned char)*s))
1887c478bd9Sstevel@tonic-gate do
1897c478bd9Sstevel@tonic-gate n1 = 10 * n1 + *s++ - '0';
1907c478bd9Sstevel@tonic-gate while (isdigit((unsigned char)*s));
1917c478bd9Sstevel@tonic-gate else
1927c478bd9Sstevel@tonic-gate n1 = -9999;
1937c478bd9Sstevel@tonic-gate n2 = n1;
1947c478bd9Sstevel@tonic-gate if (*s == '-') {
1957c478bd9Sstevel@tonic-gate s++;
1967c478bd9Sstevel@tonic-gate n2 = 0;
1977c478bd9Sstevel@tonic-gate if (isdigit((unsigned char)*s))
1987c478bd9Sstevel@tonic-gate do
1997c478bd9Sstevel@tonic-gate n2 = 10 * n2 + *s++ - '0';
2007c478bd9Sstevel@tonic-gate while (isdigit((unsigned char)*s));
2017c478bd9Sstevel@tonic-gate else
2027c478bd9Sstevel@tonic-gate n2 = 9999;
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate olist[nolist++] = n1;
2057c478bd9Sstevel@tonic-gate olist[nolist++] = n2;
2067c478bd9Sstevel@tonic-gate if (*s != '\0')
2077c478bd9Sstevel@tonic-gate s++;
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate olist[nolist] = 0;
2107c478bd9Sstevel@tonic-gate if (dbg)
2117c478bd9Sstevel@tonic-gate for (i=0; i<nolist; i += 2)
2127c478bd9Sstevel@tonic-gate printf("%3d %3d\n", olist[i], olist[i+1]);
213e5190c10Smuffin
214e5190c10Smuffin return (0);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate
217e5190c10Smuffin int
in_olist(int n)218*e0dcd577SToomas Soome in_olist(int n) /* is n in olist? */
2197c478bd9Sstevel@tonic-gate {
2207c478bd9Sstevel@tonic-gate int i;
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate if (nolist == 0)
2237c478bd9Sstevel@tonic-gate return(1); /* everything is included */
2247c478bd9Sstevel@tonic-gate for (i = 0; i < nolist; i += 2)
2257c478bd9Sstevel@tonic-gate if (n >= olist[i] && n <= olist[i+1])
2267c478bd9Sstevel@tonic-gate return(1);
2277c478bd9Sstevel@tonic-gate return(0);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate
230e5190c10Smuffin int
conv(FILE * fp)231*e0dcd577SToomas Soome conv(FILE *fp)
2327c478bd9Sstevel@tonic-gate {
233e5190c10Smuffin int c, k;
2347c478bd9Sstevel@tonic-gate int m, n, i, n1, m1;
2357c478bd9Sstevel@tonic-gate char str[100], buf[300];
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate while ((c = getc(fp)) != EOF) {
2387c478bd9Sstevel@tonic-gate switch (c) {
2397c478bd9Sstevel@tonic-gate case '\n': /* when input is text */
2407c478bd9Sstevel@tonic-gate case ' ':
2417c478bd9Sstevel@tonic-gate case 0: /* occasional noise creeps in */
2427c478bd9Sstevel@tonic-gate break;
2437c478bd9Sstevel@tonic-gate case '{': /* push down current environment */
2447c478bd9Sstevel@tonic-gate t_push();
2457c478bd9Sstevel@tonic-gate break;
2467c478bd9Sstevel@tonic-gate case '}':
2477c478bd9Sstevel@tonic-gate t_pop();
2487c478bd9Sstevel@tonic-gate break;
2497c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4':
2507c478bd9Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9':
2517c478bd9Sstevel@tonic-gate /* two motion digits plus a character */
2527c478bd9Sstevel@tonic-gate hmot((c-'0')*10 + getc(fp)-'0');
2537c478bd9Sstevel@tonic-gate put1(getc(fp));
2547c478bd9Sstevel@tonic-gate break;
2557c478bd9Sstevel@tonic-gate case 'c': /* single ascii character */
2567c478bd9Sstevel@tonic-gate put1(getc(fp));
2577c478bd9Sstevel@tonic-gate break;
2587c478bd9Sstevel@tonic-gate case 'C':
2597c478bd9Sstevel@tonic-gate fscanf(fp, "%s", str);
2607c478bd9Sstevel@tonic-gate put1s(str);
2617c478bd9Sstevel@tonic-gate break;
2627c478bd9Sstevel@tonic-gate case 't': /* straight text */
2637c478bd9Sstevel@tonic-gate fgets(buf, sizeof(buf), fp);
2647c478bd9Sstevel@tonic-gate t_text(buf);
2657c478bd9Sstevel@tonic-gate break;
2667c478bd9Sstevel@tonic-gate case 'D': /* draw function */
2677c478bd9Sstevel@tonic-gate fgets(buf, sizeof(buf), fp);
2687c478bd9Sstevel@tonic-gate switch (buf[0]) {
2697c478bd9Sstevel@tonic-gate case 'l': /* draw a line */
2707c478bd9Sstevel@tonic-gate sscanf(buf+1, "%d %d", &n, &m);
2717c478bd9Sstevel@tonic-gate drawline(n, m, ".");
2727c478bd9Sstevel@tonic-gate break;
2737c478bd9Sstevel@tonic-gate case 'c': /* circle */
2747c478bd9Sstevel@tonic-gate sscanf(buf+1, "%d", &n);
2757c478bd9Sstevel@tonic-gate drawcirc(n);
2767c478bd9Sstevel@tonic-gate break;
2777c478bd9Sstevel@tonic-gate case 'e': /* ellipse */
2787c478bd9Sstevel@tonic-gate sscanf(buf+1, "%d %d", &m, &n);
2797c478bd9Sstevel@tonic-gate drawellip(m, n);
2807c478bd9Sstevel@tonic-gate break;
2817c478bd9Sstevel@tonic-gate case 'a': /* arc */
2827c478bd9Sstevel@tonic-gate sscanf(buf+1, "%d %d %d %d", &n, &m, &n1, &m1);
2837c478bd9Sstevel@tonic-gate drawarc(n, m, n1, m1);
2847c478bd9Sstevel@tonic-gate break;
2857c478bd9Sstevel@tonic-gate case '~': /* wiggly line */
2867c478bd9Sstevel@tonic-gate drawwig(buf+1);
2877c478bd9Sstevel@tonic-gate break;
2887c478bd9Sstevel@tonic-gate default:
2897c478bd9Sstevel@tonic-gate error(FATAL, "unknown drawing function %s\n", buf);
2907c478bd9Sstevel@tonic-gate break;
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate break;
2937c478bd9Sstevel@tonic-gate case 's':
2947c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &n); /* ignore fractional sizes */
2957c478bd9Sstevel@tonic-gate setsize(t_size(n));
2967c478bd9Sstevel@tonic-gate break;
2977c478bd9Sstevel@tonic-gate case 'f':
2987c478bd9Sstevel@tonic-gate fscanf(fp, "%s", str);
2997c478bd9Sstevel@tonic-gate setfont(t_font(str));
3007c478bd9Sstevel@tonic-gate break;
3017c478bd9Sstevel@tonic-gate case 'H': /* absolute horizontal motion */
3027c478bd9Sstevel@tonic-gate /* fscanf(fp, "%d", &n); */
3037c478bd9Sstevel@tonic-gate while ((c = getc(fp)) == ' ')
3047c478bd9Sstevel@tonic-gate ;
3057c478bd9Sstevel@tonic-gate k = 0;
3067c478bd9Sstevel@tonic-gate do {
3077c478bd9Sstevel@tonic-gate k = 10 * k + c - '0';
3087c478bd9Sstevel@tonic-gate } while (isdigit(c = getc(fp)));
3097c478bd9Sstevel@tonic-gate ungetc(c, fp);
3107c478bd9Sstevel@tonic-gate hgoto(k);
3117c478bd9Sstevel@tonic-gate break;
3127c478bd9Sstevel@tonic-gate case 'h': /* relative horizontal motion */
3137c478bd9Sstevel@tonic-gate /* fscanf(fp, "%d", &n); */
3147c478bd9Sstevel@tonic-gate while ((c = getc(fp)) == ' ')
3157c478bd9Sstevel@tonic-gate ;
3167c478bd9Sstevel@tonic-gate k = 0;
3177c478bd9Sstevel@tonic-gate do {
3187c478bd9Sstevel@tonic-gate k = 10 * k + c - '0';
3197c478bd9Sstevel@tonic-gate } while (isdigit(c = getc(fp)));
3207c478bd9Sstevel@tonic-gate ungetc(c, fp);
3217c478bd9Sstevel@tonic-gate hmot(k);
3227c478bd9Sstevel@tonic-gate break;
3237c478bd9Sstevel@tonic-gate case 'w': /* word space */
3247c478bd9Sstevel@tonic-gate putc(' ', stdout);
3257c478bd9Sstevel@tonic-gate break;
3267c478bd9Sstevel@tonic-gate case 'V':
3277c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &n);
3287c478bd9Sstevel@tonic-gate vgoto(n);
3297c478bd9Sstevel@tonic-gate break;
3307c478bd9Sstevel@tonic-gate case 'v':
3317c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &n);
3327c478bd9Sstevel@tonic-gate vmot(n);
3337c478bd9Sstevel@tonic-gate break;
3347c478bd9Sstevel@tonic-gate case 'p': /* new page */
3357c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &n);
3367c478bd9Sstevel@tonic-gate t_page(n);
3377c478bd9Sstevel@tonic-gate break;
3387c478bd9Sstevel@tonic-gate case 'n': /* end of line */
3397c478bd9Sstevel@tonic-gate while (getc(fp) != '\n')
3407c478bd9Sstevel@tonic-gate ;
3417c478bd9Sstevel@tonic-gate t_newline();
3427c478bd9Sstevel@tonic-gate break;
3437c478bd9Sstevel@tonic-gate case '#': /* comment */
3447c478bd9Sstevel@tonic-gate while (getc(fp) != '\n')
3457c478bd9Sstevel@tonic-gate ;
3467c478bd9Sstevel@tonic-gate break;
3477c478bd9Sstevel@tonic-gate case 'x': /* device control */
3487c478bd9Sstevel@tonic-gate devcntrl(fp);
3497c478bd9Sstevel@tonic-gate break;
3507c478bd9Sstevel@tonic-gate default:
3517c478bd9Sstevel@tonic-gate error(!FATAL, "unknown input character %o %c\n", c, c);
3527c478bd9Sstevel@tonic-gate done();
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate }
355e5190c10Smuffin
356e5190c10Smuffin return (0);
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate
359e5190c10Smuffin int
devcntrl(FILE * fp)360*e0dcd577SToomas Soome devcntrl(FILE *fp) /* interpret device control functions */
3617c478bd9Sstevel@tonic-gate {
3627c478bd9Sstevel@tonic-gate char str[20];
3637c478bd9Sstevel@tonic-gate int c, n;
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate fscanf(fp, "%s", str);
3667c478bd9Sstevel@tonic-gate switch (str[0]) { /* crude for now */
3677c478bd9Sstevel@tonic-gate case 'i': /* initialize */
3687c478bd9Sstevel@tonic-gate fileinit();
3697c478bd9Sstevel@tonic-gate t_init(0);
3707c478bd9Sstevel@tonic-gate break;
3717c478bd9Sstevel@tonic-gate case 'T': /* device name */
3727c478bd9Sstevel@tonic-gate fscanf(fp, "%s", devname);
3737c478bd9Sstevel@tonic-gate break;
3747c478bd9Sstevel@tonic-gate case 't': /* trailer */
3757c478bd9Sstevel@tonic-gate t_trailer();
3767c478bd9Sstevel@tonic-gate break;
3777c478bd9Sstevel@tonic-gate case 'p': /* pause -- can restart */
3787c478bd9Sstevel@tonic-gate t_reset('p');
3797c478bd9Sstevel@tonic-gate break;
3807c478bd9Sstevel@tonic-gate case 's': /* stop */
3817c478bd9Sstevel@tonic-gate t_reset('s');
3827c478bd9Sstevel@tonic-gate break;
3837c478bd9Sstevel@tonic-gate case 'r': /* resolution assumed when prepared */
3847c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &res);
3857c478bd9Sstevel@tonic-gate break;
3867c478bd9Sstevel@tonic-gate case 'f': /* font used */
3877c478bd9Sstevel@tonic-gate fscanf(fp, "%d %s", &n, str);
3887c478bd9Sstevel@tonic-gate loadfont(n, str);
3897c478bd9Sstevel@tonic-gate break;
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate while (getc(fp) != '\n') /* skip rest of input line */
3927c478bd9Sstevel@tonic-gate ;
393e5190c10Smuffin
394e5190c10Smuffin return (0);
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate
397e5190c10Smuffin int
fileinit(void)398*e0dcd577SToomas Soome fileinit(void) /* read in font and code files, etc. */
3997c478bd9Sstevel@tonic-gate {
400e5190c10Smuffin return (0);
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate
403e5190c10Smuffin int
fontprint(int i)404*e0dcd577SToomas Soome fontprint(int i) /* debugging print of font i (0,...) */
4057c478bd9Sstevel@tonic-gate {
406e5190c10Smuffin return (0);
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate
409e5190c10Smuffin int
loadcode(int n,int nw)410*e0dcd577SToomas Soome loadcode(int n, int nw) /* load codetab on position n (0...); #chars is nw */
4117c478bd9Sstevel@tonic-gate {
412e5190c10Smuffin return (0);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate
415e5190c10Smuffin int
loadfont(int n,char * s)416*e0dcd577SToomas Soome loadfont(int n, char *s) /* load font info for font s on position n (1...) */
4177c478bd9Sstevel@tonic-gate {
418e5190c10Smuffin return (0);
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate
421e5190c10Smuffin int
error(int f,char * fmt,...)422*e0dcd577SToomas Soome error(int f, char *fmt, ...)
4237c478bd9Sstevel@tonic-gate {
424*e0dcd577SToomas Soome va_list ap;
425*e0dcd577SToomas Soome
4267c478bd9Sstevel@tonic-gate fprintf(stderr, "ta: ");
427*e0dcd577SToomas Soome va_start(ap, fmt);
428*e0dcd577SToomas Soome (void) vfprintf(stderr, fmt, ap);
429*e0dcd577SToomas Soome va_end(ap);
4307c478bd9Sstevel@tonic-gate fprintf(stderr, "\n");
4317c478bd9Sstevel@tonic-gate if (f)
4327c478bd9Sstevel@tonic-gate exit(1);
433e5190c10Smuffin
434e5190c10Smuffin return (0);
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate Here beginneth all the stuff that really depends
4407c478bd9Sstevel@tonic-gate on the 202 (we hope).
4417c478bd9Sstevel@tonic-gate */
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate char devname[20] = "hp2621";
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate #define ESC 033
4477c478bd9Sstevel@tonic-gate #define HOME 'H'
4487c478bd9Sstevel@tonic-gate #define CLEAR 'J'
4497c478bd9Sstevel@tonic-gate #define FF 014
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate int size = 1;
4527c478bd9Sstevel@tonic-gate int font = 1; /* current font */
4537c478bd9Sstevel@tonic-gate int hpos; /* horizontal position where we are supposed to be next (left = 0) */
4547c478bd9Sstevel@tonic-gate int vpos; /* current vertical position (down positive) */
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate int horig; /* h origin of current block; hpos rel to this */
4577c478bd9Sstevel@tonic-gate int vorig; /* v origin of current block; vpos rel to this */
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate int DX = 10; /* step size in x for drawing */
4607c478bd9Sstevel@tonic-gate int DY = 10; /* step size in y for drawing */
4617c478bd9Sstevel@tonic-gate int drawdot = '.'; /* draw with this character */
4627c478bd9Sstevel@tonic-gate int drawsize = 1; /* shrink by this factor when drawing */
4637c478bd9Sstevel@tonic-gate
464e5190c10Smuffin int
t_init(int reinit)465*e0dcd577SToomas Soome t_init(int reinit) /* initialize device */
4667c478bd9Sstevel@tonic-gate {
4677c478bd9Sstevel@tonic-gate int i, j;
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate fflush(stdout);
4707c478bd9Sstevel@tonic-gate hpos = vpos = 0;
471e5190c10Smuffin
472e5190c10Smuffin return (0);
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate #define MAXSTATE 5
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate struct state {
4787c478bd9Sstevel@tonic-gate int ssize;
4797c478bd9Sstevel@tonic-gate int sfont;
4807c478bd9Sstevel@tonic-gate int shpos;
4817c478bd9Sstevel@tonic-gate int svpos;
4827c478bd9Sstevel@tonic-gate int shorig;
4837c478bd9Sstevel@tonic-gate int svorig;
4847c478bd9Sstevel@tonic-gate };
4857c478bd9Sstevel@tonic-gate struct state state[MAXSTATE];
4867c478bd9Sstevel@tonic-gate struct state *statep = state;
4877c478bd9Sstevel@tonic-gate
488e5190c10Smuffin int
t_push(void)489*e0dcd577SToomas Soome t_push(void) /* begin a new block */
4907c478bd9Sstevel@tonic-gate {
4917c478bd9Sstevel@tonic-gate hflush();
4927c478bd9Sstevel@tonic-gate statep->ssize = size;
4937c478bd9Sstevel@tonic-gate statep->sfont = font;
4947c478bd9Sstevel@tonic-gate statep->shorig = horig;
4957c478bd9Sstevel@tonic-gate statep->svorig = vorig;
4967c478bd9Sstevel@tonic-gate statep->shpos = hpos;
4977c478bd9Sstevel@tonic-gate statep->svpos = vpos;
4987c478bd9Sstevel@tonic-gate horig = hpos;
4997c478bd9Sstevel@tonic-gate vorig = vpos;
5007c478bd9Sstevel@tonic-gate hpos = vpos = 0;
5017c478bd9Sstevel@tonic-gate if (statep++ >= state+MAXSTATE)
5027c478bd9Sstevel@tonic-gate error(FATAL, "{ nested too deep");
5037c478bd9Sstevel@tonic-gate hpos = vpos = 0;
504e5190c10Smuffin
505e5190c10Smuffin return (0);
5067c478bd9Sstevel@tonic-gate }
5077c478bd9Sstevel@tonic-gate
508e5190c10Smuffin int
t_pop(void)509*e0dcd577SToomas Soome t_pop(void) /* pop to previous state */
5107c478bd9Sstevel@tonic-gate {
5117c478bd9Sstevel@tonic-gate if (--statep < state)
5127c478bd9Sstevel@tonic-gate error(FATAL, "extra }");
5137c478bd9Sstevel@tonic-gate size = statep->ssize;
5147c478bd9Sstevel@tonic-gate font = statep->sfont;
5157c478bd9Sstevel@tonic-gate hpos = statep->shpos;
5167c478bd9Sstevel@tonic-gate vpos = statep->svpos;
5177c478bd9Sstevel@tonic-gate horig = statep->shorig;
5187c478bd9Sstevel@tonic-gate vorig = statep->svorig;
519e5190c10Smuffin
520e5190c10Smuffin return (0);
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate int np; /* number of pages seen */
5247c478bd9Sstevel@tonic-gate int npmax; /* high-water mark of np */
5257c478bd9Sstevel@tonic-gate int pgnum[40]; /* their actual numbers */
5267c478bd9Sstevel@tonic-gate long pgadr[40]; /* their seek addresses */
5277c478bd9Sstevel@tonic-gate
528e5190c10Smuffin int
t_page(int n)529*e0dcd577SToomas Soome t_page(int n) /* do whatever new page functions */
5307c478bd9Sstevel@tonic-gate {
5317c478bd9Sstevel@tonic-gate long ftell();
5327c478bd9Sstevel@tonic-gate int c, m, i;
5337c478bd9Sstevel@tonic-gate char buf[100], *bp;
5347c478bd9Sstevel@tonic-gate
5357c478bd9Sstevel@tonic-gate pgnum[np++] = n;
5367c478bd9Sstevel@tonic-gate pgadr[np] = ftell(fp);
5377c478bd9Sstevel@tonic-gate if (np > npmax)
5387c478bd9Sstevel@tonic-gate npmax = np;
5397c478bd9Sstevel@tonic-gate if (output == 0) {
5407c478bd9Sstevel@tonic-gate output = in_olist(n);
5417c478bd9Sstevel@tonic-gate t_init(1);
542e5190c10Smuffin return (0);
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate /* have just printed something, and seen p<n> for next one */
5457c478bd9Sstevel@tonic-gate putpage();
5467c478bd9Sstevel@tonic-gate fflush(stdout);
5477c478bd9Sstevel@tonic-gate if (nowait)
548e5190c10Smuffin return (0);
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate next:
5517c478bd9Sstevel@tonic-gate for (bp = buf; (*bp = readch()); )
5527c478bd9Sstevel@tonic-gate if (*bp++ == '\n')
5537c478bd9Sstevel@tonic-gate break;
5547c478bd9Sstevel@tonic-gate *bp = 0;
5557c478bd9Sstevel@tonic-gate switch (buf[0]) {
5567c478bd9Sstevel@tonic-gate case 0:
5577c478bd9Sstevel@tonic-gate done();
5587c478bd9Sstevel@tonic-gate break;
5597c478bd9Sstevel@tonic-gate case '\n':
5607c478bd9Sstevel@tonic-gate output = in_olist(n);
5617c478bd9Sstevel@tonic-gate t_init(1);
562e5190c10Smuffin return (0);
5637c478bd9Sstevel@tonic-gate case '!':
5647c478bd9Sstevel@tonic-gate callunix(&buf[1]);
5657c478bd9Sstevel@tonic-gate fputs("!\n", stderr);
5667c478bd9Sstevel@tonic-gate break;
5677c478bd9Sstevel@tonic-gate case 'e':
5687c478bd9Sstevel@tonic-gate erase = 1 - erase;
5697c478bd9Sstevel@tonic-gate break;
5707c478bd9Sstevel@tonic-gate case 'w':
5717c478bd9Sstevel@tonic-gate wflag = 1 - wflag;
5727c478bd9Sstevel@tonic-gate break;
5737c478bd9Sstevel@tonic-gate case 'a':
5747c478bd9Sstevel@tonic-gate aspect = atof(&buf[1]);
5757c478bd9Sstevel@tonic-gate break;
5767c478bd9Sstevel@tonic-gate case '-':
5777c478bd9Sstevel@tonic-gate case 'p':
5787c478bd9Sstevel@tonic-gate m = atoi(&buf[1]) + 1;
5797c478bd9Sstevel@tonic-gate if (fp == stdin) {
5807c478bd9Sstevel@tonic-gate fputs("you can't; it's not a file\n", stderr);
5817c478bd9Sstevel@tonic-gate break;
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate if (np - m <= 0) {
5847c478bd9Sstevel@tonic-gate fputs("too far back\n", stderr);
5857c478bd9Sstevel@tonic-gate break;
5867c478bd9Sstevel@tonic-gate }
5877c478bd9Sstevel@tonic-gate np -= m;
5887c478bd9Sstevel@tonic-gate fseek(fp, pgadr[np], 0);
5897c478bd9Sstevel@tonic-gate output = 1;
5907c478bd9Sstevel@tonic-gate t_init(1);
591e5190c10Smuffin return (0);
5927c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4':
5937c478bd9Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9':
5947c478bd9Sstevel@tonic-gate m = atoi(&buf[0]);
5957c478bd9Sstevel@tonic-gate for (i = 0; i < npmax; i++)
5967c478bd9Sstevel@tonic-gate if (m == pgnum[i])
5977c478bd9Sstevel@tonic-gate break;
5987c478bd9Sstevel@tonic-gate if (i >= npmax || fp == stdin) {
5997c478bd9Sstevel@tonic-gate fputs("you can't\n", stderr);
6007c478bd9Sstevel@tonic-gate break;
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate np = i + 1;
6037c478bd9Sstevel@tonic-gate fseek(fp, pgadr[np], 0);
6047c478bd9Sstevel@tonic-gate output = 1;
6057c478bd9Sstevel@tonic-gate t_init(1);
606e5190c10Smuffin return (0);
6077c478bd9Sstevel@tonic-gate case 'o':
6087c478bd9Sstevel@tonic-gate outlist(&buf[1]);
6097c478bd9Sstevel@tonic-gate output = 0;
6107c478bd9Sstevel@tonic-gate t_init(1);
611e5190c10Smuffin return (0);
6127c478bd9Sstevel@tonic-gate case '?':
6137c478bd9Sstevel@tonic-gate fputs("!cmd unix cmd\n", stderr);
6147c478bd9Sstevel@tonic-gate fputs("p print this page again\n", stderr);
6157c478bd9Sstevel@tonic-gate fputs("-n go back n pages\n", stderr);
6167c478bd9Sstevel@tonic-gate fputs("n print page n (previously printed)\n", stderr);
6177c478bd9Sstevel@tonic-gate fputs("o... set the -o output list to ...\n", stderr);
6187c478bd9Sstevel@tonic-gate fputs("en n=0 -> don't erase; n=1 -> erase\n", stderr);
6197c478bd9Sstevel@tonic-gate fputs("an sets aspect ratio to n\n", stderr);
6207c478bd9Sstevel@tonic-gate break;
6217c478bd9Sstevel@tonic-gate default:
6227c478bd9Sstevel@tonic-gate fputs("?\n", stderr);
6237c478bd9Sstevel@tonic-gate break;
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate goto next;
6267c478bd9Sstevel@tonic-gate }
6277c478bd9Sstevel@tonic-gate
628e5190c10Smuffin int
putpage(void)629*e0dcd577SToomas Soome putpage(void)
6307c478bd9Sstevel@tonic-gate {
6317c478bd9Sstevel@tonic-gate int i, j, k;
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate fflush(stdout);
634e5190c10Smuffin
635e5190c10Smuffin return (0);
6367c478bd9Sstevel@tonic-gate }
6377c478bd9Sstevel@tonic-gate
638e5190c10Smuffin int
t_newline(void)639*e0dcd577SToomas Soome t_newline(void) /* do whatever for the end of a line */
6407c478bd9Sstevel@tonic-gate {
6417c478bd9Sstevel@tonic-gate printf("\n");
6427c478bd9Sstevel@tonic-gate hpos = 0;
643e5190c10Smuffin
644e5190c10Smuffin return (0);
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate
647e5190c10Smuffin int
t_size(int n)648*e0dcd577SToomas Soome t_size(int n) /* convert integer to internal size number*/
6497c478bd9Sstevel@tonic-gate {
650e5190c10Smuffin return (0);
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate
653e5190c10Smuffin int
t_font(char * s)654*e0dcd577SToomas Soome t_font(char *s) /* convert string to internal font number */
6557c478bd9Sstevel@tonic-gate {
656e5190c10Smuffin return (0);
6577c478bd9Sstevel@tonic-gate }
6587c478bd9Sstevel@tonic-gate
659e5190c10Smuffin int
t_text(char * s)660*e0dcd577SToomas Soome t_text(char *s) /* print string s as text */
6617c478bd9Sstevel@tonic-gate {
6627c478bd9Sstevel@tonic-gate int c, w=0;
6637c478bd9Sstevel@tonic-gate char str[100];
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate if (!output)
666e5190c10Smuffin return (0);
6677c478bd9Sstevel@tonic-gate while ((c = *s++) != '\n') {
6687c478bd9Sstevel@tonic-gate if (c == '\\') {
6697c478bd9Sstevel@tonic-gate switch (c = *s++) {
6707c478bd9Sstevel@tonic-gate case '\\':
6717c478bd9Sstevel@tonic-gate case 'e':
6727c478bd9Sstevel@tonic-gate put1('\\');
6737c478bd9Sstevel@tonic-gate break;
6747c478bd9Sstevel@tonic-gate case '(':
6757c478bd9Sstevel@tonic-gate str[0] = *s++;
6767c478bd9Sstevel@tonic-gate str[1] = *s++;
6777c478bd9Sstevel@tonic-gate str[2] = '\0';
6787c478bd9Sstevel@tonic-gate put1s(str);
6797c478bd9Sstevel@tonic-gate break;
6807c478bd9Sstevel@tonic-gate }
6817c478bd9Sstevel@tonic-gate } else {
6827c478bd9Sstevel@tonic-gate put1(c);
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate hmot(w);
6857c478bd9Sstevel@tonic-gate }
686e5190c10Smuffin
687e5190c10Smuffin return (0);
6887c478bd9Sstevel@tonic-gate }
6897c478bd9Sstevel@tonic-gate
690e5190c10Smuffin int
t_reset(int c)691*e0dcd577SToomas Soome t_reset(int c)
6927c478bd9Sstevel@tonic-gate {
6937c478bd9Sstevel@tonic-gate int n;
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate output = 1;
6967c478bd9Sstevel@tonic-gate fflush(stdout);
6977c478bd9Sstevel@tonic-gate if (c == 's')
6987c478bd9Sstevel@tonic-gate t_page(9999);
699e5190c10Smuffin
700e5190c10Smuffin return (0);
7017c478bd9Sstevel@tonic-gate }
7027c478bd9Sstevel@tonic-gate
703e5190c10Smuffin int
t_trailer(void)704*e0dcd577SToomas Soome t_trailer(void)
7057c478bd9Sstevel@tonic-gate {
706e5190c10Smuffin return (0);
7077c478bd9Sstevel@tonic-gate }
7087c478bd9Sstevel@tonic-gate
709e5190c10Smuffin int
hgoto(int n)710*e0dcd577SToomas Soome hgoto(int n)
7117c478bd9Sstevel@tonic-gate {
7127c478bd9Sstevel@tonic-gate hpos = n; /* this is where we want to be */
7137c478bd9Sstevel@tonic-gate /* before printing a character, */
7147c478bd9Sstevel@tonic-gate /* have to make sure it's true */
715e5190c10Smuffin
716e5190c10Smuffin return (0);
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate
719e5190c10Smuffin int
hmot(int n)720*e0dcd577SToomas Soome hmot(int n) /* generate n units of horizontal motion */
7217c478bd9Sstevel@tonic-gate {
7227c478bd9Sstevel@tonic-gate hgoto(hpos + n);
723e5190c10Smuffin
724e5190c10Smuffin return (0);
7257c478bd9Sstevel@tonic-gate }
7267c478bd9Sstevel@tonic-gate
727e5190c10Smuffin int
hflush(void)728*e0dcd577SToomas Soome hflush(void) /* actual horizontal output occurs here */
7297c478bd9Sstevel@tonic-gate {
730e5190c10Smuffin return (0);
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate
733e5190c10Smuffin int
vgoto(int n)734*e0dcd577SToomas Soome vgoto(int n)
7357c478bd9Sstevel@tonic-gate {
7367c478bd9Sstevel@tonic-gate vpos = n;
737e5190c10Smuffin
738e5190c10Smuffin return (0);
7397c478bd9Sstevel@tonic-gate }
7407c478bd9Sstevel@tonic-gate
741e5190c10Smuffin int
vmot(int n)742*e0dcd577SToomas Soome vmot(int n) /* generate n units of vertical motion */
7437c478bd9Sstevel@tonic-gate {
7447c478bd9Sstevel@tonic-gate vgoto(vpos + n); /* ignores rounding */
745e5190c10Smuffin
746e5190c10Smuffin return (0);
7477c478bd9Sstevel@tonic-gate }
7487c478bd9Sstevel@tonic-gate
749e5190c10Smuffin int
put1s(char * s)750*e0dcd577SToomas Soome put1s(char *s) /* s is a funny char name */
7517c478bd9Sstevel@tonic-gate {
7527c478bd9Sstevel@tonic-gate int i;
7537c478bd9Sstevel@tonic-gate char *p;
7547c478bd9Sstevel@tonic-gate extern char *spectab[];
7557c478bd9Sstevel@tonic-gate static char prev[10] = "";
7567c478bd9Sstevel@tonic-gate static int previ;
7577c478bd9Sstevel@tonic-gate
7587c478bd9Sstevel@tonic-gate if (!output)
759e5190c10Smuffin return (0);
7607c478bd9Sstevel@tonic-gate if (strcmp(s, prev) != 0) {
7617c478bd9Sstevel@tonic-gate previ = -1;
7627c478bd9Sstevel@tonic-gate for (i = 0; spectab[i] != 0; i += 2)
7637c478bd9Sstevel@tonic-gate if (strcmp(spectab[i], s) == 0) {
7647c478bd9Sstevel@tonic-gate strcpy(prev, s);
7657c478bd9Sstevel@tonic-gate previ = i;
7667c478bd9Sstevel@tonic-gate break;
7677c478bd9Sstevel@tonic-gate }
7687c478bd9Sstevel@tonic-gate }
7697c478bd9Sstevel@tonic-gate if (previ >= 0) {
7707c478bd9Sstevel@tonic-gate for (p = spectab[previ+1]; *p; p++)
7717c478bd9Sstevel@tonic-gate putc(*p, stdout);
7727c478bd9Sstevel@tonic-gate } else
7737c478bd9Sstevel@tonic-gate prev[0] = 0;
774e5190c10Smuffin
775e5190c10Smuffin return (0);
7767c478bd9Sstevel@tonic-gate }
7777c478bd9Sstevel@tonic-gate
778e5190c10Smuffin int
put1(int c)779*e0dcd577SToomas Soome put1(int c) /* output char c */
7807c478bd9Sstevel@tonic-gate {
7817c478bd9Sstevel@tonic-gate if (!output)
782e5190c10Smuffin return (0);
7837c478bd9Sstevel@tonic-gate putc(c, stdout);
784e5190c10Smuffin
785e5190c10Smuffin return (0);
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate
788e5190c10Smuffin int
setsize(int n)789*e0dcd577SToomas Soome setsize(int n) /* set point size to n (internal) */
7907c478bd9Sstevel@tonic-gate {
791e5190c10Smuffin return (0);
7927c478bd9Sstevel@tonic-gate }
7937c478bd9Sstevel@tonic-gate
794e5190c10Smuffin int
t_fp(int n,char * s)795*e0dcd577SToomas Soome t_fp(int n, char *s) /* font position n now contains font s */
7967c478bd9Sstevel@tonic-gate {
797e5190c10Smuffin return (0);
7987c478bd9Sstevel@tonic-gate }
7997c478bd9Sstevel@tonic-gate
800e5190c10Smuffin int
setfont(int n)801*e0dcd577SToomas Soome setfont(int n) /* set font to n */
8027c478bd9Sstevel@tonic-gate {
803e5190c10Smuffin return (0);
8047c478bd9Sstevel@tonic-gate }
8057c478bd9Sstevel@tonic-gate
done(void)806*e0dcd577SToomas Soome void done(void)
8077c478bd9Sstevel@tonic-gate {
8087c478bd9Sstevel@tonic-gate output = 1;
8097c478bd9Sstevel@tonic-gate putpage();
8107c478bd9Sstevel@tonic-gate fflush(stdout);
8117c478bd9Sstevel@tonic-gate exit(0);
8127c478bd9Sstevel@tonic-gate }
8137c478bd9Sstevel@tonic-gate
814e5190c10Smuffin int
callunix(char line[])815*e0dcd577SToomas Soome callunix(char line[])
8167c478bd9Sstevel@tonic-gate {
8177c478bd9Sstevel@tonic-gate int rc, status, unixpid;
8187c478bd9Sstevel@tonic-gate if( (unixpid=fork())==0 ) {
8197c478bd9Sstevel@tonic-gate signal(SIGINT,sigint); signal(SIGQUIT,sigquit);
8207c478bd9Sstevel@tonic-gate close(0); dup(2);
8217c478bd9Sstevel@tonic-gate execl("/bin/sh", "-sh", "-c", line, 0);
8227c478bd9Sstevel@tonic-gate exit(255);
8237c478bd9Sstevel@tonic-gate }
8247c478bd9Sstevel@tonic-gate else if(unixpid == -1)
825e5190c10Smuffin return (0);
8267c478bd9Sstevel@tonic-gate else{ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN);
8277c478bd9Sstevel@tonic-gate while( (rc = wait(&status)) != unixpid && rc != -1 ) ;
828*e0dcd577SToomas Soome signal(SIGINT,(void(*)())done); signal(SIGQUIT,sigquit);
8297c478bd9Sstevel@tonic-gate }
830e5190c10Smuffin
831e5190c10Smuffin return (0);
8327c478bd9Sstevel@tonic-gate }
8337c478bd9Sstevel@tonic-gate
834e5190c10Smuffin int
readch(void)835*e0dcd577SToomas Soome readch(void)
836*e0dcd577SToomas Soome {
8377c478bd9Sstevel@tonic-gate char c;
8387c478bd9Sstevel@tonic-gate if (read(2,&c,1)<1) c=0;
8397c478bd9Sstevel@tonic-gate return(c);
8407c478bd9Sstevel@tonic-gate }
8417c478bd9Sstevel@tonic-gate
8427c478bd9Sstevel@tonic-gate char *spectab[] ={
8437c478bd9Sstevel@tonic-gate "em", "-",
8447c478bd9Sstevel@tonic-gate "hy", "-",
8457c478bd9Sstevel@tonic-gate "en", "-",
8467c478bd9Sstevel@tonic-gate "ru", "_",
8477c478bd9Sstevel@tonic-gate "l.", ".",
8487c478bd9Sstevel@tonic-gate "br", "|",
8497c478bd9Sstevel@tonic-gate "vr", "|",
8507c478bd9Sstevel@tonic-gate "fm", "'",
8517c478bd9Sstevel@tonic-gate "or", "|",
8527c478bd9Sstevel@tonic-gate 0, 0,
8537c478bd9Sstevel@tonic-gate };
854