?nolist
?source karstadt.defines
?source system.extdecs (fileinfo, close, processaccessid, awaitio, debug,
?      setlooptimer, myterm, open, write, abend, writeread, fileinfo,
?      spoolercommand, mypid, getcrtpid)
?source karstadt.extdecs (upshift, system^proc^entry, num^out, filenamecompress, fehler^meldung)
?ifnot 1
?list
?endif 1
?noabslist
proc mainstreet; external;
int proc spool^checkmsg (a, b, c, d); int a, .b, c, d; external;
int proc Spooljobnum (file, job^number);
int file, .job^number;

! Reassembly of spooljobnum with the realisation that Tandem has a no-wait
! facility

begin
int error,                                       !Original parameters
   .l2 [0:1],                                    !This is a message passed to collector
   open^flags;                                   !But we need this to see whether the file was opened no-wait

call spool^checkmsg (127, l2, 4, 7);             !This should be what's below
call writeread (file, l2, 4, 2);
call fileinfo (file, error,,, ,,, ,,, ,, open^flags); !See what happened
if error then
   return error lor 2 '<<' 8                     !Return the error on collector
elif open^flags .<12:15> then                    !Nowait, wait for it
   begin
   call awaitio (file);
   call fileinfo (file, error)
   end
fi;
job^number := l2;                                !Return the job number
if error then
   return error lor 2 '<<' 8
else
   return 0                                      !No error
fi
end;
proc time^Tal main;

! Set a timer and start the Tal compiler
! Woe betide it if it takes more than 5 minutes 27,67 seconds

begin
int my^pid [0:11];

string my^pids = my^pid;

call getcrtpid (mypid, my^pid);                  !Make sure we're legal
if my^pids <> "$COMP" then                       !Somebody trying to cheat
   begin
   call fehler^meldung (193 '<<' 8 + 0,,, my^pid);
   call abend
   end
fi;
code (ladr L;                                    !Get L reg contents
      sets);                                     !In S: kill local data
call setlooptimer (32767);                       !As long as we can
call mainstreet;                                 !Tal main procedure
end;
proc stop (pid) variable;
int .pid;

!Fool Tal into coming here when it is finished
!Then call stop by name, with help of system^proc^entry

begin
int file^name [0:13],
   job^number,                                   !Of spooler output
   spooler,                                      !Spooler file
   device^type,                                  !Of out file
   source^file := 6,                             !Left behind by TAL
   terminal := 7,                                !Tal output file number at present
   .error^count := %12135,                       !Error count address {Tal D03}
   buffer = file^name,
   console,
   time,
   message [0:65];

string messages = message,
   buffers = buffer,
   nulls [0:3] := [4 * [0]],
   stop^proc [0:4] := "stop ",
   .end^string;

call setlooptimer (32767, time);                 !See how much it used
buffers ':=' " CPU time - " -> @end^string;
@end^string := num^out (end^string, 32767 - time,,,, 2); !In message
end^string ':=' " seconds" -> @end^string;
call awaitio (terminal,,,, -1D);
call write (terminal, buffer, @end^string - @buffers);    !On output file (check new Tals)!
call fileinfo (terminal,,,, device^type);        !Find out what it is
?ifnot 7
if device^type = 0 then                          !Output to process
   begin
   call awaitio (terminal,,,, -1D);
   call spooljobnum (terminal, job^number);      !See if this is a spool job, get number {D2}
   if = then                                     !We made it
      begin
      file^name ':=' "$SPLS                   ";
      call open (file^name, spooler);
      if = then
         begin
         call fileinfo (source^file,, file^name); !Use name of file as report
         call spoolercommand (spooler, 2, job^number, 124, file^name [4]); !Set report
         call close (spooler)
         end
      fi
      end
   fi
   end
fi;
?endif 7
if error^count > 50 then                         !Very rude remark
   begin
   messages ':=' " This program is the work of a subhuman and" -> @end^string;
   call awaitio (terminal,,,, -1D);
   call write (terminal, message, @end^string - @messages);    !On output file (check new Tals)!
   messages ':=' " bears no relationship to the TAL language" -> @end^string
   end
elif error^count > 10 then                       !Ruder remark
   begin
   messages ':=' " This program is not as bad as some I have seen." -> @end^string;
   call awaitio (terminal,,,, -1D);
   call write (terminal, message, @end^string - @messages);    !On output file (check new Tals)!
   messages ':=' " If you work hard, someday you might become a programmer" -> @end^string
   end
elif error^count then                            !Rude remark
   begin
   messages ':=' " This program has been written incorrectly" -> @end^string;
   call awaitio (terminal,,,, -1D);
   call write (terminal, message, @end^string - @messages);    !On output file (check new Tals)!
   messages ':=' " and cannot possibly run" -> @end^string
   end
else
   begin
   messages ':=' " Although no syntactical errors were discovered," -> @end^string;
   call awaitio (terminal,,,, -1D);
   call write (terminal, message, @end^string - @messages);    !On output file (check new Tals)!
   messages ':=' " it is unlikely that this program will run" -> @end^string
   end
fi;
call awaitio (terminal,,,, -1D);
call write (terminal, message, @end^string - @messages);    !On output file (check new Tals)!
clear (file^name, "  ", 12);
file^name := "$0";
call open (file^name, console);
messages ':=' "Tal compilation of " -> @end^string;
call fileinfo (6,, file^name);                   !Name of main source file
@end^string := filenamecompress (end^string, file^name);
end^string ':=' " completed" -> @end^string;
call write (console, message, @end^string - @messages);
call close (console);
stack 0, 0;                                      !parameters for stop
code (PUSH %711;
      LADR  stop^proc;                           !Address of proc name
      LLS  1;                                    !String
      PUSH  %700;                                !On stack
      PCAL  system^proc^entry;                   !Get the PEP number
      DPCL);                                     !And stop like that
end;
