[BACK]Return to fsort.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / sort

Diff for /src/usr.bin/sort/Attic/fsort.c between version 1.13 and 1.14

version 1.13, 2006/10/18 23:30:43 version 1.14, 2006/10/28 21:14:29
Line 53 
Line 53 
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
 u_char *buffer = NULL, *linebuf = NULL;  u_char **keylist = 0, *buffer = 0, *linebuf = 0;
 size_t bufsize = BUFSIZE, linebuf_size = MAXLLEN;  size_t bufsize, linebuf_size;
 struct tempfile fstack[MAXFCT];  struct tempfile fstack[MAXFCT];
 extern char toutpath[];  extern char toutpath[];
 #define FSORTMAX 4  #define FSORTMAX 4
Line 64 
Line 64 
 fsort(int binno, int depth, union f_handle infiles, int nfiles, FILE *outfp,  fsort(int binno, int depth, union f_handle infiles, int nfiles, FILE *outfp,
     struct field *ftbl)      struct field *ftbl)
 {  {
         u_char *bufend, *weights, **keypos, *tmpbuf;          u_char *bufend, **keypos, *tmpbuf;
         static u_char **keylist;          u_char *weights;
         int ntfiles, mfct = 0, total, i, maxb, lastb, panic = 0;          int ntfiles, mfct = 0, total, i, maxb, lastb, panic = 0;
         int c, nelem;          int c, nelem;
         long sizes[NBINS+1];          long sizes[NBINS+1];
Line 85 
Line 85 
                 tfield[0].weights = ascii;                  tfield[0].weights = ascii;
         tfield[0].icol.num = 1;          tfield[0].icol.num = 1;
         weights = ftbl[0].weights;          weights = ftbl[0].weights;
         bufend = buffer + bufsize;          if (!buffer) {
         if (keylist == NULL) {                  bufsize = BUFSIZE;
                 if ((keylist = calloc(MAXNUM, sizeof(u_char *))) == NULL)                  if ((buffer = malloc(bufsize + 1)) == NULL ||
                         err(2, NULL);                      (keylist = calloc(MAXNUM, sizeof(u_char *))) == NULL)
                           errx(2, "cannot allocate memory");
                   if (!SINGL_FLD) {
                           linebuf_size = MAXLLEN;
                           if ((linebuf = malloc(linebuf_size)) == NULL)
                                   errx(2, "cannot allocate memory");
                   }
         }          }
           bufend = buffer + bufsize;
         if (binno >= 0) {          if (binno >= 0) {
                 tfiles.top = infiles.top + nfiles;                  tfiles.top = infiles.top + nfiles;
                 get = getnext;                  get = getnext;
Line 133 
Line 140 
                          */                           */
                         if (c == BUFFEND && nelem == 0) {                          if (c == BUFFEND && nelem == 0) {
                                 bufsize *= 2;                                  bufsize *= 2;
                                 tmpbuf = realloc(buffer, bufsize);                                  buffer = realloc(buffer, bufsize);
                                 if (!tmpbuf)                                  if (!buffer)
                                         err(2, "failed to realloc buffer");                                          err(2, "failed to realloc buffer");
                                 crec = (RECHEADER *)  
                                     (tmpbuf + ((u_char *)crec - buffer));  
                                 buffer = tmpbuf;  
                                 bufend = buffer + bufsize;                                  bufend = buffer + bufsize;
                                 continue;                                  continue;
                         }                          }
Line 153 
Line 157 
                                         mfct++;                                          mfct++;
                                         /* reduce number of open files */                                          /* reduce number of open files */
                                         if (mfct == 16 ||(c == EOF && ntfiles)) {                                          if (mfct == 16 ||(c == EOF && ntfiles)) {
                                                   /*
                                                    * Only copy extra incomplete
                                                    * crec data if there is any.
                                                    */
                                                   int nodata = (bufend
                                                       >= (u_char *)crec
                                                       && bufend <= crec->data);
                                                   size_t sz = 0;
   
                                                   if (!nodata) {
                                                           sz = bufend
                                                               - crec->data;
                                                           tmpbuf = malloc(sz);
                                                           if (tmpbuf == NULL)
                                                                   errx(2, "cannot"
                                                                       " allocate"
                                                                       " memory");
                                                           memmove(tmpbuf,
                                                               crec->data, sz);
                                                   }
   
                                                 fstack[tfiles.top + ntfiles].fp                                                  fstack[tfiles.top + ntfiles].fp
                                                     = ftmp();                                                      = ftmp();
                                                 fmerge(0, mstart, mfct, geteasy,                                                  fmerge(0, mstart, mfct, geteasy,
Line 160 
Line 185 
                                                   putrec, ftbl);                                                    putrec, ftbl);
                                                 ntfiles++;                                                  ntfiles++;
                                                 mfct = 0;                                                  mfct = 0;
   
                                                   if (!nodata) {
                                                           memmove(crec->data,
                                                               tmpbuf, sz);
                                                           free(tmpbuf);
                                                   }
                                         }                                          }
                                 } else {                                  } else {
                                         fstack[tfiles.top + ntfiles].fp= ftmp();                                          fstack[tfiles.top + ntfiles].fp= ftmp();

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14