ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/mt160l.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: +20 -40 lines
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: mt160l.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 mt160l mt160l.c mplot.o plot.o mfio.o syscalls.o palloc.o misc.o
8 *
9 * Mannesman Tally MT160L high-density
10 */
11
12
13 #define MAXALLOC 5000
14
15 #define DXSIZE 1064 /* x resolution */
16
17 #define DYSIZE 1024 /* y resolution */
18
19 #define LINWIDT DXSIZE /* line width */
20
21 #define LINHITE 16 /* line height */
22
23 #define NLINES (DYSIZE/LINHITE) /* number of lines */
24
25 #define CHARWIDTH 8
26
27 #define PNORM "\033[0y\033[6w"
28
29 #define PINIT "\033[6~\033[7z\033[0y\033[6w"
30
31 #define PUNINIT "\033[6~"
32
33 #define DBLON "\033[=z"
34
35 #define DBLOFF "\033[>z"
36
37 #define OUTHIGH "\033[9~\033%6"
38
39 #define OUTLOW "\033[8~\033%6"
40
41 #define XCOM "pexpand +vOCIsp %s | psort -Y +x"
42
43
44 #include "rtprocess.h"
45 #include "meta.h"
46 #include "plot.h"
47 #include "span.h"
48
49
50 char *progname;
51
52 struct span outspan;
53
54 int dxsize = DXSIZE, dysize = DYSIZE,
55 linwidt = LINWIDT, linhite = LINHITE,
56 nrows = (LINHITE-1)/8+1;
57
58 int maxalloc = MAXALLOC;
59
60 int spanmin = 0, spanmax = LINWIDT-1;
61
62 int charwidth = CHARWIDTH;
63
64 static char chrtype[16][9] = {
65 "\033[1y\033[4y",
66 "\033[0y\033[0w",
67 "\033[1y\033[4y",
68 "\033[0y\033[0w",
69 "\033[1y\033[5y",
70 "\033[0y\033[1w",
71 "\033[1y\033[5y",
72 "\033[0y\033[1w",
73 "\033[0y\033[6w",
74 "\033[0y\033[2w",
75 "\033[0y\033[6w",
76 "\033[0y\033[2w",
77 "\033[0y\033[7w",
78 "\033[0y\033[3w",
79 "\033[0y\033[7w",
80 "\033[0y\033[3w"
81 };
82
83 static int lineno = 0;
84
85 static short condonly = FALSE,
86 conditioned = FALSE;
87
88
89 int
90 main(
91 int argc,
92 char **argv
93 )
94 {
95 FILE *fp;
96 char comargs[200], command[300];
97
98 progname = *argv++;
99 argc--;
100
101 condonly = FALSE;
102 conditioned = FALSE;
103
104 while (argc && **argv == '-') {
105 switch (*(*argv+1)) {
106 case 'c':
107 condonly = TRUE;
108 break;
109 case 'r':
110 conditioned = TRUE;
111 break;
112 default:
113 error(WARNING, "unknown option");
114 break;
115 }
116 argv++;
117 argc--;
118 }
119
120 if (conditioned) {
121 fputs(PINIT, stdout);
122 if (argc)
123 while (argc) {
124 fp = efopen(*argv, "r");
125 plot(fp);
126 fclose(fp);
127 argv++;
128 argc--;
129 }
130 else
131 plot(stdin);
132 if (lineno)
133 nextpage();
134 fputs(PUNINIT, stdout);
135 } else {
136 comargs[0] = '\0';
137 while (argc) {
138 strcat(comargs, " ");
139 strcat(comargs, *argv);
140 argv++;
141 argc--;
142 }
143 sprintf(command, XCOM, comargs);
144 if (condonly)
145 return(system(command));
146 else {
147 fputs(PINIT, stdout);
148 if ((fp = popen(command, "r")) == NULL)
149 error(SYSTEM, "cannot execute input filter");
150 plot(fp);
151 pclose(fp);
152 if (lineno)
153 nextpage();
154 fputs(PUNINIT, stdout);
155 }
156 }
157 return(0);
158 }
159
160
161 void
162 thispage(void) /* rewind and initialize current page */
163 {
164 if (lineno)
165 error(USER, "cannot restart page in thispage");
166 }
167
168
169 void
170 nextpage(void) /* advance to next page */
171 {
172 fputs("\f\r", stdout);
173
174 lineno = 0;
175 }
176
177
178 void
179 contpage(void) /* continue new plot on current page */
180 {
181
182 while (lineno++ < NLINES)
183 putc('\n', stdout);
184
185 lineno = 0;
186 }
187
188
189 void
190 printspan(void) /* output span to printer */
191 {
192 register unsigned shiftreg;
193 unsigned short outc;
194 register int k;
195 unsigned short offset, mask;
196 int i,j;
197
198 if (spanmin <= spanmax)
199 for (offset = 0; offset < 2; offset++) {
200
201 k = spanmin/charwidth;
202 while (k--)
203 putc(' ', stdout);
204
205 k = spanmin%charwidth;
206 if (offset)
207 fputs(OUTHIGH, stdout);
208 else
209 fputs(OUTLOW, stdout);
210 putc((spanmax-spanmin+k+1)%256, stdout);
211 putc((spanmax-spanmin+k+1)/256, stdout);
212
213 while (k--)
214 putc('\0', stdout);
215
216 for (i = spanmin; i <= spanmax; i++) {
217 outc = '\0';
218 for (j = 0; j < 2; j++) {
219 shiftreg = outspan.cols[j*dxsize + i] >> offset;
220 if (j) {
221 shiftreg <<= 4;
222 mask = 1 << 4;
223 } else
224 mask = 1;
225 for (k = 0; k < 4; k++) {
226 outc |= shiftreg & (mask << k);
227 shiftreg >>= 1;
228 }
229 }
230 putc(outc, stdout);
231 }
232 putc('\r', stdout);
233 }
234 putc('\n', stdout);
235 lineno++;
236 }
237
238
239 void
240 printstr( /* output a string to the printer */
241 PRIMITIVE *p
242 )
243 {
244 int i;
245
246 i = CONV(p->xy[XMN], dxsize)/charwidth;
247 while (i--)
248 putc(' ', stdout);
249
250 if (p->arg0 & 0100) /* double strike */
251 fputs(DBLON, stdout);
252 else
253 fputs(DBLOFF, stdout);
254
255 fputs(chrtype[(p->arg0 >> 2) & 017], stdout);
256 fputs(p->args, stdout);
257 fputs(PNORM, stdout);
258 putc('\r', stdout);
259
260 }