[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.14 and 1.15

version 1.14, 2006/10/28 21:14:29 version 1.15, 2006/10/29 18:40:34
Line 53 
Line 53 
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
 u_char **keylist = 0, *buffer = 0, *linebuf = 0;  u_char *buffer = NULL, *bufend = NULL, *linebuf = NULL;
 size_t bufsize, linebuf_size;  size_t bufsize = BUFSIZE, linebuf_size = MAXLLEN;
 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, **keypos, *tmpbuf;          u_char *weights, **keypos, *tmpbuf;
         u_char *weights;          static u_char **keylist;
         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;
         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 140 
Line 132 
                          */                           */
                         if (c == BUFFEND && nelem == 0) {                          if (c == BUFFEND && nelem == 0) {
                                 bufsize *= 2;                                  bufsize *= 2;
                                 buffer = realloc(buffer, bufsize);                                  tmpbuf = realloc(buffer, bufsize);
                                 if (!buffer)                                  if (!tmpbuf)
                                         err(2, "failed to realloc buffer");                                          err(2, "failed to realloc buffer");
                                 bufend = buffer + bufsize;                                  crec = (RECHEADER *)
                                       (tmpbuf + ((u_char *)crec - buffer));
                                   buffer = tmpbuf;
                                   bufend = buffer + bufsize - 1;
                                 continue;                                  continue;
                         }                          }
                         if (c == BUFFEND || ntfiles || mfct) {  /* push */                          if (c == BUFFEND || ntfiles || mfct) {  /* push */
Line 157 
Line 152 
                                         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 185 
Line 159 
                                                   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();
Line 216 
Line 184 
                                 fmerge(0, tfiles, ntfiles, geteasy,                                  fmerge(0, tfiles, ntfiles, geteasy,
                                     outfp, putline, ftbl);                                      outfp, putline, ftbl);
                         break;                          break;
   
                 }                  }
                 total = maxb = lastb = 0;       /* find if one bin dominates */                  total = maxb = lastb = 0;       /* find if one bin dominates */
                 for (i = 0; i < NBINS; i++)                  for (i = 0; i < NBINS; i++)

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