program incl;{'include' preprocessor} { J Collins 13-Feb-79 (link with svrs.mac)} {file inclusion is triggered by the keyword '{' and followed by additional commentary on the same line.} type filestring = array[1..30] of char; var line: array[1..100] of char; infile, outfile: text; lvl: integer; {nest level counter} type cstring = array[1..10] of char; const kwincl = cstring('{','<','I','N','C','L','U','D','E',' '); type filepos = array[1..3] of integer; procedure savep(var f: text; var n: filepos); extern; procedure restp(var f: text; var n: filepos); extern; procedure include(var name: filestring); var nam1: filestring; rnum: filepos; {saved record number} i,j,k: integer; match: boolean; begin for i := 1 to lvl do write(' '); i := 1; while name[i] <> chr(0) do begin write(name[i]); i := i + 1 end; writeln; reset(infile, name); while not eof(infile) do begin i := 1; while not eoln(infile) do begin read(infile, line[i]); i := i + 1 end; i := i - 1; if i > 10 then begin j := 1; match := true; while (j <= 9) and match do if line[j] <> kwincl[j] then match := false else j := j + 1 end else match := false; if not match then begin for j := 1 to i do write(outfile, line[j]); writeln(outfile) end else begin j := 10; while line[j] = ' ' do j := j + 1; k := 1; while (j <= i) and (line[j] <> '>') do begin nam1[k] := line[j]; j := j + 1; k := k + 1 end; nam1[k] := chr(0); savep(infile, rnum); lvl := lvl + 1; include(nam1); lvl := lvl - 1; reset(infile, name); restp(infile, rnum) end; readln(infile) end {while not eof(infile)} end {include}; begin {main routine} lvl := 0; rewrite(outfile, argv[2]^, 2); include(argv[1]^) end.