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 #include <stdio.h> 17 18 float deltx; 19 float delty; 20 21 static void fplt(FILE *); 22 static int getsi(FILE *); 23 static void getstr(char *, FILE *); 24 static char *mapLineType(char *); 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 fclose(fin); 51 } 52 argv++; 53 } 54 if (std) 55 fplt( stdin ); 56 return (0); 57 } 58 59 60 static void 61 fplt(FILE *fin) 62 { 63 int c; 64 char s[256]; 65 int xi,yi,x0,y0,x1,y1,r,dx,n,i; 66 int pat[256]; 67 68 openpl(); 69 while((c=getc(fin)) != EOF){ 70 switch(c){ 71 case 'm': 72 xi = getsi(fin); 73 yi = getsi(fin); 74 move(xi,yi); 75 break; 76 case 'l': 77 x0 = getsi(fin); 78 y0 = getsi(fin); 79 x1 = getsi(fin); 80 y1 = getsi(fin); 81 line(x0,y0,x1,y1); 82 break; 83 case 't': 84 getstr(s,fin); 85 label(s); 86 break; 87 case 'e': 88 erase(); 89 break; 90 case 'p': 91 xi = getsi(fin); 92 yi = getsi(fin); 93 point(xi,yi); 94 break; 95 case 'n': 96 xi = getsi(fin); 97 yi = getsi(fin); 98 cont(xi,yi); 99 break; 100 case 's': 101 x0 = getsi(fin); 102 y0 = getsi(fin); 103 x1 = getsi(fin); 104 y1 = getsi(fin); 105 space(x0,y0,x1,y1); 106 break; 107 case 'a': 108 xi = getsi(fin); 109 yi = getsi(fin); 110 x0 = getsi(fin); 111 y0 = getsi(fin); 112 x1 = getsi(fin); 113 y1 = getsi(fin); 114 arc(xi,yi,x0,y0,x1,y1); 115 break; 116 case 'c': 117 xi = getsi(fin); 118 yi = getsi(fin); 119 r = getsi(fin); 120 circle(xi,yi,r); 121 break; 122 case 'f': 123 getstr(s,fin); 124 linemod( mapLineType(s) ); 125 break; 126 case 'd': 127 xi = getsi(fin); 128 yi = getsi(fin); 129 dx = getsi(fin); 130 n = getsi(fin); 131 for(i=0; i<n; i++)pat[i] = getsi(fin); 132 dot(xi,yi,dx,n,pat); 133 break; 134 } 135 /* scan to newline */ 136 while( (c = getc( fin )) != '\n' ) { 137 if ( c == EOF ) { 138 break; 139 } 140 } 141 } 142 closepl(); 143 } 144 145 /* get an integer stored in 2 ascii bytes. */ 146 static int 147 getsi(FILE *fin) 148 { 149 int i; 150 151 if ( fscanf(fin, " %d", & i) != 1 ) { 152 return(EOF); 153 } 154 return( i ); 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 166 char *lineMap[] = { 167 "solid", /* line type 0 */ 168 "solid", /* line type 1 */ 169 "dotted", /* line type 2 */ 170 "dotdashed", /* line type 3 */ 171 "shortdashed", /* line type 4 */ 172 "longdashed", /* line type 5 */ 173 "dotlongdash", /* line type 6 */ 174 "dotshortdash", /* line type 7 */ 175 "dotdotdash", /* line type 8 */ 176 } ; 177 178 static char * 179 mapLineType(char *cp) 180 { 181 int i; 182 183 if ( sscanf(cp, "%d", &i) == 1 ) { 184 if ( i < 0 || i > sizeof(lineMap)/sizeof(char *) ) { 185 i = 1; 186 } 187 return( lineMap[i] ); 188 } 189 else { 190 return( cp ); 191 } 192 } 193