| 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 |
< |
putbinary(buf, bytsiz[i], 1, output[i]); |
| 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]; |
| 299 |
|
while (n--) { |
| 300 |
|
if (!scanOK(termc[i])) |
| 301 |
|
break; |
| 302 |
< |
fputs(buf, output[i]); |
| 302 |
> |
if (fputs(buf, output[i]) == EOF) |
| 303 |
> |
break; |
| 304 |
|
} |
| 305 |
|
if (n >= 0) /* fell short? */ |
| 306 |
|
break; |
| 307 |
+ |
if (termc[i] != '\n') /* add EOL if none */ |
| 308 |
+ |
fputc('\n', output[i]); |
| 309 |
|
} else { /* 1-field output */ |
| 310 |
|
if (!scanOK(termc[i])) |
| 311 |
|
break; |
| 312 |
< |
fputs(buf, output[i]); |
| 312 |
> |
if (fputs(buf, output[i]) == EOF) |
| 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) |
| 325 |
|
break; |
| 326 |
|
} while (--outcnt); |
| 327 |
+ |
/* check ending */ |
| 328 |
+ |
if (fflush(NULL) == EOF) { |
| 329 |
+ |
fputs(argv[0], stderr); |
| 330 |
+ |
fputs(": write error on one or more outputs\n", stderr); |
| 331 |
+ |
return(1); |
| 332 |
+ |
} |
| 333 |
+ |
if (outcnt > 0) { |
| 334 |
+ |
fputs(argv[0], stderr); |
| 335 |
+ |
fputs(": warning: premature EOD\n", stderr); |
| 336 |
+ |
} |
| 337 |
|
return(0); |
| 338 |
|
} |