home *** CD-ROM | disk | FTP | other *** search
- /*
- * SampleHost.rexx -- A sample ARexx command host, written in ARexx.
- * Requires rexxhs.library and rexxsupport.library.
- *
- * Written by Eric Giguere for the AmigaWorld Tech Journal.
- */
-
- /* Make sure the libraries are accessible... */
-
- if( ~show( 'l', "rexxsupport.library" ) )then do
- if( ~addlib( "rexxsupport.library", 0, -30, 0 ) )then do
- say "Could not open rexxsupport.library"
- exit 10
- end
- end
-
- if( ~show( 'l', "rexxhs.library" ) )then do
- if( ~addlib( "rexxhs.library", 0, -30, 0 ) )then do
- say "Could not open rexxhs.library"
- exit 10
- end
- end
-
- /* OK, open up a port to wait for messages. We'll use "SAMPLEHOST"
- as the port name... */
-
- port = OpenPort( "SAMPLEHOST" )
-
- if( port = Null() )then do
- say "Could not open message port SAMPLEHOST"
- exit 10
- end
-
- /* Now wait for packets to arrive */
-
- exit_requested = 0
- packet_result = "0"
- packet_rc = 0
-
- do while( ~exit_requested )
-
- say "SAMPLEHOST waiting for requests..."
- call WaitPkt "SAMPLEHOST"
-
- do forever
- packet = GetPkt( "SAMPLEHOST" )
-
- if( packet = Null() )then break
-
- /* We'll store our arguments in stems... */
-
- args. = ''
- args.nargs = 0
-
- /* Here we check to see if a packet is a function message
- * or a command message and then do whatever is
- * appropriate...
- */
-
- if( IsFunctionCall( packet ) )then
- do
- args.nargs = NumArgs( packet )
- args.0 = GetArg( packet, 0 )
-
- say "SAMPLEHOST received a function request:"
- say " Function name:" args.0
- say " Number of arguments:" args.nargs
-
- if( args.nargs > 0 )then do
- do i = 1 to args.nargs
- args.i = GetArg( packet, i )
- say " Argument" i": ["args.i"]"
- end
- end
- end
- else
- do
- command = strip( GetArg( packet, 0 ) )
-
- say "SAMPLEHOST received a command request:"
- say " Command string: ["command"]"
-
- do i = 0 by 1 while( command ~= '' )
-
- command = strip( command )
-
- if( left( command, 1 ) = '"' )then
- do
- parse var command '"'args.i'"'command
- end
- else if( left( command, 1 ) = "'" )then
- do
- parse var command "'"args.i"'"command
- end
-
- if( args.i = '' & command ~= '' )then do
- parse var command args.i command
- end
- end
-
- if( i > 0 )then
- args.nargs = i - 1
- end
-
- args.0 = upper( args.0 )
-
- select
- when args.0 = 'GET' then call Do_Get
- when args.0 = 'SET' then call Do_Set
- when args.0 = 'EXIT' then call Do_Exit
- otherwise nop
- end
-
- call ReplyToCall packet, packet_rc, packet_result
- end
- end
-
- say "SAMPLEHOST exiting..."
- call ClosePort "SAMPLEHOST"
-
- exit 0
-
-
- /*
- * Do_Get: get the current rc or result value
- */
-
- Do_Get:
- var = upper( args.1 )
-
- if( var = 'RC' )then
- do
- say "Setting RESULT to current value of RC"
- packet_result = packet_rc
- end
- else if( var = 'RESULT' )then
- do
- say "Setting RC to 0 so you can get value of RESULT"
- packet_rc = 0
- end
-
- return
-
- /*
- * Do_Set: set the current rc or result value
- */
-
- Do_Set:
- var = upper( args.1 )
-
- if( var = 'RC' )then
- do
- if( datatype( packet_rc, 'w' ) )then do
- say "Setting RC to" args.2
- packet_rc = args.2
- end
- end
- else if( var = 'RESULT' )then
- do
- say "Setting RESULT to" args.2
-
- if( packet_rc ~= 0 )then
- say "But you need to set RC to 0 to see the value..."
-
- packet_result = args.2
- end
-
- return
-
- /*
- * Do_Exit: leave
- */
-
- Do_Exit:
- exit_requested = 1
- say "SAMPLEHOST received exit request"
-
- return
-