ToolChain/bin/targets/m68k-amigaos/ndk/Tutorials/ARexx/Host/Host.c
VOID
HandleRexxMsg(
	const struct RexxHost *	Host,
	struct RexxParseData *	Data,
	struct RexxMsg *	Message)
{
	struct CmdFunc * Table;
	struct CmdFunc * CmdFunc;
	STRPTR Command;
	STRPTR Arguments;
	LONG Error;
	LONG Len;
	LONG i;

		/* This is where the entire command string is stored,
		 * including following arguments.
		 */

	Command = Message->rm_Args[0];

		/* Skip leading blanks. */

	while(*Command == ' ' || *Command == '\t')
		Command++;

		/* Now determine the length of the command. */

	Len = 0;

	while(Command[Len])
	{
		if(Command[Len] == '\t' || Command[Len] == ' ')
			break;
		else
			Len++;
	}

		/* Now we need to check if the command we received
		 * can be handled by one of the routines in the
		 * command table.
		 */

	Table = Host->CommandTable;
	CmdFunc = NULL;

	for(i = 0 ; Table[i].CommandName != NULL ; i++)
	{
		if((strlen(Table[i].CommandName) == Len) && (Strnicmp(Command,Table[i].CommandName,Len) == 0))
		{
			CmdFunc = &Table[i];
			break;
		}
	}

		/* If no matching command could be found, return
		 * an error.
		 */

	if(CmdFunc == NULL)
		Error = ERROR_OBJECT_NOT_FOUND;
	else
	{
			/* Reset the argument pointers. */

		memset(Data->Args,0,sizeof(Data->Args));

			/* Separate the arguments from the command;
			 * first skip the leading blanks.
			 */

		Arguments = &Command[Len];

		while(*Arguments == '\t' || *Arguments == ' ')
			Arguments++;

			/* Remove trailing blanks. */

		Len = strlen(Arguments);

		while((Len > 0) &&
			(Arguments[Len - 1] == '\t' || Arguments[Len - 1] == ' '))
				Len--;

			/* We only allow for 510 characters of argument data. */

		if(Len > 510)
			Len = 510;

			/* Put the arguments into the parser buffer. */

		if(Len > 0)
			CopyMem(Arguments,Data->Line,Len);

			/* Add the line feed and the null-termination. */

		Data->Line[Len] = '\n';
		Data->Line[Len+1] = 0;

			/* Set up the parser to read from the argument
			 * buffer.
			 */

		Data->ReadArgs->RDA_Source.CS_Buffer = Data->Line;
		Data->ReadArgs->RDA_Source.CS_Length = Len + 1;
		Data->ReadArgs->RDA_Source.CS_CurChr = 0;
		Data->ReadArgs->RDA_Flags |= RDAF_NOPROMPT;

			/* Run the arguments through the parser. This will
			 * set up the Data->Args array.
			 */

		if(ReadArgs(CmdFunc->Template,(LONG *)Data->Args,Data->ReadArgs))
		{
				/* Invoke the command. */

			Error = (*CmdFunc->Function)(Host->UserData,Message,Data->Args);

				/* Free the parser data. */

			FreeArgs(Data->ReadArgs);
		}
		else
			Error = IoErr();
	}

		/* If an error occured, return the message now.
		 * In any other case the command handler will have
		 * taken care of it already.
		 */

