ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/imagew.c
Revision: 1.2
Committed: Fri Aug 1 14:14:24 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -15 lines
Log Message:
Eliminated CPM, MAC, and UNIX conditional compiles.

File Contents

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