Program SpawnTst;

{ Testing the SPAWN external procedure. 
  This program also implements a terminal lockup system. 
  It asks for a password, which is saved internally. 
  From that point, any input, other than the password, causes
  cookie to be spawned. When the password is again entered,
  the program un-slaves the terminal, and exits. 
  This requires a startup command file which:
    a) installs Spawntst
    b) slaves TI:
    c) XQT RUN SPAWNT
    d) exit
  The above command file will leave ti: slaved, with spawntst
  running. Spawntst will be in total control, until the 
  password is entered, when it will unslave ti: and exit. 

  In the above state, control can also be regained by unslaving
  the terminal from another priveleged terminal, and then 
  aborting spawnt. 

  FILE: [22,311]SPAWNTST.PAS
  Last Edit: 7-NOV-1985 15:13:51 
  AUTHOR: Jim Bostwick 5-Feb-83
  History:  7-NOV-1985 14:00:04 Randy Baldwin
            convert to Pascal-3

}

{$NOLIST}
{[A+,B+, K+, L-, R+] Pasmat Directive }

%INCLUDE EX1:[22,320]GENERAL3.TYP;
%INCLUDE EX1:[22,320]CATR56.EXT;	{ASCII -> RAD50 CONVERSION }
%INCLUDE EX1:[22,320]SPAWN.EXT;   { SPAWN A TASK }
%INCLUDE EX1:[22,320]DIRERR.EXT;  {DIRECTIVE ERROR DECODER }
%INCLUDE EX1:[22,320]STSE.EXT;	{ STOP FOR SINGLE EVENT FLAG }
{$LIST}

PROCEDURE DETACH;
 EXTERNAL;

VAR
  COMMAND: CH80;	{ INPUT FROM TI: }
  MCRNAM: RAD56; { RAD-50 MCR TASK NAME }
  SECRET: CH80; { SECRET PASSWORD }
  FUBAR:BOOLEAN; { Directive error flag }
  Match:Boolean; { Command matches secret }
  Status, I:Integer;
  COO:CH3;
  SETON:CH16;
  COOADR, SETONADR :ADDRESS;    

{--------------------------------------------------------------------}

  PROCEDURE INIT;


    BEGIN 
    COO:='SHI';
    COOADR:=LOOPHOLE(ADDRESS,REF(COO));
    SETON:='SET /NOSLAVE=TI:';
    SETONADR:=LOOPHOLE(ADDRESS,REF(SETON));
    CATR56('MCR...',MCRNAM)
    END;


{--------------------------------------------------------------------}

BEGIN
  DETACH;
  Init;
  Writeln('Hi there, enter a password:');
  Readln(Secret);
  For I:=1 to 25 do Writeln; {clear screen }
  Repeat
    Write('>');
    Readln(command);  
    Match:=True;
    I:=1;
      repeat
      If Command[I] <> Secret[I] Then Match:=False;
      I:=I+1;
      Until (Match=False) OR (I>80);
    IF Match THEN 
      BEGIN 
      Spawn(MCRNAM, F1, SETONADR, 16, Status);
      Fubar:=Direrr('SET NOSLAV',$DSW)
      END ELSE
      BEGIN 
      SPAWN(MCRNAM, F1, COOADR, 3, Status);
      Fubar:=Direrr('COOKIE    ',$DSW);
      STSE(F1);
      Fubar:=Direrr('STOPFOR F1',$DSW)
      END;
    Until Match=TRUE;
  Writeln; Writeln;
  Write('We now return control of your Television to the regularly');
  Writeln(' scheduled program.')
end.
