Exemplo n.º 1
0
/*
 * assignedRxString builds a RXSTRING of a GCI_str. The RXSTRING is set
 * in the usual manner and a terminating zero is appended without notification
 * of the target. NULL-strings are converted to empty strings.
 * Returns 1 on error, 0 on success.
 */
static int assignRxString( void *hidden,
                           PRXSTRING dest,
                           const GCI_str *src )
{
   char *h;

   if ( RXNULLSTRING( *dest ) || ( RXSTRLEN( *dest ) < (ULONG) src->used+1 ) )
   {
      if ( ( h = (char *) IfcAllocateMemory( (ULONG) (src->used+1) ) ) == NULL )
         return 1;
   }
   else
      h = RXSTRPTR( *dest );

   memcpy( h, src->val, src->used );
   h[(int) (src->used)] = '\0';
   MAKERXSTRING( *dest, h, (ULONG) src->used );
   return 0;
}
/**
 * Do post-callout processing of a command dispatch.  This
 * code runs after re-entering the interpreter, so all
 * interpreter facilities are available.
 *
 * @param result    The return RC result.
 * @param condition A potential condition return.
 */
void CommandHandlerDispatcher::complete(RexxString *command, ProtectedObject &result, ProtectedObject &condition)
{
    // did we get a numeric return code?  Turn into an Integer object.
    if (sbrc != 0)
    {
        result = new_integer(sbrc);
    }
    // maybe we got a string value back?
    else if (!RXNULLSTRING(retstr))
    {
        // make into a string value and try to convert to an integer (not an error
        // if it doesn't convert)
        result = new_string(retstr.strptr, retstr.strlength);
        // try to get this as a numeric value
        result->numberValue(sbrc);
        // handle any buffer reallocation
        if (retstr.strptr != default_return_buffer)
        {
            SystemInterpreter::releaseResultMemory(retstr.strptr);
        }
    }
    // default return code is zero
    else
    {
        result = IntegerZero;
    }

    // Check error flags from subcom handler and if needed, stick condition
    // into result array.
    if (flags & (unsigned short)RXSUBCOM_FAILURE)
    {
        // raise the condition when things are done
        condition = activity->createConditionObject(GlobalNames::FAILURE, result, command, OREF_NULL, OREF_NULL);
    }
    else if (flags & (unsigned short)RXSUBCOM_ERROR)
    {
        // raise the condition when things are done
        condition = activity->createConditionObject(GlobalNames::ERRORNAME, result, command, OREF_NULL, OREF_NULL);
    }
}
Exemplo n.º 3
0
ULONG RxDllFunc1(CHAR *name,      /* User Routine name */
	ULONG numargs,      /* Number of arguments */
	RXSTRING args[],    /* Null-terminated RXSTRINGs array*/
	CHAR *queuename,    /* Current external data queue name */
	RXSTRING *retstr)   /* return RXSTRING  */
{
	CHAR string[255];    /*local scratch buffers*/
	CHAR buff[255];
	ULONG i,j,k;         /*local counters*/

/* Example Function: accessing arguments */
/* This function returns # of args passed and the length of each argument*/

#ifdef ArgCount1  /*if defined, check for correct # of arguments*/
	if (numargs != ArgCount1) { return FUNC_FAILED;}  /*return error code(40) if bad*/
#endif
	ultoa(numargs,string,10);            /*number of arguments passed*/
	i = 0;
	while (i<numargs){                   /*step thru arguments*/
		strlcat(string," ",sizeof(string));          /*spacer*/
		if (RXNULLSTRING(args[i])) { strcat(string,"N");} /*null arg, return N*/
		else {
			if (RXZEROLENSTRING(args[i])) { strlcat(string,"0",sizeof(string));}              /*null string, return 0*/
			else {                                                                            /*non-null string passed*/

				/*accesse the actual parameter and protects the buffer from overrun*/
				strlcpy(buff,args[i].strptr,min(args[i].strlength+1,sizeof(buff)));       /* copy to buff as a C-string*/

				/*convert the arg length to a string and append to the buffer*/
				utoa(args[i].strlength,buff,10); strlcat(string,buff,sizeof(string));     /*return size: note: buff gets wacked!*/
			}
		}
		i++;    /*next arg*/
	}
	strlcpy(retstr->strptr,string,255);            /*trim string if over default return string length*/
	retstr->strlength = strlen(retstr->strptr);    /*return actual length*/
	return FUNC_OK;                                /*successful return code(0)*/
}