home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ucsdmagiscan2.zip / sysunit.text < prev    next >
Text File  |  2011-08-11  |  7KB  |  311 lines

  1.  
  2. (*$S+*)
  3.  
  4. { This unit allows the users to access the directory information
  5.   held on each disk }
  6. Unit SysUnit;
  7.  
  8.  
  9.   Interface
  10.  
  11.  
  12.   Uses
  13.      M2Types,M2IpRoot,M2Sys;
  14.  
  15.   type
  16.     FileType = String[15];
  17.     Volume = 4..12;
  18.  
  19.   var
  20.     D      : File;
  21.  
  22.  
  23.   procedure DelFile( G  : FileType;
  24.                      Vol : Volume );
  25.  
  26.   procedure PrintNames( Vol   : Volume;
  27.                        var NbrOfFiles : integer );
  28.  
  29.  
  30. Implementation
  31.  
  32. { These are the declerations that we don't really want the
  33.   user to see, as they may do silly things }
  34.  
  35.    const
  36.      FirstBlk = 8;
  37.      LastBlk  = 839;
  38.  
  39.    type
  40.      FileArray = Packed array[0..77] of FileType;
  41.  
  42.      Daterec = packed record
  43.                   Month  : 0..12;
  44.                   Day    : 0..31;
  45.                   Year   : 0..100
  46.                   end;
  47.  
  48.      FileKind = (UnTyped,XDsk,Code,Text,Info,Data,Graf,Foto,
  49.                  SecureDir);
  50.  
  51.      DirEntry = Packed Record
  52.                    DFirstBlk  : integer;
  53.                    DLastBlk   : integer;
  54.                    case DFKind : FileKind of
  55.  
  56.                       SecureDir,UnTyped : (Filler1 : 0..2048;
  57.                                            Dvid    : String[7];
  58.                                            DevoBlk : integer;
  59.                                            DNumFiles: 0..77;
  60.                                            DLoadTime: integer;
  61.                                            DLastBoot: DateRec );
  62.  
  63.                       XDsk,Code,Text,Info,Data,Graf,Foto :
  64.                                         (Filler  : 0..1024;
  65.                                          Status  : Boolean;
  66.                                          Dtid    : String[15];
  67.                                          DLastByte: 1..512;
  68.                                          DAccess : DateRec )
  69.                       end;
  70.  
  71.      Directory = array[0..77] of DirEntry;
  72.  
  73.  
  74. (* ---------------------------------------------------- *)
  75.  
  76. function IsFile(Name  : FileType;
  77.                 Vol   : Volume ) : Boolean;
  78.  This checks if the file, name, exists on the disk, vol 
  79.  
  80. var
  81.   G  : String;
  82.   i  : integer;
  83.  
  84. begin
  85. if (Not ( Vol in [4,5,11,12] )) or (Length(Name) < 1) then
  86.   begin
  87.   IsFile := False;
  88.   Exit(IsFile)
  89.   end;
  90.  
  91. case Vol of
  92.    4  : G := Concat('#4:',Name);
  93.    5  : G := Concat('#5:',Name);
  94.    11 : G := Concat('#11:',Name);
  95.    12 : G := Concat('#12:',Name);
  96.    end;
  97.  
  98. (*$I-*)
  99. Reset(D,g);
  100. i := IOResult;
  101. if i = 0 then Close(D,lock);
  102. (*$I+*)
  103. IsFile := i = 0
  104. end{IsFile};
  105.  
  106. (* ---------------------------------------------------- *)
  107.  
  108. procedure DelFile;
  109.  This procedure deletes a file from disk 
  110.  
  111. var
  112.   i,j,NbrOfFiles  : Integer;
  113.   DD              : Directory;
  114.   Dummy           : DirEntry;
  115.   Found           : Boolean;
  116.   Key             : char;
  117.  
  118. begin
  119.  
  120.  Tell the user what we are doing 
  121. write('#',vol,':',G,' =====> ');
  122.  Check that the name is valid and exists 
  123. if (Not (Vol in [4,5,11,12])) or (Length(G)<1)
  124.     or Not (IsFile(G,Vol)) then
  125.   begin
  126.   writeln('Does not exist');
  127.   Exit(DelFile);
  128.   end;
  129.  
  130.  Inform that it has been deleted ! 
  131. writeln('Deleted');
  132. { Ask if the user wishes to update the directory,
  133.   this will do the actual delete ! }
  134. write('Update Directory (Y/N) ?');
  135. repeat
  136.   read(keyboard,Key)
  137. until Key in ['Y','y','N','n'];
  138. writeln(Key);
  139.  
  140.  If we do update the directory then we have to delete 
  141. if Key in ['Y','y'] then
  142.   begin
  143.   { Get the directory info }
  144.   UnitRead(Vol,DD,SizeOf(DD),4);
  145.   NbrOfFiles := DD[0].DNumFiles;
  146.  
  147.   i := 0;
  148.   Found := False;
  149.  
  150.   { Find the file }
  151.   while not Found do
  152.     begin
  153.     with DD[i] do
  154.       if (Not (DFKind in [SecureDir,UnTyped])) and
  155.         (DTid = G) then
  156.        Found := True
  157.        else
  158.          i := i + 1;
  159.     if i > NbrOfFiles then Exit(DelFile)
  160.     end;
  161.  
  162.   { delete from the directory info }
  163.   Dummy := DD[i];
  164.   For j:= i To pred(NbrOfFiles) do
  165.     DD[j] := DD[j+1];
  166.   DD[NbrOfFiles] := Dummy;
  167.   DD[0].DNumFiles := NbrOfFiles -1;
  168.  
  169.   { Update the actual directory on the disk }
  170.   UnitWrite(Vol,DD,SizeOf(DD),4)
  171.   end;
  172.  
  173. end{DelFile};
  174.  
  175. (* ---------------------------------------------------- *)
  176.  
  177. procedure PrintNames;
  178. { This procedure displays a directory on the screen for
  179.   the user to view }
  180.  
  181. const
  182.   StrtPos  = 20;
  183.   FinisPos = 26;
  184.   DatePos  = 32;
  185.   TyPos    = 42;
  186.  
  187. var
  188.   i,k  : integer;
  189.   DD   : Directory;
  190.  
  191.   (* -------------------------------------------------- *)
  192.  
  193.   procedure PrintDAcc(var DAccess  : DateRec );
  194.  
  195.   begin
  196.   GotoXY(DatePos,k);
  197.   with DAccess do
  198.     begin
  199.     write(Day,'-');
  200.     case Month of
  201.       1  : write('Jan');
  202.       2  : write('Feb');
  203.       3  : write('Mar');
  204.       4  : write('Apr');
  205.       5  : write('May');
  206.       6  : write('Jun');
  207.       7  : write('Jul');
  208.       8  : write('Aug');
  209.       9  : write('Sep');
  210.       10 : write('Oct');
  211.       11 : write('Nov');
  212.       12 : write('Dec')
  213.       end{case};
  214.     write('-',Year)
  215.     end{with};
  216.   end{PrintDAcc};
  217.  
  218.   (* -------------------------------------------------- *)
  219.  
  220.   procedure PrintTy( DFKind  : FileKind );
  221.  
  222.   begin
  223.   GotoXY(TyPos,k);
  224.   case DFKind of
  225.      SecureDir : write(' SecureDir ');
  226.      UnTyped   : write(' UnTyped   ');
  227.      XDsk      : write(' XDsk      ');
  228.      Code      : write(' Code      ');
  229.      Text      : write(' Text      ');
  230.      Info      : write(' Info      ');
  231.      Data      : write(' Data      ');
  232.      Graf      : write(' Graf      ');
  233.      Foto      : write(' Foto      ');
  234.      end;
  235.   end{PrintTy};
  236.  
  237.   (* -------------------------------------------------- *)
  238.  
  239. begin
  240.  Get the directory information 
  241. UnitRead(Vol,DD,SizeOf(DD),4);
  242. NbrOfFiles := DD[0].DNumFiles;
  243.  
  244.  write which disk ths info is from 
  245. writeln(chr(ff),'DIRECTORY OF #',Vol,':');
  246.  
  247. k := 1;
  248.  
  249.  Take care of the first entry 
  250. with DD[1] do
  251.   begin
  252.   if DFirstBlk > FirstBlk then
  253.     begin
  254.     write('<UNUSED>');
  255.     GotoXY(StrtPos,k); write(FirstBlk);
  256.     GotoXY(FinisPos,k);write(pred(DFirstBlk));
  257.     k := k + 1;
  258.     writeln
  259.     end
  260.   end;
  261.  
  262.  For each entry display on the screen 
  263. for i := 1 to NbrOfFiles do
  264.   with DD[i] do
  265.     begin
  266.     write(Dtid);
  267.     GotoXY(StrtPos,k); write(DFirstBlk);
  268.     GotoXY(FinisPos,k);write(DLastBlk);
  269.     PrintDAcc(DAccess);
  270.     PrintTy(DFKind);
  271.     writeln; k := succ(k);
  272.     if i < NbrofFiles then
  273.       if (DLastBlk < DD[succ(i)].DFirstBlk) then
  274.         begin
  275.         write('<UNUSED>');
  276.         GotoXY(StrtPos,k); write(DLastBlk);
  277.         GotoXY(FinisPos,k);write(pred(DD[succ(i)].DFirstBlk));
  278.         k := k + 1;
  279.         writeln
  280.         end;
  281.     { if we have reached the bottom of the screen and still
  282.       have more to do... wrap around }
  283.     if (k mod 31) = 0 then
  284.       begin
  285.       Pause;
  286.       writeln(chr(ff),' DIRECTORY CONTD');
  287.       k := 1
  288.       end;
  289.     end;
  290.  
  291.  Take care of the last entry, if blank etc 
  292. with DD[NbrOfFiles] do
  293.   begin
  294.   if DlastBlk < LastBlk then
  295.     begin
  296.     write('<UNUSED>');
  297.     GotoXY(StrtPos,k); write(succ(DLastBlk));
  298.     GotoXY(FinisPos,k);write(LastBlk);
  299.     k := k + 1;
  300.     writeln
  301.     end
  302.   end
  303.  
  304.  
  305. end{PrintNames};
  306.  
  307. (* ---------------------------------------------------- *)
  308.  
  309. end{SysUnit}.
  310.  
  311.