22 |
|
static int swapped = 0; /* input is byte-swapped */ |
23 |
|
|
24 |
|
static FILE *output[MAXFILE]; |
25 |
+ |
static int ncomp[MAXFILE]; |
26 |
|
static int bytsiz[MAXFILE]; |
27 |
< |
static short hdrflags[MAXFILE]; |
27 |
> |
static int hdrflags[MAXFILE]; |
28 |
|
static const char *format[MAXFILE]; |
29 |
|
static int termc[MAXFILE]; |
30 |
|
static int nfiles = 0; |
65 |
|
static int |
66 |
|
scanOK(int termc) |
67 |
|
{ |
68 |
+ |
int skip_white = (termc == ' '); |
69 |
|
char *cp = buf; |
70 |
|
int c; |
71 |
|
|
72 |
|
while ((c = getchar()) != EOF) { |
73 |
+ |
if (skip_white && isspace(c)) |
74 |
+ |
continue; |
75 |
+ |
skip_white = 0; |
76 |
+ |
if (c == '\n' && isspace(termc)) |
77 |
+ |
c = termc; /* forgiving assumption */ |
78 |
|
*cp++ = c; |
79 |
|
if (cp-buf >= sizeof(buf)) |
80 |
|
break; |
81 |
< |
if (c == termc) { |
81 |
> |
if ((termc == ' ') ? isspace(c) : (c == termc)) { |
82 |
|
*cp = '\0'; |
83 |
|
return(cp-buf); |
84 |
|
} |
97 |
|
long outcnt = 0; |
98 |
|
int bininp = 0; |
99 |
|
int curterm = '\n'; |
100 |
+ |
int curncomp = 1; |
101 |
|
int curbytes = 0; |
102 |
|
int curflags = 0; |
103 |
|
const char *curfmt = "ascii"; |
167 |
|
break; |
168 |
|
case 'a': |
169 |
|
curfmt = "ascii"; |
170 |
< |
curbytes = -1; |
170 |
> |
curbytes = 0; |
171 |
|
break; |
172 |
|
default: |
173 |
|
goto badopt; |
174 |
|
} |
175 |
< |
if (isdigit(argv[i][3])) |
176 |
< |
curbytes *= atoi(argv[i]+3); |
177 |
< |
curbytes += (curbytes == -1); |
170 |
< |
if (curbytes > (int)sizeof(buf)) { |
175 |
> |
curncomp = isdigit(argv[i][3]) ? |
176 |
> |
atoi(argv[i]+3) : 1 ; |
177 |
> |
if (curbytes*curncomp > (int)sizeof(buf)) { |
178 |
|
fputs(argv[0], stderr); |
179 |
|
fputs(": output size too big\n", stderr); |
180 |
|
return(1); |
189 |
|
if (curbytes > 0) |
190 |
|
SET_FILE_BINARY(output[nfiles]); |
191 |
|
format[nfiles] = curfmt; |
192 |
+ |
ncomp[nfiles] = curncomp; |
193 |
|
bytsiz[nfiles++] = curbytes; |
194 |
|
break; |
195 |
|
badopt:; |
210 |
|
if (curbytes > 0) |
211 |
|
SET_FILE_BINARY(output[nfiles]); |
212 |
|
format[nfiles] = curfmt; |
213 |
+ |
ncomp[nfiles] = curncomp; |
214 |
|
bytsiz[nfiles++] = curbytes; |
215 |
|
} else { |
216 |
|
if (append & (curflags != 0)) { |
237 |
|
if (curbytes > 0) |
238 |
|
SET_FILE_BINARY(output[nfiles]); |
239 |
|
format[nfiles] = curfmt; |
240 |
+ |
ncomp[nfiles] = curncomp; |
241 |
|
bytsiz[nfiles++] = curbytes; |
242 |
|
} |
243 |
|
if (nfiles >= MAXFILE) { |
291 |
|
if (!(inpflags & DOHEADER)) |
292 |
|
newheader("RADIANCE", output[i]); |
293 |
|
printargs(argc, argv, output[i]); |
294 |
+ |
fprintf(output[i], "NCOMP=%d\n", ncomp[i]); |
295 |
|
if (format[i] != NULL) { |
296 |
|
extern const char BIGEND[]; |
297 |
|
if ((format[i][0] == 'f') | |
310 |
|
do { /* main loop */ |
311 |
|
for (i = 0; i < nfiles; i++) { |
312 |
|
if (bytsiz[i] > 0) { /* binary output */ |
313 |
< |
if (getbinary(buf, bytsiz[i], 1, stdin) < 1) |
313 |
> |
if (getbinary(buf, bytsiz[i], ncomp[i], |
314 |
> |
stdin) < ncomp[i]) |
315 |
|
break; |
316 |
< |
if (putbinary(buf, bytsiz[i], 1, output[i]) < 1) |
316 |
> |
if (putbinary(buf, bytsiz[i], ncomp[i], |
317 |
> |
output[i]) < ncomp[i]) |
318 |
|
break; |
319 |
< |
} else if (bytsiz[i] < 0) { /* N-field output */ |
320 |
< |
int n = -bytsiz[i]; |
319 |
> |
} else if (ncomp[i] > 1) { /* N-field output */ |
320 |
> |
int n = ncomp[i]; |
321 |
|
while (n--) { |
322 |
|
if (!scanOK(termc[i])) |
323 |
|
break; |