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 #include <stdio.h>
     18 
     19 float deltx;
     20 float delty;
     21 int PlotRes;
     22 
     23 static void fplt(FILE *);
     24 static int getsi(FILE *);
     25 static void getstr(char *, FILE *);
     26 
     27 int
     28 main(int argc, char *argv[])
     29 {
     30 	int std = 1;
     31 	char *progname;
     32 	FILE *fin;
     33 
     34 	progname = argv[0];
     35 	for (argc--, argv++; argc > 0; argc--, argv++) {
     36 		if (argv[0][0] == '-') {
     37 			switch (argv[0][1]) {
     38 			case 'l':
     39 				deltx = atoi(&argv[0][2]) - 1;
     40 				break;
     41 			case 'w':
     42 				delty = atoi(&argv[0][2]) - 1;
     43 				break;
     44 			case 'r':
     45 				PlotRes = atoi(&argv[0][2]);
     46 				break;
     47 			}
     48 			continue;
     49 		}
     50 		std = 0;
     51 		fin = fopen(argv[0], "r");
     52 		if (fin == NULL) {
     53 			fprintf(stderr, "%s: can't open %s\n", progname,
     54 			    argv[0]);
     55 			exit(1);
     56 		}
     57 		fplt(fin);
     58 		fclose(fin);
     59 	}
     60 	if (std)
     61 		fplt(stdin);
     62 	return (0);
     63 }
     64 
     65 static void
     66 fplt(FILE *fin)
     67 {
     68 	int c;
     69 	char s[256];
     70 	int xi,yi,x0,y0,x1,y1,r,dx,n,i;
     71 	int pat[256];
     72 
     73 	openpl();
     74 	while((c = getc(fin)) != EOF) {
     75 		switch(c) {
     76 		case 'm':
     77 			xi = getsi(fin);
     78 			yi = getsi(fin);
     79 			move(xi,yi);
     80 			break;
     81 		case 'l':
     82 			x0 = getsi(fin);
     83 			y0 = getsi(fin);
     84 			x1 = getsi(fin);
     85 			y1 = getsi(fin);
     86 			line(x0,y0,x1,y1);
     87 			break;
     88 		case 't':
     89 			getstr(s,fin);
     90 			label(s);
     91 			break;
     92 		case 'e':
     93 			erase();
     94 			break;
     95 		case 'p':
     96 			xi = getsi(fin);
     97 			yi = getsi(fin);
     98 			point(xi,yi);
     99 			break;
    100 		case 'n':
    101 			xi = getsi(fin);
    102 			yi = getsi(fin);
    103 			cont(xi,yi);
    104 			break;
    105 		case 's':
    106 			x0 = getsi(fin);
    107 			y0 = getsi(fin);
    108 			x1 = getsi(fin);
    109 			y1 = getsi(fin);
    110 			space(x0,y0,x1,y1);
    111 			break;
    112 		case 'a':
    113 			xi = getsi(fin);
    114 			yi = getsi(fin);
    115 			x0 = getsi(fin);
    116 			y0 = getsi(fin);
    117 			x1 = getsi(fin);
    118 			y1 = getsi(fin);
    119 			arc(xi,yi,x0,y0,x1,y1);
    120 			break;
    121 		case 'c':
    122 			xi = getsi(fin);
    123 			yi = getsi(fin);
    124 			r = getsi(fin);
    125 			circle(xi,yi,r);
    126 			break;
    127 		case 'f':
    128 			getstr(s,fin);
    129 			linemod(s);
    130 			break;
    131 		case 'd':
    132 			xi = getsi(fin);
    133 			yi = getsi(fin);
    134 			dx = getsi(fin);
    135 			n = getsi(fin);
    136 			for(i=0; i<n; i++)
    137 				pat[i] = getsi(fin);
    138 			dot(xi,yi,dx,n,pat);
    139 			break;
    140 		}
    141 	}
    142 	closepl();
    143 }
    144 
    145 /* get an integer stored in 2 ascii bytes. */
    146 static int
    147 getsi(FILE *fin)
    148 {
    149 	short a, b;
    150 
    151 	if((b = getc(fin)) == EOF)
    152 		return(EOF);
    153 	if((a = getc(fin)) == EOF)
    154 		return(EOF);
    155 	a = a<<8;
    156 	return(a|b);
    157 }
    158 
    159 static void
    160 getstr(char *s, FILE *fin)
    161 {
    162 
    163 	for( ; *s = getc(fin); s++)
    164 		if(*s == '\n')
    165 			break;
    166 	*s = '\0';
    167 }
    168