8 |
|
|
9 |
|
#include "rcontrib.h" |
10 |
|
#include "resolu.h" |
11 |
< |
#include "platform.h" |
11 |
> |
#include <ctype.h> |
12 |
|
|
13 |
+ |
/* Close output stream and free record */ |
14 |
+ |
static void |
15 |
+ |
closestream(void *p) |
16 |
+ |
{ |
17 |
+ |
STREAMOUT *sop = (STREAMOUT *)p; |
18 |
+ |
|
19 |
+ |
if (sop->ofp != NULL) { |
20 |
+ |
int status = 0; |
21 |
+ |
if (sop->outpipe) |
22 |
+ |
status = pclose(sop->ofp); |
23 |
+ |
else if (sop->ofp != stdout) |
24 |
+ |
status = fclose(sop->ofp); |
25 |
+ |
if (status) |
26 |
+ |
error(SYSTEM, "error closing output stream"); |
27 |
+ |
} |
28 |
+ |
free(p); |
29 |
+ |
} |
30 |
+ |
|
31 |
+ |
LUTAB ofiletab = LU_SINIT(free,closestream); /* output file table */ |
32 |
+ |
|
33 |
|
#define OF_MODIFIER 01 |
34 |
|
#define OF_BIN 02 |
35 |
|
|
112 |
|
printargs(gargc-1, gargv, fout); /* add our command */ |
113 |
|
fprintf(fout, "SOFTWARE= %s\n", VersionID); |
114 |
|
fputnow(fout); |
115 |
+ |
fputs("NCOMP=3\n", fout); /* always RGB */ |
116 |
|
if (info != NULL) /* add extra info if given */ |
117 |
|
fputs(info, fout); |
118 |
|
fputformat(formstr(outfmt), fout); |
133 |
|
STREAMOUT * |
134 |
|
getostream(const char *ospec, const char *mname, int bn, int noopen) |
135 |
|
{ |
115 |
– |
/* static const DCOLOR nocontrib = BLKCOLOR; */ |
136 |
|
static STREAMOUT stdos; |
137 |
+ |
char info[1024]; |
138 |
|
int ofl; |
139 |
|
char oname[1024]; |
140 |
|
LUENT *lep; |
141 |
|
STREAMOUT *sop; |
142 |
+ |
char *cp; |
143 |
|
|
144 |
|
if (ospec == NULL) { /* use stdout? */ |
145 |
< |
if (!noopen && !using_stdout) { |
145 |
> |
if (!noopen & !using_stdout) { |
146 |
|
if (outfmt != 'a') |
147 |
|
SET_FILE_BINARY(stdout); |
148 |
< |
if (header) |
149 |
< |
printheader(stdout, NULL); |
150 |
< |
printresolu(stdout, xres, yres); |
148 |
> |
if (header) { |
149 |
> |
cp = info; |
150 |
> |
if (yres > 0) { |
151 |
> |
sprintf(cp, "NROWS=%d\n", yres * |
152 |
> |
(xres + !xres) ); |
153 |
> |
while (*cp) ++cp; |
154 |
> |
} |
155 |
> |
if ((xres <= 0) | (stdos.reclen > 1)) |
156 |
> |
sprintf(cp, "NCOLS=%d\n", stdos.reclen); |
157 |
> |
printheader(stdout, info); |
158 |
> |
} |
159 |
> |
if (stdos.reclen == 1) |
160 |
> |
printresolu(stdout, xres, yres); |
161 |
|
if (waitflush > 0) |
162 |
|
fflush(stdout); |
163 |
|
stdos.xr = xres; stdos.yr = yres; |
195 |
|
} |
196 |
|
} |
197 |
|
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
166 |
– |
long i; |
198 |
|
if (oname[0] == '!') /* output to command */ |
199 |
|
sop->ofp = popen(oname+1, "w"); |
200 |
|
else /* else open file */ |
206 |
|
#ifdef getc_unlocked |
207 |
|
flockfile(sop->ofp); /* avoid lock/unlock overhead */ |
208 |
|
#endif |
209 |
+ |
if (accumulate > 0) { /* global resolution */ |
210 |
+ |
sop->xr = xres; sop->yr = yres; |
211 |
+ |
} |
212 |
|
if (header) { |
213 |
< |
char info[512]; |
180 |
< |
char *cp = info; |
213 |
> |
cp = info; |
214 |
|
if (ofl & OF_MODIFIER || sop->reclen == 1) { |
215 |
|
sprintf(cp, "MODIFIER=%s\n", mname); |
216 |
|
while (*cp) ++cp; |
219 |
|
sprintf(cp, "BIN=%d\n", bn); |
220 |
|
while (*cp) ++cp; |
221 |
|
} |
222 |
< |
*cp = '\0'; |
222 |
> |
if (sop->yr > 0) { |
223 |
> |
sprintf(cp, "NROWS=%d\n", sop->yr * |
224 |
> |
(sop->xr + !sop->xr) ); |
225 |
> |
while (*cp) ++cp; |
226 |
> |
} |
227 |
> |
if ((sop->xr <= 0) | (sop->reclen > 1)) |
228 |
> |
sprintf(cp, "NCOLS=%d\n", sop->reclen); |
229 |
|
printheader(sop->ofp, info); |
230 |
|
} |
231 |
< |
if (accumulate > 0) { /* global resolution */ |
232 |
< |
sop->xr = xres; sop->yr = yres; |
194 |
< |
} |
195 |
< |
printresolu(sop->ofp, sop->xr, sop->yr); |
196 |
< |
#if 0 |
197 |
< |
/* play catch-up */ |
198 |
< |
for (i = accumulate > 0 ? lastdone/accumulate : 0; i--; ) { |
199 |
< |
int j = sop->reclen; |
200 |
< |
if (j <= 0) j = 1; |
201 |
< |
while (j--) |
202 |
< |
put_contrib(nocontrib, sop->ofp); |
203 |
< |
if (outfmt == 'a') |
204 |
< |
putc('\n', sop->ofp); |
205 |
< |
} |
206 |
< |
#endif |
231 |
> |
if (sop->reclen == 1) |
232 |
> |
printresolu(sop->ofp, sop->xr, sop->yr); |
233 |
|
if (waitflush > 0) |
234 |
|
fflush(sop->ofp); |
235 |
|
} |
335 |
|
|
336 |
|
put_contrib(mp->cbin[0], sop->ofp); |
337 |
|
if (mp->nbins > 3 && /* minor optimization */ |
338 |
< |
sop == getostream(mp->outspec, mp->modname, 1, 0)) |
338 |
> |
sop == getostream(mp->outspec, mp->modname, 1, 0)) { |
339 |
|
for (j = 1; j < mp->nbins; j++) |
340 |
|
put_contrib(mp->cbin[j], sop->ofp); |
341 |
< |
else |
341 |
> |
} else { |
342 |
|
for (j = 1; j < mp->nbins; j++) { |
343 |
|
sop = getostream(mp->outspec, mp->modname, j, 0); |
344 |
|
put_contrib(mp->cbin[j], sop->ofp); |
345 |
|
} |
346 |
+ |
} |
347 |
|
} |
348 |
|
|
349 |
|
|
370 |
|
end_record() |
371 |
|
{ |
372 |
|
--waitflush; |
373 |
< |
lu_doall(&ofiletab, puteol, NULL); |
373 |
> |
lu_doall(&ofiletab, &puteol, NULL); |
374 |
|
if (using_stdout & (outfmt == 'a')) |
375 |
|
putc('\n', stdout); |
376 |
|
if (!waitflush) { |
482 |
|
oname); |
483 |
|
error(USER, errmsg); |
484 |
|
} |
485 |
< |
if ((sout.xr > 0) & (sout.yr > 0) && |
485 |
> |
if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) && |
486 |
|
(!fscnresolu(&xr, &yr, sout.ofp) || |
487 |
|
(xr != sout.xr) | |
488 |
|
(yr != sout.yr))) { |
520 |
|
*(STREAMOUT *)oent->data = sout; |
521 |
|
} |
522 |
|
} |
523 |
< |
lu_doall(&ofiletab, myclose, NULL); /* close all files */ |
523 |
> |
lu_doall(&ofiletab, &myclose, NULL); /* close all files */ |
524 |
|
} |
525 |
|
|
526 |
|
|
592 |
|
} else { |
593 |
|
sout.reclen = 0; |
594 |
|
sout.outpipe = 0; |
595 |
+ |
sout.xr = xres; |
596 |
+ |
sout.yr = yres; |
597 |
|
sout.ofp = NULL; |
598 |
|
} |
599 |
|
if (sout.ofp != NULL) { /* already open? */ |
634 |
|
oname); |
635 |
|
error(USER, errmsg); |
636 |
|
} |
637 |
< |
sout.xr = xres; sout.yr = yres; |
609 |
< |
if ((sout.xr > 0) & (sout.yr > 0) && |
637 |
> |
if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) && |
638 |
|
(!fscnresolu(&xr, &yr, sout.ofp) || |
639 |
|
(xr != sout.xr) | |
640 |
|
(yr != sout.yr))) { |
677 |
|
} |
678 |
|
/* seek on all files */ |
679 |
|
nvals = lastout * outvsiz; |
680 |
< |
lu_doall(&ofiletab, myseeko, &nvals); |
680 |
> |
lu_doall(&ofiletab, &myseeko, &nvals); |
681 |
|
/* skip repeated input */ |
682 |
+ |
lastout *= accumulate; |
683 |
|
for (nvals = 0; nvals < lastout; nvals++) { |
684 |
|
FVECT vdummy; |
685 |
|
if (getvec(vdummy) < 0 || getvec(vdummy) < 0) |
686 |
|
error(USER, "unexpected EOF on input"); |
687 |
|
} |
688 |
< |
lastray = lastdone = lastout * accumulate; |
688 |
> |
lastray = lastdone = (RNUMBER)lastout; |
689 |
|
if (raysleft) |
690 |
|
raysleft -= lastray; |
691 |
|
} |