Jump to content

Write the REXX Queue to STDOUT

From EDM2
Revision as of 17:11, 27 January 2020 by Ak120 (talk | contribs) (Created page with "<pre> ------------------------------------------------------------------: Name: RXQUEUE1.CMD: /* ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  
 /* ------------------------------------------------------------------ */
 /* Name:     RXQUEUE1.CMD                                             */
 /*                                                                    */
 /* Function: Write the contents of a REXX queue to STDOUT.            */
 /*                                                                    */
 /* Usage:    RXQUEUE1 {queueName} {/CLEAR}                            */
 /*                                                                    */
 /* Where:    queueName                                                */
 /*             name of the queue to use                               */
 /*             (def.: If the environment variable RXQUEUE is defined  */
 /*                    use the value of this variable else use the     */
 /*                    default REXX queue named SESSION)               */
 /*                                                                    */
 /*           /CLEAR                                                   */
 /*             only clear the REXX queue                              */
 /*                                                                    */
 /* Notes:    Error messages are written to STDERR.                    */
 /*                                                                    */
 /* Example:  RXQUEUE1 | myProgram                                     */
 /*                                                                    */
 /* (c) 1996 Bernd Schemmer, Germany, EMail: Bernd.Schemmer@gmx.de     */
 
 /* -------------------------- */
                     /* install error handlers                         */
 
   signal on error   Name ErrorAbort
   signal on syntax  Name ErrorAbort
   signal on failure Name ErrorAbort
   signal on halt    Name ErrorAbort
   signal on novalue Name ErrorAbort
 
 /* -------------------------- */
 
                     /* init some variables                            */
 
                     /* save the name of the current queue             */
   saveQueueName = rxqueue( 'get' )
 
                     /* name of the queue to use                       */
   queueName = ''
 
                     /* default queue to use                           */
   defaultQueueName = 'SESSION'
 
                     /* mode either CLEAR or ''                        */
   mode = ''
 
                     /* return code of this program                    */
   rxqueueRC = 0
 
 /* -------------------------- */
                     /* parse the parameter                            */
 
   parse upper arg arguments
 
   do while arguments <> ''
 
     parse var arguments thisArgument arguments
 
     select
 
       when wordpos( thisArgument, '/? /H /HELP -? -H -HELP' ) <> 0 then
       do
 
         call lineOut 'STDERR:', ,
            'RXQUEUE1.CMD - write the REXX queue to STDOUT' || '0D0A'x || ,
            '  Usage:  RXQUEUE1 {queueName} {/CLEAR}'
 
         rxqueueRC = 1
         signal programEnd
 
       end /* when */
 
       when thisArgument = '/CLEAR' then
         mode = 'CLEAR'
 
       when left( thisArgument,1 ) = '/' then
         call ShowErrorAndExit ,
          'SYS1003: The syntax of the command is incorrect.'
 
       otherwise
         if queueName = '' then
           queueName = thisArgument
         else
           call ShowErrorAndExit,
            'SYS1003: The syntax of the command is incorrect.'
 
     end /* select */
   end /* do while arguments <> '' */
 
                     /* check for environment variable if the queue    */
                     /* name is not part of the parameters             */
   if queueName = '' then
     queueName = translate( value( 'RXQUEUE',, 'OS2ENVIRONMENT' ) )
 
                     /* use the default queue if neither the parameter */
                     /* nor the environment variable is set            */
   if queueName = '' then
     queueName = defaultQueueName
 
                     /* check the name of the queue for invalid  v2.60 */
                     /* characters                               v2.60 */
   if verify( translate( queueName ), ,
         XRANGE( 'A', 'Z' ) || '0123456789.!?_' , 'NOMATCH' ) <> 0 then
     call ShowErrorAndExit ,
         'REX0122: The name ' || queueName || 'is not a valid queue name.'
 
   if queueName <> rxqueue( 'get' ) then
   do
                     /* the current queue is not the queue we should   */
                     /* use -- so we have to change the current queue  */
 
                     /* try to create the queue to check if it already */
                     /* exists                                         */
     tQueue = rxqueue( 'create', queueName )
 
                     /* imediately delete the created queue            */
     call rxqueue 'delete', tqueue
 
     if tQueue = queueName then
       call ShowErrorAndExit ,
        'REX0124: The queue ' || queueName || ' does not exist.'
 
                     /* make the queue use the current queue           */
     call rxqueue 'set', queueName
     if rxqueue( 'get' ) <> queueName then
       call ShowErrorAndExit ,
        'Cannot activate the queue "' || queueName || '".'
 
   end /* queueName <> rxqueue( 'get' ) then */
 
   if mode = 'CLEAR' then
   do
                     /* clear the queue                                */
     do while queued() <> 0
       parse pull
     end /* do while queued() <> 0 */
 
   end /* if mode = 'CLEAR' then */
   else
   do
                     /* write the queue to STDOUT                      */
     do while queued() <> 0
       call lineOut 'STDOUT:', lineIn( 'QUEUE:' )
     end /* do while queued() <> 0 */
 
   end /* else */
 
   rxqueueRC = 0
 
 /* ------------------------------------------------------------------ */
 ProgramEnd:
 
                     /* restore the REXX queue                         */
   if symbol( 'SaveQueueName' ) = 'VAR' then
     call rxqueue 'set' , SaveQueueName
 
                     /* check the RC variable                          */
   if symbol( 'rxQueueRC' ) <> 'VAR' then
     rxqueueRC = 254
 
 exit rxqueueRC
 
 /* ------------------------------------------------------------------ */
 /* error exit - print the error message to STDERR and exit with       */
 /*              rc=255                                                */
 /*                                                                    */
 ShowErrorAndExit:
   parse arg ErrorMessage
 
   call LineOut 'STDERR:', errorMessage
 
   rxqueueRC = 255
 
 signal ProgramEnd
 
 /* ------------------------------------------------------------------ */
 
 ErrorAbort:
   call LineOut 'STDERR:', 'Error "' || condition( 'c' ) || '" occured!'
   call LineOut 'STDERR:', 'Error processing "' || condition('D') || '"'
   call LineOut 'STDERR:', 'The invalid line is line no. ' || sigl
   call LineOut 'STDERR:', 'The value of RC is ' || rc
 signal ProgramEnd