Subversion Repositories SvarDOS

Rev

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

Rev 2241 Rev 2242
Line 370... Line 370...
370
 
370
 
371
  return(0);
371
  return(0);
372
}
372
}
373
 
373
 
374
 
374
 
375
static int sortcmp(const void *dtaid1, const void *dtaid2) {
375
static int sortcmp(const struct TINYDTA far *dta1, const struct TINYDTA far *dta2) {
376
  struct TINYDTA far *dta1 = &(glob_sortcmp_dat.dtabuf_root[*((unsigned short *)dtaid1)]);
-
 
377
  struct TINYDTA far *dta2 = &(glob_sortcmp_dat.dtabuf_root[*((unsigned short *)dtaid2)]);
-
 
378
  char *ordconf = glob_sortcmp_dat.order;
376
  char *ordconf = glob_sortcmp_dat.order;
379
 
377
 
380
  /* debug stuff
378
  /* debug stuff
381
  {
379
  {
382
    int i;
380
    int i;
Line 447... Line 445...
447
 
445
 
448
  return(0);
446
  return(0);
449
}
447
}
450
 
448
 
451
 
449
 
-
 
450
/* sort function for DIR /O (selection sort) */
-
 
451
static void cmd_dir_sort(struct TINYDTA far *dta, unsigned short dtacount) {
-
 
452
  int i, t, smallest;
-
 
453
  for (i = 0; i < (dtacount - 1); i++) {
-
 
454
    // find "smallest" entry
-
 
455
    smallest = i;
-
 
456
    for (t = i + 1; t < dtacount; t++) {
-
 
457
      if (sortcmp(dta + t, dta + smallest) < 0) smallest = t;
-
 
458
    }
-
 
459
    // if smallest different than current found then swap
-
 
460
    if (smallest != i) {
-
 
461
      struct TINYDTA entry;
-
 
462
      memcpy_ltr_far(&entry, dta + i, sizeof(struct TINYDTA));
-
 
463
      memcpy_ltr_far(dta + i, dta + smallest, sizeof(struct TINYDTA));
-
 
464
      memcpy_ltr_far(dta + smallest, &entry, sizeof(struct TINYDTA));
-
 
465
    }
-
 
466
  }
-
 
467
}
-
 
468
 
-
 
469
 
452
#define DIR_ATTR_DEFAULT (DOS_ATTR_RO | DOS_ATTR_DIR | DOS_ATTR_ARC)
470
#define DIR_ATTR_DEFAULT (DOS_ATTR_RO | DOS_ATTR_DIR | DOS_ATTR_ARC)
453
 
471
 
454
struct dirrequest {
472
struct dirrequest {
455
  unsigned char attrfilter_may;
473
  unsigned char attrfilter_may;
456
  unsigned char attrfilter_must;
474
  unsigned char attrfilter_must;
Line 595... Line 613...
595
    struct nls_patterns nls;
613
    struct nls_patterns nls;
596
    char buff64[64];
614
    char buff64[64];
597
    char path[128];
615
    char path[128];
598
    struct DTA dtastack[64]; /* used for /S, max number of subdirs in DOS5 is 42 (A/B/C/...) */
616
    struct DTA dtastack[64]; /* used for /S, max number of subdirs in DOS5 is 42 (A/B/C/...) */
599
    unsigned char dtastacklen;
617
    unsigned char dtastacklen;
600
    unsigned short orderidx[MAX_SORTABLE_FILES / sizeof(struct TINYDTA)];
-
 
601
  } *buf;
618
  } *buf;
602
  unsigned long summary_recurs_fcount = 0; /* used for /s global summary */
619
  unsigned long summary_recurs_fcount = 0; /* used for /s global summary */
603
  unsigned long summary_recurs_totsz = 0;  /* used for /s global summary */
620
  unsigned long summary_recurs_totsz = 0;  /* used for /s global summary */
604
  unsigned long summary_fcount;
621
  unsigned long summary_fcount;
605
  unsigned long summary_totsz;
622
  unsigned long summary_totsz;
Line 852... Line 869...
852
      if (req.flags & DIR_FLAG_RECUR) goto CHECK_RECURS;
869
      if (req.flags & DIR_FLAG_RECUR) goto CHECK_RECURS;
853
      nls_outputnl_doserr(2); /* "File not found" */
870
      nls_outputnl_doserr(2); /* "File not found" */
854
      goto GAMEOVER;
871
      goto GAMEOVER;
855
    }
872
    }
856
 
873
 
857
    /* sort the list - the tricky part is that my array is a far address while
-
 
858
     * qsort works only with near pointers, so I have to use an ugly (and
-
 
859
     * global) auxiliary table */
874
    /* sort the list */
860
    for (i = 0; i < dtabufcount; i++) buf->orderidx[i] = i;
-
 
861
    qsort(buf->orderidx, dtabufcount, 2, &sortcmp);
875
    cmd_dir_sort(dtabuf, dtabufcount);
862
 
876
 
863
    /* preload first entry (last from orderidx, since entries are sorted in reverse) */
877
    /* preload first entry (last, since entries are sorted in reverse) */
864
    dtabufcount--;
878
    dtabufcount--;
865
    memcpy_ltr_far(((unsigned char *)dta) + 22, &(dtabuf[buf->orderidx[dtabufcount]]), sizeof(struct TINYDTA));
879
    memcpy_ltr_far(((unsigned char *)dta) + 22, dtabuf + dtabufcount, sizeof(struct TINYDTA));
866
    dta->attr = dtabuf[buf->orderidx[dtabufcount]].time_sec2; /* restore attr from the abused time_sec2 field */
880
    dta->attr = dtabuf[dtabufcount].time_sec2; /* restore attr from the abused time_sec2 field */
867
  }
881
  }
868
 
882
 
869
  wcolcount = 0; /* may be used for columns counting with wide mode */
883
  wcolcount = 0; /* may be used for columns counting with wide mode */
870
 
884
 
871
  for (;;) {
885
  for (;;) {
Line 958... Line 972...
958
 
972
 
959
    NEXT_ENTRY:
973
    NEXT_ENTRY:
960
    /* take next entry, either from buf or disk */
974
    /* take next entry, either from buf or disk */
961
    if (dtabufcount > 0) {
975
    if (dtabufcount > 0) {
962
      dtabufcount--;
976
      dtabufcount--;
963
      memcpy_ltr_far(((unsigned char *)dta) + 22, &(dtabuf[buf->orderidx[dtabufcount]]), sizeof(struct TINYDTA));
977
      memcpy_ltr_far(((unsigned char *)dta) + 22, dtabuf + dtabufcount, sizeof(struct TINYDTA));
964
      dta->attr = dtabuf[buf->orderidx[dtabufcount]].time_sec2; /* restore attr from the abused time_sec2 field */
978
      dta->attr = dtabuf[dtabufcount].time_sec2; /* restore attr from the abused time_sec2 field */
965
    } else {
979
    } else {
966
      if (findnext(dta) != 0) break;
980
      if (findnext(dta) != 0) break;
967
    }
981
    }
968
 
982
 
969
  }
983
  }