home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / OPDIRX.ZIP / OPDIRX.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1990-02-24  |  2.0 KB  |  83 lines

  1. {$R-,S-,I-,V-,B-,F+,O+,A-}
  2. {$I OPDEFINE.INC}
  3.  
  4. unit OpDirX;
  5.  
  6. { OPDIR extension to allow directory sorts based on extension, name }
  7.  
  8. interface
  9.  
  10. uses opdir;
  11.  
  12.   procedure SortExt(DirPtr : DirListPtr);
  13.     {-Sort alphabetically by extension, then by name}
  14.   procedure SortDirExt(DirPtr : DirListPtr);
  15.     {-Sort directories first, then alphabetically by extension and name}
  16.  
  17. implementation
  18.  
  19. uses Dos,
  20.      OpInline,
  21.      OpString;
  22.  
  23.   function LessExt(var X, Y : DirRec) : Boolean;
  24.     {-Sort ordering -- alphabetically by extension then name}
  25.   var
  26.     Xdrive : Boolean;
  27.     Ydrive : Boolean;
  28.   begin
  29.     Xdrive := (X.Attr = diDriveAttr);
  30.     Ydrive := (Y.Attr = diDriveAttr);
  31.     if Xdrive = Ydrive then
  32.       if ByteFlagIsSet(X.Attr, Directory) then
  33.         LessExt := (X.Name < Y.Name)
  34.       else
  35.         LessExt := (JustExtension(X.Name)+X.Name <
  36.           JustExtension(Y.Name)+Y.Name)
  37.     else
  38.       LessExt := Xdrive;
  39.   end;
  40.  
  41.   procedure SortExt(DirPtr : DirListPtr);
  42.     {-Sort alphabetically by name, then by extension}
  43.   begin
  44.     with DirPtr^ do begin
  45.       diLess := LessExt;
  46.       diQuickSort(1, pkItems);
  47.     end;
  48.   end;
  49.  
  50.   function LessDirExt(var X, Y : DirRec) : Boolean;
  51.     {-Sort directories first, then alphabetically by extension and name}
  52.   var
  53.     Xdir : Boolean;
  54.     Ydir : Boolean;
  55.     Xdrive : Boolean;
  56.     Ydrive : Boolean;
  57.   begin
  58.     Xdrive := (X.Attr = diDriveAttr);
  59.     Ydrive := (Y.Attr = diDriveAttr);
  60.     if Xdrive = Ydrive then begin
  61.       Xdir := ByteFlagIsSet(X.Attr, Directory);
  62.       Ydir := ByteFlagIsSet(Y.Attr, Directory);
  63.       if Xdir = YDir then
  64.         LessDirExt := LessExt(X, Y)
  65.       else
  66.         LessDirExt := Xdir;
  67.     end else
  68.       LessDirExt := Xdrive;
  69.   end;
  70.  
  71.   procedure SortDirExt(DirPtr : DirListPtr);
  72.     {-Sort directories first, then alphabetically by extension and name}
  73.   begin
  74.     with DirPtr^ do begin
  75.       diLess := LessDirExt;
  76.       diQuickSort(1, pkItems);
  77.     end;
  78.   end;
  79.  
  80. {$IFDEF InitAllUnits}
  81. begin
  82. {$ENDIF}
  83. end.