1 | #ifndef lint |
---|
2 | #define _NOTICE static char |
---|
3 | _NOTICE N1[] = "Copyright (c) 1985,1987,1990,1992 Adobe Systems Incorporated"; |
---|
4 | _NOTICE N2[] = "GOVERNMENT END USERS: See Notice file in TranScript library directory"; |
---|
5 | _NOTICE N3[] = "-- probably /usr/lib/ps/Notice"; |
---|
6 | _NOTICE RCSID[]="$Header: /afs/dev.mit.edu/source/repository/third/transcript/src/psplot.c,v 1.1.1.1 1996-10-07 20:25:52 ghudson Exp $"; |
---|
7 | #endif |
---|
8 | /* psplot.c |
---|
9 | * |
---|
10 | * Copyright (C) 1985,1987,1990,1992 Adobe Systems Incorporated. All rights |
---|
11 | * reserved. |
---|
12 | * GOVERNMENT END USERS: See Notice file in TranScript library directory |
---|
13 | * -- probably /usr/lib/ps/Notice |
---|
14 | * |
---|
15 | * convert plot(5) file to a PostScript print file |
---|
16 | * |
---|
17 | * all the smarts are in the prolog, so the conversion is very "soft" |
---|
18 | * |
---|
19 | * this is a straightforward filter from stdin to stdout. |
---|
20 | * |
---|
21 | * RCSLOG: |
---|
22 | * $Log: not supported by cvs2svn $ |
---|
23 | * Revision 3.3 1992/08/21 16:26:32 snichols |
---|
24 | * Release 4.0 |
---|
25 | * |
---|
26 | * Revision 3.2 1992/07/14 22:13:32 snichols |
---|
27 | * Updated copyright. |
---|
28 | * |
---|
29 | * Revision 3.1 1992/06/01 22:36:53 snichols |
---|
30 | * get rid of unneeded declaration of getpwuid. |
---|
31 | * |
---|
32 | * Revision 3.0 1991/06/17 16:50:45 snichols |
---|
33 | * Release 3.0 |
---|
34 | * |
---|
35 | * Revision 2.3 1990/12/12 10:39:01 snichols |
---|
36 | * new configuration stuff. |
---|
37 | * |
---|
38 | * Revision 2.2 87/11/17 16:52:07 byron |
---|
39 | * *** empty log message *** |
---|
40 | * |
---|
41 | * Revision 2.2 87/11/17 16:52:07 byron |
---|
42 | * Release 2.1 |
---|
43 | * |
---|
44 | * Revision 2.1.1.4 87/11/12 13:41:48 byron |
---|
45 | * Changed Government user's notice. |
---|
46 | * |
---|
47 | * Revision 2.1.1.3 87/04/23 10:26:36 byron |
---|
48 | * Copyright notice. |
---|
49 | * |
---|
50 | * Revision 2.1.1.2 87/04/22 10:04:17 byron |
---|
51 | * Normal exit now returns 0 explicitly. |
---|
52 | * |
---|
53 | * Revision 2.1.1.1 87/04/09 11:19:36 byron |
---|
54 | * Fixed setting of donegraphics. Was printing extra blank pages. |
---|
55 | * |
---|
56 | * Revision 2.1 85/11/24 11:50:57 shore |
---|
57 | * Product Release 2.0 |
---|
58 | * |
---|
59 | * Revision 1.3 85/11/20 00:47:08 shore |
---|
60 | * bug fix in quoted characters (\ddd) |
---|
61 | * uses getopt |
---|
62 | * |
---|
63 | * Revision 1.2 85/05/14 11:26:32 shore |
---|
64 | * |
---|
65 | * |
---|
66 | * |
---|
67 | */ |
---|
68 | |
---|
69 | #include <stdio.h> |
---|
70 | #include <pwd.h> |
---|
71 | #include <string.h> |
---|
72 | #include "transcript.h" |
---|
73 | #include "config.h" |
---|
74 | |
---|
75 | private int SeenFile = 0; /* true once a file is processed */ |
---|
76 | private int UserProlog = 0; /* true if user specified a prolog */ |
---|
77 | private char prologfile[512]; /* user specified prolog file name */ |
---|
78 | private char *prog; /* argv[0] program name */ |
---|
79 | private char *libdir; /* ps library directory path */ |
---|
80 | extern char *optarg; /* getopt current opt char */ |
---|
81 | extern int optind; /* getopt argv index */ |
---|
82 | extern int getopt(); |
---|
83 | |
---|
84 | private short int getint() { |
---|
85 | register int b1, b2; |
---|
86 | b1 = getchar() & 0377; |
---|
87 | b2 = getchar(); |
---|
88 | return ((((b2>128)?(b2-256):b2)<<8) + b1); |
---|
89 | } |
---|
90 | |
---|
91 | private VOID CopyFile() { |
---|
92 | int c,d; |
---|
93 | short int x,y,x0,y0,x1,y1,r; |
---|
94 | static int curpage = 1; |
---|
95 | int donegraphics = 0; |
---|
96 | |
---|
97 | printf("%%%%Page: %d %d\n", curpage, curpage); |
---|
98 | while ((c = getchar()) != EOF) { |
---|
99 | switch (c) { |
---|
100 | case 'm': /* move */ |
---|
101 | case 'n': /* cont */ |
---|
102 | case 'p': /* point */ |
---|
103 | x = getint(); |
---|
104 | y = getint(); |
---|
105 | printf("%d %d %c\n", x, y, c); |
---|
106 | if (c != 'm') donegraphics = 1; |
---|
107 | break; |
---|
108 | |
---|
109 | case 'l': /* line */ |
---|
110 | x0 = getint(); |
---|
111 | y0 = getint(); |
---|
112 | x1 = getint(); |
---|
113 | y1 = getint(); |
---|
114 | /* turn it around for current point */ |
---|
115 | printf("%d %d %d %d l\n",x1,y1,x0,y0); |
---|
116 | donegraphics = 1; |
---|
117 | break; |
---|
118 | |
---|
119 | case 't': /* label */ |
---|
120 | putchar('('); |
---|
121 | for(d = getchar(); d != '\n'; d = getchar()) { |
---|
122 | if ((d == ')') || (d == '(') || (d == '\\')) |
---|
123 | putchar('\\'); |
---|
124 | if ((d > 0176) || (d <040)) { |
---|
125 | putchar('\\'); |
---|
126 | putchar(((d>>6)&07)+'0'); |
---|
127 | putchar(((d>>3)&07)+'0'); |
---|
128 | putchar((d&07)+'0'); |
---|
129 | } |
---|
130 | else putchar(d); |
---|
131 | } |
---|
132 | printf(")t\n"); |
---|
133 | donegraphics = 1; |
---|
134 | break; |
---|
135 | |
---|
136 | case 'a': /* arc */ |
---|
137 | x = getint(); |
---|
138 | y = getint(); |
---|
139 | x0 = getint(); |
---|
140 | y0 = getint(); |
---|
141 | x1 = getint(); |
---|
142 | y1 = getint(); |
---|
143 | printf("%d %d %d %d %d %d a\n", x, y, x0, y0, x1, y1); |
---|
144 | donegraphics = 1; |
---|
145 | break; |
---|
146 | |
---|
147 | case 'c': /* circle */ |
---|
148 | x = getint(); |
---|
149 | y = getint(); |
---|
150 | r = getint(); |
---|
151 | printf("%d %d %d c\n", x, y, r); |
---|
152 | donegraphics = 1; |
---|
153 | break; |
---|
154 | |
---|
155 | case 'e': /* erase */ |
---|
156 | if (donegraphics){ |
---|
157 | printf("e\n"); |
---|
158 | curpage++; |
---|
159 | printf("%%%%Page: %d %d\n", curpage, curpage); |
---|
160 | donegraphics = 0; |
---|
161 | } |
---|
162 | break; |
---|
163 | |
---|
164 | case 'f': /* linemod */ |
---|
165 | for(d = '/'; d != '\n'; d = getchar()) putchar(d); |
---|
166 | printf(" f\n"); |
---|
167 | break; |
---|
168 | |
---|
169 | case 's': /* space */ |
---|
170 | x0 = getint(); |
---|
171 | y0 = getint(); |
---|
172 | x1 = getint(); |
---|
173 | y1 = getint(); |
---|
174 | printf("%d %d %d %d s\n", x0, y0, x1, y1); |
---|
175 | break; |
---|
176 | |
---|
177 | default: |
---|
178 | fprintf(stderr, "%s: unknown plot(5) command %03o\n",prog,c); |
---|
179 | exit(2); |
---|
180 | } |
---|
181 | } |
---|
182 | if (donegraphics) { |
---|
183 | printf("e\n"); |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | main(argc, argv) |
---|
188 | char **argv; |
---|
189 | { |
---|
190 | register int argp; |
---|
191 | long clock; |
---|
192 | struct passwd *pswd; |
---|
193 | char hostname[256]; |
---|
194 | |
---|
195 | prog = *argv; |
---|
196 | /* put out comment header, lie about magic number to always |
---|
197 | * avoid page reversal! |
---|
198 | */ |
---|
199 | printf("%%!\n"); |
---|
200 | pswd = getpwuid((int) getuid()); |
---|
201 | VOIDC gethostname(hostname, sizeof hostname); |
---|
202 | printf("%%%%Creator: %s:%s(%s)\n",hostname,pswd->pw_name, pswd->pw_gecos); |
---|
203 | printf("%%%%Title: Unix plot file\n"); |
---|
204 | printf("%%%%CreationDate: %s",(VOIDC time(&clock),ctime(&clock))); |
---|
205 | printf("%%%%DocumentFonts: Courier\n"); |
---|
206 | printf("%%%%EndComments\n"); |
---|
207 | |
---|
208 | while ((argp = getopt(argc, argv, "g:")) != EOF) { |
---|
209 | switch (argp) { |
---|
210 | case 'g': /* user prolog */ |
---|
211 | VOIDC strcpy(prologfile,optarg); |
---|
212 | UserProlog = TRUE; |
---|
213 | break; |
---|
214 | |
---|
215 | case '?': |
---|
216 | default: |
---|
217 | fprintf(stderr,"%s: unknown option %c ignored\n",prog,argp); |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | /* put out prologue */ |
---|
222 | if (!UserProlog) { |
---|
223 | if ((libdir = envget("PSLIBDIR")) == NULL) libdir = PSLibDir; |
---|
224 | VOIDC sprintf(prologfile,"%s/psplot.pro",libdir); |
---|
225 | } |
---|
226 | if (copyfile(prologfile, stdout)) { |
---|
227 | fprintf(stderr,"%s: can't open plot prolog file %s\n", |
---|
228 | prog, prologfile); |
---|
229 | exit(2); |
---|
230 | } |
---|
231 | printf("StartPSPlot\n"); |
---|
232 | printf("%%%%EndProlog\n"); |
---|
233 | |
---|
234 | for (; optind < argc ; optind++) { |
---|
235 | if (freopen(argv[optind],"r",stdin) == NULL) { |
---|
236 | fprintf(stderr,"%s: can't open %s\n",prog,argv[optind]); |
---|
237 | exit(1); |
---|
238 | } |
---|
239 | CopyFile(); |
---|
240 | VOIDC fclose(stdin); |
---|
241 | SeenFile = TRUE; |
---|
242 | } |
---|
243 | if (!SeenFile) { |
---|
244 | CopyFile(); |
---|
245 | } |
---|
246 | printf("%%%%Trailer\n"); |
---|
247 | printf("EndPSPlot\n"); |
---|
248 | VOIDC fclose(stdout); |
---|
249 | exit(0); |
---|
250 | } |
---|