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