{Portable Prolog APM Command Line Interface Module}

{Command format:  PROLOG <restore file> <option list>

{Options disguised as:     -Boot}
{                          -Trace}
{                          -Quiet}
{                          -Print}
{                          -ATOM=<n> etc}

%include "Inc:Util.Imp"

%external %routine %spec Prolog Interpreter (%string (127) File)

%external %integer %spec Options

%include "GDec.Inc"

%constant %integer N Stacks = 6

%external %integer %array %spec Stk Len (1:N Stacks)
%external %string (10) %array %spec Stack Id (1:N Stacks)

%constant %byte %array Increment (1 : N Stacks) = %c
   40,      {Atom}
   24,      {Aux}
   96,      {Trail}
   96,      {Skel Heap}
   96,      {Global Stack}
   96       {Local Stack}

%begin
   %integer I,
            Print = 0,
            Size

   %own %integer Bits,
                 Store Boards = 1
   %own %string (255) Input File = ""

   Define Param ("RESTORE - a prolog saved state",
                 Input File,
                 PAM Major)

   Define Boolean Params ("Quiet,Trace,Bootstrap,Print",
                          Bits,
                          0)

   %for I = 1, 1, 6 %cycle
      Define Int Param (Stack Id (I),
                        STK Len (I),
                        PAM Major)
   %repeat


   Define Int Param ("STORE - number of store boards",
                     Store Boards,
                     PAM Major)

   Process Parameters (CLI Param)

   Options = Options ! Quiet Option     %if Bits&16_80000000 # 0
   Options = Options ! Trace Option     %if Bits&16_40000000 # 0
   Options = Options ! Bootstrap Option %if Bits&16_20000000 # 0


   %if Store Boards > 1 %start
      Store Boards = Store Boards - 1
      %for I = 1, 1, N Stacks %cycle
         Stk Len (I) = Stk Len (I) + Increment (I)*Store Boards
      %repeat
   %finish
   %if Bits&16_10000000 # 0 %start
      %for I = 1, 1, N Stacks %cycle
         Print String (Stack Id (I))
         Spaces (6 - Length (Stack Id (I)))
         Print String (" = ")
         Write (Stk Len (I), 0)
         Print Symbol ('K')
         New Line
      %repeat
   %finish

   Prolog Interpreter (Input File)   
%end

%end %of %file
