ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rcollate.c
(Generate patch)

Comparing ray/src/util/rcollate.c (file contents):
Revision 2.36 by greg, Mon Sep 7 17:08:08 2020 UTC vs.
Revision 2.38 by greg, Thu Jan 20 17:35:03 2022 UTC

# Line 29 | Line 29 | typedef struct {
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  
# Line 87 | Line 87 | load_stream(MEMLOAD *mp, FILE *fp)
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;
# Line 112 | Line 111 | load_file(MEMLOAD *mp, FILE *fp)
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;
# Line 138 | Line 137 | load_file(MEMLOAD *mp, FILE *fp)
137          }
138          return(1);
139   }
140 + #endif
141  
142   /* free a record index */
143   #define free_records(rp)        free(rp)
# Line 218 | Line 218 | count_columns(const RECINDEX *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;
# Line 360 | Line 360 | check_sizes()
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];
# Line 379 | Line 379 | get_block_pos(int r, int c, int blklvl[][2], int nlvls
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  
# Line 404 | Line 404 | do_reorder(const MEMLOAD *mp)
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)
# Line 419 | Line 419 | do_reorder(const MEMLOAD *mp)
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);
# Line 432 | Line 432 | do_reorder(const MEMLOAD *mp)
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)
# Line 461 | Line 461 | do_reorder(const MEMLOAD *mp)
461                                                  /* reorder records */
462          for (i = 0; i < no_rows; i++) {
463              for (j = 0; j < no_columns; j++) {
464 <                long    n = get_input_pos(i, j);
464 >                ssize_t n = get_input_pos(i, j);
465                  if (n >= nrecords) {
466                          fputs("Index past end-of-file\n", stderr);
467                          return(0);
# Line 491 | Line 491 | badspec:
491   static int
492   do_resize(FILE *fp)
493   {
494 <        long    records2go = ni_rows*ni_columns;
494 >        ssize_t records2go = ni_rows*ni_columns;
495          int     columns2go = no_columns;
496          char    word[256];
497                          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines