home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 545b.lha / RexxHS / samplehost.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1991-09-07  |  4.0 KB  |  179 lines

  1. /*
  2.  * SampleHost.rexx -- A sample ARexx command host, written in ARexx.
  3.  *                    Requires rexxhs.library and rexxsupport.library.
  4.  *
  5.  * Written by Eric Giguere for the AmigaWorld Tech Journal.
  6.  */
  7.  
  8. /* Make sure the libraries are accessible... */
  9.  
  10. if( ~show( 'l', "rexxsupport.library" ) )then do
  11.     if( ~addlib( "rexxsupport.library", 0, -30, 0 ) )then do
  12.         say "Could not open rexxsupport.library"
  13.         exit 10
  14.     end
  15. end
  16.  
  17. if( ~show( 'l', "rexxhs.library" ) )then do
  18.     if( ~addlib( "rexxhs.library", 0, -30, 0 ) )then do
  19.         say "Could not open rexxhs.library"
  20.         exit 10
  21.     end
  22. end
  23.  
  24. /* OK, open up a port to wait for messages.  We'll use "SAMPLEHOST"
  25.    as the port name... */
  26.  
  27. port = OpenPort( "SAMPLEHOST" )
  28.  
  29. if( port = Null() )then do
  30.     say "Could not open message port SAMPLEHOST"
  31.     exit 10
  32. end
  33.  
  34. /* Now wait for packets to arrive */
  35.  
  36. exit_requested = 0
  37. packet_result  = "0"
  38. packet_rc      = 0
  39.  
  40. do while( ~exit_requested )
  41.  
  42.     say "SAMPLEHOST waiting for requests..."
  43.     call WaitPkt "SAMPLEHOST"
  44.  
  45.     do forever
  46.         packet = GetPkt( "SAMPLEHOST" )
  47.  
  48.         if( packet = Null() )then break
  49.  
  50.         /* We'll store our arguments in stems... */
  51.  
  52.         args.      = ''
  53.         args.nargs = 0
  54.  
  55.         /* Here we check to see if a packet is a function message
  56.          * or a command message and then do whatever is
  57.          * appropriate...
  58.          */
  59.  
  60.         if( IsFunctionCall( packet ) )then
  61.           do
  62.             args.nargs = NumArgs( packet )
  63.             args.0     = GetArg( packet, 0 )
  64.  
  65.             say "SAMPLEHOST received a function request:"
  66.             say "    Function name:" args.0
  67.             say "    Number of arguments:" args.nargs
  68.  
  69.             if( args.nargs > 0 )then do
  70.                 do i = 1 to args.nargs
  71.                     args.i = GetArg( packet, i )
  72.                     say "        Argument" i": ["args.i"]"
  73.                 end
  74.             end
  75.           end
  76.         else
  77.           do
  78.             command = strip( GetArg( packet, 0 ) )
  79.  
  80.             say "SAMPLEHOST received a command request:"
  81.             say "    Command string: ["command"]"
  82.  
  83.             do i = 0 by 1 while( command ~= '' )
  84.  
  85.                 command = strip( command )
  86.  
  87.                 if( left( command, 1 ) = '"' )then
  88.                   do
  89.                       parse var command '"'args.i'"'command
  90.                   end
  91.                 else if( left( command, 1 ) = "'" )then
  92.                   do
  93.                       parse var command "'"args.i"'"command
  94.                   end
  95.  
  96.                 if( args.i = '' & command ~= '' )then do
  97.                       parse var command args.i command
  98.                 end
  99.             end
  100.  
  101.             if( i > 0 )then
  102.                 args.nargs = i - 1
  103.           end
  104.  
  105.         args.0 = upper( args.0 )
  106.  
  107.         select
  108.             when args.0 = 'GET' then call Do_Get
  109.             when args.0 = 'SET' then call Do_Set
  110.             when args.0 = 'EXIT' then call Do_Exit
  111.             otherwise nop
  112.         end
  113.  
  114.         call ReplyToCall packet, packet_rc, packet_result
  115.    end
  116. end
  117.  
  118. say "SAMPLEHOST exiting..."
  119. call ClosePort "SAMPLEHOST"
  120.  
  121. exit 0
  122.  
  123.  
  124. /*
  125.  * Do_Get: get the current rc or result value
  126.  */
  127.  
  128. Do_Get:
  129.     var = upper( args.1 )
  130.  
  131.     if( var = 'RC' )then
  132.       do
  133.         say "Setting RESULT to current value of RC"
  134.         packet_result = packet_rc
  135.       end
  136.     else if( var = 'RESULT' )then
  137.       do
  138.         say "Setting RC to 0 so you can get value of RESULT"
  139.         packet_rc = 0
  140.       end
  141.  
  142.     return
  143.  
  144. /*
  145.  * Do_Set: set the current rc or result value
  146.  */
  147.  
  148. Do_Set:
  149.     var = upper( args.1 )
  150.  
  151.     if( var = 'RC' )then
  152.       do
  153.         if( datatype( packet_rc, 'w' ) )then do
  154.             say "Setting RC to" args.2
  155.             packet_rc = args.2
  156.         end
  157.       end
  158.     else if( var = 'RESULT' )then
  159.       do
  160.         say "Setting RESULT to" args.2
  161.  
  162.         if( packet_rc ~= 0 )then
  163.             say "But you need to set RC to 0 to see the value..."
  164.  
  165.         packet_result = args.2
  166.       end
  167.  
  168.     return
  169.  
  170. /*
  171.  * Do_Exit: leave
  172.  */
  173.  
  174. Do_Exit:
  175.     exit_requested = 1
  176.     say "SAMPLEHOST received exit request"
  177.  
  178.     return
  179.