program map(input:-);

{Asks for a file name.  Tells you what pages are in use in the file,
  also the end of file figured in 3 different ways.  output is self-
  explanatory.}

var
  count,bperw,bperp,used,first,page:integer;
  fdb:packed record
	fbret:0..77B;fbbsz:0..77B;fbmod:0..77B;fbpgc:0..777777B;
	fbsiz:integer
	end;

function ffufp(page:integer):integer;
     var val,ret:integer;
  begin
  jsys(211B,2,ret;input:page;val);
  if ret = 2
   then begin
    val := val mod 1000000B;
    count := count + 1;
    end
   else begin
    if val <> 600546B
      then writeln(tty,'? Unexpected jsys error on FFUFP');
    val := -1;
    end;
  ffufp := val
  end;

begin
  jsys(63B;0:input,2:11B,fdb);
  with fdb do 
    begin
    if fbbsz = 0
      then bperw := 1
      else bperw := 36 div fbbsz;
    bperp := bperw * 512;
    page := (fbsiz + bperp - 1) div bperp;
    writeln(tty);
    writeln(tty,'EOF at byte ',fbsiz:0,'(',fbbsz:0,'), implying ',page:0,' pages');
    writeln(tty,'GTFDB page count: ',fbpgc:0);
    end;
writeln(tty,'Used pages:');
count := 0;
first := ffufp(0);
page := first;
if first < 0
  then writeln(tty,'% Empty file')
  else repeat
    repeat
      page := page+1;
      used := ffufp(page)
     until used <> page;
    if first = page-1
      then writeln(tty,'  ',first:0)
      else writeln(tty,'  ',first:0, ':', page-1:0);
    first := used;
    page := first;
   until used < 0;
writeln(tty,'Actual count of pages: ',count:0);
end.

