home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / njpipes.zip / template3.nrx < prev    next >
Text File  |  1998-08-30  |  2KB  |  71 lines

  1. /* uncomment package if this code is in a subdirectory of one on your classpath
  2.  * and change xxxx to the name of the subdirectory
  3.  */
  4. -- package xxxx
  5.  
  6. options binary
  7.  
  8. package stages
  9.  
  10. import pipes.
  11.  
  12. class template3 extends stage
  13.  
  14. /* run a basic stage that has very little setup to do */
  15.  
  16. method run()
  17.  
  18.    /* insert objects that need to be reset every invokation here */
  19.  
  20.    rc = int 0
  21.    s0 = boolean 1
  22.    s1 = boolean 1
  23.  
  24.    do -- to catch the terminating StageError
  25.  
  26.       /* setup code goes here
  27.        *
  28.        * if there are setup problems then
  29.        *    signal StageError(11,'termplate1 had this error')
  30.        *
  31.        */
  32.  
  33.       a = arg()    -- this could also be in a setup method see template2.txt
  34.  
  35.       /* body of the stage is here */
  36.  
  37.       loop forever
  38.  
  39.          aobj = peekto()             -- pass an object but test a rexx object
  40.          robj = rexx aobj            -- ie the objects piped are strings...
  41.          if robj = a then
  42.             do
  43.                if s0 then do
  44.                   selectOutput(0)
  45.                   output(aobj)
  46.                catch StageError      -- Using this structure if we capture
  47.                   s0 = 0             -- the StageError(s) can and will end
  48.                end                   -- up reporting a RC=4 instead of RC=12
  49.             end                      -- geting the RC via mrc will work...
  50.          else
  51.             if s1 then do
  52.                selectOutput(1)
  53.                output(aobj)
  54.             catch StageError
  55.                s1 = 0
  56.             end
  57.          readto()
  58.  
  59.       /* catch any cast exceptions that occur and issue a StageError */
  60.  
  61.       catch ClassCastException
  62.          signal StageError(13,'Error - Input not convertable to rexx')
  63.       end
  64.  
  65.    catch StageError
  66.    end
  67.  
  68.    rc = mrc()     -- extract maxium rc from all StageErrors raised by njPipes
  69.  
  70. exit(rc*(rc<>12))
  71.