home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / MBUG / MBUG094.ARC / NMANGR2.PRO < prev    next >
Text File  |  1979-12-31  |  5KB  |  153 lines

  1. Function GetBlock(Index,ExtentNo,BlockNo:integer ;Var NDirIndex:integer):integer;
  2. Var
  3.    WorkSpaceName:string[12];
  4.    DirIx:integer;
  5. begin
  6.     NDirIndex:=-1;
  7.     DirIx:=dirIndex[Index];
  8.     WorkSpaceName:=Directory[DirIx].Dname;
  9.     DirIx:=DirIx+ExtentNo;
  10.     If (DirIx<=EndOfDirectory)
  11.       and (WorkSpaceName=Directory[DirIx].Dname) then
  12.       begin
  13.         with Directory[DirIx] do
  14.         begin
  15.             NDirIndex:=DirIx;
  16.             GetRecord(DriveSelected,Dtrack,Dsector);
  17.             GetBlock:=DMA[Doffset+16+BlockNo]
  18.         end
  19.       end
  20.     else GetBlock:=0
  21. end;
  22.  
  23. Function  RecordNo(WSpFileRecNo,Index:integer):integer;
  24.  
  25. Var
  26.   RecInBlock,RecInExtnt,ExtentNo,
  27.   MaxRec,BlockNo,Block,NDirIndex:integer;
  28. Const
  29.   LogExtnts=1; { 1 shl EXM (for WorkSpace EXM = 0)
  30.                  the number of logical extents in a physical extent}
  31.  
  32. begin
  33.    If WSpFileRecNo>=0 then
  34.    begin
  35.       ExtentNo:=WSpFileRecNo div 128; {records in 16k (a WorkSpace Phys Extent)}
  36.       RecInExtnt :=WSpFileRecNo mod 128;
  37.       BlockNo    :=RecInExtnt div 16;  {records in 2k block use by WorkSpace}
  38.       RecInBlock :=RecInExtnt mod 16;
  39.       Block:=getBlock(Index,ExtentNo,BlockNo,NDirIndex);
  40.       If Block<>0
  41.          Then with Directory[NDirIndex] do
  42.               MaxRec:= ((DMA[Doffset+$0C] mod LogExtnts) shl 7 )+DMA[Doffset+$0F];
  43.    end;
  44.    If (Block<>0) and (RecInExtnt<MaxRec) and (WSpFileRecNo>=0) then
  45.       RecordNo:=Block*16+RecInBlock
  46.    else
  47.       recordNo:=-1;
  48. end;
  49.  
  50. Procedure LocateRecInFile(    Index:integer;RecNo:integer;
  51.                           Var Okay:Boolean;
  52.                           Var Track,Sector:integer);
  53.  
  54.  
  55. Var
  56.   ExtSz,BlkSz,RecInExtnt,ExtentNo,BlockNo,Block,NDirIndex,
  57.   MaxRec,LogExtnts:integer;
  58.   BigDrv:boolean;
  59.   DirBlocks:BlockData;
  60. begin
  61.    Okay:=True;
  62.    BlkSz:=1 shl BSH;  {records in  block }
  63.    ExtSz:= BlkSz shl 3; {records in Physical  Extent)}
  64.    BigDrv:=DSM>$FF;
  65.    If not(BigDrv) then ExtSz:=ExtSz shl 1;
  66.    LogExtnts:=ExtSz div 128; {No of Logical extnts in a Physical Extent}
  67.    ExtentNo:= RecNo div ExtSz;
  68.    RecInExtnt := RecNo mod ExtSz;
  69.    BlockNo    :=0;
  70.    Block:=getBlock(Index,ExtentNo,BlockNo,NDirIndex);{finds correct extent}
  71.    If Block=0 then Begin Writeln(' **** Record Error in WorkSpace**** ');halt;end;
  72.    with Directory[NDirIndex] do for loop:=0 to 15 do  begin
  73.         DirBlocks[loop]:=DMA[Doffset+16+loop];
  74.         MaxRec:= ((DMA[Doffset+$0C] mod LogExtnts) shl 7 )+DMA[Doffset+$0F];
  75.    end;
  76.    If RecInExtnt>=MaxRec then Okay:=False;
  77.    LocateRecord(DirBlocks,RecInExtnt,Track,Sector,BigDrv);
  78. end;
  79.  
  80. Procedure DisplayWSPFile(WSpIndex,Index:integer);
  81.  
  82. Var
  83.    Resp:Char;
  84.    Okay:boolean;
  85.    ORecrd,Recrd,FRecrd,Error:Integer;
  86.    RecrdR:Real;
  87.    RecrdStr:String[5];
  88. Const
  89.    Cmd=16;
  90.  
  91. Begin
  92.   ClrScr;
  93.   Write('Drive = ',DriveStr,' WrkSp = ',Directory[DirIndex[WSpIndex]].Dname);
  94.   Writeln(' File = ',Directory[DirIndex[Index]].Dname);
  95.   Recrd:=0;RecrdR:=0;
  96.   FRecrd:= RecordNo(Recrd,Index);
  97.   If FRecrd>=0 then
  98.      repeat
  99.        ORecrd:=Recrd;
  100.        LocateRecinFile(WSpIndex,FRecrd,Okay,Track,Sector);
  101.        If Not(Okay) then begin
  102.           GotoXY(1,Cmd);
  103.           Writeln('*** Error in Record No ***           ')
  104.        end;
  105.        getRecord(DriveSelected,Track,Sector);
  106.        GotoXY(1,2);
  107.        Writeln('           Track = ',Track,' Sector = ',Sector,' Record = ',RecrdR:5:0,'   ');
  108.        GotoXY(1,4);
  109.        DisplaySector(SectorData);
  110.        GotoXY(1,Cmd);
  111.        Writeln('Commands => ESC, +, -, R, P                   ' );
  112.        repeat
  113.           Read(Kbd,Resp);
  114.        until Resp in [#27,'+',';','-','=','R','r','P','p'];
  115.        Case Resp of
  116.             'P','p':ScreenDump;
  117.             '+',';':RecrdR:=RecrdR+1;
  118.             '-','=':RecrdR:=RecrdR-1;
  119.             'R','r':begin
  120.                         Repeat
  121.                            GotoXY(1,Cmd);
  122.                            Write('                                    ');
  123.                            GotoXY(1,Cmd);
  124.                            Write('Which record number please ? ');
  125.                            BufLen:=5;
  126.                            Read(RecrdStr);
  127.                            Val(RecrdStr,RecrdR,Error);
  128.                            WriteLn('            ');
  129.                         until (Error=0) and (RecrdR>=0) and (RecrdR<=65535.0)
  130.                     end;
  131.         end;
  132.         If RecrdR>32767
  133.              then Recrd:=Trunc(RecrdR-65536.0)
  134.              else Recrd:=Trunc(RecrdR);
  135.         FRecrd:= RecordNo(Recrd,Index);
  136.         If FRecrd=-1 then
  137.          begin
  138.              Recrd:=ORecrd;
  139.              RecrdR:=ORecrd;
  140.              GotoXY(1,Cmd);
  141.              WriteLn('**** ERROR in record no. ****         ');
  142.              Delay(1500);
  143.              Recrd:=ORecrd;
  144.              FRecrd:= RecordNo(Recrd,Index);
  145.          end
  146.      until Resp=#27
  147.      else
  148.       begin
  149.         Writeln('***** This File is EMPTY ***** ');
  150.         Delay(2000);
  151.      end;
  152. end;
  153.