4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * drive hp2621 terminal
44 * just to see stuff quickly. like troff -a
48 output language from troff:
49 all numbers are character strings
52 fn font as number from 1-n
54 Cxyz funny char xyz. terminated by white space
55 Hn go to absolute horizontal position n
56 Vn go to absolute vertical position n (down is positive)
57 hn go n units horizontally (relative)
59 nnc move right nn (exactly 2 digits!), then print c
60 (this wart is an optimization that shrinks output file size
61 about 35% and run-time about 15% while preserving ascii-ness)
62 w paddable word space - no action needed
63 nb a end of line (information only -- no action needed)
64 b = space before line, a = after
67 Dt ...\n draw operation 't':
68 Dl x y line from here by x,y
69 Dc d circle of diameter d with left side here
70 De x y ellipse of axes x,y with left side here
71 Da x y u v arc counter-clockwise from here to u,v from center
72 with center x,y from here
73 D~ x y x y ... wiggly line by x,y then x,y ...
74 x ...\n device control functions:
76 x T s name of device is s
77 x r n h v resolution is n/inch
78 h = min horizontal motion, v = min vert
79 x p pause (can restart)
80 x s stop -- done for ever
82 x f n s font position n contains font s
83 x H n set character height to n
84 x S n set character slant to n
86 Subcommands like "i" are often spelled out like "init".
96 int output
= 0; /* do we do output at all? */
97 int nolist
= 0; /* output page list if > 0 */
98 int olist
[20]; /* pairs of page numbers */
101 float aspect
= 1.5; /* default aspect ratio */
102 int wflag
= 0; /* wait, looping, for new input if on */
108 struct font
*fontbase
[NFONT
];
109 short psizes
[] ={ 11, 16, 22, 36, 0}; /* approx sizes available */
110 short *pstab
= psizes
;
113 int smnt
; /* index of first special font */
118 char *widthtab
[NFONT
]; /* widtab would be a better name */
119 char *codetab
[NFONT
]; /* device codes */
124 int res
= 972; /* input assumed computed according to this resolution */
125 /* initial value to avoid 0 divide */
126 FILE *tf
= stdout
; /* output file */
127 char *fontdir
= "/usr/lib/font";
128 extern char devname
[];
130 FILE *fp
= stdin
; /* input file pointer */
132 int nowait
= 0; /* 0 => wait at bottom of each page */
135 main(int argc
, char **argv
)
140 while (argc
> 1 && argv
[1][0] == '-') {
141 switch (argv
[1][1]) {
143 aspect
= atof(&argv
[1][2]);
149 outlist(&argv
[1][2]);
152 dbg
= atoi(&argv
[1][2]);
153 if (dbg
== 0) dbg
= 1;
155 case 'w': /* no wait at bottom of page */
167 if (strcmp(*++argv
, "-") == 0)
169 else if ((fp
= fopen(*argv
, "r")) == NULL
)
170 error(FATAL
, "can't open %s", *argv
);
180 outlist(s
) /* process list of page numbers to be printed */
188 if (isdigit((unsigned char)*s
))
190 n1
= 10 * n1
+ *s
++ - '0';
191 while (isdigit((unsigned char)*s
));
198 if (isdigit((unsigned char)*s
))
200 n2
= 10 * n2
+ *s
++ - '0';
201 while (isdigit((unsigned char)*s
));
205 olist
[nolist
++] = n1
;
206 olist
[nolist
++] = n2
;
212 for (i
=0; i
<nolist
; i
+= 2)
213 printf("%3d %3d\n", olist
[i
], olist
[i
+1]);
219 in_olist(n
) /* is n in olist? */
225 return(1); /* everything is included */
226 for (i
= 0; i
< nolist
; i
+= 2)
227 if (n
>= olist
[i
] && n
<= olist
[i
+1])
238 char str
[100], buf
[300];
240 while ((c
= getc(fp
)) != EOF
) {
242 case '\n': /* when input is text */
244 case 0: /* occasional noise creeps in */
246 case '{': /* push down current environment */
252 case '0': case '1': case '2': case '3': case '4':
253 case '5': case '6': case '7': case '8': case '9':
254 /* two motion digits plus a character */
255 hmot((c
-'0')*10 + getc(fp
)-'0');
258 case 'c': /* single ascii character */
262 fscanf(fp
, "%s", str
);
265 case 't': /* straight text */
266 fgets(buf
, sizeof(buf
), fp
);
269 case 'D': /* draw function */
270 fgets(buf
, sizeof(buf
), fp
);
272 case 'l': /* draw a line */
273 sscanf(buf
+1, "%d %d", &n
, &m
);
276 case 'c': /* circle */
277 sscanf(buf
+1, "%d", &n
);
280 case 'e': /* ellipse */
281 sscanf(buf
+1, "%d %d", &m
, &n
);
285 sscanf(buf
+1, "%d %d %d %d", &n
, &m
, &n1
, &m1
);
286 drawarc(n
, m
, n1
, m1
);
288 case '~': /* wiggly line */
292 error(FATAL
, "unknown drawing function %s\n", buf
);
297 fscanf(fp
, "%d", &n
); /* ignore fractional sizes */
301 fscanf(fp
, "%s", str
);
302 setfont(t_font(str
));
304 case 'H': /* absolute horizontal motion */
305 /* fscanf(fp, "%d", &n); */
306 while ((c
= getc(fp
)) == ' ')
310 k
= 10 * k
+ c
- '0';
311 } while (isdigit(c
= getc(fp
)));
315 case 'h': /* relative horizontal motion */
316 /* fscanf(fp, "%d", &n); */
317 while ((c
= getc(fp
)) == ' ')
321 k
= 10 * k
+ c
- '0';
322 } while (isdigit(c
= getc(fp
)));
326 case 'w': /* word space */
330 fscanf(fp
, "%d", &n
);
334 fscanf(fp
, "%d", &n
);
337 case 'p': /* new page */
338 fscanf(fp
, "%d", &n
);
341 case 'n': /* end of line */
342 while (getc(fp
) != '\n')
346 case '#': /* comment */
347 while (getc(fp
) != '\n')
350 case 'x': /* device control */
354 error(!FATAL
, "unknown input character %o %c\n", c
, c
);
363 devcntrl(fp
) /* interpret device control functions */
369 fscanf(fp
, "%s", str
);
370 switch (str
[0]) { /* crude for now */
371 case 'i': /* initialize */
375 case 'T': /* device name */
376 fscanf(fp
, "%s", devname
);
378 case 't': /* trailer */
381 case 'p': /* pause -- can restart */
387 case 'r': /* resolution assumed when prepared */
388 fscanf(fp
, "%d", &res
);
390 case 'f': /* font used */
391 fscanf(fp
, "%d %s", &n
, str
);
395 while (getc(fp
) != '\n') /* skip rest of input line */
402 fileinit() /* read in font and code files, etc. */
408 fontprint(i
) /* debugging print of font i (0,...) */
414 loadcode(n
, nw
) /* load codetab on position n (0...); #chars is nw */
421 loadfont(n
, s
) /* load font info for font s on position n (1...) */
429 error(f
, s
, a1
, a2
, a3
, a4
, a5
, a6
, a7
)
432 fprintf(stderr
, "ta: ");
433 fprintf(stderr
, s
, a1
, a2
, a3
, a4
, a5
, a6
, a7
);
434 fprintf(stderr
, "\n");
443 Here beginneth all the stuff that really depends
444 on the 202 (we hope).
448 char devname
[20] = "hp2621";
456 int font
= 1; /* current font */
457 int hpos
; /* horizontal position where we are supposed to be next (left = 0) */
458 int vpos
; /* current vertical position (down positive) */
460 int horig
; /* h origin of current block; hpos rel to this */
461 int vorig
; /* v origin of current block; vpos rel to this */
463 int DX
= 10; /* step size in x for drawing */
464 int DY
= 10; /* step size in y for drawing */
465 int drawdot
= '.'; /* draw with this character */
466 int drawsize
= 1; /* shrink by this factor when drawing */
469 t_init(reinit
) /* initialize device */
490 struct state state
[MAXSTATE
];
491 struct state
*statep
= state
;
494 t_push() /* begin a new block */
497 statep
->ssize
= size
;
498 statep
->sfont
= font
;
499 statep
->shorig
= horig
;
500 statep
->svorig
= vorig
;
501 statep
->shpos
= hpos
;
502 statep
->svpos
= vpos
;
506 if (statep
++ >= state
+MAXSTATE
)
507 error(FATAL
, "{ nested too deep");
514 t_pop() /* pop to previous state */
516 if (--statep
< state
)
517 error(FATAL
, "extra }");
518 size
= statep
->ssize
;
519 font
= statep
->sfont
;
520 hpos
= statep
->shpos
;
521 vpos
= statep
->svpos
;
522 horig
= statep
->shorig
;
523 vorig
= statep
->svorig
;
528 int np
; /* number of pages seen */
529 int npmax
; /* high-water mark of np */
530 int pgnum
[40]; /* their actual numbers */
531 long pgadr
[40]; /* their seek addresses */
534 t_page(n
) /* do whatever new page functions */
541 pgadr
[np
] = ftell(fp
);
545 output
= in_olist(n
);
549 /* have just printed something, and seen p<n> for next one */
556 for (bp
= buf
; (*bp
= readch()); )
565 output
= in_olist(n
);
570 fputs("!\n", stderr
);
579 aspect
= atof(&buf
[1]);
583 m
= atoi(&buf
[1]) + 1;
585 fputs("you can't; it's not a file\n", stderr
);
589 fputs("too far back\n", stderr
);
593 fseek(fp
, pgadr
[np
], 0);
597 case '0': case '1': case '2': case '3': case '4':
598 case '5': case '6': case '7': case '8': case '9':
600 for (i
= 0; i
< npmax
; i
++)
603 if (i
>= npmax
|| fp
== stdin
) {
604 fputs("you can't\n", stderr
);
608 fseek(fp
, pgadr
[np
], 0);
618 fputs("!cmd unix cmd\n", stderr
);
619 fputs("p print this page again\n", stderr
);
620 fputs("-n go back n pages\n", stderr
);
621 fputs("n print page n (previously printed)\n", stderr
);
622 fputs("o... set the -o output list to ...\n", stderr
);
623 fputs("en n=0 -> don't erase; n=1 -> erase\n", stderr
);
624 fputs("an sets aspect ratio to n\n", stderr
);
627 fputs("?\n", stderr
);
644 t_newline() /* do whatever for the end of a line */
653 t_size(n
) /* convert integer to internal size number*/
660 t_font(s
) /* convert string to internal font number */
667 t_text(s
) /* print string s as text */
675 while ((c
= *s
++) != '\n') {
720 hpos
= n
; /* this is where we want to be */
721 /* before printing a character, */
722 /* have to make sure it's true */
728 hmot(n
) /* generate n units of horizontal motion */
737 hflush() /* actual horizontal output occurs here */
751 vmot(n
) /* generate n units of vertical motion */
754 vgoto(vpos
+ n
); /* ignores rounding */
760 put1s(s
) /* s is a funny char name */
765 extern char *spectab
[];
766 static char prev
[10] = "";
771 if (strcmp(s
, prev
) != 0) {
773 for (i
= 0; spectab
[i
] != 0; i
+= 2)
774 if (strcmp(spectab
[i
], s
) == 0) {
781 for (p
= spectab
[previ
+1]; *p
; p
++)
790 put1(c
) /* output char c */
801 setsize(n
) /* set point size to n (internal) */
808 t_fp(n
, s
) /* font position n now contains font s */
816 setfont(n
) /* set font to n */
834 int rc
, status
, unixpid
;
835 if( (unixpid
=fork())==0 ) {
836 signal(SIGINT
,sigint
); signal(SIGQUIT
,sigquit
);
838 execl("/bin/sh", "-sh", "-c", line
, 0);
841 else if(unixpid
== -1)
843 else{ signal(SIGINT
, SIG_IGN
); signal(SIGQUIT
, SIG_IGN
);
844 while( (rc
= wait(&status
)) != unixpid
&& rc
!= -1 ) ;
845 signal(SIGINT
,(void(*)())done
); signal(SIGQUIT
,(void(*)())sigquit
);
854 if (read(2,&c
,1)<1) c
=0;