{link pregen,imp1,incfile}
{Takes paspre.imp and generates ichead.inc}
%begin                   {Pascal predefinition file generator}
   %externalroutinespec PASS1(%integername Stats, Faults, %integer Options)
   %externalroutinespec Delete %alias "IMP_DELETE"(%string(255) File)
   %externalstring(255)%fnspec Cli Param
   %from Common %include Option3l
   %integer Stats, Faults
   %string(255) File = CliParam

   %begin
      %integer Num = 0, S
      %constinteger IMP = 1, INC = 2
      %begin
        %on 9 %start
           Printstring("cannot access ".File)
           Newline
           %stop
         %finish
         Open Input(1, FILE);  Select Input(1)
      %end

      %on 9 %start
         Select Output(INC)
         Printstring("%constinteger Free Index =");  Write(Num, 1);  Newline
         Close Output
         Select Output(IMP);  Close Output
         Select Output(0)
         Select Input(1);  Close Input
         Printstring("predef.inc complete");  Newline
         %return
      %finish

      Open Output(IMP, "TMP1.IMP")
      Open Output(INC, "PREDEF.INC")
      %cycle
         Skipsymbol %while Nextsymbol <= ' '
         Select Output(IMP)
         %cycle
            Readsymbol(S)
            Printsymbol(S)
         %repeat %until S = ' '
         Readsymbol(S) %until S # ' '
         Select Output(INC)
         Num = Num+1
         Printstring("%constinteger ")
         %cycle
            Printsymbol(S)
            Readsymbol(S)
         %repeat %until S = '%' %or S = NL
         Printstring(" = ");  Write(Num, 1)
         Newline
         Select Output(IMP)
         Printstring("v");  Write(Num, 0)
         Space
         %cycle
            Printsymbol(S)
            %exit %if S = NL
            Readsymbol(S)
         %repeat
      %repeat
   %end

   Open Input(1, "NL:");  Select Input(1)
   Open Input(2, "TMP1.IMP")
   Open Binary Output(1, "TMP2.TMP")
   Select Output(1)
   Pass1(Stats, Faults, LL Predef)
   Select  Input(1);  Close  Input
   Select Output(1);  Close Output
   %if Faults # 0 %start
      Printstring("Program contains");  Write(Faults, 1)
      Printstring(" fault");  Printsymbol('s') %if Faults # 1
   %else
      Delete("TMP1.IMP.")
      %begin
         %integer S, J, P = 0, Last = 0
         %bytearray Hold(1:5000)
         Open Binary Input(1, "TMP2.TMP")
         Select Input(1)
         Readsymbol(S) %for J = 1, 1, 3        {skip language flags}
         %cycle
            Readsymbol(S)
            %exit %if S = NL %and Hold(P) = ';'
            P = P+1;  Hold(P) = S
         %repeat
         Close Input
         Hold(P) = 'I'            {overwrite ; with I - input switch}
         P = P+1;  Hold(P) = NL   {to bounce off}
         Open Output(1, "Ichead.inc");  Select Output(1)
         Printstring("%constinteger Ichead Length =");  Write(P, 1);  Newline
         Printstring("%constbytearray Ichead Data(1:Ichead Length) =")
         S = 0
         %for J = 1, 1, P %cycle
            S = S-1
            S = 18 %and Newline %if S <= 0
            Write(Hold(J), -3)
            Printsymbol(',') %unless J = P
         %repeat
         Newline
         Select Output(0)
         Printstring("Ichead.inc complete")
         Write(P, 8);  Printstring(" bytes")
         Newline
      %end
   %finish
   Newline
   Delete("TMP2.TMP.")
%endofprogram
