6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdlib.h> |
9 |
– |
#include <unistd.h> |
9 |
|
#include <string.h> |
10 |
|
#include <ctype.h> |
11 |
|
#include "platform.h" |
12 |
|
#include "rtio.h" |
13 |
|
#include "resolu.h" |
14 |
< |
#ifndef _WIN32 |
14 |
> |
#ifdef _WIN32 |
15 |
> |
#undef ftello |
16 |
> |
#define ftello ftell |
17 |
> |
#undef ssize_t |
18 |
> |
#define ssize_t size_t |
19 |
> |
#else |
20 |
|
#include <sys/mman.h> |
21 |
|
#endif |
22 |
|
|
39 |
|
char *rec[1]; /* record array (extends struct) */ |
40 |
|
} RECINDEX; |
41 |
|
|
42 |
+ |
int warnings = 1; /* report warnings? */ |
43 |
+ |
|
44 |
|
/* free loaded file */ |
45 |
|
static void |
46 |
|
free_load(MEMLOAD *mp) |
278 |
|
RECINDEX *rp = NULL; |
279 |
|
long nrecords; |
280 |
|
int i, j; |
281 |
+ |
/* propogate sizes */ |
282 |
+ |
if (ni_rows <= 0) |
283 |
+ |
ni_rows = no_columns; |
284 |
+ |
if (ni_columns <= 0) |
285 |
+ |
ni_columns = no_rows; |
286 |
|
/* get # records (& index) */ |
287 |
|
if (record_width > 0) { |
288 |
|
if ((rp = index_records(mp, record_width)) == NULL) |
290 |
|
if (ni_columns <= 0) |
291 |
|
ni_columns = count_columns(rp); |
292 |
|
nrecords = rp->nrecs; |
293 |
< |
} else if ((ni_rows > 0) & (ni_columns > 0)) |
293 |
> |
} else if ((ni_rows > 0) & (ni_columns > 0)) { |
294 |
|
nrecords = ni_rows*ni_columns; |
295 |
< |
else |
295 |
> |
if (nrecords > mp->len / -record_width) { |
296 |
> |
fprintf(stderr, |
297 |
> |
"Input too small for specified size and type\n"); |
298 |
> |
return(0); |
299 |
> |
} |
300 |
> |
} else |
301 |
|
nrecords = mp->len / -record_width; |
302 |
|
/* check sizes */ |
287 |
– |
if (ni_rows <= 0) |
288 |
– |
ni_rows = no_columns; |
289 |
– |
if (ni_columns <= 0) |
290 |
– |
ni_columns = no_rows; |
303 |
|
if ((ni_rows <= 0) & (ni_columns > 0)) |
304 |
|
ni_rows = nrecords/ni_columns; |
305 |
|
if ((ni_columns <= 0) & (ni_rows > 0)) |
390 |
|
putc('\t', stdout); |
391 |
|
} while (--records2go); /* expected EOD? */ |
392 |
|
done: |
393 |
< |
if (columns2go != no_columns) |
393 |
> |
if (warnings && columns2go != no_columns) |
394 |
|
fprintf(stderr, "Warning -- incomplete final row\n"); |
395 |
< |
if (fget_word(word, fp) != NULL) |
396 |
< |
fprintf(stderr, "Warning -- data beyond expected EOF\n"); |
395 |
> |
if (warnings && fget_word(word, fp) != NULL) |
396 |
> |
fprintf(stderr, "Warning -- characters beyond expected EOD\n"); |
397 |
|
return(1); |
398 |
|
} |
399 |
|
|
476 |
|
record_width *= atoi(argv[i]+3); |
477 |
|
} |
478 |
|
break; |
479 |
+ |
case 'w': /* warnings on/off */ |
480 |
+ |
warnings = !warnings; |
481 |
+ |
break; |
482 |
|
default: |
483 |
|
goto userr; |
484 |
|
} |
498 |
|
/* check for no-op */ |
499 |
|
if (!transpose && (record_width < 0 || |
500 |
|
(no_columns == ni_columns) & (no_rows == ni_rows))) { |
501 |
< |
fprintf(stderr, "%s: no-op -- copying input verbatim\n", |
501 |
> |
if (warnings) |
502 |
> |
fprintf(stderr, "%s: no-op -- copying input verbatim\n", |
503 |
|
argv[0]); |
504 |
|
if (!output_stream(stdin)) |
505 |
|
return(1); |
533 |
|
return(0); |
534 |
|
userr: |
535 |
|
fprintf(stderr, |
536 |
< |
"Usage: %s [-h][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n", |
536 |
> |
"Usage: %s [-h][-w][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row] [input.dat]\n", |
537 |
|
argv[0]); |
538 |
|
return(1); |
539 |
|
} |