8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdlib.h> |
11 |
– |
#include <string.h> |
12 |
– |
#include <stdio.h> |
11 |
|
#include <ctype.h> |
12 |
|
|
13 |
+ |
#include "rtio.h" |
14 |
|
#include "platform.h" |
15 |
|
#include "resolu.h" |
17 |
– |
#include "rtio.h" |
16 |
|
|
17 |
|
#define DOHEADER 1 |
18 |
|
#define DORESOLU 2 |
19 |
|
|
20 |
|
#define MAXFILE 512 /* maximum number of files */ |
21 |
|
|
22 |
< |
FILE *output[MAXFILE]; |
23 |
< |
int bytsiz[MAXFILE]; |
24 |
< |
short hdrflags[MAXFILE]; |
25 |
< |
const char *format[MAXFILE]; |
26 |
< |
int termc[MAXFILE]; |
27 |
< |
int nfiles = 0; |
22 |
> |
static FILE *output[MAXFILE]; |
23 |
> |
static int bytsiz[MAXFILE]; |
24 |
> |
static short hdrflags[MAXFILE]; |
25 |
> |
static const char *format[MAXFILE]; |
26 |
> |
static int termc[MAXFILE]; |
27 |
> |
static int nfiles = 0; |
28 |
|
|
29 |
< |
int outheader = 0; /* output header to each stream? */ |
29 |
> |
static int outheader = 0; /* output header to each stream? */ |
30 |
|
|
31 |
< |
RESOLU ourres = {PIXSTANDARD, 0, 0}; |
31 |
> |
static RESOLU ourres = {PIXSTANDARD, 0, 0}; |
32 |
|
|
33 |
< |
char buf[16384]; |
33 |
> |
static char buf[16384]; /* input buffer used in scanOK() */ |
34 |
|
|
35 |
|
|
36 |
|
/* process header line */ |
96 |
|
switch (argv[i][1]) { |
97 |
|
case 't': |
98 |
|
curterm = argv[i][2]; |
99 |
+ |
if (!curterm) curterm = '\n'; |
100 |
|
break; |
101 |
|
case 'i': |
102 |
|
switch (argv[i][2]) { |
164 |
|
break; |
165 |
|
case 'a': |
166 |
|
curfmt = "ascii"; |
167 |
< |
curbytes = argv[i][3] ? -1 : 0; |
167 |
> |
curbytes = -1; |
168 |
|
break; |
169 |
|
default: |
170 |
|
goto badopt; |
177 |
|
fputs(": output size too big\n", stderr); |
178 |
|
return(1); |
179 |
|
} |
180 |
< |
if (curbytes > 0) { |
182 |
< |
curterm = '\0'; |
183 |
< |
++bininp; |
184 |
< |
} |
180 |
> |
bininp += (curbytes > 0); |
181 |
|
break; |
182 |
|
case '\0': |
183 |
|
outres |= (curflags & DORESOLU); |
292 |
|
if (bytsiz[i] > 0) { /* binary output */ |
293 |
|
if (getbinary(buf, bytsiz[i], 1, stdin) < 1) |
294 |
|
break; |
295 |
< |
if (putbinary(buf, bytsiz[i], 1, output[i]) != 1) |
295 |
> |
if (putbinary(buf, bytsiz[i], 1, output[i]) < 1) |
296 |
|
break; |
297 |
|
} else if (bytsiz[i] < 0) { /* N-field output */ |
298 |
|
int n = -bytsiz[i]; |
313 |
|
break; |
314 |
|
if (termc[i] != '\n') /* add EOL if none */ |
315 |
|
fputc('\n', output[i]); |
316 |
+ |
} |
317 |
+ |
/* skip input EOL? */ |
318 |
+ |
if (!bininp && termc[nfiles-1] != '\n') { |
319 |
+ |
int c = getchar(); |
320 |
+ |
if ((c != '\n') & (c != EOF)) |
321 |
+ |
ungetc(c, stdin); |
322 |
|
} |
323 |
|
} |
324 |
|
if (i < nfiles) |