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 */ |
281 |
|
if (ni_columns <= 0) |
282 |
|
ni_columns = count_columns(rp); |
283 |
|
nrecords = rp->nrecs; |
284 |
< |
} else if ((ni_rows > 0) & (ni_columns > 0)) |
284 |
> |
} else if ((ni_rows > 0) & (ni_columns > 0)) { |
285 |
|
nrecords = ni_rows*ni_columns; |
286 |
< |
else |
286 |
> |
if (nrecords > mp->len / -record_width) { |
287 |
> |
fprintf(stderr, |
288 |
> |
"Input too small for specified size and type\n"); |
289 |
> |
return(0); |
290 |
> |
} |
291 |
> |
} else |
292 |
|
nrecords = mp->len / -record_width; |
293 |
|
/* check sizes */ |
294 |
|
if (ni_rows <= 0) |
385 |
|
putc('\t', stdout); |
386 |
|
} while (--records2go); /* expected EOD? */ |
387 |
|
done: |
388 |
< |
if (columns2go != no_columns) |
388 |
> |
if (warnings && columns2go != no_columns) |
389 |
|
fprintf(stderr, "Warning -- incomplete final row\n"); |
390 |
< |
if (fget_word(word, fp) != NULL) |
391 |
< |
fprintf(stderr, "Warning -- data beyond expected EOF\n"); |
390 |
> |
if (warnings && fget_word(word, fp) != NULL) |
391 |
> |
fprintf(stderr, "Warning -- characters beyond expected EOD\n"); |
392 |
|
return(1); |
393 |
|
} |
394 |
|
|
471 |
|
record_width *= atoi(argv[i]+3); |
472 |
|
} |
473 |
|
break; |
474 |
+ |
case 'w': /* warnings on/off */ |
475 |
+ |
warnings = !warnings; |
476 |
+ |
break; |
477 |
|
default: |
478 |
|
goto userr; |
479 |
|
} |
493 |
|
/* check for no-op */ |
494 |
|
if (!transpose && (record_width < 0 || |
495 |
|
(no_columns == ni_columns) & (no_rows == ni_rows))) { |
496 |
< |
fprintf(stderr, "%s: no-op -- copying input verbatim\n", |
496 |
> |
if (warnings) |
497 |
> |
fprintf(stderr, "%s: no-op -- copying input verbatim\n", |
498 |
|
argv[0]); |
499 |
|
if (!output_stream(stdin)) |
500 |
|
return(1); |
528 |
|
return(0); |
529 |
|
userr: |
530 |
|
fprintf(stderr, |
531 |
< |
"Usage: %s [-h][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n", |
531 |
> |
"Usage: %s [-h][-w][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n", |
532 |
|
argv[0]); |
533 |
|
return(1); |
534 |
|
} |