{LIST program for new subsystem}

%begin
!!!%OPTION "NOOPEN,STACK=15"

%include "sysinc:command.inc"

%string(31)  label,
             outfile
%integer     offer flag = 0
%externalroutinespec  NEWPAGE
%systemroutinespec    OFFER (%string(31) file name, %integer copies, mode,
                                                     %string(7)  destination)

%routine  LIST FILE (%string(31)  source fd)
   %constinteger  line max = 132,
                  lines on page = 60
   %constinteger  FF = 12   {Form-feed character}

   %integer  lines = 0,
             page  = 0,
             source line = 0,
             last sym = NL,
             last line = -1

   %string(132)  line = "",
                 title = source fd."                     ".date."  ".time."   page"

   %routine  PRINT LINE
      %if lines = 0 %start
         newpage;  page = page+1
         newline
         print string(title);  write(page,4)
         newlines(2)
         lines = lines on page
      %finish
      %if source line = last line %start
         print string(" ...")
      %else
         write(source line,-4)
         last line = source line
      %finish
      space
      print string(line);  newline
      lines = lines-1;  line = ""
   %end

   %on %event 9 %start
      close input      {the stream that just protested}
      %if event_sub = 1 %start   {EOF}
         print line %if line # ""
!!!!         newpage
      %else
         newlines(10)
         spaces(15)
         print string("* * * ".source fd." does not exist * * *".SNL)
      %finish
      %return
   %finish

   open input(1,source fd);  select input(1)
   %cycle
      source line = source line + 1 %if last sym = NL
      %cycle
         read symbol(last sym)
         last sym = NL %and lines = 0 %if last sym = FF
         %exit %if last sym = NL %or length(line) = line max
         line = line . to string(last sym)
      %repeat
      print line
   %repeat
%end;      ! LIST FILE

   outfile = command_out1;  outfile = "LP:" %if outfile = "" {default}
   label = command_in1
   %if length(outfile) >= 3 %and substring(outfile,1,3) = "LP:" %start
      label = substring(outfile,4,length(outfile))
      outfile = "$LIST"
      offer flag = 1
   %finish

   open output(1,outfile); select output(1)
   list file(command_in1)
   list file(command_in2) %if command_in2 # ""
   list file(command_in3) %if command_in3 # ""
   close output

   offer("$LIST", 1, 0, "LP:".label) %if offer flag # 0

%endofprogram
