home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug047.arc / COMPDIR.PAS < prev    next >
Pascal/Delphi Source File  |  1979-12-31  |  6KB  |  312 lines

  1. {   This program is a utility to compare the directory entries of two
  2.  diskettes and report any differences.
  3.  
  4.                                         by Tom Onishi
  5.                                         version 1.1
  6.                                         Dec. 8, 1986                  }
  7.  
  8. type
  9.   String11   = String[11];
  10.   DirecArray = Array[1..128] of String11;
  11.  
  12. const
  13.   FindFirst = $11;
  14.   FindNext  = $12;
  15.   SetDMA    = $1A;
  16.   ResetD    = $25;
  17.  
  18. var
  19.   DMA            : Array[0..127] of Byte;
  20.   FCB            : Array[0..35] of Byte;
  21.   Drive          : Char;
  22.   Count          : Integer;
  23.   AReg, CReg     : Integer;
  24.   MaxEnt1,
  25.   MaxEnt2        : Integer;
  26.   Direc1, Direc2 : DirecArray;
  27.   Quit           : Boolean;
  28.   ChangeDisks    : Boolean;
  29.  
  30.  
  31. Procedure Initialise;
  32.  
  33. type
  34.   CharSet = Set of Char;
  35.  
  36. var
  37.   LegalDrive : CharSet;
  38.  
  39. begin
  40.   ClrScr;
  41.   GotoXY(27,3);
  42.   Writeln('COMPARE DIRECTORIES  V1.0');
  43.   GotoXY(28,5);
  44.   Writeln('by Tom Onishi   2/12/86');
  45.   LegalDrive := ['A'..'P'];
  46.   Repeat
  47.     GotoXY(5,10);
  48.     Write('Drive of disks to be compared? ');
  49.     Read(Drive);
  50.     Drive := Upcase(Drive);
  51.     If not (Drive in LegalDrive)
  52.       then Writeln('      Drivespec Error.', ^G)
  53.       else ClrEol
  54.   Until Drive in LegalDrive
  55.  
  56. end;  {Initialise}
  57.  
  58.  
  59. Procedure ResetDisk;
  60.  
  61. var
  62.   x,n      : Integer;
  63.   DriveBit : Integer;
  64.  
  65. begin
  66.   x:= 1;
  67.   DriveBit := x Shl (Ord(Drive) - Ord('A'));
  68.   Bdos(ResetD, DriveBit);
  69.   Bdos(SetDMA, Addr(DMA));
  70.   FillChar(FCB, Sizeof(FCB), 0);
  71.   FCB[0] := 1 + Ord(Drive) - Ord('A');
  72.   For n := 1 to 11 do
  73.     FCB[n] := Ord('?');
  74.   CReg := FindFirst
  75. end;  {ResetDisk}
  76.  
  77.  
  78. Procedure OneEntry(var D : DirecArray);
  79.  
  80. var
  81.   i, y      : Integer;
  82.   TempEntry : String11;
  83.  
  84. begin
  85.   AReg := Bdos(CReg, Addr(FCB));
  86.   If AReg <> $FF then
  87.   begin
  88.     y := AReg Shl 5;
  89.     TempEntry[0] := Chr(11);
  90.     For i := 1 to 11 do
  91.       TempEntry[i] := Chr(DMA[y+i]);
  92.     D[Count] := TempEntry
  93.   end
  94. end;  {OneEntry}
  95.  
  96.  
  97. Procedure GetDirec( var Dir : DirecArray);
  98.  
  99. begin
  100.   ResetDisk;
  101.   Count := 1;
  102.   OneEntry(Dir);
  103.   If AReg = $FF
  104.     then
  105.     begin
  106.       Writeln('Disk has no entries.');
  107.       Halt
  108.     end
  109.     else
  110.       CReg := FindNext;
  111.   While AReg <> $FF do
  112.   begin
  113.     Count := Count + 1;
  114.     OneEntry(Dir)
  115.   end
  116. end;  {GetDirec}
  117.  
  118.  
  119. Function Strip(Entry : String11) : String11;
  120. { This function strips the systems flags in the filetype.}
  121.  
  122. var
  123.   i : Integer;
  124.  
  125. begin
  126.   For i := 1 to 11 do
  127.   begin
  128.     If Ord(Entry[i]) >= 128
  129.       then Entry[i] := Chr(Ord(Entry[i]) - 128)
  130.   end;  {For}
  131.   Strip := Entry
  132. end;  {Strip}
  133.  
  134.  
  135. Procedure Sort(var Dir : DirecArray; n : Integer);
  136.  
  137. var
  138.   i, j                : Integer;
  139.   Bottom, Middle, Top : Integer;
  140.   Temp                : String11;
  141.  
  142. begin
  143.   For i := 2 to n do
  144.   begin
  145.     Temp   := Dir[i];
  146.     Bottom := 1;
  147.     Top    := i - 1;
  148.     While Bottom <= Top do
  149.     begin
  150.       Middle := (Bottom + Top) div 2;
  151.       If Strip(Temp) < Strip(Dir[Middle])
  152.         then Top := Middle - 1
  153.         else Bottom := Middle + 1
  154.     end;  {while}
  155.     For j := i - 1 downto Bottom do
  156.       Dir[j+1] := Dir[j];
  157.     Dir[Bottom] := Temp
  158.   end  {for}
  159. end;  {Sort}
  160.  
  161. Function Option : Integer;
  162.  
  163. var
  164.   i, e      : Integer;
  165.   Temp,
  166.   DiskName  : String11;
  167.   Selection : Char;
  168.  
  169. begin
  170.   ClrScr;
  171.   GotoXY(10,3);
  172.   Temp := Direc1[1];
  173.   If Temp[1] = '-'
  174.     then DiskName := Temp
  175.     else DiskName := 'first disk';
  176.   Writeln('<1> - List of files exclusive to ', DiskName, '.');
  177.   GotoXY(10,4);
  178.   Temp := Direc2[1];
  179.   If Temp[1] = '-'
  180.     then DiskName := Temp
  181.     else DiskName := 'second disk';
  182.   Writeln('<2> - List of files exclusive to ', DiskName, '.');
  183.   GotoXY(10,5);
  184.   Writeln('<3> - List of files common to both disks.');
  185.   GotoXY(10,6);
  186.   Writeln('<4> - Compare new disks.');
  187.   GotoXY(10,7);
  188.   Writeln('<5> - Quit.');
  189.   Repeat
  190.     GotoXY(5,10);
  191.     Write('Enter Selection : ');
  192.     Read(Kbd, Selection);
  193.     Val(Selection, i, e);
  194.     If e = 0
  195.       then Option := i
  196.       else Write(^G^G)
  197.   Until e = 0
  198. end;  {Option}
  199.  
  200.  
  201. Procedure Exclusive(D1, D2 : DirecArray; Max1, max2 : Integer);
  202.  
  203. var
  204.   i, n, x : Integer;
  205.  
  206. begin
  207.   ClrScr;
  208.   x := 0;
  209.   i := 1;
  210.   n := 1;
  211.   While (i <= Max1) and (n <= Max2) do
  212.   begin
  213.     If D1[i] = D2[n]
  214.       then
  215.       begin
  216.         i := i + 1;
  217.         n := n + 1
  218.       end
  219.       else
  220.       begin
  221.       If D1[i] > D2[n]
  222.         then n := n + 1
  223.         else
  224.         begin
  225.           If x Mod 5 = 0
  226.             then Writeln
  227.             else Write(' : ');
  228.           Write(D1[i]);
  229.           x := x + 1;
  230.           i := i + 1
  231.         end
  232.       end
  233.   end;  {while}
  234.   GotoXY(5,24);
  235.   Write('Press <RETURN> for Menu.');
  236.   Readln
  237. end;  {Exclusive}
  238.  
  239.  
  240. Procedure Common(D1, D2 : DirecArray; Max1, Max2 : Integer);
  241.  
  242. var
  243.   i, n, x : Integer;
  244.  
  245. begin
  246.   i := 1;
  247.   n := 1;
  248.   x := 0;
  249.   ClrScr;
  250.   While (i <= Max1) and (n <= Max2) do
  251.   begin
  252.   If D1[i] < D2[n]
  253.     then
  254.       i := i + 1
  255.     else
  256.     begin
  257.       If D1[i] = D2[n]
  258.         then
  259.         begin
  260.           If x Mod 5 = 0
  261.             then Writeln
  262.             else Write(' : ');
  263.           Write(D1[i]);
  264.           i := i + 1;
  265.           n := n + 1;
  266.           x := x + 1
  267.         end
  268.         else
  269.           n := n + 1
  270.     end
  271.   end;
  272.   GotoXY(5,24);
  273.   Write('Press <RETURN> for Menu.');
  274.   Readln
  275. end;  {Common}
  276.  
  277.  
  278. Begin
  279.  
  280.   Initialise;
  281.   Repeat
  282.     ChangeDisks := false;
  283.     GotoXY(5,14);
  284.     Write('Insert first disk into Drive ', Drive, ' and press <RETURN>:');
  285.     Readln;
  286.     GetDirec(Direc1);
  287.     MaxEnt1 := Count - 1;
  288.     Sort(Direc1, MaxEnt1);
  289.     GotoXY(5,15);
  290.     Write('Insert second disk into Drive ', Drive, ' and press <RETURN>:');
  291.     Readln;
  292.     GetDirec(Direc2);
  293.     MaxEnt2 := Count - 1;
  294.     Sort(Direc2, MaxEnt2);
  295.     Repeat
  296.       Quit := false;
  297.       Case Option of
  298.         1 : Exclusive(Direc1, Direc2, MaxEnt1, MaxEnt2);
  299.         2 : Exclusive(Direc2, Direc1, MaxEnt2, MaxEnt1);
  300.         3 : Common(Direc1, Direc2, MaxEnt1, MaxEnt2);
  301.         4 : begin
  302.               ChangeDisks := true;
  303.               Quit := true
  304.             end;
  305.         5 : Quit := true;
  306.       Else Writeln(^G^G)
  307.       end  {case}
  308.     Until Quit
  309.   Until not ChangeDisks
  310.  
  311. End.
  312.