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

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.4 static const char RCSid[] = "$Id: mx80.c,v 1.3 2003/10/27 10:28:59 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * Program to print meta-files on a dot-matrix printer
6     *
7     * cc -o mx80 mx80.c mplot.o plot.o mfio.o syscalls.o palloc.o misc.o
8     *
9     * Epson MX-80 printer
10     */
11    
12    
13     #define MAXALLOC 5000
14    
15     #define DXSIZE 480 /* x resolution */
16    
17     #define DYSIZE 616 /* y resolution */
18    
19     #define LINWIDT DXSIZE /* line width */
20    
21     #define LINHITE 8 /* line height */
22    
23     #define NLINES (DYSIZE/LINHITE) /* number of lines */
24    
25     #define CHARWIDTH 6
26    
27     #define PNORM ""
28    
29     #define PINIT "\033@\033#\0331\033U1"
30    
31     #define PUNINIT "\033@\033="
32    
33     #define OUTPUT "\033K"
34    
35     #define XCOM "pexpand +vOCIsp %s | psort -Y +x"
36    
37    
38    
39 schorsch 1.3 #include "rtprocess.h"
40 greg 1.1 #include "meta.h"
41     #include "plot.h"
42     #include "span.h"
43    
44    
45     char *progname;
46    
47     struct span outspan;
48    
49     int dxsize = DXSIZE, dysize = DYSIZE,
50     linwidt = LINWIDT, linhite = LINHITE,
51     nrows = (LINHITE-1)/8+1;
52    
53     int maxalloc = MAXALLOC;
54    
55     int spanmin = 0, spanmax = LINWIDT-1;
56    
57     int charwidth = CHARWIDTH;
58    
59     static int lineno = 0;
60    
61     static short condonly = FALSE,
62     conditioned = FALSE;
63    
64    
65 schorsch 1.4 int
66     main(
67     int argc,
68     char **argv
69     )
70 greg 1.1 {
71     FILE *fp;
72     char comargs[200], command[300];
73    
74     progname = *argv++;
75     argc--;
76    
77     condonly = FALSE;
78     conditioned = FALSE;
79    
80     while (argc && **argv == '-') {
81     switch (*(*argv+1)) {
82     case 'c':
83     condonly = TRUE;
84     break;
85     case 'r':
86     conditioned = TRUE;
87     break;
88     default:
89     error(WARNING, "unknown option");
90     break;
91     }
92     argv++;
93     argc--;
94     }
95    
96     if (conditioned) {
97     fputs(PINIT, stdout);
98     if (argc)
99     while (argc) {
100     fp = efopen(*argv, "r");
101     plot(fp);
102     fclose(fp);
103     argv++;
104     argc--;
105     }
106     else
107     plot(stdin);
108     fputs(PUNINIT, stdout);
109     } else {
110     comargs[0] = '\0';
111     while (argc) {
112     strcat(comargs, " ");
113     strcat(comargs, *argv);
114     argv++;
115     argc--;
116     }
117     sprintf(command, XCOM, comargs);
118     if (condonly)
119     return(system(command));
120     else {
121     fputs(PINIT, stdout);
122     if ((fp = popen(command, "r")) == NULL)
123     error(SYSTEM, "cannot execute input filter");
124     plot(fp);
125     pclose(fp);
126     fputs(PUNINIT, stdout);
127     }
128     }
129    
130     return(0);
131     }
132    
133    
134 schorsch 1.4 void
135     thispage(void) /* rewind and initialize current page */
136 greg 1.1 {
137     if (lineno)
138     error(USER, "cannot restart page in thispage");
139     }
140    
141    
142 schorsch 1.4 void
143     nextpage(void) /* advance to next page */
144 greg 1.1 {
145     fputs("\f\r", stdout);
146    
147     lineno = 0;
148     }
149    
150    
151 schorsch 1.4 void
152     contpage(void) /* continue new plot on current page */
153 greg 1.1 {
154     while (lineno++ < NLINES)
155     putc('\n', stdout);
156    
157     lineno = 0;
158     }
159    
160    
161 schorsch 1.4 void
162     printspan(void) /* output span to printer */
163 greg 1.1 {
164     register int k;
165    
166     if (spanmin <= spanmax) {
167    
168     k = spanmin/charwidth;
169     while (k--)
170     putc(' ', stdout);
171    
172     k = spanmin%charwidth;
173     fputs(OUTPUT, stdout);
174     putc((spanmax-spanmin+k+1)%256, stdout);
175     putc((spanmax-spanmin+k+1)/256, stdout);
176     while (k--)
177     putc('\0', stdout);
178    
179     for (k = spanmin; k <= spanmax; k++)
180     putc(outspan.cols[k], stdout);
181    
182     putc('\r', stdout);
183     }
184     putc('\n', stdout);
185     lineno++;
186    
187     }
188    
189    
190 schorsch 1.4 void
191     printstr( /* output a string to the printer */
192     PRIMITIVE *p
193     )
194 greg 1.1
195     {
196     int i;
197    
198     i = CONV(p->xy[XMN], dxsize)/charwidth;
199     while (i--)
200     putc(' ', stdout);
201    
202     fputs(p->args, stdout);
203     fputs(PNORM, stdout);
204     putc('\r', stdout);
205    
206     }