	if(Error)
		ReturnErrorMsg(Message,Host->PortName,Error);
}
/****** Host/HandleRexxMsg ***************************************************
*
*   NAME
*       HandleRexxMsg -- Process incoming rexx message and invoke the
*           apropriate function handler.
*
*   SYNOPSIS
*       HandleRexxMsg(Host,Data,Message)
*
*       VOID HandleRexxMsg(const struct RexxHost *Host,
*           struct RexxParseData *Data,struct RexxMsg *Message);
*
*   FUNCTION
*       This routine prepares the ground for the final command execution.
*       It tries to find the command the Rexx message should invoke and
*       parses the command arguments. If a matching command could be found
*       and the arguments are correct the corresponding function is invoked.
*       When control has passed through this routine the Rexx message will
*       have been replied.
*
*   INPUTS
*       Host - ARexx Host environment as created by CreateRexxHost
*
*       Data - Parser data as created by CreateParseData
*
*       Message - Pointer to RexxMsg received from client.
*
*   NOTES
*       This routine should only be called by a Process.
*
*   RESULT
*       None
*
*   SEE ALSO
*       dos.library/ReadArgs
*       CreateParseData
*       CreateRexxHost
*
******************************************************************************
*
*/
Host/HandleRexxMsg
NAME
HandleRexxMsg -- Process incoming rexx message and invoke the
apropriate function handler.





FUNCTION
This routine prepares the ground for the final command execution.
It tries to find the command the Rexx message should invoke and
parses the command arguments. If a matching command could be found
and the arguments are correct the corresponding function is invoked.
When control has passed through this routine the Rexx message will
have been replied.

INPUTS
Host - ARexx Host environment as created by CreateRexxHost

Parser data as created by CreateParseData

Pointer to RexxMsg received from client.

NOTES
This routine should only be called by a Process.

RESULT
None


