| 35 |
|
char *rec[1]; /* record array (extends struct) */ |
| 36 |
|
} RECINDEX; |
| 37 |
|
|
| 38 |
+ |
int warnings = 1; /* report warnings? */ |
| 39 |
+ |
|
| 40 |
|
/* free loaded file */ |
| 41 |
|
static void |
| 42 |
|
free_load(MEMLOAD *mp) |
| 75 |
|
mp->len = (size_t)(flen - skip); |
| 76 |
|
#ifdef MAP_FILE |
| 77 |
|
if (mp->len > 1L<<20) { /* map file if > 1 MByte */ |
| 78 |
< |
mp->base = mmap(NULL, mp->len, PROT_READ|PROT_WRITE, |
| 77 |
< |
MAP_PRIVATE, fd, skip); |
| 78 |
> |
mp->base = mmap(NULL, mp->len, PROT_READ, MAP_PRIVATE, fd, skip); |
| 79 |
|
if (mp->base != MAP_FAILED) { |
| 80 |
|
mp->mapped = 1; |
| 81 |
|
return(1); /* mmap() success */ |
| 274 |
|
RECINDEX *rp = NULL; |
| 275 |
|
long nrecords; |
| 276 |
|
int i, j; |
| 277 |
+ |
/* propogate sizes */ |
| 278 |
+ |
if (ni_rows <= 0) |
| 279 |
+ |
ni_rows = no_columns; |
| 280 |
+ |
if (ni_columns <= 0) |
| 281 |
+ |
ni_columns = no_rows; |
| 282 |
|
/* get # records (& index) */ |
| 283 |
|
if (record_width > 0) { |
| 284 |
|
if ((rp = index_records(mp, record_width)) == NULL) |
| 286 |
|
if (ni_columns <= 0) |
| 287 |
|
ni_columns = count_columns(rp); |
| 288 |
|
nrecords = rp->nrecs; |
| 289 |
< |
} else if ((ni_rows > 0) & (ni_columns > 0)) |
| 289 |
> |
} else if ((ni_rows > 0) & (ni_columns > 0)) { |
| 290 |
|
nrecords = ni_rows*ni_columns; |
| 291 |
< |
else |
| 291 |
> |
if (nrecords > mp->len / -record_width) { |
| 292 |
> |
fprintf(stderr, |
| 293 |
> |
"Input too small for specified size and type\n"); |
| 294 |
> |
return(0); |
| 295 |
> |
} |
| 296 |
> |
} else |
| 297 |
|
nrecords = mp->len / -record_width; |
| 298 |
|
/* check sizes */ |
| 288 |
– |
if (ni_rows <= 0) |
| 289 |
– |
ni_rows = no_columns; |
| 290 |
– |
if (ni_columns <= 0) |
| 291 |
– |
ni_columns = no_rows; |
| 299 |
|
if ((ni_rows <= 0) & (ni_columns > 0)) |
| 300 |
|
ni_rows = nrecords/ni_columns; |
| 301 |
|
if ((ni_columns <= 0) & (ni_rows > 0)) |
| 386 |
|
putc('\t', stdout); |
| 387 |
|
} while (--records2go); /* expected EOD? */ |
| 388 |
|
done: |
| 389 |
< |
if (columns2go != no_columns) |
| 389 |
> |
if (warnings && columns2go != no_columns) |
| 390 |
|
fprintf(stderr, "Warning -- incomplete final row\n"); |
| 391 |
< |
if (fget_word(word, fp) != NULL) |
| 392 |
< |
fprintf(stderr, "Warning -- data beyond expected EOF\n"); |
| 391 |
> |
if (warnings && fget_word(word, fp) != NULL) |
| 392 |
> |
fprintf(stderr, "Warning -- characters beyond expected EOD\n"); |
| 393 |
|
return(1); |
| 394 |
|
} |
| 395 |
|
|
| 472 |
|
record_width *= atoi(argv[i]+3); |
| 473 |
|
} |
| 474 |
|
break; |
| 475 |
+ |
case 'w': /* warnings on/off */ |
| 476 |
+ |
warnings = !warnings; |
| 477 |
+ |
break; |
| 478 |
|
default: |
| 479 |
|
goto userr; |
| 480 |
|
} |
| 494 |
|
/* check for no-op */ |
| 495 |
|
if (!transpose && (record_width < 0 || |
| 496 |
|
(no_columns == ni_columns) & (no_rows == ni_rows))) { |
| 497 |
< |
fprintf(stderr, "%s: no-op -- copying input verbatim\n", |
| 497 |
> |
if (warnings) |
| 498 |
> |
fprintf(stderr, "%s: no-op -- copying input verbatim\n", |
| 499 |
|
argv[0]); |
| 500 |
|
if (!output_stream(stdin)) |
| 501 |
|
return(1); |
| 529 |
|
return(0); |
| 530 |
|
userr: |
| 531 |
|
fprintf(stderr, |
| 532 |
< |
"Usage: %s [-h][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n", |
| 532 |
> |
"Usage: %s [-h][-w][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n", |
| 533 |
|
argv[0]); |
| 534 |
|
return(1); |
| 535 |
|
} |