Subversion Repositories SvarDOS

Rev

Rev 2193 | Rev 2196 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2193 Rev 2194
Line 688... Line 688...
688
  }
688
  }
689
 
689
 
690
  /* if sorting is involved, then let's buffer all results (and sort them) */
690
  /* if sorting is involved, then let's buffer all results (and sort them) */
691
  if (req.flags & DIR_FLAG_SORT) {
691
  if (req.flags & DIR_FLAG_SORT) {
692
    /* allocate a memory buffer - try several sizes until one succeeds */
692
    /* allocate a memory buffer - try several sizes until one succeeds */
693
    const unsigned short memsz[] = {65500, 32000, 16000, 8000, 4000, 2000, 1000, 0};
-
 
694
    unsigned short max_dta_bufcount = 0;
693
    unsigned short max_dta_bufcount;
-
 
694
 
695
    for (i = 0; memsz[i] != 0; i++) {
695
    /* compute the amount of DTAs I can buffer */
-
 
696
    for (max_dta_bufcount = MAX_SORTABLE_FILES; max_dta_bufcount != 0; max_dta_bufcount /= 2) {
696
      dtabuf = _fmalloc(memsz[i]);
697
      dtabuf = _fmalloc(max_dta_bufcount * sizeof(struct TINYDTA));
697
      if (dtabuf != NULL) break;
698
      if (dtabuf != NULL) break;
698
    }
699
    }
-
 
700
    /* printf("max_dta_bufcount = %u\n", max_dta_bufcount); */
699
 
701
 
700
    if (dtabuf == NULL) {
702
    if (dtabuf == NULL) {
701
      nls_outputnl_doserr(8); /* out of memory */
703
      nls_outputnl_doserr(8); /* out of memory */
702
      goto FAIL;
704
      goto FAIL;
703
    }
705
    }
704
 
706
 
705
    /* remember the address so I can free it afterwards */
707
    /* remember the address so I can free it afterwards */
706
    glob_sortcmp_dat.dtabuf_root = dtabuf;
708
    glob_sortcmp_dat.dtabuf_root = dtabuf;
707
 
709
 
708
    /* compute the amount of DTAs I can buffer */
-
 
709
    max_dta_bufcount = memsz[i] / sizeof(struct TINYDTA);
-
 
710
    if (max_dta_bufcount > MAX_SORTABLE_FILES) max_dta_bufcount = MAX_SORTABLE_FILES;
-
 
711
    /* printf("max_dta_bufcount = %u\n", max_dta_bufcount); */
-
 
712
 
-
 
713
    do {
710
    do {
714
      /* if /S then remember first directory encountered (but not . nor ..) */
711
      /* if /S then remember first directory encountered (but not . nor ..) */
715
      if ((req.flags & DIR_FLAG_RECUR) && (buf->dirpending == 0) && (dta->attr & DOS_ATTR_DIR) && (dta->fname[0] != '.')) {
712
      if ((req.flags & DIR_FLAG_RECUR) && (buf->dirpending == 0) && (dta->attr & DOS_ATTR_DIR) && (dta->fname[0] != '.')) {
716
        buf->dirpending = 1;
713
        buf->dirpending = 1;
717
        memcpy(&(buf->dtastack[buf->dtastacklen]), dta, sizeof(struct DTA));
714
        memcpy(&(buf->dtastack[buf->dtastacklen]), dta, sizeof(struct DTA));