Host / HandleRexxMsg NAME HandleRexxMsg -- Process incoming rexx message and invoke the apropriate function handler . FUNCTION This routine prepares the ground for the final command execution . It tries to find the command the Rexx message should invoke and parses the command arguments . If a matching command could be found and the arguments are correct the corresponding function is invoked . When control has passed through this routine the Rexx message will have been replied . INPUTS Host - ARexx Host environment as created by CreateRexxHost Parser data as created by CreateParseData Pointer to RexxMsg received from client . NOTES This routine should only be called by a Process . RESULT None
VOID
HandleRexxMsg(
	const struct RexxHost *	Host,
	struct RexxParseData *	Data,
	struct RexxMsg *	Message)
{
	struct CmdFunc * Table;
	struct CmdFunc * CmdFunc;
	STRPTR Command;
	STRPTR Arguments;
	LONG Error;
	LONG Len;
	LONG i;
	Command = Message->rm_Args[0];
	while(*Command == ' ' || *Command == '\t')
		Command++;
	Len = 0;
	while(Command[Len])
	{
		if(Command[Len] == '\t' || Command[Len] == ' ')
			break;
		else
			Len++;
	}
	Table = Host->CommandTable;
	CmdFunc = NULL;
	for(i = 0 ; Table[i].CommandName != NULL ; i++)
	{
		if((strlen(Table[i].CommandName) == Len) && (Strnicmp(Command,Table[i].CommandName,Len) == 0))
		{
			CmdFunc = &Table[i];
			break;
		}
	}
	if(CmdFunc == NULL)
		Error = ERROR_OBJECT_NOT_FOUND;
	else
	{
		memset(Data->Args,0,sizeof(Data->Args));
		Arguments = &Command[Len];
		while(*Arguments == '\t' || *Arguments == ' ')
			Arguments++;
		Len = strlen(Arguments);
		while((Len > 0) &&
			(Arguments[Len - 1] == '\t' || Arguments[Len - 1] == ' '))
				Len--;
		if(Len > 510)
			Len = 510;
		if(Len > 0)
			CopyMem(Arguments,Data->Line,Len);
		Data->Line[Len] = '\n';
		Data->Line[Len+1] = 0;
		Data->ReadArgs->RDA_Source.CS_Buffer = Data->Line;
		Data->ReadArgs->RDA_Source.CS_Length = Len + 1;
		Data->ReadArgs->RDA_Source.CS_CurChr = 0;
		Data->ReadArgs->RDA_Flags |= RDAF_NOPROMPT;
		if(ReadArgs(CmdFunc->Template,(LONG *)Data->Args,Data->ReadArgs))
		{
			Error = (*CmdFunc->Function)(Host->UserData,Message,Data->Args);
			FreeArgs(Data->ReadArgs);
		}
		else
			Error = IoErr();
	}
	if(Error)
		ReturnErrorMsg(Message,Host->PortName,Error);
}
VOID HandleRexxMsg ( const struct RexxHost * Host , struct RexxParseData * Data , struct RexxMsg * Message ) { struct CmdFunc * Table ; struct CmdFunc * CmdFunc ; STRPTR Command ; STRPTR Arguments ; LONG Error ; LONG Len ; LONG i ; Command = Message -> rm_Args [ 0 ] ; while ( * Command == ' ' || * Command == ' \t ' ) Command ++ ; Len = 0 ; while ( Command [ Len ] ) { if ( Command [ Len ] == ' \t ' || Command [ Len ] == ' ' ) break ; else Len ++ ; } Table = Host -> CommandTable ; CmdFunc = NULL ; for ( i = 0 ; Table [ i ] . CommandName != NULL ; i ++ ) { if ( ( strlen ( Table [ i ] . CommandName ) == Len ) && ( Strnicmp ( Command , Table [ i ] . CommandName , Len ) == 0 ) ) { CmdFunc = & Table [ i ] ; break ; } } if ( CmdFunc == NULL ) Error = ERROR_OBJECT_NOT_FOUND ; else { memset ( Data -> Args , 0 , sizeof ( Data -> Args ) ) ; Arguments = & Command [ Len ] ; while ( * Arguments == ' \t ' || * Arguments == ' ' ) Arguments ++ ; Len = strlen ( Arguments ) ; while ( ( Len > 0 ) && ( Arguments [ Len - 1 ] == ' \t ' || Arguments [ Len - 1 ] == ' ' ) ) Len -- ; if ( Len > 510 ) Len = 510 ; if ( Len > 0 ) CopyMem ( Arguments , Data -> Line , Len ) ; Data -> Line [ Len ] = ' \n ' ; Data -> Line [ Len + 1 ] = 0 ; Data -> ReadArgs -> RDA_Source . CS_Buffer = Data -> Line ; Data -> ReadArgs -> RDA_Source . CS_Length = Len + 1 ; Data -> ReadArgs -> RDA_Source . CS_CurChr = 0 ; Data -> ReadArgs -> RDA_Flags |= RDAF_NOPROMPT ; if ( ReadArgs ( CmdFunc -> Template , ( LONG * ) Data -> Args , Data -> ReadArgs ) ) { Error = ( * CmdFunc -> Function ) ( Host -> UserData , Message , Data -> Args ) ; FreeArgs ( Data -> ReadArgs ) ; } else Error = IoErr ( ) ; } if ( Error ) ReturnErrorMsg ( Message , Host -> PortName , Error ) ; }
Host/HandleRexxMsg
NAME
HandleRexxMsg -- Process incoming rexx message and invoke the
apropriate function handler.
Host / HandleRexxMsg NAME HandleRexxMsg -- Process incoming rexx message and invoke the apropriate function handler .
/* This is where the entire command string is stored,
		 * including following arguments.
		 */ /* Skip leading blanks. */ /* Now determine the length of the command. */ /* Now we need to check if the command we received
		 * can be handled by one of the routines in the
		 * command table.
		 */ /* If no matching command could be found, return
		 * an error.
		 */ /* Reset the argument pointers. */ /* Separate the arguments from the command;
			 * first skip the leading blanks.
			 */ /* Remove trailing blanks. */ /* We only allow for 510 characters of argument data. */ /* Put the arguments into the parser buffer. */ /* Add the line feed and the null-termination. */ /* Set up the parser to read from the argument
			 * buffer.
			 */ /* Run the arguments through the parser. This will
			 * set up the Data->Args array.
			 */ /* Invoke the command. */ /* Free the parser data. */ /* If an error occured, return the message now.
		 * In any other case the command handler will have
		 * taken care of it already.
		 */