home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / dirutils / browser.lzh / Browser / BrowserII_Src.LZH / Sort.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-08  |  2.5 KB  |  121 lines

  1. /*
  2.  *    Sort.c - Copyright © 1991 by S.R. & P.C.
  3.  *
  4.  *    Created:    21 Feb 1991  09:39:43
  5.  *    Modified:    15 Mar 1991  21:01:37
  6.  *
  7.  *    Make>> make
  8.  */
  9.  
  10. #include "Global.h"
  11. #include "proto/Sort.h"
  12.  
  13.  
  14. int CmpName(struct ScrollEntry **e1, struct ScrollEntry **e2);
  15.  
  16. static int CmpSize(struct ScrollEntry **e1, struct ScrollEntry **e2);
  17. #pragma regcall(CmpSize(a0, a1))
  18.  
  19. static int CmpDate(struct ScrollEntry **e1, struct ScrollEntry **e2);
  20. #pragma regcall(CmpDate(a0, a1))
  21.  
  22. static int CmpKey(struct ScrollEntry **e1, struct ScrollEntry **e2);
  23. #pragma regcall(CmpKey(a0, a1))
  24.  
  25. static int CmpType(struct ScrollEntry **e1, struct ScrollEntry **e2);
  26. #pragma regcall(CmpType(a0, a1))
  27.  
  28.  
  29. static int (*SortTab[])() = { CmpName, CmpDate, CmpSize, CmpKey };
  30.  
  31.  
  32. /***    public stuff    ***/
  33.  
  34. void Sort(struct BrowserWindow *Win)
  35. {
  36.     int (*SortFct)();
  37.  
  38.     SortFct = SortTab[Win->bw_Sort & 0x0F];
  39.     if (Win->bw_Sort & TYPE_SORT) {
  40.         QSort(Win->bw_EntryArray, Win->bw_ShownEntries, 4, CmpType);
  41.         QSort(Win->bw_EntryArray, Win->bw_ShownDirs, 4, SortFct);
  42.         QSort(&Win->bw_EntryArray[Win->bw_ShownDirs], Win->bw_ShownFiles, 4, SortFct);
  43.     }
  44.     else
  45.         QSort(Win->bw_EntryArray, Win->bw_ShownEntries, 4, SortFct);
  46. }
  47.  
  48.  
  49. /***    local stuff    ***/
  50.  
  51. static int CmpNumber(long n1, long n2);
  52. #pragma regcall(CmpNumber(a0, a1))
  53.  
  54. static int CCmpName(struct ScrollEntry **e1, struct ScrollEntry **e2);
  55. #pragma regcall(CCmpName(a0, a1))
  56.  
  57.  
  58. /* Can't be call directly from QSort since _ArpBase must be accessed through a4 */
  59.  
  60. static int CCmpName(struct ScrollEntry **e1, struct ScrollEntry **e2)
  61. {
  62.     return Strcmp((*e1)->se_FileInfo.fi_Name, (*e2)->se_FileInfo.fi_Name);
  63. }
  64.  
  65.  
  66. #asm
  67.  
  68.     public _CmpName
  69.     public _geta4
  70.  
  71. _CmpName:
  72.     move.l    a4,-(sp)
  73.     bsr        _geta4
  74.     bsr        _CCmpName
  75.     move.l    (sp)+,a4
  76.     rts
  77.  
  78. #endasm
  79.  
  80.  
  81. static int CmpNumber(long n1, long n2)
  82. {
  83.     if (n1 < n2)
  84.         return -1;
  85.     else if (n1 > n2)
  86.         return 1;
  87.     else
  88.         return 0;
  89. }
  90.  
  91.  
  92. static int CmpSize(struct ScrollEntry **e1, struct ScrollEntry **e2)
  93. {
  94.     return CmpNumber((*e1)->se_FileInfo.fi_Size, (*e2)->se_FileInfo.fi_Size);
  95. }
  96.  
  97.  
  98. static int CmpDate(struct ScrollEntry **e1, struct ScrollEntry **e2)
  99. {
  100.     return CmpNumber((*e1)->se_FileInfo.fi_Secs, (*e2)->se_FileInfo.fi_Secs);
  101. }
  102.  
  103.  
  104. static int CmpKey(struct ScrollEntry **e1, struct ScrollEntry **e2)
  105. {
  106.     return CmpNumber((*e1)->se_FileInfo.fi_DiskKey, (*e2)->se_FileInfo.fi_DiskKey);
  107. }
  108.  
  109.  
  110. static int CmpType(struct ScrollEntry **e1, struct ScrollEntry **e2)
  111. {
  112.     if ((*e1)->se_FileInfo.fi_Type == (*e2)->se_FileInfo.fi_Type)
  113.         return 0;
  114.     else if((*e1)->se_FileInfo.fi_Type == DLX_DIR)
  115.         return -1;
  116.     else
  117.         return 1;
  118. }
  119.  
  120.  
  121.