1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate /* 34*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 35*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 36*7c478bd9Sstevel@tonic-gate * All Rights Reserved 37*7c478bd9Sstevel@tonic-gate * 38*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 39*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 40*7c478bd9Sstevel@tonic-gate * contributors. 41*7c478bd9Sstevel@tonic-gate */ 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate /* 44*7c478bd9Sstevel@tonic-gate * drive hp2621 terminal 45*7c478bd9Sstevel@tonic-gate * just to see stuff quickly. like troff -a 46*7c478bd9Sstevel@tonic-gate */ 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate /* 49*7c478bd9Sstevel@tonic-gate output language from troff: 50*7c478bd9Sstevel@tonic-gate all numbers are character strings 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate sn size in points 53*7c478bd9Sstevel@tonic-gate fn font as number from 1-n 54*7c478bd9Sstevel@tonic-gate cx ascii character x 55*7c478bd9Sstevel@tonic-gate Cxyz funny char xyz. terminated by white space 56*7c478bd9Sstevel@tonic-gate Hn go to absolute horizontal position n 57*7c478bd9Sstevel@tonic-gate Vn go to absolute vertical position n (down is positive) 58*7c478bd9Sstevel@tonic-gate hn go n units horizontally (relative) 59*7c478bd9Sstevel@tonic-gate vn ditto vertically 60*7c478bd9Sstevel@tonic-gate nnc move right nn (exactly 2 digits!), then print c 61*7c478bd9Sstevel@tonic-gate (this wart is an optimization that shrinks output file size 62*7c478bd9Sstevel@tonic-gate about 35% and run-time about 15% while preserving ascii-ness) 63*7c478bd9Sstevel@tonic-gate w paddable word space - no action needed 64*7c478bd9Sstevel@tonic-gate nb a end of line (information only -- no action needed) 65*7c478bd9Sstevel@tonic-gate b = space before line, a = after 66*7c478bd9Sstevel@tonic-gate pn begin page n 67*7c478bd9Sstevel@tonic-gate #...\n comment 68*7c478bd9Sstevel@tonic-gate Dt ...\n draw operation 't': 69*7c478bd9Sstevel@tonic-gate Dl x y line from here by x,y 70*7c478bd9Sstevel@tonic-gate Dc d circle of diameter d with left side here 71*7c478bd9Sstevel@tonic-gate De x y ellipse of axes x,y with left side here 72*7c478bd9Sstevel@tonic-gate Da x y u v arc counter-clockwise from here to u,v from center 73*7c478bd9Sstevel@tonic-gate with center x,y from here 74*7c478bd9Sstevel@tonic-gate D~ x y x y ... wiggly line by x,y then x,y ... 75*7c478bd9Sstevel@tonic-gate x ...\n device control functions: 76*7c478bd9Sstevel@tonic-gate x i init 77*7c478bd9Sstevel@tonic-gate x T s name of device is s 78*7c478bd9Sstevel@tonic-gate x r n h v resolution is n/inch 79*7c478bd9Sstevel@tonic-gate h = min horizontal motion, v = min vert 80*7c478bd9Sstevel@tonic-gate x p pause (can restart) 81*7c478bd9Sstevel@tonic-gate x s stop -- done for ever 82*7c478bd9Sstevel@tonic-gate x t generate trailer 83*7c478bd9Sstevel@tonic-gate x f n s font position n contains font s 84*7c478bd9Sstevel@tonic-gate x H n set character height to n 85*7c478bd9Sstevel@tonic-gate x S n set character slant to n 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate Subcommands like "i" are often spelled out like "init". 88*7c478bd9Sstevel@tonic-gate */ 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate #include <stdio.h> 91*7c478bd9Sstevel@tonic-gate #include <signal.h> 92*7c478bd9Sstevel@tonic-gate #include <ctype.h> 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate #include "dev.h" 95*7c478bd9Sstevel@tonic-gate #define NFONT 10 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate int output = 0; /* do we do output at all? */ 98*7c478bd9Sstevel@tonic-gate int nolist = 0; /* output page list if > 0 */ 99*7c478bd9Sstevel@tonic-gate int olist[20]; /* pairs of page numbers */ 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate int erase = 1; 102*7c478bd9Sstevel@tonic-gate float aspect = 1.5; /* default aspect ratio */ 103*7c478bd9Sstevel@tonic-gate int wflag = 0; /* wait, looping, for new input if on */ 104*7c478bd9Sstevel@tonic-gate void (*sigint)(); 105*7c478bd9Sstevel@tonic-gate void (*sigquit)(); 106*7c478bd9Sstevel@tonic-gate void done(); 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate struct dev dev; 109*7c478bd9Sstevel@tonic-gate struct font *fontbase[NFONT]; 110*7c478bd9Sstevel@tonic-gate short psizes[] ={ 11, 16, 22, 36, 0}; /* approx sizes available */ 111*7c478bd9Sstevel@tonic-gate short *pstab = psizes; 112*7c478bd9Sstevel@tonic-gate int nsizes = 1; 113*7c478bd9Sstevel@tonic-gate int nfonts; 114*7c478bd9Sstevel@tonic-gate int smnt; /* index of first special font */ 115*7c478bd9Sstevel@tonic-gate int nchtab; 116*7c478bd9Sstevel@tonic-gate char *chname; 117*7c478bd9Sstevel@tonic-gate short *chtab; 118*7c478bd9Sstevel@tonic-gate char *fitab[NFONT]; 119*7c478bd9Sstevel@tonic-gate char *widthtab[NFONT]; /* widtab would be a better name */ 120*7c478bd9Sstevel@tonic-gate char *codetab[NFONT]; /* device codes */ 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate #define FATAL 1 123*7c478bd9Sstevel@tonic-gate #define BMASK 0377 124*7c478bd9Sstevel@tonic-gate int dbg = 0; 125*7c478bd9Sstevel@tonic-gate int res = 972; /* input assumed computed according to this resolution */ 126*7c478bd9Sstevel@tonic-gate /* initial value to avoid 0 divide */ 127*7c478bd9Sstevel@tonic-gate FILE *tf = stdout; /* output file */ 128*7c478bd9Sstevel@tonic-gate char *fontdir = "/usr/lib/font"; 129*7c478bd9Sstevel@tonic-gate extern char devname[]; 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate FILE *fp = stdin; /* input file pointer */ 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate int nowait = 0; /* 0 => wait at bottom of each page */ 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate main(argc, argv) 136*7c478bd9Sstevel@tonic-gate char *argv[]; 137*7c478bd9Sstevel@tonic-gate { 138*7c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate setbuf(stdout, buf); 141*7c478bd9Sstevel@tonic-gate while (argc > 1 && argv[1][0] == '-') { 142*7c478bd9Sstevel@tonic-gate switch (argv[1][1]) { 143*7c478bd9Sstevel@tonic-gate case 'a': 144*7c478bd9Sstevel@tonic-gate aspect = atof(&argv[1][2]); 145*7c478bd9Sstevel@tonic-gate break; 146*7c478bd9Sstevel@tonic-gate case 'e': 147*7c478bd9Sstevel@tonic-gate erase = 0; 148*7c478bd9Sstevel@tonic-gate break; 149*7c478bd9Sstevel@tonic-gate case 'o': 150*7c478bd9Sstevel@tonic-gate outlist(&argv[1][2]); 151*7c478bd9Sstevel@tonic-gate break; 152*7c478bd9Sstevel@tonic-gate case 'd': 153*7c478bd9Sstevel@tonic-gate dbg = atoi(&argv[1][2]); 154*7c478bd9Sstevel@tonic-gate if (dbg == 0) dbg = 1; 155*7c478bd9Sstevel@tonic-gate break; 156*7c478bd9Sstevel@tonic-gate case 'w': /* no wait at bottom of page */ 157*7c478bd9Sstevel@tonic-gate nowait = 1; 158*7c478bd9Sstevel@tonic-gate break; 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate argc--; 161*7c478bd9Sstevel@tonic-gate argv++; 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate if (argc <= 1) 165*7c478bd9Sstevel@tonic-gate conv(stdin); 166*7c478bd9Sstevel@tonic-gate else 167*7c478bd9Sstevel@tonic-gate while (--argc > 0) { 168*7c478bd9Sstevel@tonic-gate if (strcmp(*++argv, "-") == 0) 169*7c478bd9Sstevel@tonic-gate fp = stdin; 170*7c478bd9Sstevel@tonic-gate else if ((fp = fopen(*argv, "r")) == NULL) 171*7c478bd9Sstevel@tonic-gate error(FATAL, "can't open %s", *argv); 172*7c478bd9Sstevel@tonic-gate conv(fp); 173*7c478bd9Sstevel@tonic-gate fclose(fp); 174*7c478bd9Sstevel@tonic-gate } 175*7c478bd9Sstevel@tonic-gate done(); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate outlist(s) /* process list of page numbers to be printed */ 179*7c478bd9Sstevel@tonic-gate char *s; 180*7c478bd9Sstevel@tonic-gate { 181*7c478bd9Sstevel@tonic-gate int n1, n2, i; 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate nolist = 0; 184*7c478bd9Sstevel@tonic-gate while (*s) { 185*7c478bd9Sstevel@tonic-gate n1 = 0; 186*7c478bd9Sstevel@tonic-gate if (isdigit((unsigned char)*s)) 187*7c478bd9Sstevel@tonic-gate do 188*7c478bd9Sstevel@tonic-gate n1 = 10 * n1 + *s++ - '0'; 189*7c478bd9Sstevel@tonic-gate while (isdigit((unsigned char)*s)); 190*7c478bd9Sstevel@tonic-gate else 191*7c478bd9Sstevel@tonic-gate n1 = -9999; 192*7c478bd9Sstevel@tonic-gate n2 = n1; 193*7c478bd9Sstevel@tonic-gate if (*s == '-') { 194*7c478bd9Sstevel@tonic-gate s++; 195*7c478bd9Sstevel@tonic-gate n2 = 0; 196*7c478bd9Sstevel@tonic-gate if (isdigit((unsigned char)*s)) 197*7c478bd9Sstevel@tonic-gate do 198*7c478bd9Sstevel@tonic-gate n2 = 10 * n2 + *s++ - '0'; 199*7c478bd9Sstevel@tonic-gate while (isdigit((unsigned char)*s)); 200*7c478bd9Sstevel@tonic-gate else 201*7c478bd9Sstevel@tonic-gate n2 = 9999; 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate olist[nolist++] = n1; 204*7c478bd9Sstevel@tonic-gate olist[nolist++] = n2; 205*7c478bd9Sstevel@tonic-gate if (*s != '\0') 206*7c478bd9Sstevel@tonic-gate s++; 207*7c478bd9Sstevel@tonic-gate } 208*7c478bd9Sstevel@tonic-gate olist[nolist] = 0; 209*7c478bd9Sstevel@tonic-gate if (dbg) 210*7c478bd9Sstevel@tonic-gate for (i=0; i<nolist; i += 2) 211*7c478bd9Sstevel@tonic-gate printf("%3d %3d\n", olist[i], olist[i+1]); 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate in_olist(n) /* is n in olist? */ 215*7c478bd9Sstevel@tonic-gate int n; 216*7c478bd9Sstevel@tonic-gate { 217*7c478bd9Sstevel@tonic-gate int i; 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate if (nolist == 0) 220*7c478bd9Sstevel@tonic-gate return(1); /* everything is included */ 221*7c478bd9Sstevel@tonic-gate for (i = 0; i < nolist; i += 2) 222*7c478bd9Sstevel@tonic-gate if (n >= olist[i] && n <= olist[i+1]) 223*7c478bd9Sstevel@tonic-gate return(1); 224*7c478bd9Sstevel@tonic-gate return(0); 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate conv(fp) 228*7c478bd9Sstevel@tonic-gate register FILE *fp; 229*7c478bd9Sstevel@tonic-gate { 230*7c478bd9Sstevel@tonic-gate register int c, k; 231*7c478bd9Sstevel@tonic-gate int m, n, i, n1, m1; 232*7c478bd9Sstevel@tonic-gate char str[100], buf[300]; 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate while ((c = getc(fp)) != EOF) { 235*7c478bd9Sstevel@tonic-gate switch (c) { 236*7c478bd9Sstevel@tonic-gate case '\n': /* when input is text */ 237*7c478bd9Sstevel@tonic-gate case ' ': 238*7c478bd9Sstevel@tonic-gate case 0: /* occasional noise creeps in */ 239*7c478bd9Sstevel@tonic-gate break; 240*7c478bd9Sstevel@tonic-gate case '{': /* push down current environment */ 241*7c478bd9Sstevel@tonic-gate t_push(); 242*7c478bd9Sstevel@tonic-gate break; 243*7c478bd9Sstevel@tonic-gate case '}': 244*7c478bd9Sstevel@tonic-gate t_pop(); 245*7c478bd9Sstevel@tonic-gate break; 246*7c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4': 247*7c478bd9Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9': 248*7c478bd9Sstevel@tonic-gate /* two motion digits plus a character */ 249*7c478bd9Sstevel@tonic-gate hmot((c-'0')*10 + getc(fp)-'0'); 250*7c478bd9Sstevel@tonic-gate put1(getc(fp)); 251*7c478bd9Sstevel@tonic-gate break; 252*7c478bd9Sstevel@tonic-gate case 'c': /* single ascii character */ 253*7c478bd9Sstevel@tonic-gate put1(getc(fp)); 254*7c478bd9Sstevel@tonic-gate break; 255*7c478bd9Sstevel@tonic-gate case 'C': 256*7c478bd9Sstevel@tonic-gate fscanf(fp, "%s", str); 257*7c478bd9Sstevel@tonic-gate put1s(str); 258*7c478bd9Sstevel@tonic-gate break; 259*7c478bd9Sstevel@tonic-gate case 't': /* straight text */ 260*7c478bd9Sstevel@tonic-gate fgets(buf, sizeof(buf), fp); 261*7c478bd9Sstevel@tonic-gate t_text(buf); 262*7c478bd9Sstevel@tonic-gate break; 263*7c478bd9Sstevel@tonic-gate case 'D': /* draw function */ 264*7c478bd9Sstevel@tonic-gate fgets(buf, sizeof(buf), fp); 265*7c478bd9Sstevel@tonic-gate switch (buf[0]) { 266*7c478bd9Sstevel@tonic-gate case 'l': /* draw a line */ 267*7c478bd9Sstevel@tonic-gate sscanf(buf+1, "%d %d", &n, &m); 268*7c478bd9Sstevel@tonic-gate drawline(n, m, "."); 269*7c478bd9Sstevel@tonic-gate break; 270*7c478bd9Sstevel@tonic-gate case 'c': /* circle */ 271*7c478bd9Sstevel@tonic-gate sscanf(buf+1, "%d", &n); 272*7c478bd9Sstevel@tonic-gate drawcirc(n); 273*7c478bd9Sstevel@tonic-gate break; 274*7c478bd9Sstevel@tonic-gate case 'e': /* ellipse */ 275*7c478bd9Sstevel@tonic-gate sscanf(buf+1, "%d %d", &m, &n); 276*7c478bd9Sstevel@tonic-gate drawellip(m, n); 277*7c478bd9Sstevel@tonic-gate break; 278*7c478bd9Sstevel@tonic-gate case 'a': /* arc */ 279*7c478bd9Sstevel@tonic-gate sscanf(buf+1, "%d %d %d %d", &n, &m, &n1, &m1); 280*7c478bd9Sstevel@tonic-gate drawarc(n, m, n1, m1); 281*7c478bd9Sstevel@tonic-gate break; 282*7c478bd9Sstevel@tonic-gate case '~': /* wiggly line */ 283*7c478bd9Sstevel@tonic-gate drawwig(buf+1); 284*7c478bd9Sstevel@tonic-gate break; 285*7c478bd9Sstevel@tonic-gate default: 286*7c478bd9Sstevel@tonic-gate error(FATAL, "unknown drawing function %s\n", buf); 287*7c478bd9Sstevel@tonic-gate break; 288*7c478bd9Sstevel@tonic-gate } 289*7c478bd9Sstevel@tonic-gate break; 290*7c478bd9Sstevel@tonic-gate case 's': 291*7c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &n); /* ignore fractional sizes */ 292*7c478bd9Sstevel@tonic-gate setsize(t_size(n)); 293*7c478bd9Sstevel@tonic-gate break; 294*7c478bd9Sstevel@tonic-gate case 'f': 295*7c478bd9Sstevel@tonic-gate fscanf(fp, "%s", str); 296*7c478bd9Sstevel@tonic-gate setfont(t_font(str)); 297*7c478bd9Sstevel@tonic-gate break; 298*7c478bd9Sstevel@tonic-gate case 'H': /* absolute horizontal motion */ 299*7c478bd9Sstevel@tonic-gate /* fscanf(fp, "%d", &n); */ 300*7c478bd9Sstevel@tonic-gate while ((c = getc(fp)) == ' ') 301*7c478bd9Sstevel@tonic-gate ; 302*7c478bd9Sstevel@tonic-gate k = 0; 303*7c478bd9Sstevel@tonic-gate do { 304*7c478bd9Sstevel@tonic-gate k = 10 * k + c - '0'; 305*7c478bd9Sstevel@tonic-gate } while (isdigit(c = getc(fp))); 306*7c478bd9Sstevel@tonic-gate ungetc(c, fp); 307*7c478bd9Sstevel@tonic-gate hgoto(k); 308*7c478bd9Sstevel@tonic-gate break; 309*7c478bd9Sstevel@tonic-gate case 'h': /* relative horizontal motion */ 310*7c478bd9Sstevel@tonic-gate /* fscanf(fp, "%d", &n); */ 311*7c478bd9Sstevel@tonic-gate while ((c = getc(fp)) == ' ') 312*7c478bd9Sstevel@tonic-gate ; 313*7c478bd9Sstevel@tonic-gate k = 0; 314*7c478bd9Sstevel@tonic-gate do { 315*7c478bd9Sstevel@tonic-gate k = 10 * k + c - '0'; 316*7c478bd9Sstevel@tonic-gate } while (isdigit(c = getc(fp))); 317*7c478bd9Sstevel@tonic-gate ungetc(c, fp); 318*7c478bd9Sstevel@tonic-gate hmot(k); 319*7c478bd9Sstevel@tonic-gate break; 320*7c478bd9Sstevel@tonic-gate case 'w': /* word space */ 321*7c478bd9Sstevel@tonic-gate putc(' ', stdout); 322*7c478bd9Sstevel@tonic-gate break; 323*7c478bd9Sstevel@tonic-gate case 'V': 324*7c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &n); 325*7c478bd9Sstevel@tonic-gate vgoto(n); 326*7c478bd9Sstevel@tonic-gate break; 327*7c478bd9Sstevel@tonic-gate case 'v': 328*7c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &n); 329*7c478bd9Sstevel@tonic-gate vmot(n); 330*7c478bd9Sstevel@tonic-gate break; 331*7c478bd9Sstevel@tonic-gate case 'p': /* new page */ 332*7c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &n); 333*7c478bd9Sstevel@tonic-gate t_page(n); 334*7c478bd9Sstevel@tonic-gate break; 335*7c478bd9Sstevel@tonic-gate case 'n': /* end of line */ 336*7c478bd9Sstevel@tonic-gate while (getc(fp) != '\n') 337*7c478bd9Sstevel@tonic-gate ; 338*7c478bd9Sstevel@tonic-gate t_newline(); 339*7c478bd9Sstevel@tonic-gate break; 340*7c478bd9Sstevel@tonic-gate case '#': /* comment */ 341*7c478bd9Sstevel@tonic-gate while (getc(fp) != '\n') 342*7c478bd9Sstevel@tonic-gate ; 343*7c478bd9Sstevel@tonic-gate break; 344*7c478bd9Sstevel@tonic-gate case 'x': /* device control */ 345*7c478bd9Sstevel@tonic-gate devcntrl(fp); 346*7c478bd9Sstevel@tonic-gate break; 347*7c478bd9Sstevel@tonic-gate default: 348*7c478bd9Sstevel@tonic-gate error(!FATAL, "unknown input character %o %c\n", c, c); 349*7c478bd9Sstevel@tonic-gate done(); 350*7c478bd9Sstevel@tonic-gate } 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate } 353*7c478bd9Sstevel@tonic-gate 354*7c478bd9Sstevel@tonic-gate devcntrl(fp) /* interpret device control functions */ 355*7c478bd9Sstevel@tonic-gate FILE *fp; 356*7c478bd9Sstevel@tonic-gate { 357*7c478bd9Sstevel@tonic-gate char str[20]; 358*7c478bd9Sstevel@tonic-gate int c, n; 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate fscanf(fp, "%s", str); 361*7c478bd9Sstevel@tonic-gate switch (str[0]) { /* crude for now */ 362*7c478bd9Sstevel@tonic-gate case 'i': /* initialize */ 363*7c478bd9Sstevel@tonic-gate fileinit(); 364*7c478bd9Sstevel@tonic-gate t_init(0); 365*7c478bd9Sstevel@tonic-gate break; 366*7c478bd9Sstevel@tonic-gate case 'T': /* device name */ 367*7c478bd9Sstevel@tonic-gate fscanf(fp, "%s", devname); 368*7c478bd9Sstevel@tonic-gate break; 369*7c478bd9Sstevel@tonic-gate case 't': /* trailer */ 370*7c478bd9Sstevel@tonic-gate t_trailer(); 371*7c478bd9Sstevel@tonic-gate break; 372*7c478bd9Sstevel@tonic-gate case 'p': /* pause -- can restart */ 373*7c478bd9Sstevel@tonic-gate t_reset('p'); 374*7c478bd9Sstevel@tonic-gate break; 375*7c478bd9Sstevel@tonic-gate case 's': /* stop */ 376*7c478bd9Sstevel@tonic-gate t_reset('s'); 377*7c478bd9Sstevel@tonic-gate break; 378*7c478bd9Sstevel@tonic-gate case 'r': /* resolution assumed when prepared */ 379*7c478bd9Sstevel@tonic-gate fscanf(fp, "%d", &res); 380*7c478bd9Sstevel@tonic-gate break; 381*7c478bd9Sstevel@tonic-gate case 'f': /* font used */ 382*7c478bd9Sstevel@tonic-gate fscanf(fp, "%d %s", &n, str); 383*7c478bd9Sstevel@tonic-gate loadfont(n, str); 384*7c478bd9Sstevel@tonic-gate break; 385*7c478bd9Sstevel@tonic-gate } 386*7c478bd9Sstevel@tonic-gate while (getc(fp) != '\n') /* skip rest of input line */ 387*7c478bd9Sstevel@tonic-gate ; 388*7c478bd9Sstevel@tonic-gate } 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate fileinit() /* read in font and code files, etc. */ 391*7c478bd9Sstevel@tonic-gate { 392*7c478bd9Sstevel@tonic-gate } 393*7c478bd9Sstevel@tonic-gate 394*7c478bd9Sstevel@tonic-gate fontprint(i) /* debugging print of font i (0,...) */ 395*7c478bd9Sstevel@tonic-gate { 396*7c478bd9Sstevel@tonic-gate } 397*7c478bd9Sstevel@tonic-gate 398*7c478bd9Sstevel@tonic-gate loadcode(n, nw) /* load codetab on position n (0...); #chars is nw */ 399*7c478bd9Sstevel@tonic-gate int n, nw; 400*7c478bd9Sstevel@tonic-gate { 401*7c478bd9Sstevel@tonic-gate } 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate loadfont(n, s) /* load font info for font s on position n (1...) */ 404*7c478bd9Sstevel@tonic-gate int n; 405*7c478bd9Sstevel@tonic-gate char *s; 406*7c478bd9Sstevel@tonic-gate { 407*7c478bd9Sstevel@tonic-gate } 408*7c478bd9Sstevel@tonic-gate 409*7c478bd9Sstevel@tonic-gate error(f, s, a1, a2, a3, a4, a5, a6, a7) 410*7c478bd9Sstevel@tonic-gate char *s; 411*7c478bd9Sstevel@tonic-gate { 412*7c478bd9Sstevel@tonic-gate fprintf(stderr, "ta: "); 413*7c478bd9Sstevel@tonic-gate fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7); 414*7c478bd9Sstevel@tonic-gate fprintf(stderr, "\n"); 415*7c478bd9Sstevel@tonic-gate if (f) 416*7c478bd9Sstevel@tonic-gate exit(1); 417*7c478bd9Sstevel@tonic-gate } 418*7c478bd9Sstevel@tonic-gate 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate /* 421*7c478bd9Sstevel@tonic-gate Here beginneth all the stuff that really depends 422*7c478bd9Sstevel@tonic-gate on the 202 (we hope). 423*7c478bd9Sstevel@tonic-gate */ 424*7c478bd9Sstevel@tonic-gate 425*7c478bd9Sstevel@tonic-gate 426*7c478bd9Sstevel@tonic-gate char devname[20] = "hp2621"; 427*7c478bd9Sstevel@tonic-gate 428*7c478bd9Sstevel@tonic-gate #define ESC 033 429*7c478bd9Sstevel@tonic-gate #define HOME 'H' 430*7c478bd9Sstevel@tonic-gate #define CLEAR 'J' 431*7c478bd9Sstevel@tonic-gate #define FF 014 432*7c478bd9Sstevel@tonic-gate 433*7c478bd9Sstevel@tonic-gate int size = 1; 434*7c478bd9Sstevel@tonic-gate int font = 1; /* current font */ 435*7c478bd9Sstevel@tonic-gate int hpos; /* horizontal position where we are supposed to be next (left = 0) */ 436*7c478bd9Sstevel@tonic-gate int vpos; /* current vertical position (down positive) */ 437*7c478bd9Sstevel@tonic-gate 438*7c478bd9Sstevel@tonic-gate int horig; /* h origin of current block; hpos rel to this */ 439*7c478bd9Sstevel@tonic-gate int vorig; /* v origin of current block; vpos rel to this */ 440*7c478bd9Sstevel@tonic-gate 441*7c478bd9Sstevel@tonic-gate int DX = 10; /* step size in x for drawing */ 442*7c478bd9Sstevel@tonic-gate int DY = 10; /* step size in y for drawing */ 443*7c478bd9Sstevel@tonic-gate int drawdot = '.'; /* draw with this character */ 444*7c478bd9Sstevel@tonic-gate int drawsize = 1; /* shrink by this factor when drawing */ 445*7c478bd9Sstevel@tonic-gate 446*7c478bd9Sstevel@tonic-gate t_init(reinit) /* initialize device */ 447*7c478bd9Sstevel@tonic-gate int reinit; 448*7c478bd9Sstevel@tonic-gate { 449*7c478bd9Sstevel@tonic-gate int i, j; 450*7c478bd9Sstevel@tonic-gate 451*7c478bd9Sstevel@tonic-gate fflush(stdout); 452*7c478bd9Sstevel@tonic-gate hpos = vpos = 0; 453*7c478bd9Sstevel@tonic-gate } 454*7c478bd9Sstevel@tonic-gate 455*7c478bd9Sstevel@tonic-gate #define MAXSTATE 5 456*7c478bd9Sstevel@tonic-gate 457*7c478bd9Sstevel@tonic-gate struct state { 458*7c478bd9Sstevel@tonic-gate int ssize; 459*7c478bd9Sstevel@tonic-gate int sfont; 460*7c478bd9Sstevel@tonic-gate int shpos; 461*7c478bd9Sstevel@tonic-gate int svpos; 462*7c478bd9Sstevel@tonic-gate int shorig; 463*7c478bd9Sstevel@tonic-gate int svorig; 464*7c478bd9Sstevel@tonic-gate }; 465*7c478bd9Sstevel@tonic-gate struct state state[MAXSTATE]; 466*7c478bd9Sstevel@tonic-gate struct state *statep = state; 467*7c478bd9Sstevel@tonic-gate 468*7c478bd9Sstevel@tonic-gate t_push() /* begin a new block */ 469*7c478bd9Sstevel@tonic-gate { 470*7c478bd9Sstevel@tonic-gate hflush(); 471*7c478bd9Sstevel@tonic-gate statep->ssize = size; 472*7c478bd9Sstevel@tonic-gate statep->sfont = font; 473*7c478bd9Sstevel@tonic-gate statep->shorig = horig; 474*7c478bd9Sstevel@tonic-gate statep->svorig = vorig; 475*7c478bd9Sstevel@tonic-gate statep->shpos = hpos; 476*7c478bd9Sstevel@tonic-gate statep->svpos = vpos; 477*7c478bd9Sstevel@tonic-gate horig = hpos; 478*7c478bd9Sstevel@tonic-gate vorig = vpos; 479*7c478bd9Sstevel@tonic-gate hpos = vpos = 0; 480*7c478bd9Sstevel@tonic-gate if (statep++ >= state+MAXSTATE) 481*7c478bd9Sstevel@tonic-gate error(FATAL, "{ nested too deep"); 482*7c478bd9Sstevel@tonic-gate hpos = vpos = 0; 483*7c478bd9Sstevel@tonic-gate } 484*7c478bd9Sstevel@tonic-gate 485*7c478bd9Sstevel@tonic-gate t_pop() /* pop to previous state */ 486*7c478bd9Sstevel@tonic-gate { 487*7c478bd9Sstevel@tonic-gate if (--statep < state) 488*7c478bd9Sstevel@tonic-gate error(FATAL, "extra }"); 489*7c478bd9Sstevel@tonic-gate size = statep->ssize; 490*7c478bd9Sstevel@tonic-gate font = statep->sfont; 491*7c478bd9Sstevel@tonic-gate hpos = statep->shpos; 492*7c478bd9Sstevel@tonic-gate vpos = statep->svpos; 493*7c478bd9Sstevel@tonic-gate horig = statep->shorig; 494*7c478bd9Sstevel@tonic-gate vorig = statep->svorig; 495*7c478bd9Sstevel@tonic-gate } 496*7c478bd9Sstevel@tonic-gate 497*7c478bd9Sstevel@tonic-gate int np; /* number of pages seen */ 498*7c478bd9Sstevel@tonic-gate int npmax; /* high-water mark of np */ 499*7c478bd9Sstevel@tonic-gate int pgnum[40]; /* their actual numbers */ 500*7c478bd9Sstevel@tonic-gate long pgadr[40]; /* their seek addresses */ 501*7c478bd9Sstevel@tonic-gate 502*7c478bd9Sstevel@tonic-gate t_page(n) /* do whatever new page functions */ 503*7c478bd9Sstevel@tonic-gate { 504*7c478bd9Sstevel@tonic-gate long ftell(); 505*7c478bd9Sstevel@tonic-gate int c, m, i; 506*7c478bd9Sstevel@tonic-gate char buf[100], *bp; 507*7c478bd9Sstevel@tonic-gate 508*7c478bd9Sstevel@tonic-gate pgnum[np++] = n; 509*7c478bd9Sstevel@tonic-gate pgadr[np] = ftell(fp); 510*7c478bd9Sstevel@tonic-gate if (np > npmax) 511*7c478bd9Sstevel@tonic-gate npmax = np; 512*7c478bd9Sstevel@tonic-gate if (output == 0) { 513*7c478bd9Sstevel@tonic-gate output = in_olist(n); 514*7c478bd9Sstevel@tonic-gate t_init(1); 515*7c478bd9Sstevel@tonic-gate return; 516*7c478bd9Sstevel@tonic-gate } 517*7c478bd9Sstevel@tonic-gate /* have just printed something, and seen p<n> for next one */ 518*7c478bd9Sstevel@tonic-gate putpage(); 519*7c478bd9Sstevel@tonic-gate fflush(stdout); 520*7c478bd9Sstevel@tonic-gate if (nowait) 521*7c478bd9Sstevel@tonic-gate return; 522*7c478bd9Sstevel@tonic-gate 523*7c478bd9Sstevel@tonic-gate next: 524*7c478bd9Sstevel@tonic-gate for (bp = buf; (*bp = readch()); ) 525*7c478bd9Sstevel@tonic-gate if (*bp++ == '\n') 526*7c478bd9Sstevel@tonic-gate break; 527*7c478bd9Sstevel@tonic-gate *bp = 0; 528*7c478bd9Sstevel@tonic-gate switch (buf[0]) { 529*7c478bd9Sstevel@tonic-gate case 0: 530*7c478bd9Sstevel@tonic-gate done(); 531*7c478bd9Sstevel@tonic-gate break; 532*7c478bd9Sstevel@tonic-gate case '\n': 533*7c478bd9Sstevel@tonic-gate output = in_olist(n); 534*7c478bd9Sstevel@tonic-gate t_init(1); 535*7c478bd9Sstevel@tonic-gate return; 536*7c478bd9Sstevel@tonic-gate case '!': 537*7c478bd9Sstevel@tonic-gate callunix(&buf[1]); 538*7c478bd9Sstevel@tonic-gate fputs("!\n", stderr); 539*7c478bd9Sstevel@tonic-gate break; 540*7c478bd9Sstevel@tonic-gate case 'e': 541*7c478bd9Sstevel@tonic-gate erase = 1 - erase; 542*7c478bd9Sstevel@tonic-gate break; 543*7c478bd9Sstevel@tonic-gate case 'w': 544*7c478bd9Sstevel@tonic-gate wflag = 1 - wflag; 545*7c478bd9Sstevel@tonic-gate break; 546*7c478bd9Sstevel@tonic-gate case 'a': 547*7c478bd9Sstevel@tonic-gate aspect = atof(&buf[1]); 548*7c478bd9Sstevel@tonic-gate break; 549*7c478bd9Sstevel@tonic-gate case '-': 550*7c478bd9Sstevel@tonic-gate case 'p': 551*7c478bd9Sstevel@tonic-gate m = atoi(&buf[1]) + 1; 552*7c478bd9Sstevel@tonic-gate if (fp == stdin) { 553*7c478bd9Sstevel@tonic-gate fputs("you can't; it's not a file\n", stderr); 554*7c478bd9Sstevel@tonic-gate break; 555*7c478bd9Sstevel@tonic-gate } 556*7c478bd9Sstevel@tonic-gate if (np - m <= 0) { 557*7c478bd9Sstevel@tonic-gate fputs("too far back\n", stderr); 558*7c478bd9Sstevel@tonic-gate break; 559*7c478bd9Sstevel@tonic-gate } 560*7c478bd9Sstevel@tonic-gate np -= m; 561*7c478bd9Sstevel@tonic-gate fseek(fp, pgadr[np], 0); 562*7c478bd9Sstevel@tonic-gate output = 1; 563*7c478bd9Sstevel@tonic-gate t_init(1); 564*7c478bd9Sstevel@tonic-gate return; 565*7c478bd9Sstevel@tonic-gate case '0': case '1': case '2': case '3': case '4': 566*7c478bd9Sstevel@tonic-gate case '5': case '6': case '7': case '8': case '9': 567*7c478bd9Sstevel@tonic-gate m = atoi(&buf[0]); 568*7c478bd9Sstevel@tonic-gate for (i = 0; i < npmax; i++) 569*7c478bd9Sstevel@tonic-gate if (m == pgnum[i]) 570*7c478bd9Sstevel@tonic-gate break; 571*7c478bd9Sstevel@tonic-gate if (i >= npmax || fp == stdin) { 572*7c478bd9Sstevel@tonic-gate fputs("you can't\n", stderr); 573*7c478bd9Sstevel@tonic-gate break; 574*7c478bd9Sstevel@tonic-gate } 575*7c478bd9Sstevel@tonic-gate np = i + 1; 576*7c478bd9Sstevel@tonic-gate fseek(fp, pgadr[np], 0); 577*7c478bd9Sstevel@tonic-gate output = 1; 578*7c478bd9Sstevel@tonic-gate t_init(1); 579*7c478bd9Sstevel@tonic-gate return; 580*7c478bd9Sstevel@tonic-gate case 'o': 581*7c478bd9Sstevel@tonic-gate outlist(&buf[1]); 582*7c478bd9Sstevel@tonic-gate output = 0; 583*7c478bd9Sstevel@tonic-gate t_init(1); 584*7c478bd9Sstevel@tonic-gate return; 585*7c478bd9Sstevel@tonic-gate case '?': 586*7c478bd9Sstevel@tonic-gate fputs("!cmd unix cmd\n", stderr); 587*7c478bd9Sstevel@tonic-gate fputs("p print this page again\n", stderr); 588*7c478bd9Sstevel@tonic-gate fputs("-n go back n pages\n", stderr); 589*7c478bd9Sstevel@tonic-gate fputs("n print page n (previously printed)\n", stderr); 590*7c478bd9Sstevel@tonic-gate fputs("o... set the -o output list to ...\n", stderr); 591*7c478bd9Sstevel@tonic-gate fputs("en n=0 -> don't erase; n=1 -> erase\n", stderr); 592*7c478bd9Sstevel@tonic-gate fputs("an sets aspect ratio to n\n", stderr); 593*7c478bd9Sstevel@tonic-gate break; 594*7c478bd9Sstevel@tonic-gate default: 595*7c478bd9Sstevel@tonic-gate fputs("?\n", stderr); 596*7c478bd9Sstevel@tonic-gate break; 597*7c478bd9Sstevel@tonic-gate } 598*7c478bd9Sstevel@tonic-gate goto next; 599*7c478bd9Sstevel@tonic-gate } 600*7c478bd9Sstevel@tonic-gate 601*7c478bd9Sstevel@tonic-gate putpage() 602*7c478bd9Sstevel@tonic-gate { 603*7c478bd9Sstevel@tonic-gate int i, j, k; 604*7c478bd9Sstevel@tonic-gate 605*7c478bd9Sstevel@tonic-gate fflush(stdout); 606*7c478bd9Sstevel@tonic-gate } 607*7c478bd9Sstevel@tonic-gate 608*7c478bd9Sstevel@tonic-gate t_newline() /* do whatever for the end of a line */ 609*7c478bd9Sstevel@tonic-gate { 610*7c478bd9Sstevel@tonic-gate printf("\n"); 611*7c478bd9Sstevel@tonic-gate hpos = 0; 612*7c478bd9Sstevel@tonic-gate } 613*7c478bd9Sstevel@tonic-gate 614*7c478bd9Sstevel@tonic-gate t_size(n) /* convert integer to internal size number*/ 615*7c478bd9Sstevel@tonic-gate int n; 616*7c478bd9Sstevel@tonic-gate { 617*7c478bd9Sstevel@tonic-gate } 618*7c478bd9Sstevel@tonic-gate 619*7c478bd9Sstevel@tonic-gate t_font(s) /* convert string to internal font number */ 620*7c478bd9Sstevel@tonic-gate char *s; 621*7c478bd9Sstevel@tonic-gate { 622*7c478bd9Sstevel@tonic-gate } 623*7c478bd9Sstevel@tonic-gate 624*7c478bd9Sstevel@tonic-gate t_text(s) /* print string s as text */ 625*7c478bd9Sstevel@tonic-gate char *s; 626*7c478bd9Sstevel@tonic-gate { 627*7c478bd9Sstevel@tonic-gate int c, w=0; 628*7c478bd9Sstevel@tonic-gate char str[100]; 629*7c478bd9Sstevel@tonic-gate 630*7c478bd9Sstevel@tonic-gate if (!output) 631*7c478bd9Sstevel@tonic-gate return; 632*7c478bd9Sstevel@tonic-gate while ((c = *s++) != '\n') { 633*7c478bd9Sstevel@tonic-gate if (c == '\\') { 634*7c478bd9Sstevel@tonic-gate switch (c = *s++) { 635*7c478bd9Sstevel@tonic-gate case '\\': 636*7c478bd9Sstevel@tonic-gate case 'e': 637*7c478bd9Sstevel@tonic-gate put1('\\'); 638*7c478bd9Sstevel@tonic-gate break; 639*7c478bd9Sstevel@tonic-gate case '(': 640*7c478bd9Sstevel@tonic-gate str[0] = *s++; 641*7c478bd9Sstevel@tonic-gate str[1] = *s++; 642*7c478bd9Sstevel@tonic-gate str[2] = '\0'; 643*7c478bd9Sstevel@tonic-gate put1s(str); 644*7c478bd9Sstevel@tonic-gate break; 645*7c478bd9Sstevel@tonic-gate } 646*7c478bd9Sstevel@tonic-gate } else { 647*7c478bd9Sstevel@tonic-gate put1(c); 648*7c478bd9Sstevel@tonic-gate } 649*7c478bd9Sstevel@tonic-gate hmot(w); 650*7c478bd9Sstevel@tonic-gate } 651*7c478bd9Sstevel@tonic-gate } 652*7c478bd9Sstevel@tonic-gate 653*7c478bd9Sstevel@tonic-gate t_reset(c) 654*7c478bd9Sstevel@tonic-gate { 655*7c478bd9Sstevel@tonic-gate int n; 656*7c478bd9Sstevel@tonic-gate 657*7c478bd9Sstevel@tonic-gate output = 1; 658*7c478bd9Sstevel@tonic-gate fflush(stdout); 659*7c478bd9Sstevel@tonic-gate if (c == 's') 660*7c478bd9Sstevel@tonic-gate t_page(9999); 661*7c478bd9Sstevel@tonic-gate } 662*7c478bd9Sstevel@tonic-gate 663*7c478bd9Sstevel@tonic-gate t_trailer() 664*7c478bd9Sstevel@tonic-gate { 665*7c478bd9Sstevel@tonic-gate } 666*7c478bd9Sstevel@tonic-gate 667*7c478bd9Sstevel@tonic-gate hgoto(n) 668*7c478bd9Sstevel@tonic-gate { 669*7c478bd9Sstevel@tonic-gate hpos = n; /* this is where we want to be */ 670*7c478bd9Sstevel@tonic-gate /* before printing a character, */ 671*7c478bd9Sstevel@tonic-gate /* have to make sure it's true */ 672*7c478bd9Sstevel@tonic-gate } 673*7c478bd9Sstevel@tonic-gate 674*7c478bd9Sstevel@tonic-gate hmot(n) /* generate n units of horizontal motion */ 675*7c478bd9Sstevel@tonic-gate int n; 676*7c478bd9Sstevel@tonic-gate { 677*7c478bd9Sstevel@tonic-gate hgoto(hpos + n); 678*7c478bd9Sstevel@tonic-gate } 679*7c478bd9Sstevel@tonic-gate 680*7c478bd9Sstevel@tonic-gate hflush() /* actual horizontal output occurs here */ 681*7c478bd9Sstevel@tonic-gate { 682*7c478bd9Sstevel@tonic-gate } 683*7c478bd9Sstevel@tonic-gate 684*7c478bd9Sstevel@tonic-gate vgoto(n) 685*7c478bd9Sstevel@tonic-gate { 686*7c478bd9Sstevel@tonic-gate vpos = n; 687*7c478bd9Sstevel@tonic-gate } 688*7c478bd9Sstevel@tonic-gate 689*7c478bd9Sstevel@tonic-gate vmot(n) /* generate n units of vertical motion */ 690*7c478bd9Sstevel@tonic-gate int n; 691*7c478bd9Sstevel@tonic-gate { 692*7c478bd9Sstevel@tonic-gate vgoto(vpos + n); /* ignores rounding */ 693*7c478bd9Sstevel@tonic-gate } 694*7c478bd9Sstevel@tonic-gate 695*7c478bd9Sstevel@tonic-gate put1s(s) /* s is a funny char name */ 696*7c478bd9Sstevel@tonic-gate char *s; 697*7c478bd9Sstevel@tonic-gate { 698*7c478bd9Sstevel@tonic-gate int i; 699*7c478bd9Sstevel@tonic-gate char *p; 700*7c478bd9Sstevel@tonic-gate extern char *spectab[]; 701*7c478bd9Sstevel@tonic-gate static char prev[10] = ""; 702*7c478bd9Sstevel@tonic-gate static int previ; 703*7c478bd9Sstevel@tonic-gate 704*7c478bd9Sstevel@tonic-gate if (!output) 705*7c478bd9Sstevel@tonic-gate return; 706*7c478bd9Sstevel@tonic-gate if (strcmp(s, prev) != 0) { 707*7c478bd9Sstevel@tonic-gate previ = -1; 708*7c478bd9Sstevel@tonic-gate for (i = 0; spectab[i] != 0; i += 2) 709*7c478bd9Sstevel@tonic-gate if (strcmp(spectab[i], s) == 0) { 710*7c478bd9Sstevel@tonic-gate strcpy(prev, s); 711*7c478bd9Sstevel@tonic-gate previ = i; 712*7c478bd9Sstevel@tonic-gate break; 713*7c478bd9Sstevel@tonic-gate } 714*7c478bd9Sstevel@tonic-gate } 715*7c478bd9Sstevel@tonic-gate if (previ >= 0) { 716*7c478bd9Sstevel@tonic-gate for (p = spectab[previ+1]; *p; p++) 717*7c478bd9Sstevel@tonic-gate putc(*p, stdout); 718*7c478bd9Sstevel@tonic-gate } else 719*7c478bd9Sstevel@tonic-gate prev[0] = 0; 720*7c478bd9Sstevel@tonic-gate } 721*7c478bd9Sstevel@tonic-gate 722*7c478bd9Sstevel@tonic-gate put1(c) /* output char c */ 723*7c478bd9Sstevel@tonic-gate int c; 724*7c478bd9Sstevel@tonic-gate { 725*7c478bd9Sstevel@tonic-gate if (!output) 726*7c478bd9Sstevel@tonic-gate return; 727*7c478bd9Sstevel@tonic-gate putc(c, stdout); 728*7c478bd9Sstevel@tonic-gate } 729*7c478bd9Sstevel@tonic-gate 730*7c478bd9Sstevel@tonic-gate setsize(n) /* set point size to n (internal) */ 731*7c478bd9Sstevel@tonic-gate int n; 732*7c478bd9Sstevel@tonic-gate { 733*7c478bd9Sstevel@tonic-gate } 734*7c478bd9Sstevel@tonic-gate 735*7c478bd9Sstevel@tonic-gate t_fp(n, s) /* font position n now contains font s */ 736*7c478bd9Sstevel@tonic-gate int n; 737*7c478bd9Sstevel@tonic-gate char *s; 738*7c478bd9Sstevel@tonic-gate { 739*7c478bd9Sstevel@tonic-gate } 740*7c478bd9Sstevel@tonic-gate 741*7c478bd9Sstevel@tonic-gate setfont(n) /* set font to n */ 742*7c478bd9Sstevel@tonic-gate int n; 743*7c478bd9Sstevel@tonic-gate { 744*7c478bd9Sstevel@tonic-gate } 745*7c478bd9Sstevel@tonic-gate 746*7c478bd9Sstevel@tonic-gate void done() 747*7c478bd9Sstevel@tonic-gate { 748*7c478bd9Sstevel@tonic-gate output = 1; 749*7c478bd9Sstevel@tonic-gate putpage(); 750*7c478bd9Sstevel@tonic-gate fflush(stdout); 751*7c478bd9Sstevel@tonic-gate exit(0); 752*7c478bd9Sstevel@tonic-gate } 753*7c478bd9Sstevel@tonic-gate 754*7c478bd9Sstevel@tonic-gate callunix(line) 755*7c478bd9Sstevel@tonic-gate char line[]; 756*7c478bd9Sstevel@tonic-gate { 757*7c478bd9Sstevel@tonic-gate int rc, status, unixpid; 758*7c478bd9Sstevel@tonic-gate if( (unixpid=fork())==0 ) { 759*7c478bd9Sstevel@tonic-gate signal(SIGINT,sigint); signal(SIGQUIT,sigquit); 760*7c478bd9Sstevel@tonic-gate close(0); dup(2); 761*7c478bd9Sstevel@tonic-gate execl("/bin/sh", "-sh", "-c", line, 0); 762*7c478bd9Sstevel@tonic-gate exit(255); 763*7c478bd9Sstevel@tonic-gate } 764*7c478bd9Sstevel@tonic-gate else if(unixpid == -1) 765*7c478bd9Sstevel@tonic-gate return; 766*7c478bd9Sstevel@tonic-gate else{ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); 767*7c478bd9Sstevel@tonic-gate while( (rc = wait(&status)) != unixpid && rc != -1 ) ; 768*7c478bd9Sstevel@tonic-gate signal(SIGINT,(void(*)())done); signal(SIGQUIT,(void(*)())sigquit); 769*7c478bd9Sstevel@tonic-gate } 770*7c478bd9Sstevel@tonic-gate } 771*7c478bd9Sstevel@tonic-gate 772*7c478bd9Sstevel@tonic-gate readch(){ 773*7c478bd9Sstevel@tonic-gate char c; 774*7c478bd9Sstevel@tonic-gate if (read(2,&c,1)<1) c=0; 775*7c478bd9Sstevel@tonic-gate return(c); 776*7c478bd9Sstevel@tonic-gate } 777*7c478bd9Sstevel@tonic-gate 778*7c478bd9Sstevel@tonic-gate char *spectab[] ={ 779*7c478bd9Sstevel@tonic-gate "em", "-", 780*7c478bd9Sstevel@tonic-gate "hy", "-", 781*7c478bd9Sstevel@tonic-gate "en", "-", 782*7c478bd9Sstevel@tonic-gate "ru", "_", 783*7c478bd9Sstevel@tonic-gate "l.", ".", 784*7c478bd9Sstevel@tonic-gate "br", "|", 785*7c478bd9Sstevel@tonic-gate "vr", "|", 786*7c478bd9Sstevel@tonic-gate "fm", "'", 787*7c478bd9Sstevel@tonic-gate "or", "|", 788*7c478bd9Sstevel@tonic-gate 0, 0, 789*7c478bd9Sstevel@tonic-gate }; 790