| 33 |
|
char *rec[1]; /* record array (extends struct) */ |
| 34 |
|
} RECINDEX; |
| 35 |
|
|
| 36 |
< |
int warnings = 1; /* report warnings? */ |
| 36 |
> |
int warnings = 1; /* report warnings? */ |
| 37 |
|
|
| 38 |
+ |
char *fmtid = NULL; /* format id */ |
| 39 |
+ |
int comp_size = 0; /* binary bytes/channel */ |
| 40 |
+ |
int n_comp = 0; /* components/record */ |
| 41 |
+ |
int ni_columns = 0; /* number of input columns */ |
| 42 |
+ |
int ni_rows = 0; /* number of input rows */ |
| 43 |
+ |
int no_columns = 0; /* number of output columns */ |
| 44 |
+ |
int no_rows = 0; /* number of output rows */ |
| 45 |
+ |
int transpose = 0; /* transpose rows & cols? */ |
| 46 |
+ |
int i_header = 1; /* input header? */ |
| 47 |
+ |
int o_header = 1; /* output header? */ |
| 48 |
+ |
int outArray[MAXLEVELS][2]; /* output block nesting */ |
| 49 |
+ |
int outLevels = 0; /* number of blocking levels */ |
| 50 |
+ |
int check = 0; /* force data check? */ |
| 51 |
+ |
|
| 52 |
|
/* free loaded file */ |
| 53 |
|
static void |
| 54 |
|
free_load(MEMLOAD *mp) |
| 197 |
|
break; /* got requisite # words */ |
| 198 |
|
do { /* else find next word */ |
| 199 |
|
if (*cp == '\n') { |
| 200 |
< |
fprintf(stderr, |
| 187 |
< |
"Unexpected EOL in record!\n"); |
| 200 |
> |
fputs("Unexpected EOL in record!\n", stderr); |
| 201 |
|
free_records(rp); |
| 202 |
|
return(NULL); |
| 203 |
|
} |
| 233 |
|
static int |
| 234 |
|
print_record(const RECINDEX *rp, ssize_t n) |
| 235 |
|
{ |
| 236 |
< |
int words2go = rp->nw_rec; |
| 237 |
< |
char *scp; |
| 236 |
> |
static char delims[] = " \t\n\r\f"; |
| 237 |
> |
int words2go = rp->nw_rec; |
| 238 |
> |
char *scp; |
| 239 |
|
|
| 240 |
|
if ((n < 0) | (n >= rp->nrecs)) |
| 241 |
|
return(0); |
| 242 |
|
scp = rp->rec[n]; |
| 243 |
+ |
|
| 244 |
+ |
if (check && !isfltd(scp, delims)) |
| 245 |
+ |
goto formerr; |
| 246 |
|
do { |
| 247 |
|
putc(*scp++, stdout); |
| 248 |
|
if (!*scp | isspace(*scp)) { |
| 253 |
|
if (++scp >= rp->rec[n+1]) |
| 254 |
|
break; |
| 255 |
|
while (!*scp | isspace(*scp)); |
| 256 |
+ |
|
| 257 |
+ |
if (check && !isfltd(scp, delims)) |
| 258 |
+ |
goto formerr; |
| 259 |
|
} |
| 260 |
|
} while (scp < rp->rec[n+1]); |
| 261 |
|
/* caller adds record sep. */ |
| 262 |
|
return(1); |
| 263 |
+ |
formerr: |
| 264 |
+ |
fputs("Badly formed number: ", stderr); |
| 265 |
+ |
while (*scp && !isspace(*scp)) |
| 266 |
+ |
fputc(*scp++, stderr); |
| 267 |
+ |
fputc('\n', stderr); |
| 268 |
+ |
return(0); |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
/* copy a stream to stdout */ |
| 307 |
|
return(buf); |
| 308 |
|
} |
| 309 |
|
|
| 284 |
– |
char *fmtid = NULL; /* format id */ |
| 285 |
– |
int comp_size = 0; /* binary bytes/channel */ |
| 286 |
– |
int n_comp = 0; /* components/record */ |
| 287 |
– |
int ni_columns = 0; /* number of input columns */ |
| 288 |
– |
int ni_rows = 0; /* number of input rows */ |
| 289 |
– |
int no_columns = 0; /* number of output columns */ |
| 290 |
– |
int no_rows = 0; /* number of output rows */ |
| 291 |
– |
int transpose = 0; /* transpose rows & cols? */ |
| 292 |
– |
int i_header = 1; /* input header? */ |
| 293 |
– |
int o_header = 1; /* output header? */ |
| 294 |
– |
int outArray[MAXLEVELS][2]; /* output block nesting */ |
| 295 |
– |
int outLevels = 0; /* number of blocking levels */ |
| 296 |
– |
int check = 0; /* force data check? */ |
| 297 |
– |
|
| 310 |
|
/* parse RxCx... string */ |
| 311 |
|
static int |
| 312 |
|
get_array(const char *spec, int blklvl[][2], int nlvls) |
| 480 |
|
return(0); |
| 481 |
|
} |
| 482 |
|
if (rp != NULL) { /* ASCII output */ |
| 483 |
< |
print_record(rp, n); |
| 483 |
> |
if (!print_record(rp, n)) |
| 484 |
> |
return(0); |
| 485 |
|
putc(tabEOL[j >= no_columns-1], stdout); |
| 486 |
|
} else { /* binary output */ |
| 487 |
|
putbinary((char *)mp->base + (n_comp*comp_size)*n, |
| 489 |
|
} |
| 490 |
|
} |
| 491 |
|
if (ferror(stdout)) { |
| 492 |
< |
fprintf(stderr, "Error writing to stdout\n"); |
| 492 |
> |
fputs("Error writing to stdout\n", stderr); |
| 493 |
|
return(0); |
| 494 |
|
} |
| 495 |
|
} |
| 497 |
|
free_records(rp); |
| 498 |
|
return(1); |
| 499 |
|
badspec: |
| 500 |
< |
fprintf(stderr, "Bad dimension(s)\n"); |
| 500 |
> |
fputs("Bad dimension(s)\n", stderr); |
| 501 |
|
return(0); |
| 502 |
|
} |
| 503 |
|
|
| 504 |
< |
/* resize ASCII stream input by ignoring EOLs between records */ |
| 504 |
> |
/* resize stream input by ignoring EOLs between ASCII records */ |
| 505 |
|
static int |
| 506 |
|
do_resize(FILE *fp) |
| 507 |
|
{ |
| 522 |
|
(no_columns == ni_columns) & (no_rows == ni_rows)) |
| 523 |
|
return(output_stream(fp)); /* no-op -- just copy */ |
| 524 |
|
if (no_columns <= 0) { |
| 525 |
< |
fprintf(stderr, "Missing -oc specification\n"); |
| 525 |
> |
fputs("Missing -oc specification\n", stderr); |
| 526 |
|
return(0); |
| 527 |
|
} |
| 528 |
|
if ((records2go <= 0) & (no_rows > 0)) |
| 542 |
|
break; |
| 543 |
|
goto done; /* normal EOD */ |
| 544 |
|
} |
| 545 |
+ |
if (check && !isflt(word)) { |
| 546 |
+ |
fputs("Badly formed number: ", stderr); |
| 547 |
+ |
fputs(word, stderr); |
| 548 |
+ |
fputc('\n', stderr); |
| 549 |
+ |
return(0); |
| 550 |
+ |
} |
| 551 |
|
fputs(word, stdout); |
| 552 |
|
if (n) { /* mid-record? */ |
| 553 |
|
int c = getc(fp); |
| 558 |
|
} |
| 559 |
|
} |
| 560 |
|
if (n >= 0) { |
| 561 |
< |
fprintf(stderr, "Incomplete record / unexpected EOF\n"); |
| 561 |
> |
fputs("Incomplete record / unexpected EOF\n", stderr); |
| 562 |
|
return(0); |
| 563 |
|
} |
| 564 |
|
if (--columns2go <= 0) { /* time to end output row? */ |
| 569 |
|
} while (--records2go); /* expected EOD? */ |
| 570 |
|
done: |
| 571 |
|
if (warnings && columns2go != no_columns) |
| 572 |
< |
fprintf(stderr, "Warning -- incomplete final row\n"); |
| 572 |
> |
fputs("Warning -- incomplete final row\n", stderr); |
| 573 |
|
if (warnings && fget_word(word, fp) != NULL) |
| 574 |
< |
fprintf(stderr, "Warning -- characters beyond expected EOD\n"); |
| 574 |
> |
fputs("Warning -- characters beyond expected EOD\n", stderr); |
| 575 |
|
return(1); |
| 576 |
|
} |
| 577 |
|
|
| 723 |
|
SET_FILE_BINARY(stdin); |
| 724 |
|
SET_FILE_BINARY(stdout); |
| 725 |
|
} |
| 726 |
+ |
#ifdef getc_unlocked /* avoid stupid semaphores */ |
| 727 |
+ |
flockfile(stdin); |
| 728 |
+ |
flockfile(stdout); |
| 729 |
+ |
#endif |
| 730 |
|
/* check for no-op */ |
| 731 |
|
if (!transpose & !check & (outLevels <= 1) & (i_header == o_header) && |
| 732 |
|
(no_columns == ni_columns) & (no_rows == ni_rows)) { |