home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / tttsrc51.zip / DIRTTT5.PAS < prev    next >
Pascal/Delphi Source File  |  1993-03-08  |  44KB  |  1,640 lines

  1. {--------------------------------------------------------------------------}
  2. {                         TechnoJock's Turbo Toolkit                       }
  3. {                                                                          }
  4. {                              Version   5.10                              }
  5. {                                                                          }
  6. {                                                                          }
  7. {               Copyright 1986-1993 TechnoJock Software, Inc.              }
  8. {                           All Rights Reserved                            }
  9. {                          Restricted by License                           }
  10. {--------------------------------------------------------------------------}
  11.  
  12.           {--------------------------------}
  13.           {       Unit:   DirTTT5          }
  14.           {--------------------------------}
  15.  
  16.  
  17. {$S-,R-,V-}
  18. {$IFNDEF DEBUG}
  19. {$D-}
  20. {$ENDIF}
  21.  
  22.  
  23. unit  DirTTT5;
  24.  
  25. {Change History:    04/01/89  Changed logic if no file found and DIRFULL
  26.               is false - Line 1174
  27.        5.01A  05/18/89  Added line to allow only directores to be displayed.
  28.               Line 923
  29.      Special  05/25/89  Changed memory disposal scheme
  30.        5.01b  07/23/89  Removed a '+' from string expression to enable compile
  31.               with Quick Pascal (!)
  32.              5.02a  01/23/90  Added check for AllowEsc
  33.              5.02b  04/04/90  Corrected pointer problem on empty directories
  34.              5.02c  09/17/90  Corrected pointer problem on empty directories
  35.              5.10   01/04/93  DPMI compatible version
  36. }
  37.  
  38. (*
  39. {$DEFINE DIRFULL}
  40. *)
  41.  
  42. INTERFACE
  43.  
  44. Uses DOS,CRT,FastTTT5,WinTTT5,StrnTTT5,KeyTTT5,ReadTTT5;
  45.  
  46. Const
  47.    DHelpKey = #187;                     {Alter these keys if desired.       }
  48.    DHelpStr:string[2] = 'F1';           {Note: to disable these keys, set   }
  49.    DToggleKey = #32;                    {      appropriate flags in Var D.   }
  50.    DToggleStr: string[5] = 'Space';
  51.    DZoomKey = #172;
  52. {$IFDEF DIRFULL}
  53.    DZoomStr: string[5] = 'Alt-Z';
  54.    DJumpParentKey = #176;
  55.    DJumpParentStr: string[5] = 'Alt-B';
  56.    DChangeDirKey = #174;
  57.    DChangeDirStr: string[5] = 'Alt-C';
  58.    DSortOrderKey = #152;
  59.    DSortOrderStr: string[5] = 'Alt-O';
  60.    DSortSizeKey = #159;
  61.    DSortSizeStr: string[5] = 'Alt-S';
  62.    DSortNameKey = #177;
  63.    DSortNameStr: string[5] = 'Alt-N';
  64.    DSortExtKey = #146;
  65.    DSortExtStr: string[5] = 'Alt-E';
  66.    DSortTimeKey = #148;
  67.    DSortTimeStr: string[5] = 'Alt-T';
  68.    DSortDOSKey = #160;
  69.    DSortDOSStr: string[5] = 'Alt-D';
  70.    DSortDos  = 1;
  71.    DSortName = 2;
  72.    DSortExt  = 3;
  73.    DSortSize = 4;
  74.    DSortTime = 5;
  75.    Ascending = 1;
  76.    Descending = 2;
  77. {$ENDIF}
  78.  
  79. Type
  80.    DirDisplay = record
  81.           TopX       : byte;
  82.           TopY       : Byte;
  83.           Rows       : byte;
  84.           Attrib     : byte;
  85.           BoxType    : byte;
  86.           BoxFCol    : byte;
  87.           BoxBCol    : byte;
  88.           KeyFCol    : byte;
  89.           BacCol     : byte;
  90.           NorFCol    : byte;
  91.           DirFCol    : byte;
  92.           HiFCol     : byte;
  93.           HiBCol     : byte;
  94.           AllowEsc   : boolean;
  95.           ShowDetails: boolean;
  96.           Colswide   : byte;
  97.           DisplayInfo: boolean;
  98.           RestoreScreen : boolean;
  99.           AllowHelp     : boolean;
  100.           AllowToggle   : boolean;
  101.           AllowZoom     : boolean;
  102.           ZoomLine      : byte;
  103.           AllowSort     : boolean;
  104.           InitSort      : byte;
  105.           Asc           : byte;
  106.           AllowCD       : boolean;
  107.           SelectDir     : boolean;
  108.           AllowInput    : boolean;
  109.       end;
  110.  
  111. Var
  112.    DTTT : DirDisplay;
  113.    NoMemory : boolean;
  114.  
  115. Function Display_Directory(DIRFULLFileName: StrScreen;var Retcode:integer): StrScreen;
  116. Procedure Default_Settings;
  117.  
  118. IMPLEMENTATION
  119.  
  120.  
  121. Procedure Default_Settings;
  122. begin
  123.     With  DTTT  do
  124.     begin
  125.   TopX    := 0;
  126.   TopY    := 0;
  127.   Rows    := 0;
  128.   AllowEsc := true;
  129.   Attrib := Readonly + Directory + Archive;
  130.   BoxType := 1;
  131.   ShowDetails := true;
  132.   ColsWide := 5;
  133. {$IFDEF DIRFULL}
  134.   DisplayInfo := true;
  135.   AllowHelp := true;
  136.   AllowZoom   := true;
  137.   ZoomLine := 25;
  138.   AllowSort := true;
  139.   InitSort := DSortDOS;     {sort in DOS order}
  140.   AllowInput := True;
  141. {$ELSE}
  142.   DisplayInfo := false;
  143. {$ENDIF}
  144.   AllowCD := true;
  145.   SelectDir := false;
  146.   RestoreSCreen := true;
  147.   AllowToggle := true;
  148.   Asc := 1;
  149.   If not ColorScreen then
  150.   begin
  151.       BoxFCol := white;
  152.       BoxBCol := black;
  153.       KeyFCol := white;
  154.       BacCol := black;
  155.       NorFCol := white;
  156.       DirFCol := lightgray;
  157.       HiFcol := black;
  158.       HiBcol := lightgray
  159.   end
  160.   else
  161.   begin
  162.       BoxFCol := lightgray;
  163.       BoxBCol := blue;
  164.       KeyFCol := yellow;
  165.       BacCol := black;
  166.       NorFCol := white;
  167.       DirFCol := yellow;
  168.       HiFcol := black;
  169.       HiBcol := cyan;
  170.   end;
  171.     end; {with}
  172. end;
  173.  
  174.  
  175.  
  176. Function Display_Directory( DIRFULLFilename: StrScreen; var Retcode : integer): StrScreen;
  177. {
  178.         X1                                    X2
  179.      Y1 >      _____________________________________
  180.         |                                     | >
  181.         |                                     | >  Infodepth
  182.         |                                     | >
  183.      Y2 >     |_____________________________________| >
  184.         |                                     |
  185.         |                                     |
  186.         |                                     |
  187.         |                                     |
  188.         |                                     |
  189.         |                                     |
  190.      Y3 >     |_____________________________________|
  191.  
  192.  
  193.     Retcodes >    0  -  filechosen
  194.         1  -  user escaped
  195.         2  -  not enough memory
  196.         3  -  no files matching
  197.         99 -  unexpected error
  198.  
  199. }
  200. Type
  201.   FRptr = ^FR;
  202.   FR = record
  203.       Name : string[8];
  204.       Ext  : string[3];
  205.       Size : longint;
  206.       Time : longint;
  207.       Attr : byte;
  208.       Fn : integer;
  209.       PrevFR: FRptr;
  210.       NextFR : FRptr;
  211.        end;
  212.  
  213. const
  214.   OKCode = 0;           {ret codes}
  215.   EscCode = 1;
  216.   MemCode = 2;
  217.   NofilesCode = 3;
  218.   UnKnownCode = 99;
  219.   InfoDepth = 4;        {no of lines in information box, i.e.Y1 to Y2}
  220.   ReadMsg = 'Reading files';
  221.   SortMsg = 'Sorting files';
  222.   NoneMsg = 'No files ... ';
  223. var
  224.   X1,X2,Y1,Y2,Y3,R,Y3_Unzoomed : byte;{box dimensions}
  225.   StartDir : StrScreen;      {default directory}
  226.   ColumnsWide : byte;
  227.   TopFn : integer;           {file number of top file in the display}
  228.   BotFn : integer;           {file number of bottom file in the display}
  229.   HiFn  : integer;           {file number of hilighted file}
  230.   Zoomed: boolean;           {is file display extended to bottom of screen}
  231.   ShowingDetails : boolean;
  232.   PathName : StrScreen;      {the path section of filename}
  233.   FileMask : StrScreen;
  234.   FirstFile : FRptr;
  235.   List_End : FRptr;
  236.   ChosenFile: strscreen;
  237.   TotalFiles: word;
  238.   TotalDirs : word;
  239.   TotalBytes: LongInt;
  240.   Ftemp : FRPtr;
  241.   Scrn : pointer;
  242.   CursRec : array[1..4] of byte;
  243.   SortOrder : byte;               {1-DOS, 2-Name, 3-Ext, 4-Size, 5-Time}
  244.   SortAsc : boolean;
  245.  
  246.     Function Subdirectory(B : byte):boolean;
  247.     begin
  248.   Subdirectory := ((B and Directory) = Directory);
  249.     end;
  250.  
  251.     Function FileAttribs(B:byte):StrScreen;
  252.     var
  253.       S : StrScreen;
  254.     begin
  255.   S := '    ';
  256.   If ((B and ReadOnly) = Readonly) then
  257.      S[1] := 'R';
  258.   If ((B and Hidden) = Hidden) then
  259.      S[2] := 'H';
  260.   If ((B and SysFile) = SysFile) then
  261.      S[3] := 'S';
  262.   If ((B and Archive) = Archive) then
  263.      S[4] := 'A';
  264.   FileAttribs := S;
  265.      end;
  266.  
  267.      Function LongFileDesc(F:FRptr):StrScreen;
  268.      var
  269.        DT :datetime;
  270.        S  : StrScreen;
  271.      begin
  272.    If ShowingDetails then
  273.    begin
  274.        with F^ do
  275.        begin
  276.       UnPackTime(Time,DT);
  277.       With DT do
  278.       begin
  279.           If Ext = '' then
  280.         S := Padleft(Name,12,' ')
  281.           else
  282.         S :=  Padleft(Name+'.'+Ext,12,' ');                 {start with name}
  283.           If Subdirectory(Attr) then                  {add file size}
  284.         S := S + Padright('<DIR>',8,' ')
  285.           else
  286.         S := S + Padright(Int_to_Str(Size),8,' ');
  287.           S := S + '    ';
  288.           Case Month of                               {add month}
  289.           1 : S := S + 'Jan ';
  290.           2 : S := S + 'Feb ';
  291.           3 : S := S + 'Mar ';
  292.           4 : S := S + 'Apr ';
  293.           5 : S := S + 'May ';
  294.           6 : S := S + 'Jun ';
  295.           7 : S := S + 'Jul ';
  296.           8 : S := S + 'Aug ';
  297.           9 : S := S + 'Sep ';
  298.           10: S := S + 'Oct ';
  299.           11: S := S + 'Nov ';
  300.           12: S := S + 'Dec ';
  301.           end;
  302.           S :=   S                                   {add the day,year}
  303.           + Padright(Int_to_Str(Day),2,'0')
  304.           + ','
  305.           + Int_to_Str(Year)
  306.           + '    ';
  307.           If Hour > 12 then                          {add a/p time}
  308.         S :=  S
  309.              +Padright(Int_to_Str(Hour-12),2,' ')
  310.              +':'
  311.              +Padright(Int_to_Str(Min),2,'0')
  312.              +'p'
  313.           else
  314.         S :=  S
  315.               +Padright(Int_to_Str(Hour),2,' ')
  316.               +':'
  317.               +Padright(Int_to_Str(Min),2,'0')
  318.               +'a';
  319.         S := S + '  '+FileAttribs(Attr);
  320.       end;   {with DT}
  321.        end; {with F^}
  322.    end
  323.    else    {not one column}
  324.     If F^.Ext = '' then
  325.        S := Padleft(F^.Name,12,' ')
  326.     else
  327.        S := Padleft(F^.Name+'.'+F^.Ext,12,' ');
  328.    LongFileDesc := S;
  329.      end;
  330.  
  331.     Function PathSlash(S : StrScreen):StrScreen;
  332.     begin
  333.   If S[length(S)] <> '\' then
  334.      S := S + '\';
  335.   PathSlash := S;
  336.     end;  {Sub Func PathSlash}
  337.  
  338.     Function PathNoSlash(S : StrScreen):StrScreen;
  339.     begin
  340.   If S[length(S)] = '\' then
  341.      Delete(S,length(S),1);
  342.   PathNoSlash := S;
  343.     end;  {Sub Func PathSlash}
  344.  
  345.     Function PathParent(S : StrScreen):StrScreen;
  346.     var P1 : byte;
  347.     begin
  348.   S := PathNoSlash(S);
  349.   P1 := LastPos('\',S);
  350.   PathParent := copy(S,1,P1);
  351.     end;
  352.  
  353.     Function PathChild(S : StrScreen):StrScreen;
  354.     begin
  355.   PathChild := PathSlash(PathName + S);
  356.     end;
  357.  
  358.     Procedure Extract_Path_Mask;
  359.     var P1,P2 : byte;
  360.     begin
  361.   P1 := LastPos('\',DIRFULLFileName);
  362.   P2 := Pos(':',DIRFULLFilename);
  363.   If (P1 = 0) and (P2 = 0) then
  364.   begin
  365.       FileMask := DIRFULLFileName;
  366.       PathName := PathSlash(StartDir);
  367.       exit;
  368.   end;
  369.   If P1 = length(DIRFULLFileName) then
  370.   begin
  371.       FileMask := '*.*';
  372.       PathName := DIRFULLFileName;
  373.       exit;
  374.   end;
  375.   If (P1 = 0) and (P2 = 2) then   { x:filename.ext}
  376.   begin
  377.      Filemask := copy(DIRFULLFileName,3,length(DIRFULLFileName));
  378.      {$I-}
  379.      GetDir(ord(upcase(DIRFULLFileName[1]))-64,PathName);
  380.      {$I-}
  381.      If IOResult <> 0 then
  382.         PathName := PathSlash(StartDir)
  383.      else
  384.         PathName := PathSlash(PathName);
  385.      exit;
  386.   end;
  387.   Filemask := copy(DIRFULLFileName,succ(P1),12);
  388.   PathName := copy(DIRFULLFileName,1,P1);
  389.     end;  {Extract_Path_Mask}
  390.  
  391.     Procedure LoadFiles(Mask:StrScreen;Attrib:byte);
  392.     var
  393.       Finfo : SearchRec;
  394.       Recsize : word;
  395.  
  396.       Procedure PushOnHeap(var F:FrPtr);
  397.       var P : byte;
  398.       begin
  399.     with F^ do
  400.     begin
  401.         Attr := Finfo.Attr;
  402.         Time := Finfo.Time;
  403.         Size := Finfo.Size;
  404.         If FInfo.Name = '..' then
  405.         begin
  406.        Name := '..';
  407.        Ext := '';
  408.         end
  409.         else
  410.         begin
  411.        P := pos('.',Finfo.Name);
  412.        If P = 0 then
  413.        begin
  414.            Name := Finfo.Name;
  415.            Ext := '';
  416.       end
  417.       else
  418.       begin
  419.           Name := copy(FInfo.Name,1, pred(P));
  420.           Ext := copy(Finfo.Name,succ(P),3);
  421.       end;
  422.         end;
  423.         Fn := succ(TotalFiles);
  424.         NextFR := nil;
  425.         PrevFr := nil;
  426.         TotalBytes := TotalBytes + Size;
  427.     end;
  428.     Inc(TotalFiles);
  429.     If Finfo.Attr = Directory then
  430.        Inc(TotalDirs);
  431.       end;   {sub sub proc TransferFileToHeap}
  432.  
  433.       Procedure AllocHeap;
  434.       begin
  435.     If ( (Attrib = Directory) and (FInfo.Attr <> Directory) ) then
  436.        exit;   {if only looking for directory entries}
  437.     If (Finfo.Name <> '.') and (DosError = 0) then
  438.     begin
  439.         If (TotalFiles = 0) then
  440.         begin
  441.        PushOnHeap(FirstFile);
  442.        FirstFile^.PrevFR := nil;
  443.        Ftemp :=  FirstFile;
  444.        List_End := FirstFile;
  445.         end
  446.         else
  447.         begin
  448.        GetMem(Ftemp^.NextFR,Recsize);
  449.        PushOnHeap(FTemp^.NextFr);
  450.        FTemp := Ftemp^.NextFR;
  451.        FTemp^.PrevFR := List_End;
  452.        List_End := Ftemp;
  453.         end; {If TotalFiles = 0}
  454.    end; { If name <> '.'}
  455.       end;
  456.  
  457.     begin
  458.   RecSize := Sizeof(FirstFile^);
  459.   If MaxAvail < 2*Recsize then
  460.   begin
  461.       NoMemory := true;
  462.       exit;
  463.   end;
  464.   Fastwrite(X1+2,Y2+1,attr(DTTT.NorFcol+blink,DTTT.BacCol),ReadMsg);
  465.   FindFirst(PathName+Mask,Attrib,Finfo);
  466.   If DosError <> 0 then
  467.      exit;
  468.   If TotalFiles = 0 then
  469.   begin
  470.      GetMem(FirstFile,RecSize);
  471.            FirstFile^.NextFr := nil; {5.02c}
  472.   end;
  473.   AllocHeap;
  474.   While (DosError = 0) and (NoMemory = false) do
  475.   begin
  476.       If MaxAvail < RecSize then
  477.          NoMemory := true
  478.       else
  479.       begin
  480.      FindNext(Finfo);
  481.      AllocHeap;
  482.       end; {If MaxAvail}
  483.   end; {while}
  484.     end; {Sub Proc Loadfiles}
  485.  
  486.     Procedure UnLoadFiles;
  487.     {runs down the linked list and FREES all the data
  488.     on the heap}
  489.     var
  490.        Temp1,
  491.        Temp2 : FRPtr;
  492.     begin
  493.        Temp1 := FirstFile;
  494.        while Temp1 <> Nil do
  495.        begin
  496.     Temp2 := Temp1;
  497.     Temp1 := Temp1^.NextFr;
  498.     FreeMem(Temp2,sizeof(Temp2^));
  499.        end;
  500.        FirstFile := nil;   {5.02c}
  501.     end; {of proc UnLoadFiles}
  502.  
  503.  
  504.     Procedure Calculate_Box_Dimensions;
  505.     var
  506.       Boxwidth : byte;
  507.     begin
  508.   If ShowingDetails then
  509.      Boxwidth := 54
  510.   else
  511.      Boxwidth := succ(DTTT.Colswide*14);
  512.   with DTTT do
  513.   begin
  514.       If (TopX < 1) or (TopX > 80) then
  515.          X1 :=  (80 - Boxwidth) div 2
  516.       else
  517.       begin
  518.          If TopX <= (80 - Boxwidth) then
  519.        X1 := TopX
  520.          else                               {move box left until it fits}
  521.        X1 := 80 - Boxwidth;
  522.       end;
  523.       X2 := X1 + Boxwidth;
  524.       If Rows in [1..23] then
  525.          R := Rows
  526.       else
  527.          R := 8;
  528.       If (TopY < 1) or (TopY > DisplayLines - 2) then
  529.          Y1 := 5
  530.       else
  531.          Y1 := TopY;
  532.       If not DisplayInfo then
  533.          Y2 := Y1
  534.       else
  535.       begin
  536.      If Y1 + InfoDepth < DisplayLines - 2 then
  537.         Y2 := Y1 + InfoDepth
  538.      else                               {no room for info}
  539.         Y2 := Y1;
  540.       end;
  541.       Y3 := Y2 + succ(R);
  542.       If Y3 > DisplayLines then
  543.       begin
  544.          Y3 := DisplayLines;
  545.          If Y2 <> Y1 then
  546.          begin
  547.         Y2 := Y3 - succ(R);
  548.         Y1 := Y2 - InfoDepth;
  549.          end
  550.          else
  551.          begin
  552.         Y2 := Y3 - succ(R);
  553.         Y1 := Y2;
  554.          end;
  555.       end;
  556.   end;
  557.     end;  {sub proc Calculate_Box_Dimensions}
  558.  
  559.     Procedure Display_Box;
  560.     var
  561.       LChar,Rchar : char;
  562.       Col,
  563.       I : integer;
  564.     begin
  565.   with DTTT do
  566.   begin
  567.       If Y2 = Y1 then
  568.          ClearText(X1,Y1,X2,Y3,NorFCol,Baccol)
  569.       else
  570.       begin
  571.      ClearText(X1,Y1,X2,pred(Y2),BoxFCol,BoxBcol);
  572.      ClearText(X1,Y2,X2,Y3,NorFCol,Baccol);
  573.       end;
  574.       Col := attr(BoxFcol,BoxBCol);
  575.       If (BoxType in [5..9]) then
  576.       begin
  577.      Box(X1,Y1,X2,Y3,BoxFcol,BoxBcol,Boxtype-5);
  578.      If (X2 < 80) and (Y3 < DisplayLines) then
  579.      begin
  580.          For I := succ(Y1) to succ(Y3) do
  581.         Fastwrite(succ(X2),I,ShadColor,chr(219));
  582.          Fastwrite(succ(X1),succ(Y3),ShadColor,replicate(X2-X1,chr(219)));
  583.      end;
  584.       end
  585.       else
  586.          Box(X1,Y1,X2,Y3,BoxFcol,BoxBcol,Boxtype);
  587.       If Y2 > Y1 then
  588.       begin
  589.      Horizline(succ(X1),pred(X2),Y2,BoxFCol,BoxBcol,Boxtype);
  590.      Case Boxtype of
  591.      1,6 : begin
  592.           LChar := chr(195);
  593.           RChar := chr(180);
  594.            end;
  595.      2,7 : begin
  596.           LChar := chr(204);
  597.           RChar := chr(185);
  598.            end;
  599.      3,8 : begin
  600.           LChar := chr(199);
  601.           RChar := chr(182);
  602.            end;
  603.      4,9 : begin
  604.           LChar := chr(181);
  605.           RChar := chr(198);
  606.            end;
  607.      else      Lchar := ' ';
  608.           Rchar := ' ';
  609.      end;  {case}
  610.      Fastwrite(X1,Y2,Col,Lchar);
  611.      Fastwrite(X2,Y2,Col,Rchar);
  612.       end;
  613.   end;
  614.     end;  {sub proc display box}
  615.  
  616.     Procedure DisplayPath;
  617.     var
  618.        L : byte;
  619.        Y : byte;
  620.        P : StrScreen;
  621.     begin
  622.   P := Pathname+Filemask;
  623.   L := length(P);
  624.   If Y2 = Y1 then
  625.   begin
  626.      Y := Y1;
  627.      If L > (X2-X1-2) then
  628.         P := chr(17)+copy(P,L-(X2-X1)+4,L);
  629.   end
  630.   else
  631.   begin
  632.      Y := Y1 + 2;
  633.      If L > (X2-X1-2) then
  634.         P := chr(17)+copy(P,L-(X2-X1-1)+4,L);
  635.   end;
  636.   Fastwrite(X1+2,Y,attr(DTTT.BoxFcol,DTTT.BoxBCol),P);
  637.     end;  {sub Proc DisplayPath}
  638.  
  639.  
  640.     Procedure FillInfo;
  641.     var
  642.       TB,Di : StrScreen;
  643.       C,H,L  : byte;
  644.     begin
  645.   with DTTT do
  646.   begin
  647.       C := attr(BoxFCol,BoxBCol);
  648.       H := attr(KeyFcol,BoxBCol);
  649.       If (Y2 = Y1) then
  650.       begin
  651.      DisplayPath;
  652.      exit;
  653.       end;
  654. {$IFDEF DIRFULL}
  655.       If  (ColumnsWide < 3 ) and (ShowingDetails = false) then
  656.       begin
  657.      DisplayPath;
  658.      Fastwrite(X1+2,Y1+1,H,chr(17)+char(217));
  659.      Fastwrite(X1+5,Y1+1,C,'Select');
  660.      Fastwrite(X1+2,Y1+3,C,'Files: ');
  661.      Fastwrite(X1+9,Y1+3,C,Int_To_Str(TotalFiles-TotalDirs));
  662.      exit;
  663.       end;
  664.       ClearText(succ(X1),Succ(Y1),pred(X2),Pred(Y2),BoxFcol,BoxBCol);
  665.       Fastwrite(X1 + 2,Y1 + 3,C,'Matching files: ');
  666.       Fastwrite(X1 + 18,Y1 + 3,C,Int_To_Str(TotalFiles-TotalDirs));
  667.       TB := 'Total bytes: '+Int_To_Str(TotalBytes);
  668.       Fastwrite(X2 -length(TB) - 1,Y1 + 3,C,TB);
  669.       If AllowHelp then
  670.       begin
  671.      Fastwrite(X1+2,Y1+1,H,DHelpStr);    {Prompt at left}
  672.      Fastwrite(X1+3+length(DHelpStr),Y1+1,C,'Help');
  673.       end;
  674.       L := pred(X1)
  675.          + ((X2-X1) div 2)
  676.          - (length(DToggleStr)+ 7) div 2;     {next prompt in center}
  677.       Fastwrite(L,Y1+1,H,chr(17)+char(217));
  678.       L := L + 3;
  679.       Fastwrite(L,Y1+1,C,'Select');
  680.       If AllowToggle then
  681.       begin
  682.      L := X2 - length(DToggleStr) - 8;   {right justified}
  683.      Fastwrite(L,Y1+1,H,DToggleStr);
  684.      L := L + 1 + length(DToggleStr);
  685.      Fastwrite(L,Y1+1,C,'Toggle');
  686.       end;
  687.   end;
  688.   DisplayPath;
  689. {$ELSE}
  690.        end;
  691. {$ENDIF}
  692.     end;  {sub proc Fillinfo}
  693.  
  694.     Function FilePointer(Fn:word): FRptr;
  695.     {MODIFY to go from current pointer - for speed}
  696.     var
  697.       P : FRptr;
  698.       I : integer;
  699.     begin
  700.   If  SortAsc then
  701.   begin
  702.       P := FirstFile;
  703.       If Fn > 1 then
  704.          For I := 2 to Fn do
  705.         P := P^.NextFr;
  706.   end
  707.   else {Descending}
  708.   begin
  709.       P := List_End;
  710.       If Fn > 1 then
  711.          For I := 2 to Fn do
  712.         P := P^.PrevFr;
  713.   end;
  714.   FilePointer := P;
  715.     end;  {sub proc filepointer}
  716.  
  717.     Function Y_Coord(Fn : word):byte;
  718.     begin
  719.    Y_Coord := Succ(Y2) + ((Fn-TopFn) DIV ColumnsWide);
  720.     end;
  721.  
  722.     Function X_Coord(Fn : word):byte;
  723.     begin
  724.      X_Coord := succ(X1) + 14*((Fn-TopFn) MOD Columnswide);
  725.     end;
  726.  
  727.     Function TopLine:Boolean;
  728.     begin
  729.     TopLine := (HiFn <= ColumnsWide);
  730.     end;
  731.  
  732.     Function BottomLine:Boolean;
  733.     begin
  734.     BottomLine := (HiFn + ColumnsWide > TotalFiles);
  735.     end;
  736.  
  737.     Function FirstColumn:boolean;
  738.     begin
  739.      If Columnswide = 1 then
  740.         FirstColumn := true
  741.      else
  742.         FirstColumn := (HiFn MOD ColumnsWide = 1);
  743.     end;
  744.  
  745.     Function LastColumn:boolean;
  746.     begin
  747.      LastColumn := (HiFn MOD ColumnsWide = 0);
  748.     end;
  749.  
  750.     Procedure RecalcTopFn;
  751.     begin
  752.   If ColumnsWide = 1 then
  753.      TopFn := succ(BotFn -R)
  754.   else
  755.       TopFn :=  Succ(   BotFn
  756.             - pred(R)*ColumnsWide
  757.             - BotFn MOD ColumnsWide
  758.           );
  759.     end;
  760.  
  761.     Procedure RecalcBotFn;
  762.     begin
  763.   BotFn := pred( TopFn + ColumnsWide*R);
  764.   If BotFn > TotalFiles then
  765.      BotFn := TotalFiles;
  766.     end;
  767.  
  768.     Procedure LolightFile(Fn:word);
  769.     var
  770.       C : byte;
  771.       F : FRptr;
  772.     begin
  773.   If (Fn < TopFn) or (Fn > BotFn ) then
  774.      exit;    {file not in display area}
  775.   F := Filepointer(Fn);
  776.   If Subdirectory(F^.Attr) then
  777.      C := attr(DTTT.DirFcol,DTTT.BacCol)
  778.   else
  779.      C := attr(DTTT.NorFCol,DTTT.BacCol);
  780.   Fastwrite(X_Coord(Fn),
  781.        Y_Coord(Fn),
  782.        C,
  783.        ' '+LongFileDesc(F)+' ');
  784.     end;
  785.  
  786.     Procedure HilightFile(Fn:word);
  787.     var
  788.       F : FRptr;
  789.     begin
  790.   If (Fn < TopFn) or (Fn > BotFn) then
  791.      exit;    {file not in display area}
  792.   F := Filepointer(Fn);
  793.   Fastwrite(X_Coord(Fn),
  794.        Y_Coord(Fn),
  795.        attr(DTTT.HiFcol,DTTT.HiBCol),
  796.        ' '+LongFileDesc(F)+' ')
  797.     end;
  798.  
  799.     Function File_name(Fn : word):StrScreen;
  800.     var
  801.        F : FRPtr;
  802.        Fname : strscreen;
  803.     begin
  804.   F := FilePointer(Fn);
  805.   Fname := F^.Name;
  806.   If F^.Ext <> '' then
  807.      Fname := Fname+'.'+F^.Ext;
  808.   File_Name := Fname;
  809.     end;   {Sub Funct File_name}
  810.  
  811.     Procedure DisplayFiles;
  812.     var
  813.       I : integer;
  814.     begin
  815.   If (Columnswide > 1) and (BotFn = TotalFiles) then    {clear line}
  816.      ClearText(succ(X1),pred(Y3),Pred(X2),pred(Y3),DTTT.NorFcol,DTTT.BacCol);
  817.   For I := TopFn to BotFn do
  818.       If (I <> HiFn) and (I <= TotalFiles) then
  819.          LolightFile(I);
  820.   HiLightFile(HiFn);
  821.     end; {sub proc DisplayFiles}
  822.  
  823.     Procedure Scroll_Down;
  824.     begin
  825.   TopFn := TopFn + Columnswide;
  826.   RecalcBotFn;
  827.   DisplayFiles;
  828.     end; {scroll_down}
  829.  
  830.     Procedure Scroll_Up;
  831.     begin
  832.   TopFn := TopFn - Columnswide;
  833.   RecalcBotFn;
  834.   DisplayFiles;
  835.     end; {scroll_up}
  836.  
  837.     Procedure Scroll_Top;
  838.     begin
  839.   TopFn := 1;
  840.   RecalcBotFn;
  841.   HiFn := 1;
  842.   DisplayFiles;
  843.     end; {scroll_Home}
  844.  
  845.     Procedure Scroll_Bottom;
  846.     begin
  847.   TopFn := succ(TotalFiles - R);
  848.   BotFn := TotalFiles;
  849.   HiFn := TotalFiles;
  850.   DisplayFiles;
  851.     end; {scroll_Home}
  852.  
  853.  
  854. {\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\    SORTING   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}
  855. {$IFDEF DIRFULL}
  856.  
  857. Function Larger(Ptr1,Ptr2: FRptr) : boolean;
  858. var
  859.    N1,N2 : string[8];
  860.    E1,E2 : string[8];
  861. begin
  862.     Case SortOrder of
  863.     DSortDos   : Larger := (Ptr1^.Fn > Ptr2^.Fn);
  864.     DSortNAME  : If Ptr1^.Name = Ptr2^.Name then
  865.          Larger := Ptr1^.Ext > Ptr2^.Ext
  866.       else
  867.          Larger := Ptr1^.Name > Ptr2^.Name;
  868.     DSortEXT   : If Ptr1^.Ext = Ptr2^.Ext then
  869.          Larger := Ptr1^.Name > Ptr2^.Name
  870.       else
  871.          Larger := Ptr1^.Ext > Ptr2^.Ext;
  872.     DSortSIZE  : Larger := (Ptr1^.Size > Ptr2^.Size);
  873.     DSortTIME  : Larger := (Ptr1^.Time > Ptr2^.Time);
  874.     else Larger := false;
  875.     end; {Case}
  876. end; {suc proc larger}
  877.  
  878. Procedure SwapIt(var Ptr1,Ptr2: FRPtr);
  879. var
  880.    Temp : FR;
  881.    Size : integer;
  882. begin
  883.     Temp := Ptr2^;
  884.     Size := sizeof(Temp) - 8;
  885.     Move(Ptr1^,Ptr2^,Size);
  886.     Move(Temp,Ptr1^,Size);
  887. end;  {sub proc Swap}
  888.  
  889. Procedure ShellSort;
  890. var
  891.    I,J,Delta : longint;
  892.    Swapped : boolean;
  893.    Ptr1,Ptr2 : FRPtr;
  894.  
  895. begin
  896.     Delta := TotalFiles div 2;
  897.     repeat
  898.    Repeat
  899.         Swapped := false;
  900.         Ptr1 := FirstFile;
  901.         Ptr2 := Ptr1;
  902.         For I := 1 to Delta do
  903.        Ptr2 := Ptr2^.NextFr;
  904.         For I := 1 to TotalFiles - Delta do
  905.         begin
  906.        If I > 1 then
  907.        begin
  908.            Ptr1 := Ptr1^.NextFr;
  909.            Ptr2 := Ptr2^.NextFr;
  910.        end;
  911.        If Larger(Ptr1,Ptr2) then
  912.        begin
  913.            SwapIt(Ptr1,Ptr2);
  914.            Swapped := true;
  915.        end;
  916.         end;
  917.    Until (not Swapped);
  918.    Delta := delta div 2;
  919.     Until Delta = 0;
  920. end;
  921.  
  922.            Procedure ReSort;
  923.            begin
  924.            ClearText(succ(X1),Succ(Y2),pred(X2),pred(Y3),DTTT.NorFcol,DTTT.BacCol);
  925.            Fastwrite(X1 + 2,succ(Y2),attr(DTTT.NorFcol+blink,DTTT.BacCol),SortMsg);
  926.            ShellSort;
  927.            TopFn := 1;
  928.            HiFn := 1;
  929.            RecalcBotFn;
  930.            DisplayFiles;
  931.            end;
  932. {$ENDIF}
  933.  
  934.     Procedure DisplayNewDirectory;
  935.     var A : byte;
  936.     begin
  937.   A := DTTT.attrib and (AnyFile - VolumeID);
  938.   Display_Box;
  939.   TotalFiles := 0;
  940.   TotalBytes := 0;
  941.   TotalDirs  := 0;
  942.   If DTTT.AllowCd or DTTT.SelectDir then
  943.   begin
  944.       If Subdirectory(A) then
  945.       begin
  946.       LoadFiles('*.*',Directory);                {load directory details first}
  947.       If A <> Directory then                     {Fix 5.01A}
  948.          Loadfiles(Filemask,A and (anyfile - Directory));  {then load other files with mask}
  949.       end
  950.       else
  951.       LoadFiles(Filemask,A and (Anyfile - Directory));
  952.   end
  953.   else                  {automatically removed directory type files}
  954.        LoadFiles(Filemask,A and (anyfile - Directory));
  955.   FillInfo;
  956. {$IFDEF DIRFULL}
  957.   If SortOrder <> DSortDOS then
  958.      ShellSort;
  959. {$ENDIF}
  960.   If TotalFiles = 0 then
  961.      Fastwrite(X1+2,Y2+1,attr(DTTT.NorFcol,DTTT.BacCol),NoneMsg)
  962.   else
  963.      Scroll_Top;
  964.     end;  {sub proc DisplayNewDirectory}
  965.  
  966. {$IFDEF DIRFULL}
  967.     Procedure ShowHelpScreen;
  968.     const
  969.   width = 55;
  970.   depth = 14;
  971.     var
  972.       Str : StrScreen;
  973.       S  : word;
  974.       Sc : pointer;
  975.       X,Y : byte;
  976.       ChH : char;
  977.     begin
  978.   If X1 + width > 80 then
  979.      X := pred((80 - width) div 2)
  980.   else
  981.      X := X1;
  982.   If Y1 + Depth > DisplayLines then
  983.      Y := pred((DisplayLines -Depth) div 2)
  984.   else
  985.      Y := Y1;
  986.   S := 160*DisplayLines;
  987.   If MaxAvail < S then
  988.      exit;
  989.   GetMem(Sc,S);
  990.   MoveFromScreen(BaseOfScreen^,Sc^,S Div 2);
  991.   FBox(X,Y,pred(X+ width),pred(Y+Depth),DTTT.BoxFCol,DTTT.BoxBCol,1);
  992.   Case SortOrder of
  993.   DSortDos  : Str := ' DOS';
  994.   DSortName : Str := ' NAME';
  995.   DSortExt  : Str := ' EXT';
  996.   DSortSize : Str := ' SIZE';
  997.   DSortTime : Str := ' TIME';
  998.   end; {case}
  999.   If SortAsc then
  1000.      Str := Str +' in ASCENDING order'
  1001.   else
  1002.      Str := Str +' in DESCENDING order';
  1003.   If Zoomed then
  1004.      Str := Str +' (Zoomed) '
  1005.   else
  1006.      Str := Str+' (not zoomed) ';
  1007.   Str := ' Current: '+Str;
  1008.   WriteBetween(X,X + Width,pred(Y)+depth,DTTT.KeyFCol,DTTT.BoxBCol,Str);
  1009.   If DTTT.AllowSort then
  1010.   begin
  1011.       Fastwrite(X+4,Y+2,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortDOSStr);
  1012.       Fastwrite(X+7+length(DSortDOSStr),Y+2,
  1013.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1014.            'sort in native DOS order');
  1015.       Fastwrite(X+4,Y+3,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortNameStr);
  1016.       Fastwrite(X+7+length(DSortNameStr),Y+3,
  1017.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1018.            'sort alphabetically by file Name');
  1019.       Fastwrite(X+4,Y+4,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortExtStr);
  1020.       Fastwrite(X+7+length(DSortExtStr),Y+4,
  1021.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1022.            'sort alphabetically by file Extension');
  1023.       Fastwrite(X+4,Y+5,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortSizeStr);
  1024.       Fastwrite(X+7+length(DSortSizeStr),Y+5,
  1025.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1026.            'sort by file Size');
  1027.       Fastwrite(X+4,Y+6,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortTimeStr);
  1028.       Fastwrite(X+7+length(DSortTimeStr),Y+6,
  1029.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1030.            'sort by date/Time of file');
  1031.       Fastwrite(X+4,Y+7,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortOrderStr);
  1032.       Fastwrite(X+7+length(DSortOrderStr),Y+7,
  1033.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1034.            'sort in ascending or descending Order');
  1035.   end
  1036.   else
  1037.      WriteBetween(X,X+Width,Y+3,DTTT.BoxFCol,DTTT.BoxBCol,'SORTING DISABLED');
  1038.   If DTTT.AllowZoom then
  1039.   begin
  1040.       Fastwrite(X+4,Y+9,attr(DTTT.KeyFCol,DTTT.BoxBCol),DZoomStr);
  1041.       Fastwrite(X+7+length(DZoomStr),Y+9,
  1042.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1043.            'toggle long/short box size');
  1044.   end;
  1045.   If DTTT.AllowCD then
  1046.   begin
  1047.       Fastwrite(X+4,Y+11,attr(DTTT.KeyFCol,DTTT.BoxBCol),DChangeDirStr);
  1048.       Fastwrite(X+7+length(DChangeDirStr),Y+11,
  1049.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1050.            'change to new drive/directory');
  1051.       Fastwrite(X+4,Y+12,attr(DTTT.KeyFCol,DTTT.BoxBCol),DJumpParentSTr);
  1052.       Fastwrite(X+7+length(DJumpParentStr),Y+12,
  1053.            attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1054.            'backup to parent directory');
  1055.   end;
  1056.   WriteBetween(X, X + Width, Y,
  1057.           DTTT.BoxFCol + Blink, DTTT.BoxBCol,
  1058.           ' press any key ... ');
  1059.  
  1060.   ChH := upcase(GetKey);
  1061.   MoveToScreen(Sc^,BaseOfScreen^, S Div 2);
  1062.   FreeMem(Sc,S);
  1063.     end;
  1064.  
  1065.     Procedure PromptForDirectory;
  1066.     const
  1067.        width = 55;
  1068.     var
  1069.        S : word;
  1070.        Sc : pointer;
  1071.        X : byte;
  1072.        OldP,OldM,Strng : String;
  1073.     begin
  1074.   S := 160*DisplayLines;
  1075.   If MaxAvail < S then
  1076.      exit;
  1077.   OldP := Pathname;
  1078.   OldM := FileMask;
  1079.   GetMem(Sc,S);
  1080.   MoveFromScreen(BaseOfScreen^,Sc^,S Div 2);    {SaveThescreen}
  1081.   If X1 + width > 80 then
  1082.      X := pred((80 - width) div 2)
  1083.   else
  1084.      X := X1;
  1085.   FBox(X,Y1,pred(X + width),Y1 + 2,DTTT.BoxFCol,DTTT.BoxBCol,2);
  1086.   WriteBetween(X,X+Width,Y1,DTTT.KeyFCol,DTTT.BoxBCol,'  Directory of Files  ');
  1087.   Strng := PathName+FileMask;
  1088.   Read_String_Upper(X+1,Y1+1,width - 2,'',0,Strng);
  1089.   MoveToScreen(Sc^,BaseOfScreen^, S Div 2);
  1090.   FreeMem(Sc,S);
  1091.   If (R_Char <> #027) then
  1092.   begin
  1093.       DIRFULLFileName := Strng;
  1094.       Extract_Path_Mask;
  1095.       UnLoadFiles;
  1096.       DisplayNewDirectory;
  1097.       If TotalFiles = 0 then   {re-read original directory}
  1098.       begin
  1099.          sound(800);delay(200);nosound;
  1100.          PathName := OldP;
  1101.          FileMask := OldM;
  1102.          UnLoadFiles;
  1103.          DisplayNewDirectory;
  1104.       end;
  1105.   end;
  1106.     end;
  1107.  
  1108.     Function PromptForFilename(C:char):string;
  1109.     const
  1110.        width = 55;
  1111.     var
  1112.        S : word;
  1113.        Sc : pointer;
  1114.        X : byte;
  1115.        Strng : String;
  1116.        Msg : Strscreen;
  1117.     begin
  1118.   S := 160*DisplayLines;
  1119.   If MaxAvail < S then
  1120.      exit;
  1121.   GetMem(Sc,S);
  1122.   MoveFromScreen(BaseOfScreen^,Sc^,S Div 2);    {SaveThescreen}
  1123.   If X1 + width > 80 then
  1124.      X := pred((80 - width) div 2)
  1125.   else
  1126.      X := X1;
  1127.   FBox(X,Y1,pred(X + width),Y1 + 2,DTTT.BoxFCol,DTTT.BoxBCol,2);
  1128.   If C = #0 then
  1129.   begin
  1130.      Msg := '  No files  - enter filename  ';
  1131.      Strng := '';
  1132.   end
  1133.   else
  1134.   begin
  1135.      Msg := '  Enter filename (or Esc)  ';
  1136.      Strng := C;
  1137.   end;
  1138.   WriteBetween(X,X+Width,Y1,DTTT.KeyFCol,DTTT.BoxBCol,Msg);
  1139.   Read_String_Upper(X+1,Y1+1,width-2,'',0,Strng);
  1140.   MoveToScreen(Sc^,BaseOfScreen^, S Div 2);
  1141.   FreeMem(Sc,S);
  1142.   If (R_Char <> #027) then
  1143.       PromptForFilename := Strng
  1144.   else
  1145.       PromptForFilename := '';
  1146.     end;
  1147.  
  1148. {$ENDIF}
  1149.  
  1150. {\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}
  1151. {$IFDEF DIRFULL}
  1152.      Function No_Files_Found: integer;
  1153.      {returns 99 if user escaped
  1154.      or 0  if user enter a file
  1155.      }
  1156.      begin
  1157.  
  1158.    ChosenFile := PromptForFilename(#0);
  1159.    If ChosenFile = '' then
  1160.    begin
  1161.        No_Files_Found := 99;
  1162.        exit;
  1163.    end;
  1164.    If (pos('*',ChosenFile) > 0)
  1165.    or (pos('?',ChosenFile) > 0)
  1166.    or (ChosenFile[Length(ChosenFile)] = '\') then
  1167.    begin
  1168.        DIRFULLFileName := ChosenFile;
  1169.        Extract_Path_Mask;
  1170.        UnLoadFiles;
  1171.        DisplayNewDirectory;
  1172.    end
  1173.    else
  1174.    begin
  1175.        If  (pos('\',ChosenFile) = 0)
  1176.        and (pos(':',ChosenFile) = 0) then
  1177.        begin
  1178.       ChosenFile := PathName + ChosenFile;
  1179.       No_Files_Found := 0;
  1180.       exit;
  1181.        end;
  1182.    end;
  1183.    No_Files_Found := 1;
  1184.      end; {of func No_Files_Found}
  1185. {$ENDIF}
  1186.  
  1187.     Procedure Process_Keys;
  1188.     var
  1189.       ChD : char;
  1190.       Finished : Boolean;
  1191.     begin
  1192.   Finished := false;
  1193.   If TotalFiles = 0 then
  1194.   begin
  1195. {$IFDEF DIRFULL}
  1196.       Repeat
  1197.       Case No_Files_Found of
  1198.       0 : exit;  {user selected a file}
  1199.       99: begin  {user escaped}
  1200.          Retcode := NoFilesCode;
  1201.          Exit;
  1202.           end;
  1203.       end; {case}
  1204.       until TotalFiles <> 0;
  1205. {$ELSE}
  1206.      Retcode := NoFilesCode;
  1207.      WriteAt(succ(X1),succ(Y2),DTTT.DirFCol,DTTT.BoxBCol,       {5.01}
  1208.      'No files found.... press any key');
  1209.      ChD := GetKey;
  1210.      Exit;
  1211. {$ENDIF}
  1212.   end;
  1213.   Repeat
  1214.        ChD := upcase(GetKey);
  1215.        Case ChD of
  1216.        #129,                  {mouse down, down arrow}
  1217.        #208 :  If not BottomLine then
  1218.           begin
  1219.          LoLightFile(HiFn);
  1220.          Hifn := HiFn + Columnswide;
  1221.          If HiFn <= BotFn then
  1222.             HiLightFile(HiFn)
  1223.          else
  1224.             Scroll_Down;
  1225.           end;
  1226.        #128,                      {mouse up, up arrow}
  1227.        #200 : If not TopLine then
  1228.          begin
  1229.         LoLightFile(HiFn);
  1230.         Hifn := HiFn - Columnswide;
  1231.         If HiFn >= TopFn then
  1232.            HiLightFile(HiFn)
  1233.         else
  1234.            Scroll_Up;
  1235.          end;
  1236.        #205 : If HiFn < TotalFiles then  {right arrow}
  1237.          begin
  1238.         LolightFile(HiFn);
  1239.         Inc(HiFn);
  1240.         If HiFn > BotFn then
  1241.            Scroll_Down
  1242.         else
  1243.            HiLightFile(HiFn);
  1244.          end;
  1245.        #131 : If  (LastColumn = false) and (HiFn < BotFn) then  {mouse right}
  1246.          begin
  1247.         LolightFile(HiFn);
  1248.         Inc(HiFn);
  1249.         HiLightFile(HiFn);
  1250.          end;
  1251.        #130 : If (FirstColumn = false) then   {mouse left}
  1252.          begin
  1253.             LolightFile(HiFn);
  1254.             Dec(HiFn);
  1255.             HiLightFile(HiFn);
  1256.          end;
  1257.        #203 : If HiFn > 1 then {Left arrow}
  1258.          begin
  1259.         LolightFile(HiFn);
  1260.         Dec(HiFn);
  1261.         If HiFn < TopFn then
  1262.            Scroll_Up
  1263.         else
  1264.            HiLightFile(HiFn);
  1265.          end;
  1266.        #199 : If Columnswide = 1 then
  1267.          begin
  1268.         If TopFn = 1 then
  1269.         begin
  1270.             LoLightFile(HiFn);
  1271.             HiFn := 1;
  1272.              HiLightFile(HiFn);
  1273.         end
  1274.         else
  1275.            Scroll_Top;
  1276.          end
  1277.          else  {multiple column}
  1278.          begin
  1279.         If not FirstColumn then   {home}
  1280.         begin
  1281.             LoLightFile(HiFn);
  1282.             HiFn := HiFn - (pred(HiFn) mod ColumnsWide);
  1283.             HiLightFile(HiFn);
  1284.         end;
  1285.          end;
  1286.        #207 : If ColumnsWide = 1  then   {end}
  1287.          begin
  1288.         If TotalFiles <= BotFn then
  1289.         begin
  1290.              LoLightFile(HiFn);
  1291.              HiFn := TotalFiles;
  1292.              HiLightFile(HiFn);
  1293.         end
  1294.         else
  1295.            Scroll_Bottom;
  1296.          end
  1297.          else
  1298.          begin
  1299.         If not LastColumn then
  1300.         begin
  1301.             LoLightFile(HiFn);
  1302.             HiFn := HiFn
  1303.              + Columnswide
  1304.              - HiFn mod ColumnsWide;
  1305.             If HiFn > BotFn then
  1306.                HiFn := BotFn;
  1307.             HiLightFile(HiFn);
  1308.         end;
  1309.          end;
  1310.        #245 : If HiFn < TotalFiles then      {Ctrl End}
  1311.          begin
  1312.         If BotFn = TotalFiles then
  1313.         begin
  1314.              LoLightFile(HiFn);
  1315.              HiFn := TotalFiles;
  1316.              HiLightFile(HiFn);
  1317.         end
  1318.         else
  1319.         begin
  1320.            BotFn := TotalFiles;
  1321.            RecalcTopFn;
  1322.            HiFn := TotalFiles;
  1323.            DisplayFiles;
  1324.         end;
  1325.          end;
  1326.        #201 : If HiFn > 1 then               {PgUp}
  1327.          begin
  1328.         If TopFn > 1 then
  1329.         begin
  1330.             TopFn := TopFn - R*ColumnsWide;
  1331.             If TopFn < 1 then
  1332.                TopFn := 1;
  1333.         end;
  1334.         RecalcBotFn;
  1335.         HiFN := HiFn - R*ColumnsWide;
  1336.         If HiFn < 1 then
  1337.            HiFn := 1;
  1338.         DisplayFiles;
  1339.          end;
  1340.        #209 : If Hifn < TotalFiles then      {PgDn}
  1341.          begin
  1342.         If BotFn < TotalFiles then
  1343.         begin
  1344.             TopFn := TopFN + R*ColumnsWide;
  1345.             BotFn := BotFn + R*ColumnsWide;
  1346.             HiFn := HiFn + R*ColumnsWide;
  1347.             If BotFn > TotalFiles then
  1348.             begin
  1349.            BotFn := TotalFiles;
  1350.            RecalcTopFn;
  1351.            If  (HiFn < TopFn) then
  1352.                Repeat
  1353.               HiFn := HiFn + ColumnsWide;
  1354.                Until HiFN >= TopFN
  1355.            else
  1356.                If (HiFn > BotFn)  then
  1357.               HiFn := BotFn;
  1358.             end;
  1359.             DisplayFiles;
  1360.         end
  1361.         else     {Botfn is last file}
  1362.         begin
  1363.             LoLightFile(HiFn);
  1364.             If BottomLine then
  1365.            HiFn := BotFn
  1366.             else
  1367.            HiFn := HiFn + R*ColumnsWide;
  1368.             If HiFn > BotFn then
  1369.                HiFn := BotFn;
  1370.             HiLightFile(HiFn);
  1371.         end;
  1372.          end;
  1373.        #247 : If HiFn > 1 then      {Ctrl Home}
  1374.          begin
  1375.         If TopFn = 1 then
  1376.         begin
  1377.              LoLightFile(HiFn);
  1378.              HiFn := 1;
  1379.              HiLightFile(HiFn);
  1380.         end
  1381.         else
  1382.            Scroll_Top;
  1383.          end;
  1384.        DTogglekey : If DTTT.AllowToggle then
  1385.          begin
  1386.         ShowingDetails := not ShowingDetails;
  1387.         If Not ShowingDetails then
  1388.            ColumnsWide := DTTT.ColsWide
  1389.         else
  1390.            Columnswide := 1;
  1391.         MoveToScreen(Scrn^,BaseofScreen^,80*DisplayLines);
  1392.         Calculate_Box_Dimensions;
  1393.         If Zoomed then
  1394.         begin
  1395.             Y3 := DTTT.Zoomline;
  1396.             R := pred(Y3 - Y2);
  1397.         end;
  1398.         TopFn := 0;
  1399.         Repeat
  1400.             If TopFN = 0 then
  1401.                TopFn := 1
  1402.             else
  1403.                TopFn := TopFN + R*ColumnsWide;
  1404.             BotFn := pred( TopFn + ColumnsWide*R);
  1405.             If BotFn > TotalFiles then
  1406.             begin
  1407.                BotFn := TotalFiles;
  1408.                If BotFn - pred(R*ColumnsWide) > 0 then
  1409.              TopFn := BotFN - pred(R*ColumnsWide);
  1410.             end;
  1411.         until ((HiFn >= TopFn) and (HiFn <= BotFn));
  1412.         Display_Box;
  1413.         FillInfo;
  1414.         DisplayFiles;
  1415.          end;
  1416. {$IFDEF DIRFULL}
  1417.    DZoomKey : If DTTT.AllowZoom then
  1418.          begin
  1419.         If Zoomed then
  1420.         begin
  1421.            MoveToScreen(Scrn^,BaseofScreen^,80*DisplayLines);
  1422.             Zoomed := false;
  1423.             Y3 := Y3_Unzoomed;
  1424.             R := pred(Y3 - Y2);
  1425.             RecalcBotFn;
  1426.             If HiFn > BotFn then
  1427.                HiFn := BotFn;
  1428.             Display_Box;
  1429.             FillInfo;
  1430.             DisplayFiles;
  1431.         end
  1432.         else
  1433.         begin
  1434.             If (DTTT.ZoomLine > Y3) and (DTTT.ZoomLine <= DisplayLines) then
  1435.             begin
  1436.            MoveToScreen(Scrn^,BaseofScreen^,80*DisplayLines);
  1437.            Zoomed := true;
  1438.            Y3 := DTTT.ZoomLine;
  1439.            R := pred(Y3 - Y2);
  1440.            RecalcBotFn;
  1441.            Display_Box;
  1442.            FillInfo;
  1443.            DisplayFiles;
  1444.             end;
  1445.         end;
  1446.          end;
  1447.     DSortOrderKey : If DTTT.AllowSort then
  1448.          begin
  1449.         SortAsc := not SortAsc;
  1450.         TopFn := 1;
  1451.         HiFn := 1;
  1452.         RecalcBotFn;
  1453.         DisplayFiles;
  1454.          end;
  1455.     DSortNameKey  : If DTTT.AllowSort and (SortOrder <> DSortName) then
  1456.          begin
  1457.         SortOrder := DSortName;
  1458.         ReSort;
  1459.          end;
  1460.     DSortExtKey   : If DTTT.AllowSort and (SortOrder <> DSortExt) then
  1461.          begin
  1462.         SortOrder := DSortExt;
  1463.         ReSort;
  1464.          end;
  1465.     DSortSizeKey  : If DTTT.AllowSort and (SortOrder <> DSortSize) then
  1466.          begin
  1467.         SortOrder := DSortSize;
  1468.         ReSort;
  1469.          end;
  1470.     DSortTimeKey  : If DTTT.AllowSort and (SortOrder <> DSortTime) then
  1471.          begin
  1472.         SortOrder := DSortTime;
  1473.         ReSort;
  1474.          end;
  1475.     DSortDOSKey   : If DTTT.AllowSort and (SortOrder <> DSortDOS) then
  1476.          begin
  1477.         SortOrder := DSortDOS;
  1478.         ReSort;
  1479.          end;
  1480.     DHelpKey      : If DTTT.AllowHelp then
  1481.             ShowHelpScreen;
  1482.     DJumpParentKey: If DTTT.AllowCD and (length(PathName) > 3) then  {Enter}
  1483.          begin
  1484.         PathName := PathParent(PathName);
  1485.         UnLoadFiles;
  1486.         DisplayNewDirectory;
  1487.          end;
  1488.     DChangeDirKey : If DTTT.AllowCD then
  1489.             PromptForDirectory;
  1490.     #33..#126     :  If DTTT.AllowInput then
  1491.           begin               {user entered an alpha numeric}
  1492.          ChosenFile := PromptForFilename(ChD);
  1493.          If ChosenFile <> '' then
  1494.          begin
  1495.              If (ChosenFile[Length(ChosenFile)] = ':') then
  1496.             ChosenFile := ChosenFile +'*.*';
  1497.              If (pos('*',ChosenFile) > 0)
  1498.              or (pos('?',ChosenFile) > 0)
  1499.              or (ChosenFile[Length(ChosenFile)] = '\') then
  1500.              begin
  1501.             DIRFULLFileName := ChosenFile;
  1502.             Extract_Path_Mask;
  1503.             UnLoadFiles;
  1504.             DisplayNewDirectory;
  1505.              end
  1506.              else
  1507.              begin
  1508.            If (pos('\',ChosenFile) = 0)
  1509.            and (pos(':',ChosenFile) = 0) then
  1510.                ChosenFile := PathName + ChosenFile;
  1511.            Finished := true;
  1512.              end;
  1513.          end;
  1514.           end;
  1515. {$ENDIF}
  1516.        #133,                                                 {Mouse left}
  1517.        #13  : If SubDirectory(FilePointer(HiFn)^.Attr) then  {Enter}
  1518.          begin
  1519.         If File_Name(HiFn) = '..' then
  1520.            PathName := PathParent(PathName)
  1521.         else
  1522.            PathName := PathChild(File_Name(HiFn));
  1523.         If (DTTT.SelectDir = false) then
  1524.         begin
  1525.            UnLoadFiles;
  1526.            DisplayNewDirectory;
  1527.         end
  1528.         else                      {return the Directory}
  1529.         begin
  1530.             Finished := true;
  1531.             ChosenFile := PathNoSlash(PathName);
  1532.         end;
  1533.          end
  1534.          else
  1535.          begin
  1536.         Finished := true;
  1537.         ChosenFile := PathName+File_Name(HiFn);
  1538.          end;
  1539.        #132,                          {mouse right}
  1540.        #027 : if DTTT.AllowEsc then
  1541.                     begin                   {esc}
  1542.         Finished := true;
  1543.         Retcode := EscCode;
  1544.         ChosenFile := '';
  1545.          end;
  1546.        end;  {case}
  1547.        If TotalFiles = 0 then
  1548.        begin
  1549.        {$IFDEF DIRFULL}
  1550.         Repeat
  1551.            Case No_Files_Found of
  1552.            0 : exit;  {user selected a file}
  1553.            99: begin  {user escaped}
  1554.                Retcode := NoFilesCode;
  1555.                Exit;
  1556.             end;
  1557.            end; {case}
  1558.         until TotalFiles <> 0;
  1559.        {$ELSE}
  1560.      Retcode := NoFilesCode;
  1561.      Exit;
  1562.        {$ENDIF}
  1563.        end;
  1564.   Until Finished;
  1565.     end; {sub proc Process_Keys}
  1566.  
  1567.     Procedure SaveInitScreen;
  1568.     var S : word;
  1569.     begin
  1570.   S := 160*DisplayLines;
  1571.   If MaxAvail < S then
  1572.      NoMemory := true
  1573.   else
  1574.   begin
  1575.       Getmem(Scrn,160*DisplayLines);
  1576.       MoveFromScreen(BaseOfScreen^,Scrn^,S div 2);
  1577.       FindCursor(CursRec[1],Cursrec[2],Cursrec[3],Cursrec[4]);
  1578.       OffCursor;
  1579.   end;
  1580.     end;
  1581.  
  1582.     Procedure Clear;
  1583.     begin
  1584.   If DTTT.RestoreScreen then
  1585.       MoveToScreen(Scrn^,BaseofScreen^,80*DisplayLines);
  1586.   PosCursor(Cursrec[1],Cursrec[2]);
  1587.   SizeCursor(Cursrec[3],Cursrec[4]);
  1588.   UnLoadFiles;
  1589.   If Scrn <> Nil then
  1590.     FreeMem(Scrn,160*DisplayLines);
  1591.     end;
  1592.  
  1593. begin          {main procedure}
  1594.     FirstFile := nil;    {5.02b}
  1595.     NoMemory := False;
  1596.     Zoomed := False;
  1597.     ShowingDetails := DTTT.ShowDetails;
  1598.     SortAsc := DTTT.Asc = 1;
  1599.     SortOrder := DTTT.InitSort;
  1600.     If Not ShowingDetails then
  1601.        ColumnsWide := DTTT.ColsWide
  1602.     else
  1603.        Columnswide := 1;
  1604.     SaveInitScreen;
  1605.     If NoMemory then
  1606.     begin
  1607.   Retcode := Memcode;
  1608.   exit;
  1609.     end;
  1610.     {$I-}
  1611.     GetDir(0,StartDir);
  1612.     {SI+}
  1613.     If IOResult <> 0 then
  1614.     begin
  1615.   Retcode := UnknownCode;
  1616.   exit;
  1617.     end;
  1618.     Retcode := OKCode;     {assume it will succeed!}
  1619.     Extract_Path_Mask;
  1620.     Calculate_Box_Dimensions;
  1621.     Y3_unzoomed := Y3;   {ugh?}
  1622.     DisplayNewDirectory;
  1623.     If NoMemory then
  1624.     begin
  1625.        Clear;
  1626.        Retcode := Memcode;
  1627.     end
  1628.     else
  1629.     begin
  1630.        Process_Keys;
  1631.        Clear;
  1632.     end;
  1633.     Display_Directory := ChosenFile;
  1634. end;
  1635.  
  1636. begin
  1637.     Default_Settings;
  1638.     Horiz_Sensitivity := 3;
  1639. end.
  1640.