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 * Convert the standard plot input into a readable form for debugging. 19 */ 20 21 #include <stdio.h> 22 23 float deltx; 24 float delty; 25 26 static void arc(int, int, int, int, int, int); 27 static void circle(int, int, int); 28 static void closepl(void); 29 static void cont(int, int); 30 static void dot(int, int, int, int, char *); 31 static void erase(void); 32 static void fplt(FILE *); 33 static int getsi(FILE *); 34 static void getstr(char *, FILE *); 35 static void label(char *); 36 static void line(int, int, int, int); 37 static void linemod(char *); 38 static void move(int, int); 39 static void openpl(void); 40 static void point(int, int); 41 static void space(int, int, int, int); 42 43 int 44 main(int argc, char **argv) 45 { 46 int std=1; 47 FILE *fin; 48 49 while(argc-- > 1) { 50 if(*argv[1] == '-') 51 switch(argv[1][1]) { 52 case 'l': 53 deltx = atoi(&argv[1][2]) - 1; 54 break; 55 case 'w': 56 delty = atoi(&argv[1][2]) - 1; 57 break; 58 } 59 else { 60 std = 0; 61 if ((fin = fopen(argv[1], "r")) == NULL) { 62 fprintf(stderr, "can't open %s\n", argv[1]); 63 exit(1); 64 } 65 fplt(fin); 66 fclose(fin); 67 } 68 argv++; 69 } 70 if (std) 71 fplt( stdin ); 72 return (0); 73 } 74 75 76 static void 77 fplt(FILE *fin) 78 { 79 int c; 80 char s[256]; 81 int xi,yi,x0,y0,x1,y1,r,dx,n,i; 82 int pat[256]; 83 84 openpl(); 85 while((c = getc(fin)) != EOF){ 86 switch(c){ 87 case 'm': 88 xi = getsi(fin); 89 yi = getsi(fin); 90 move(xi,yi); 91 break; 92 case 'l': 93 x0 = getsi(fin); 94 y0 = getsi(fin); 95 x1 = getsi(fin); 96 y1 = getsi(fin); 97 line(x0,y0,x1,y1); 98 break; 99 case 't': 100 getstr(s,fin); 101 label(s); 102 break; 103 case 'e': 104 erase(); 105 break; 106 case 'p': 107 xi = getsi(fin); 108 yi = getsi(fin); 109 point(xi,yi); 110 break; 111 case 'n': 112 xi = getsi(fin); 113 yi = getsi(fin); 114 cont(xi,yi); 115 break; 116 case 's': 117 x0 = getsi(fin); 118 y0 = getsi(fin); 119 x1 = getsi(fin); 120 y1 = getsi(fin); 121 space(x0,y0,x1,y1); 122 break; 123 case 'a': 124 xi = getsi(fin); 125 yi = getsi(fin); 126 x0 = getsi(fin); 127 y0 = getsi(fin); 128 x1 = getsi(fin); 129 y1 = getsi(fin); 130 arc(xi,yi,x0,y0,x1,y1); 131 break; 132 case 'c': 133 xi = getsi(fin); 134 yi = getsi(fin); 135 r = getsi(fin); 136 circle(xi,yi,r); 137 break; 138 case 'f': 139 getstr(s,fin); 140 linemod(s); 141 break; 142 case 'd': 143 xi = getsi(fin); 144 yi = getsi(fin); 145 dx = getsi(fin); 146 n = getsi(fin); 147 for(i=0; i<n; i++)pat[i] = getsi(fin); 148 dot(xi, yi, dx, n, (char *)pat); 149 break; 150 } 151 } 152 closepl(); 153 } 154 155 /* get an integer stored in 2 ascii bytes. */ 156 static int 157 getsi(FILE *fin) 158 { 159 short a, b; 160 if((b = getc(fin)) == EOF) 161 return(EOF); 162 if((a = getc(fin)) == EOF) 163 return(EOF); 164 a = a<<8; 165 return(a|b); 166 } 167 168 static void 169 getstr(char *s, FILE *fin) 170 { 171 for( ; *s = getc(fin); s++) 172 if(*s == '\n') 173 break; 174 *s = '\0'; 175 } 176 177 /* Print out the arguments to plot routines. */ 178 179 static void 180 space(int x0, int y0, int x1, int y1) 181 { 182 printf( "s %d %d %d %d\n", x0, y0, x1, y1 ); 183 } 184 185 static void 186 openpl(void) 187 { 188 } 189 190 static void 191 closepl(void) 192 { 193 } 194 195 static void 196 erase(void) 197 { 198 printf( "e\n" ); 199 } 200 201 static void 202 move(int xi, int yi) 203 { 204 printf( "m %d %d\n", xi, yi ); 205 } 206 207 static void 208 cont(int xi, int yi) 209 { 210 printf( "n %d %d\n", xi, yi ); 211 } 212 213 static void 214 line(int x0, int y0, int x1, int y1) 215 { 216 printf( "l %d %d %d %d\n", x0, y0, x1, y1 ); 217 } 218 219 static void 220 point(int xi, int yi) 221 { 222 printf( "p %d %d\n", xi, yi ); 223 } 224 225 static void 226 label(char *s) 227 { 228 printf( "t%s\n\n", s ); 229 } 230 231 232 static void 233 arc(int xcent, int ycent, int xbeg, int ybeg, int xend, int yend) 234 { 235 printf( "a %d %d %d %d %d %d\n", xcent, ycent, xbeg, ybeg, xend, yend ); 236 } 237 238 static void 239 circle(int xc, int yc, int r) 240 { 241 printf( "c %d %d %d\n", xc, yc, r ); 242 } 243 244 static void 245 linemod(char *line) 246 { 247 printf( "f%s\n\n", line ); 248 } 249 250 /* don't know what this should do */ 251 static void 252 dot(int xi, int yi, int dx, int n, char *pat) 253 { 254 printf("d %d %d %d %d %s\n\n", xi, yi, dx, n, pat); 255 } 256