ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/imagew.c
Revision: 1.4
Committed: Sat Nov 15 02:13:37 2003 UTC (20 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 1.3: +32 -38 lines
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: imagew.c,v 1.3 2003/10/27 10:28:59 schorsch Exp $";
3 #endif
4 /*
5 * Program to print meta-files on a dot-matrix printer
6 *
7 * cc -o image image.c mplot.o plot.o mfio.o syscalls.o palloc.o misc.o
8 *
9 * Apple Imagewriter
10 */
11
12
13 #define MAXALLOC 5000
14
15 #define DXSIZE 576 /* x resolution */
16
17 #define DYSIZE 576 /* y resolution */
18
19 #define LINWIDT DXSIZE /* line width */
20
21 #define LINHITE 8 /* line height */
22
23 #define NLINES (DYSIZE/LINHITE)
24
25 #define CHARWIDTH 8
26
27 #define PNORM "\033n\017\033\""
28
29 #define PCLEAR "\033c"
30
31 #define PINIT "\033>\033n\033T16"
32
33 #define LFNORM "\033f"
34
35 #define LFREV "\033r"
36
37 #define DBLON "\033!"
38
39 #define DBLOFF ""
40
41 #define PTAB "\033F"
42
43 #define OUTPUT "\033g"
44
45 #define XCOM "pexpand +vtOCIps %s | psort -Y +x"
46
47
48
49 #include "rtprocess.h"
50 #include "meta.h"
51 #include "plot.h"
52 #include "span.h"
53
54
55 static int flipbyte(register int b);
56 static void pinit(void);
57 static void pclear(void);
58 static void puninit(void);
59
60
61 char *progname;
62
63 struct span outspan;
64
65 int dxsize = DXSIZE, dysize = DYSIZE,
66 linwidt = LINWIDT, linhite = LINHITE,
67 nrows = (LINHITE-1)/8+1;
68
69 int maxalloc = MAXALLOC;
70
71 int spanmin = 0, spanmax = LINWIDT-1;
72
73 int charwidth = CHARWIDTH;
74
75 static char chrtype[16][5] = {
76 "\033N",
77 "\033N\016",
78 "\033N",
79 "\033N\016",
80 "\033E",
81 "\033E\016",
82 "\033E",
83 "\033E\016",
84 "\033q",
85 "\033q\016",
86 "\033q",
87 "\033q\016",
88 "\033Q",
89 "\033Q\016",
90 "\033Q",
91 "\033Q\016"
92 };
93
94 static int lineno = 0;
95
96 static short condonly = FALSE,
97 conditioned = FALSE;
98
99
100 int
101 main(
102 int argc,
103 char **argv
104 )
105
106 {
107 FILE *fp;
108 char comargs[200], command[300];
109
110 progname = *argv++;
111 argc--;
112
113 condonly = FALSE;
114 conditioned = FALSE;
115
116 while (argc && **argv == '-') {
117 switch (*(*argv+1)) {
118 case 'c':
119 condonly = TRUE;
120 break;
121 case 'r':
122 conditioned = TRUE;
123 break;
124 default:
125 error(WARNING, "unknown option");
126 break;
127 }
128 argv++;
129 argc--;
130 }
131
132 if (conditioned) {
133 pinit();
134 if (argc)
135 while (argc) {
136 fp = efopen(*argv, "r");
137 plot(fp);
138 fclose(fp);
139 argv++;
140 argc--;
141 }
142 else
143 plot(stdin);
144 if (lineno > 0)
145 nextpage();
146 puninit();
147 } else {
148 comargs[0] = '\0';
149 while (argc) {
150 strcat(comargs, " ");
151 strcat(comargs, *argv);
152 argv++;
153 argc--;
154 }
155 sprintf(command, XCOM, comargs);
156 if (condonly)
157 return(system(command));
158 else {
159 pinit();
160 if ((fp = popen(command, "r")) == NULL)
161 error(SYSTEM, "cannot execute input filter");
162 plot(fp);
163 pclose(fp);
164 if (lineno > 0)
165 nextpage();
166 puninit();
167 }
168 }
169
170 return(0);
171 }
172
173
174 void
175 thispage(void) /* rewind and initialize current page */
176 {
177 if (lineno != 0) {
178 fputs(LFREV, stdout);
179 while (lineno) {
180 putc('\n', stdout);
181 lineno--;
182 }
183 fputs(LFNORM, stdout);
184 }
185 }
186
187
188 void
189 nextpage(void) /* advance to next page */
190 {
191
192 fputs("\f\r", stdout);
193
194 lineno = 0;
195
196 }
197
198
199 void
200 contpage(void) /* continue on this page */
201 {
202
203 while (lineno++ < NLINES)
204 putc('\n', stdout);
205
206 lineno = 0;
207
208 }
209
210
211 void
212 printspan(void) /* output span to printer */
213 {
214 register int i;
215
216 if (spanmin <= spanmax) {
217
218 fprintf(stdout, "%s%4d", PTAB, spanmin);
219 fprintf(stdout, "%s%3d", OUTPUT, (spanmax-spanmin)/8 + 1);
220
221 for (i = spanmin; i <= spanmax; i++)
222 putc(flipbyte(outspan.cols[i]), stdout);
223
224 i = 7 - (spanmax-spanmin)%8;
225 while (i--)
226 putc('\0', stdout);
227
228 putc('\r', stdout);
229 }
230
231 putc('\n', stdout);
232 lineno++;
233
234 }
235
236
237
238
239 int
240 flipbyte( /* flip an 8-bit byte end-to-end */
241 register int b
242 )
243 {
244 register int i, a = 0;
245
246 if (b)
247 for (i = 0; i < 8; i++) {
248 a <<= 1;
249 a |= b & 01;
250 b >>= 1;
251 }
252
253 return(a);
254 }
255
256
257 void
258 printstr( /* output a string to the printer */
259 PRIMITIVE *p
260 )
261
262 {
263
264 fprintf(stdout, "%s%4d", PTAB, CONV(p->xy[XMN], dxsize));
265
266 if (p->arg0 & 0100) /* double strike */
267 fputs(DBLON, stdout);
268 else
269 fputs(DBLOFF, stdout);
270
271 fputs(chrtype[(p->arg0 >> 2) & 017], stdout);
272 fputs(p->args, stdout);
273 fputs(PNORM, stdout);
274 putc('\r', stdout);
275 }
276
277
278 void
279 pinit(void) /* initialize printer for output */
280 {
281 pclear();
282 /* get eighth bit */
283 fputs("\033Z", stdout);
284 putc('\0', stdout);
285 putc(' ', stdout);
286 fputs(PINIT, stdout);
287 }
288
289
290 void
291 puninit(void) /* uninitialize printer */
292 {
293 pclear();
294 }
295
296
297 void
298 pclear(void) /* clear printer and sleep */
299 {
300 register int i, j;
301
302 fputs(PCLEAR, stdout);
303 fflush(stdout);
304 for (i = 0; i < 1000; i++)
305 for (j = 0; j < 500; j++)
306 ;
307
308 }