6 |
|
* File i/o and recovery |
7 |
|
*/ |
8 |
|
|
9 |
+ |
#include <ctype.h> |
10 |
+ |
#include "platform.h" |
11 |
|
#include "rcontrib.h" |
12 |
|
#include "resolu.h" |
13 |
|
|
113 |
|
printargs(gargc-1, gargv, fout); /* add our command */ |
114 |
|
fprintf(fout, "SOFTWARE= %s\n", VersionID); |
115 |
|
fputnow(fout); |
116 |
+ |
fputs("NCOMP=3\n", fout); /* always RGB */ |
117 |
|
if (info != NULL) /* add extra info if given */ |
118 |
|
fputs(info, fout); |
119 |
|
fputformat(formstr(outfmt), fout); |
134 |
|
STREAMOUT * |
135 |
|
getostream(const char *ospec, const char *mname, int bn, int noopen) |
136 |
|
{ |
134 |
– |
/* static const DCOLOR nocontrib = BLKCOLOR; */ |
137 |
|
static STREAMOUT stdos; |
138 |
+ |
char info[1024]; |
139 |
|
int ofl; |
140 |
|
char oname[1024]; |
141 |
|
LUENT *lep; |
142 |
|
STREAMOUT *sop; |
143 |
+ |
char *cp; |
144 |
|
|
145 |
|
if (ospec == NULL) { /* use stdout? */ |
146 |
|
if (!noopen & !using_stdout) { |
147 |
|
if (outfmt != 'a') |
148 |
|
SET_FILE_BINARY(stdout); |
149 |
< |
if (header) |
150 |
< |
printheader(stdout, NULL); |
151 |
< |
printresolu(stdout, xres, yres); |
149 |
> |
if (header) { |
150 |
> |
cp = info; |
151 |
> |
if (yres > 0) { |
152 |
> |
sprintf(cp, "NROWS=%d\n", yres * |
153 |
> |
(xres + !xres) ); |
154 |
> |
while (*cp) ++cp; |
155 |
> |
} |
156 |
> |
if ((xres <= 0) | (stdos.reclen > 1)) |
157 |
> |
sprintf(cp, "NCOLS=%d\n", stdos.reclen); |
158 |
> |
printheader(stdout, info); |
159 |
> |
} |
160 |
> |
if (stdos.reclen == 1) |
161 |
> |
printresolu(stdout, xres, yres); |
162 |
|
if (waitflush > 0) |
163 |
|
fflush(stdout); |
164 |
|
stdos.xr = xres; stdos.yr = yres; |
196 |
|
} |
197 |
|
} |
198 |
|
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
185 |
– |
long i; |
199 |
|
if (oname[0] == '!') /* output to command */ |
200 |
|
sop->ofp = popen(oname+1, "w"); |
201 |
|
else /* else open file */ |
207 |
|
#ifdef getc_unlocked |
208 |
|
flockfile(sop->ofp); /* avoid lock/unlock overhead */ |
209 |
|
#endif |
210 |
+ |
if (accumulate > 0) { /* global resolution */ |
211 |
+ |
sop->xr = xres; sop->yr = yres; |
212 |
+ |
} |
213 |
|
if (header) { |
214 |
< |
char info[512]; |
199 |
< |
char *cp = info; |
214 |
> |
cp = info; |
215 |
|
if (ofl & OF_MODIFIER || sop->reclen == 1) { |
216 |
|
sprintf(cp, "MODIFIER=%s\n", mname); |
217 |
|
while (*cp) ++cp; |
220 |
|
sprintf(cp, "BIN=%d\n", bn); |
221 |
|
while (*cp) ++cp; |
222 |
|
} |
223 |
< |
*cp = '\0'; |
223 |
> |
if (sop->yr > 0) { |
224 |
> |
sprintf(cp, "NROWS=%d\n", sop->yr * |
225 |
> |
(sop->xr + !sop->xr) ); |
226 |
> |
while (*cp) ++cp; |
227 |
> |
} |
228 |
> |
if ((sop->xr <= 0) | (sop->reclen > 1)) |
229 |
> |
sprintf(cp, "NCOLS=%d\n", sop->reclen); |
230 |
|
printheader(sop->ofp, info); |
231 |
|
} |
232 |
< |
if (accumulate > 0) { /* global resolution */ |
233 |
< |
sop->xr = xres; sop->yr = yres; |
213 |
< |
} |
214 |
< |
printresolu(sop->ofp, sop->xr, sop->yr); |
215 |
< |
#if 0 |
216 |
< |
/* play catch-up */ |
217 |
< |
for (i = accumulate > 0 ? lastdone/accumulate : 0; i--; ) { |
218 |
< |
int j = sop->reclen; |
219 |
< |
if (j <= 0) j = 1; |
220 |
< |
while (j--) |
221 |
< |
put_contrib(nocontrib, sop->ofp); |
222 |
< |
if (outfmt == 'a') |
223 |
< |
putc('\n', sop->ofp); |
224 |
< |
} |
225 |
< |
#endif |
232 |
> |
if (sop->reclen == 1) |
233 |
> |
printresolu(sop->ofp, sop->xr, sop->yr); |
234 |
|
if (waitflush > 0) |
235 |
|
fflush(sop->ofp); |
236 |
|
} |
483 |
|
oname); |
484 |
|
error(USER, errmsg); |
485 |
|
} |
486 |
< |
if ((sout.xr > 0) & (sout.yr > 0) && |
486 |
> |
if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) && |
487 |
|
(!fscnresolu(&xr, &yr, sout.ofp) || |
488 |
|
(xr != sout.xr) | |
489 |
|
(yr != sout.yr))) { |
593 |
|
} else { |
594 |
|
sout.reclen = 0; |
595 |
|
sout.outpipe = 0; |
596 |
+ |
sout.xr = xres; |
597 |
+ |
sout.yr = yres; |
598 |
|
sout.ofp = NULL; |
599 |
|
} |
600 |
|
if (sout.ofp != NULL) { /* already open? */ |
635 |
|
oname); |
636 |
|
error(USER, errmsg); |
637 |
|
} |
638 |
< |
sout.xr = xres; sout.yr = yres; |
629 |
< |
if ((sout.xr > 0) & (sout.yr > 0) && |
638 |
> |
if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) && |
639 |
|
(!fscnresolu(&xr, &yr, sout.ofp) || |
640 |
|
(xr != sout.xr) | |
641 |
|
(yr != sout.yr))) { |