Home | History | Annotate | Download | only in plot
      1 /*
      2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
      3  * Use is subject to license terms.
      4  */
      5 
      6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
      7 /*	  All Rights Reserved  	*/
      8 
      9 /*
     10  * Copyright (c) 1980 Regents of the University of California.
     11  * All rights reserved. The Berkeley software License Agreement
     12  * specifies the terms and conditions for redistribution.
     13  */
     14 
     15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     16 
     17 /*
     18 This driver is used with crtplot.c.
     19 It is essentially the same driver as the one in /usr/src/cmd/plot.
     20 Unfortunately, the curses library has some of the same names as does
     21 as the functions that the driver calls.  These have been changed.
     22 
     23 Also, one of the commands has been removed since they don't make sense
     24 for crt's.
     25 */
     26 
     27 
     28 #include <stdio.h>
     29 
     30 float deltx;
     31 float delty;
     32 
     33 static void	fplt(FILE *);
     34 static int	getsi(FILE *);
     35 static void	getstr(char *, FILE *);
     36 
     37 int
     38 main(int argc, char **argv)
     39 {
     40 	int std=1;
     41 	FILE *fin;
     42 
     43 	while(argc-- > 1) {
     44 		if(*argv[1] == '-')
     45 			switch(argv[1][1]) {
     46 				case 'l':
     47 					deltx = atoi(&argv[1][2]) - 1;
     48 					break;
     49 				case 'w':
     50 					delty = atoi(&argv[1][2]) - 1;
     51 					break;
     52 				}
     53 
     54 		else {
     55 			std = 0;
     56 			if ((fin = fopen(argv[1], "r")) == NULL) {
     57 				printw("can't open %s\n", argv[1]);
     58 				exit(1);
     59 				}
     60 			fplt(fin);
     61 			}
     62 		argv++;
     63 		}
     64 	if (std)
     65 		fplt( stdin );
     66 
     67 	return (0);
     68 }
     69 
     70 static void
     71 fplt(FILE *fin)
     72 {
     73 	int c;
     74 	char s[256];
     75 	int xi,yi,x0,y0,x1,y1,r/*,dx,n,i*/;
     76 	/*int pat[256];*/
     77 
     78 	openpl();
     79 	while((c=getc(fin)) != EOF){
     80 		switch(c){
     81 		case 'm':
     82 			xi = getsi(fin);
     83 			yi = getsi(fin);
     84 			plot_move(xi,yi);
     85 			break;
     86 		case 'l':
     87 			x0 = getsi(fin);
     88 			y0 = getsi(fin);
     89 			x1 = getsi(fin);
     90 			y1 = getsi(fin);
     91 			line(x0,y0,x1,y1);
     92 			break;
     93 		case 't':
     94 			getstr(s,fin);
     95 			label(s);
     96 			break;
     97 		case 'e':
     98 			plot_erase();
     99 			break;
    100 		case 'p':
    101 			xi = getsi(fin);
    102 			yi = getsi(fin);
    103 			point(xi,yi);
    104 			break;
    105 		case 'n':
    106 			xi = getsi(fin);
    107 			yi = getsi(fin);
    108 			cont(xi,yi);
    109 			break;
    110 		case 's':
    111 			x0 = getsi(fin);
    112 			y0 = getsi(fin);
    113 			x1 = getsi(fin);
    114 			y1 = getsi(fin);
    115 			space(x0,y0,x1,y1);
    116 			break;
    117 		case 'a':
    118 			xi = getsi(fin);
    119 			yi = getsi(fin);
    120 			x0 = getsi(fin);
    121 			y0 = getsi(fin);
    122 			x1 = getsi(fin);
    123 			y1 = getsi(fin);
    124 			arc(xi,yi,x0,y0,x1,y1);
    125 			break;
    126 		case 'c':
    127 			xi = getsi(fin);
    128 			yi = getsi(fin);
    129 			r = getsi(fin);
    130 			circle(xi,yi,r);
    131 			break;
    132 		case 'f':
    133 			getstr(s,fin);
    134 			linemod(s);
    135 			break;
    136 		default:
    137 			fprintf(stderr, "Unknown command %c (%o)\n", c, c);
    138 			break;
    139 			}
    140 		}
    141 	closepl();
    142 }
    143 
    144 /* get an integer stored in 2 ascii bytes. */
    145 static int
    146 getsi(FILE *fin)
    147 {
    148 	short a, b;
    149 	if((b = getc(fin)) == EOF)
    150 		return(EOF);
    151 	if((a = getc(fin)) == EOF)
    152 		return(EOF);
    153 	a = a<<8;
    154 	return(a|b);
    155 }
    156 
    157 static void
    158 getstr(char *s, FILE *fin)
    159 {
    160 	for( ; *s = getc(fin); s++)
    161 		if(*s == '\n')
    162 			break;
    163 	*s = '\0';
    164 }
    165