29 |
|
|
30 |
|
typedef struct { |
31 |
|
int nw_rec; /* number of words per record */ |
32 |
< |
long nrecs; /* number of records we found */ |
32 |
> |
ssize_t nrecs; /* number of records we found */ |
33 |
|
char *rec[1]; /* record array (extends struct) */ |
34 |
|
} RECINDEX; |
35 |
|
|
87 |
|
return(mp->len > 0); |
88 |
|
} |
89 |
|
|
90 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
91 |
+ |
/* too difficult to fix this */ |
92 |
+ |
#define load_file load_stream |
93 |
+ |
#else |
94 |
|
/* load a file into memory */ |
95 |
|
static int |
96 |
|
load_file(MEMLOAD *mp, FILE *fp) |
97 |
|
{ |
98 |
|
int fd; |
99 |
|
off_t skip, flen, fpos; |
96 |
– |
|
97 |
– |
#if defined(_WIN32) || defined(_WIN64) |
98 |
– |
/* too difficult to fix this */ |
99 |
– |
return load_stream(mp, fp); |
100 |
– |
#endif |
100 |
|
if (mp == NULL) |
101 |
|
return(-1); |
102 |
|
mp->mapped = NULL; |
111 |
|
return((int)(flen - skip)); |
112 |
|
mp->len = (size_t)(flen - skip); |
113 |
|
#ifdef MAP_FILE |
114 |
< |
if (mp->len > 1L<<20) { /* map file if > 1 MByte */ |
114 |
> |
if (mp->len >= 1L<<20) { /* map file if >= 1 MByte */ |
115 |
|
mp->mapped = mmap(NULL, flen, PROT_READ, MAP_PRIVATE, fd, 0); |
116 |
|
if (mp->mapped != MAP_FAILED) { |
117 |
|
mp->base = (char *)mp->mapped + skip; |
137 |
|
} |
138 |
|
return(1); |
139 |
|
} |
140 |
+ |
#endif |
141 |
|
|
142 |
|
/* free a record index */ |
143 |
|
#define free_records(rp) free(rp) |
218 |
|
|
219 |
|
/* copy nth record from index to stdout */ |
220 |
|
static int |
221 |
< |
print_record(const RECINDEX *rp, long n) |
221 |
> |
print_record(const RECINDEX *rp, ssize_t n) |
222 |
|
{ |
223 |
|
int words2go = rp->nw_rec; |
224 |
|
char *scp; |
360 |
|
} |
361 |
|
|
362 |
|
/* call to compute block input position */ |
363 |
< |
static long |
363 |
> |
static ssize_t |
364 |
|
get_block_pos(int r, int c, int blklvl[][2], int nlvls) |
365 |
|
{ |
366 |
< |
long n = 0; |
366 |
> |
ssize_t n = 0; |
367 |
|
|
368 |
|
while (nlvls > 1) { |
369 |
|
int sr = r/blklvl[1][0]; |
379 |
|
} |
380 |
|
|
381 |
|
/* return input offset based on array ordering and transpose option */ |
382 |
< |
static long |
382 |
> |
static ssize_t |
383 |
|
get_input_pos(int r, int c) |
384 |
|
{ |
385 |
< |
long n; |
385 |
> |
ssize_t n; |
386 |
|
|
387 |
|
if (outLevels > 1) { /* block reordering */ |
388 |
|
n = get_block_pos(r, c, outArray, outLevels); |
389 |
|
if (transpose) { |
390 |
|
r = n/ni_rows; |
391 |
|
c = n - r*ni_rows; |
392 |
< |
n = (long)c*ni_columns + r; |
392 |
> |
n = (ssize_t)c*ni_columns + r; |
393 |
|
} |
394 |
|
} else if (transpose) /* transpose only */ |
395 |
< |
n = (long)c*ni_columns + r; |
395 |
> |
n = (ssize_t)c*ni_columns + r; |
396 |
|
else /* XXX should never happen! */ |
397 |
< |
n = (long)r*no_columns + c; |
397 |
> |
n = (ssize_t)r*no_columns + c; |
398 |
|
return(n); |
399 |
|
} |
400 |
|
|
404 |
|
{ |
405 |
|
static const char tabEOL[2] = {'\t','\n'}; |
406 |
|
RECINDEX *rp = NULL; |
407 |
< |
long nrecords; |
407 |
> |
ssize_t nrecords; |
408 |
|
int i, j; |
409 |
|
/* propogate sizes */ |
410 |
|
if (ni_rows <= 0) |
419 |
|
ni_columns = count_columns(rp); |
420 |
|
nrecords = rp->nrecs; |
421 |
|
} else if ((ni_rows > 0) & (ni_columns > 0)) { |
422 |
< |
nrecords = ni_rows*ni_columns; |
422 |
> |
nrecords = (ssize_t)ni_rows*ni_columns; |
423 |
|
if (nrecords > mp->len/(n_comp*comp_size)) { |
424 |
|
fputs("Input too small for specified size and type\n", |
425 |
|
stderr); |
432 |
|
ni_rows = nrecords/ni_columns; |
433 |
|
else if ((ni_columns <= 0) & (ni_rows > 0)) |
434 |
|
ni_columns = nrecords/ni_rows; |
435 |
< |
if (nrecords != ni_rows*ni_columns) |
435 |
> |
if (nrecords != (ssize_t)ni_rows*ni_columns) |
436 |
|
goto badspec; |
437 |
|
if (transpose) { |
438 |
|
if (no_columns <= 0) |
456 |
|
if (o_header) { /* finish header? */ |
457 |
|
printf("NROWS=%d\n", no_rows); |
458 |
|
printf("NCOLS=%d\n", no_columns); |
459 |
+ |
fputformat(fmtid, stdout); |
460 |
|
fputc('\n', stdout); |
461 |
|
} |
462 |
|
/* reorder records */ |
463 |
|
for (i = 0; i < no_rows; i++) { |
464 |
|
for (j = 0; j < no_columns; j++) { |
465 |
< |
long n = get_input_pos(i, j); |
465 |
> |
ssize_t n = get_input_pos(i, j); |
466 |
|
if (n >= nrecords) { |
467 |
|
fputs("Index past end-of-file\n", stderr); |
468 |
|
return(0); |
492 |
|
static int |
493 |
|
do_resize(FILE *fp) |
494 |
|
{ |
495 |
< |
long records2go = ni_rows*ni_columns; |
495 |
> |
ssize_t records2go = ni_rows*ni_columns; |
496 |
|
int columns2go = no_columns; |
497 |
|
char word[256]; |
498 |
|
|
501 |
|
printf("NROWS=%d\n", no_rows); |
502 |
|
if (no_columns > 0) |
503 |
|
printf("NCOLS=%d\n", no_columns); |
504 |
+ |
fputformat(fmtid, stdout); |
505 |
|
fputc('\n', stdout); |
506 |
|
} |
507 |
|
/* sanity checks */ |
730 |
|
newheader("RADIANCE", stdout); |
731 |
|
printargs(a, argv, stdout); |
732 |
|
printf("NCOMP=%d\n", n_comp); |
731 |
– |
fputformat(fmtid, stdout); |
733 |
|
} |
734 |
|
if (transpose | check | (outLevels > 1) || (o_header && no_rows <= 0)) { |
735 |
|
MEMLOAD myMem; /* need to map into memory */ |