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.20 by greg, Tue Jun 16 19:06:29 2015 UTC vs.
Revision 2.26 by greg, Thu Aug 2 18:33:50 2018 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
11   #include "platform.h"
12   #include "rtio.h"
13   #include "resolu.h"
14 < #ifdef _WIN32
15 < #undef ftello
16 < #define ftello  ftell
17 < #undef ssize_t
18 < #define ssize_t size_t
14 > #if defined(_WIN32) || defined(_WIN64)
15 >  #undef ftello
16 >  #define       ftello  ftell
17 >  #undef ssize_t
18 >  #define ssize_t       size_t
19   #else
20 < #include <sys/mman.h>
20 >  #include <sys/mman.h>
21   #endif
22  
23 #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
24 #undef getc
25 #undef putc
26 #define getc    getc_unlocked
27 #define putc    putc_unlocked
28 #endif
29
23   typedef struct {
24          void    *base;          /* pointer to base memory */
25          size_t  len;            /* allocated memory length */
# Line 74 | Line 67 | load_stream(MEMLOAD *mp, FILE *fp)
67                  return(-1);
68          while ((nr = fread(buf, 1, sizeof(buf), fp)) > 0) {
69                  if (!alloced)
70 <                        mp->base = malloc(nr);
70 >                        mp->base = malloc(alloced = nr);
71                  else if (mp->len+nr > alloced)
72                          mp->base = realloc(mp->base,
73                                  alloced = alloced*(2+(nr==sizeof(buf)))/2+nr);
# Line 99 | Line 92 | load_file(MEMLOAD *mp, FILE *fp)
92          int     fd;
93          off_t   skip, flen;
94  
95 < #ifdef _WIN32                           /* too difficult to fix this */
95 > #if defined(_WIN32) || defined(_WIN64)
96 >                                /* too difficult to fix this */
97          return load_stream(mp, fp);
98   #endif
99          if (mp == NULL)
# Line 144 | Line 138 | load_file(MEMLOAD *mp, FILE *fp)
138   static RECINDEX *
139   index_records(const MEMLOAD *mp, int nw_rec)
140   {
141 +        int             nall = 0;
142          RECINDEX        *rp;
143          char            *cp, *mend;
144          int             n;
# Line 152 | Line 147 | index_records(const MEMLOAD *mp, int nw_rec)
147                  return(NULL);
148          if (nw_rec <= 0)
149                  return(NULL);
150 <        rp = (RECINDEX *)malloc(sizeof(RECINDEX) + mp->len/(2*nw_rec)*sizeof(char *));
150 >        nall = 1000;
151 >        rp = (RECINDEX *)malloc(sizeof(RECINDEX) + nall*sizeof(char *));
152          if (rp == NULL)
153                  return(NULL);
154          rp->nw_rec = nw_rec;
# Line 164 | Line 160 | index_records(const MEMLOAD *mp, int nw_rec)
160                          ++cp;
161                  if (cp >= mend)
162                          break;
163 +                if (rp->nrecs >= nall) {
164 +                        nall += nall>>1;        /* get more record space */
165 +                        rp = (RECINDEX *)realloc(rp,
166 +                                        sizeof(RECINDEX) + nall*sizeof(char *));
167 +                        if (rp == NULL)
168 +                                return(NULL);
169 +                }
170                  rp->rec[rp->nrecs++] = cp;      /* point to first non-white */
171                  n = rp->nw_rec;
172                  while (++cp < mend)             /* find end of record */
# Line 359 | Line 362 | do_transpose(const MEMLOAD *mp)
362                          print_record(rp, j*ni_columns + i);
363                          putc(tabEOL[j >= no_columns-1], stdout);
364                  } else {                        /* binary output */
365 <                        fwrite((char *)mp->base +
365 >                        putbinary((char *)mp->base +
366                                          (n_comp*comp_size)*(j*ni_columns + i),
367 <                                        n_comp*comp_size, 1, stdout);
367 >                                        comp_size, n_comp, stdout);
368                  }
369              if (ferror(stdout)) {
370                  fprintf(stderr, "Error writing to stdout\n");
# Line 438 | Line 441 | done:
441   static int
442   headline(char *s, void *p)
443   {
444 <        static char     fmt[32];
444 >        static char     fmt[MAXFMTLEN];
445          int             n;
446  
447          if (formatval(fmt, s)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines