:READ KERMAIL EXEC A
/*
Date: Wed, 26 Jun 91 08:20:26 MEZ
From: Erwin Halpern <Z00EHR01@AWIUNI11.BITNET>
 
  KERMAIL EXEC T
 
  Purpose:
     Route MAIL received from MS-KERMIT via CMS-KERMIT
     to MAILER for distribution.
 
  Requirements:
     At least one Read/Write-disk accessed
 
  Call:
     Is done internally by CMS-KERMIT
 
  Function:
     CMS-KERMIT calls KERMAIL once with the argument "." to assure
     that KERMAIL is available. In this case KERMAIL returns with RC=0.
     Then when CMS-KERMIT has received the mail-file from the PC, it
     calls KERMAIL with the (Arg) format shown below.  KERMAIL now looks
     if FN FT FM really exists and sends it to MAILER via MAIL.
*/
 
Arg fn ft fm '(' mailids '(' mailopts
if fn = '' | fn = "." then return 0
'SET CMSTYPE HT'
'STATE' fn ft fm
rrc=-rc
if rrc ^= 0 then do
   'SET CMSTYPE RT'
    return rrc
end
'MAIL' mailids '( NOE NOL NOPR F' fn ft fm mailopts
rrc=rc
if rrc > 0 then rrc=-rrc
'SET CMSTYPE RT'
'ERASE' fn ft fm
return rrc
:READ KERMPRT EXEC A
&TRACE *
*-------------------------------------------------------------
* KERMPRT EXEC - Sample command for driving PRINT distribution
*         jfc   90/06/25
*------------------------------------------------------------
&IF &N LT 2 &EXIT 0
&X = -1 + &LOCATION OF ( &ARGSTRING
&IF &X LT 3 &EXIT -20
&FILEID = &LEFT OF &ARGSTRING &X
&X = 2 + &X
&OPTIONS = &PIECE OF &ARGSTRING &X
&UPPER VARS &OPTIONS
* -- COULD CHECK SYNTAX HERE ...
SENTRIES
&STACKSIZE = &RC
EXECIO * CP (LIFO ST QUERY VIRTUAL 009
SENTRIES
&STACKSIZE = &RC - &STACKSIZE
&LOOP 1 &STACKSIZE
  &READ STRING &X
&CHR = &PIECE OF &X 9 1
&TERM = 23
&IF .&CHR NE . &TERM = &TERM + 2
&START = &TERM + 7
&TERM = &PIECE OF &X &TERM 6
&START = &PIECE OF &X &START 5
CP SPOOL 9 NOTERM START
&PRINT -- KERMPRT SENDING &FILEID TO PRINTER
PRINT &FILEID (&OPTIONS
&R = &RC
&IF .&START NE .START CP SPOOL 9 PURGE
EXECIO 0 CP (SKIP ST SPOOL 9 &TERM &START
&IF &R NE 0 &EXIT -20
ERASE &FILEID
&EXIT 0
:READ PC EXEC A
/*   PC Exec - J.F. Chandler - 1992 April
   (modified 1995 to use APC instead of obsolete TERMINALS)
 
   Intended to be executed either from inside Kermit or out.
   If used within Kermit, remember to SET SYSCMD ON.
 
   Syntax:  PC cmd
   The PC Kermit is placed in server mode via APC, then the "cmd"
   is executed, and then a FINISH is executed.
 
   Typical examples: PC SEND fn ft
                     PC GET file.ext
 
   Special case:  PC PRINT file
   The printer is enabled via ANSI escape sequence, the file is then
   displayed, and the printer is disabled.
*/
Parse Arg cmd
If Words(cmd) <= 1 Then Do
  Say 'Missing parameter(s)'
  Exit 99
  End
Trace OFF
print = Abbrev('PRINT',Word(cmd,1),2)
If Right(Strip(cmd),1) = ',' Then Do
  Say 'Syntax error'
  Exit 99
  End
If print Then Do
  open_cmd = 'XECHO ^[[5i'      /* Enable printer */
  cmd = 'XTYPE' Subword(cmd,2)
  close_cmd = 'XECHO ^[[4i'     /* Disable printer */
  End
Else Do
  open_cmd = 'APC SERVER'       /* start server */
  close_cmd = 'FINISH'
  End
Address KERMIT open_cmd
If rc<>0 Then Signal INVOKE     /* Kermit not started yet */
Address KERMIT cmd
r = rc
Address KERMIT close_cmd
Select
  When r=2  Then Say 'Transfer cancelled'
  When r=5  Then Say 'Bad packet count or chksum'
  When r=6  Then Say 'Invalid packet syntax'
  When r=7  Then Say 'Invalid packet type'
  When r=8  Then Say 'Lost a packet'
  When r=9  Then Say 'Micro sent a NAK'
  When r=10 Then Say 'Micro aborted'
  When r=12 Then Say 'File not found'
  When r=13 Then Say 'Disk or file is full'
  When r=14 Then Say 'Disk I/O error'
  When r=15 Then Say 'Missing operand'
  When r=17 Then Say 'Syntax error'
  When r=19 Then Say 'Records truncated'
  When r=20 Then Say 'Bad communication line'
  When r=21 Then Say '8th-bit quote not set'
  When r=22 Then Say 'File too short'
  When r=23 Then Say 'Missing start-of-packet'
  When r=24 Then Say 'Option error on filespec'
  When r=25 Then Say 'Unable to dispose of file'
  Otherwise Nop
  End
Exit r
*
INVOKE:
Push 'QUIT'
Push close_cmd
Push cmd
Push open_cmd
Address CMS 'KERMIT'
:READ PC OLD A
/*   PC Exec - J.F. Chandler - 1992 April
   (modified December to use TERMINALS instead of TERMINLR)
 
   Intended to be executed either from inside Kermit or out.
   Syntax:  PC cmd
   The PC Kermit is placed in server mode via TERMINALS, then the "cmd"
   is executed, and then a FINISH is executed.
 
   Special case:  PC PRINT file
   The printer is enabled via ANSI escape sequence, the file is then
   displayed, and the printer is disabled.
*/
Parse Arg cmd
If Words(cmd) <= 1 Then Do
  Say 'Missing parameter(s)'
  Exit 99
  End
Trace OFF
print = Abbrev('PRINT',Word(cmd,1),2)
If Right(Strip(cmd),1) = ',' Then Do
  Say 'Syntax error'
  Exit 99
  End
If print Then Do
  open_cmd = 'XECHO ^[[5i'      /* Enable printer */
  cmd = 'XTYPE' Subword(cmd,2)
  close_cmd = 'XECHO ^[[4i'     /* Disable printer */
  End
Else Do
  open_cmd = 'XECHO ^[[?34h    ^[[?34h'    /* start server (extra) */
  close_cmd = 'FINISH'
  End
Address KERMIT open_cmd
If rc<>0 Then Signal INVOKE     /* Kermit not started yet */
Address KERMIT cmd
r = rc
Address KERMIT close_cmd
Select
  When r=2  Then Say 'Transfer cancelled'
  When r=5  Then Say 'Bad packet count or chksum'
  When r=6  Then Say 'Invalid packet syntax'
  When r=7  Then Say 'Invalid packet type'
  When r=8  Then Say 'Lost a packet'
  When r=9  Then Say 'Micro sent a NAK'
  When r=10 Then Say 'Micro aborted'
  When r=12 Then Say 'File not found'
  When r=13 Then Say 'Disk or file is full'
  When r=14 Then Say 'Disk I/O error'
  When r=15 Then Say 'Missing operand'
  When r=17 Then Say 'Syntax error'
  When r=19 Then Say 'Records truncated'
  When r=20 Then Say 'Bad communication line'
  When r=22 Then Say 'File too short'
  When r=23 Then Say 'Missing start-of-packet'
  Otherwise Nop
  End
Exit r
*
INVOKE:
Push 'QUIT'
Push close_cmd
Push cmd
Push open_cmd
Address CMS 'KERMIT'
