program extscan;
const
ext_max_routine = 150; (* max no of words (of 2 chars each) pr inline routine *)
ext_max_charbuf = 5000; (* number of words in charbuf *)
descr_max_param= 30; (* max number of parameters of a module *)
c_size_identifier= 12;
descr_free_words = 4; (*number of unused words in descr*)

var ext_pass5: file of integer;
    file_position, not_resolved : integer;

ext_open_codes:
record
cur_word_ptr : integer; (* points at first free word in charbuf *)
charbuf : array [ 1 .. ext_max_charbuf ] of integer;
end;


type

identifier= packed array [ 1..c_size_identifier ] of char;
(*    type definitions from modules:     *)

ext_states = (ext_unused, ext_declared, ext_open, ext_closed);

param_ptr= ^ param_descr;

param_descr = record
next_param: param_ptr;
kind,
size : integer;
end;

procedure ext_scan;
const
size_of_codedescr = 8; (* no of words in descr, containing date etc *)
var
i, j, codewords, skipwords, codepos,
descr_length, no_of_pages, size_of_page, bytes_on_last_page, kind_of_obj,
app, pno, next_word,
curkey, prevkey : integer;
ident : identifier;
paramtab : array [ 1 .. descr_max_param ] of param_descr;
found : boolean;
param_p: param_ptr;

begin

reset (ext_pass5);
read(ext_pass5, next_word);
file_position := 0;
not_resolved  := 1;

with ext_open_codes do
while not eof(ext_pass5) and (next_word > 0) and (not_resolved > 0) do
begin
descr_length := next_word;
read (ext_pass5,
no_of_pages,
size_of_page,
bytes_on_last_page,
kind_of_obj);

(* read name *)
for i := 1 to 6 do
begin
read (ext_pass5, app);
ident [ i*2-1 ] := chr (app div 256);
ident [ i*2   ] := chr (app mod 256);
end;
for i := 13 to c_size_identifier do ident [ i ] := ' ';
writeln('identifier: ', ident);

(* skip entry points etc *)
for i := 1 to 5 do read (ext_pass5, next_word);
(*read last param offset*)
read (ext_pass5,app);

(*skip the free words*)
for i := 1 to descr_free_words do read(ext_pass5, next_word);

(*read number of params *)
read (ext_pass5,pno);
writeln('params: ',pno);

if pno > descr_max_param then writeln('error-ext_param_number');
for i := 1 to pno do
with paramtab[ i ] do
read (ext_pass5, kind, size);

file_position := descr_length div 2 + file_position;
codewords := ((no_of_pages - 1) * size_of_page + bytes_on_last_page + 1) div 2;
skipwords := codewords;
writeln('code : ', codewords);

if (kind_of_obj = 4) or (kind_of_obj = 5) then
begin (* open routine in library *)

writeln('open - routine');
end;

(* skip any remaining part of code-body *)
for i := 1 to skipwords do read(ext_pass5, next_word);
file_position := file_position + codewords;
(* skip external link part *)
read (ext_pass5, pno);
file_position := file_position + 1;
for i := 1 to pno do
begin
(* skip external name *)
for j := 1 to 6 do read (ext_pass5, next_word);
file_position := file_position + 6;
(* skip parameter list *)
read (ext_pass5, j); (* number of params *)
file_position := file_position + 2*j + 1;
for j := 2*j downto 1 do read (ext_pass5, next_word);
(* skip number of uses *)
read (ext_pass5, next_word);
file_position := file_position + 1;
end;
(* skip internal link part *)
read (ext_pass5, pno);
pno := pno * 4; (* four words per entry *)
for i := 1 to pno do read (ext_pass5, next_word);
file_position := file_position + pno + 1;

(* now the libraryfile is positioned at start of next entry *)
read(ext_pass5, next_word);
end; (* scan of library file *)

end; (* procedure extscan *)

begin
  assign(ext_pass5, 'rtp35022.lib');
  ext_scan;
end.