ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/imagew.c
Revision: 1.3
Committed: Mon Oct 27 10:28:59 2003 UTC (20 years, 6 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -6 lines
Log Message:
Various compatibility fixes.

File Contents

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