xref: /onnv-gate/usr/src/cmd/tplot/driver.c (revision 335:d26e4323ca82)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*335Smuffin 
23*335Smuffin /*
24*335Smuffin  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25*335Smuffin  * Use is subject to license terms.
26*335Smuffin  */
27*335Smuffin 
280Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
290Sstevel@tonic-gate /*	  All Rights Reserved  	*/
300Sstevel@tonic-gate 
31*335Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <stdio.h>
340Sstevel@tonic-gate #include <math.h>
350Sstevel@tonic-gate #include <errno.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate float deltx = 4095.0;
380Sstevel@tonic-gate float delty = 4095.0;
390Sstevel@tonic-gate 
40*335Smuffin static void	fplt(FILE *);
41*335Smuffin static int	getsi(FILE *);
42*335Smuffin static void	getsd(char *, FILE *);
43*335Smuffin 
44*335Smuffin int
main(int argc,char ** argv)45*335Smuffin main(int argc, char **argv)
46*335Smuffin {
470Sstevel@tonic-gate 	int std=1;
480Sstevel@tonic-gate 	FILE *fin;
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 	while(argc-- > 1) {
510Sstevel@tonic-gate 		if(*argv[1] == '-')
520Sstevel@tonic-gate 			switch(argv[1][1]) {
530Sstevel@tonic-gate 				case 'l':
540Sstevel@tonic-gate 					deltx = atoi(&argv[1][2]) - 1;
550Sstevel@tonic-gate 					break;
560Sstevel@tonic-gate 				case 'w':
570Sstevel@tonic-gate 					delty = atoi(&argv[1][2]) - 1;
580Sstevel@tonic-gate 					break;
590Sstevel@tonic-gate 				}
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 		else {
620Sstevel@tonic-gate 			std = 0;
630Sstevel@tonic-gate 			if ((fin = fopen(argv[1], "r")) == NULL) {
640Sstevel@tonic-gate 				fprintf(stderr, "can't open %s\n", argv[1]);
650Sstevel@tonic-gate 				exit(1);
660Sstevel@tonic-gate 				}
670Sstevel@tonic-gate 			fplt(fin);
680Sstevel@tonic-gate 			}
690Sstevel@tonic-gate 		argv++;
700Sstevel@tonic-gate 		}
710Sstevel@tonic-gate 	if (std)
720Sstevel@tonic-gate 		fplt( stdin );
73*335Smuffin 	return (0);
74*335Smuffin }
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 
77*335Smuffin static void
fplt(FILE * fin)78*335Smuffin fplt(FILE *fin)
79*335Smuffin {
800Sstevel@tonic-gate 	int c;
810Sstevel@tonic-gate 	char s[256];
820Sstevel@tonic-gate 	int xi,yi,x0,y0,x1,y1,r,dx,n,i;
830Sstevel@tonic-gate 	int pat[256];
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	openpl();
860Sstevel@tonic-gate 	while((c=getc(fin)) != EOF){
870Sstevel@tonic-gate 		switch(c){
880Sstevel@tonic-gate 		case 'm':
890Sstevel@tonic-gate 			xi = getsi(fin);
900Sstevel@tonic-gate 			yi = getsi(fin);
910Sstevel@tonic-gate 			move(xi,yi);
920Sstevel@tonic-gate 			break;
930Sstevel@tonic-gate 		case 'l':
940Sstevel@tonic-gate 			x0 = getsi(fin);
950Sstevel@tonic-gate 			y0 = getsi(fin);
960Sstevel@tonic-gate 			x1 = getsi(fin);
970Sstevel@tonic-gate 			y1 = getsi(fin);
980Sstevel@tonic-gate 			line(x0,y0,x1,y1);
990Sstevel@tonic-gate 			break;
1000Sstevel@tonic-gate 		case 't':
1010Sstevel@tonic-gate 			getsd(s,fin);
1020Sstevel@tonic-gate 			label(s);
1030Sstevel@tonic-gate 			break;
1040Sstevel@tonic-gate 		case 'e':
1050Sstevel@tonic-gate 			erase();
1060Sstevel@tonic-gate 			break;
1070Sstevel@tonic-gate 		case 'p':
1080Sstevel@tonic-gate 			xi = getsi(fin);
1090Sstevel@tonic-gate 			yi = getsi(fin);
1100Sstevel@tonic-gate 			point(xi,yi);
1110Sstevel@tonic-gate 			break;
1120Sstevel@tonic-gate 		case 'n':
1130Sstevel@tonic-gate 			xi = getsi(fin);
1140Sstevel@tonic-gate 			yi = getsi(fin);
1150Sstevel@tonic-gate 			cont(xi,yi);
1160Sstevel@tonic-gate 			break;
1170Sstevel@tonic-gate 		case 's':
1180Sstevel@tonic-gate 			x0 = getsi(fin);
1190Sstevel@tonic-gate 			y0 = getsi(fin);
1200Sstevel@tonic-gate 			x1 = getsi(fin);
1210Sstevel@tonic-gate 			y1 = getsi(fin);
1220Sstevel@tonic-gate 			space(x0,y0,x1,y1);
1230Sstevel@tonic-gate 			break;
1240Sstevel@tonic-gate 		case 'a':
1250Sstevel@tonic-gate 			xi = getsi(fin);
1260Sstevel@tonic-gate 			yi = getsi(fin);
1270Sstevel@tonic-gate 			x0 = getsi(fin);
1280Sstevel@tonic-gate 			y0 = getsi(fin);
1290Sstevel@tonic-gate 			x1 = getsi(fin);
1300Sstevel@tonic-gate 			y1 = getsi(fin);
1310Sstevel@tonic-gate 			arc(xi,yi,x0,y0,x1,y1);
1320Sstevel@tonic-gate 			break;
1330Sstevel@tonic-gate 		case 'c':
1340Sstevel@tonic-gate 			xi = getsi(fin);
1350Sstevel@tonic-gate 			yi = getsi(fin);
1360Sstevel@tonic-gate 			r = getsi(fin);
1370Sstevel@tonic-gate 			circle(xi,yi,r);
1380Sstevel@tonic-gate 			break;
1390Sstevel@tonic-gate 		case 'f':
1400Sstevel@tonic-gate 			getsd(s,fin);
1410Sstevel@tonic-gate 			linemod(s);
1420Sstevel@tonic-gate 			break;
1430Sstevel@tonic-gate 		case 'd':
1440Sstevel@tonic-gate 			xi = getsi(fin);
1450Sstevel@tonic-gate 			yi = getsi(fin);
1460Sstevel@tonic-gate 			dx = getsi(fin);
1470Sstevel@tonic-gate 			n = getsi(fin);
1480Sstevel@tonic-gate 			for(i=0; i<n; i++)pat[i] = getsi(fin);
1490Sstevel@tonic-gate 			dot(xi,yi,dx,n,pat);
1500Sstevel@tonic-gate 			break;
1510Sstevel@tonic-gate 			}
1520Sstevel@tonic-gate 		}
1530Sstevel@tonic-gate 	closepl();
154*335Smuffin }
155*335Smuffin 
156*335Smuffin static int
getsi(FILE * fin)157*335Smuffin getsi(FILE *fin)
158*335Smuffin {
159*335Smuffin 	/* get an integer stored in 2 ascii bytes. */
1600Sstevel@tonic-gate 	short a, b;
1610Sstevel@tonic-gate 	if((b = getc(fin)) == EOF)
1620Sstevel@tonic-gate 		return(EOF);
1630Sstevel@tonic-gate 	if((a = getc(fin)) == EOF)
1640Sstevel@tonic-gate 		return(EOF);
1650Sstevel@tonic-gate 	a = a<<8;
1660Sstevel@tonic-gate 	return(a|b);
1670Sstevel@tonic-gate }
168*335Smuffin 
169*335Smuffin static void
getsd(char * s,FILE * fin)170*335Smuffin getsd(char *s, FILE *fin)
171*335Smuffin {
1720Sstevel@tonic-gate 	for( ; *s = getc(fin); s++)
1730Sstevel@tonic-gate 		if(*s == '\n')
1740Sstevel@tonic-gate 			break;
1750Sstevel@tonic-gate 	*s = '\0';
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate 
178*335Smuffin int
matherr(struct exception * x)179*335Smuffin matherr(struct exception *x)
1800Sstevel@tonic-gate {
1810Sstevel@tonic-gate if(x->type==DOMAIN)
1820Sstevel@tonic-gate 	{errno=EDOM;
1830Sstevel@tonic-gate 	if(!strcmp("log",x->name))x->retval = (-HUGE);
1840Sstevel@tonic-gate 	else x->retval = 0;
1850Sstevel@tonic-gate 	return(1);
1860Sstevel@tonic-gate 	}
1870Sstevel@tonic-gate else  if ((x->type)==SING)
1880Sstevel@tonic-gate 	{errno=EDOM;
1890Sstevel@tonic-gate 	x->retval = (-HUGE);
1900Sstevel@tonic-gate 	return(1);
1910Sstevel@tonic-gate 	}
1920Sstevel@tonic-gate else return(0);
1930Sstevel@tonic-gate }
194