Beispiel #1
0
/*
 * Returns the translated function code from GCI_result to the code that
 * Regina shall return to the caller.
 * This function set the textual representation of an error code to that value
 * that will be accessed by RxFuncErrMsg() and sets the variable GCI_RC to
 * that value, too.
 *
 * dispo is either NULL (or the content is NULL) or contains the position of
 * the error within the structure. dispo's content will be deallocated.
 */
static int GCIcode2ReginaFuncCode( tsd_t *TSD,
                                   GCI_result rc,
                                   GCI_str *dispo,
                                   int forceError )
{
   GCI_str description, fullinfo, *fi = NULL, *out;
   volatile char *tmpDispo, *tmpFull = NULL, *tmpBest;
   streng *h;
   char GCI_RC[7];
   GCI_strOfCharBuffer(GCI_RC);

   GCI_strcats( &str_GCI_RC, "GCI_RC" );
   GCI_describe( &description, rc );

   if ( ( dispo != NULL ) && ( GCI_content( dispo ) == NULL ) )
      dispo = NULL;

   if ( ( dispo != NULL ) && ( rc != GCI_OK ) )
   {
      if ( GCI_stralloc( TSD, &fullinfo, GCI_strlen( dispo ) +
                                         GCI_strlen( &description ) +
                                         3 ) == GCI_OK )
      {
         fi = &fullinfo;
         GCI_strcpy( fi, &description );
         GCI_strcats( fi, ": " );
         GCI_strcat( fi, dispo );
      }
   }

   out = ( fi != NULL ) ? fi : &description;
   GCI_writeRexx( TSD, &str_GCI_RC, out, 0 );

   if ( ( rc == GCI_OK ) && !forceError )
   {
      if ( dispo != NULL )
         GCI_strfree( TSD, dispo );
      if ( fi != NULL )
         GCI_strfree( TSD, fi );
      return 0;
   }

   h = streng_of( TSD, &description );
   tmpDispo = tmpstr_of( TSD, h );
   Free_stringTSD( h );

   if ( fi != NULL )
   {
      h = streng_of( TSD, fi );
      tmpFull = tmpstr_of( TSD, h );
      Free_stringTSD( h );
   }

   if ( dispo != NULL )
      GCI_strfree( TSD, dispo );
   if ( fi != NULL )
      GCI_strfree( TSD, fi );

   /*
    * We have two temporary strings describing the error condition.
    * All stuff we have to deallocate is deallocated. Let's go.
    */
   tmpBest = ( tmpFull != NULL ) ? tmpFull : tmpDispo;
   set_err_message( TSD, (char *) tmpBest, "" );

   switch ( rc )
   {
      case GCI_NoMemory:
         exiterror( ERR_STORAGE_EXHAUSTED, 0 );

      case GCI_WrongInput:
         exiterror( ERR_INCORRECT_CALL, 980, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_NumberRange:
         exiterror( ERR_INCORRECT_CALL, 981, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_StringRange:
         exiterror( ERR_INCORRECT_CALL, 982, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_UnsupportedType:
         if ( !forceError )
            return 71; /* RXFUNC_BADTYPE + 1 */
         exiterror( ERR_INCORRECT_CALL, 983, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_UnsupportedNumber:
         exiterror( ERR_INCORRECT_CALL, 984, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_BufferTooSmall:
         exiterror( ERR_INCORRECT_CALL, 985, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_MissingName:
         exiterror( ERR_INCORRECT_CALL, 986, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_MissingValue:
         exiterror( ERR_INCORRECT_CALL, 987, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_IllegalName:
         exiterror( ERR_INCORRECT_CALL, 988, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_RexxError:
         exiterror( ERR_INCORRECT_CALL, 989, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_NoBaseType:
         exiterror( ERR_INCORRECT_CALL, 990, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_SyntaxError:
         exiterror( ERR_INCORRECT_CALL, 991, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_ArgStackOverflow:
         exiterror( ERR_INCORRECT_CALL, 992, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      case GCI_NestingOverflow:
         exiterror( ERR_INCORRECT_CALL, 993, ( tmpDispo ) ? ": " : "", ( tmpDispo ) ? tmpDispo : "" );

      default:
         break;
   }
   exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, tmpBest );
   return 0; /* Keep the compiler happy */
}
Beispiel #2
0
/*
 * parse is the local implementation of GCI_parsetree below. Most parameters
 * are in *cb. Have a look at callblock at top of file or at GCI_parsestring
 * below.
 * itemnumber is the iterator of the container item or array item, the later
 * always has number 1.
 *
 * The function loops over a type structure tree, the current node name is
 * placed in cb->buffer. We do a depth-first iteration.
 *
 * Indirect array[x] are replaced by a combination of
 * indirect container[1], array[x]. This allows a better addressing later.
 * The indirect container is flagged as "generated" in this case.
 *
 * THE GENERATED TYPES MAY HAVE ILLEGAL BIT SIZES. IT ISN'T CHECKED ALWAYS!
 *
 * Return values:
 * GCI_OK:              Everything is fine.
 *
 *                      In case of an error cb->buffer will contain the
 *                      variable's name where the problem raises first.
 *
 * GCI_MissingName:     A variable's name isn't set. This is the equivalence
 *                      for GCI_MissingValue in the type parsing step. The
 *                      system may or may not raise a NOVALUE condition instead
 *                      depending on the implementation.
 * GCI_BufferTooSmall:  The variable's name buffer cb->buffer can't hold the
 *                      complete variable's name or the type string exceeds
 *                      256 byte.
 * GCI_IllegalName:     The variables name in cb->buffer is illegal in terms of
 *                      Rexx. In general, the basename of GCI_paretree is
 *                      wrong.
 * GCI_RexxError:       An unexpected error is returned by the interpreter
 *                      while trying to access Rexx variables.
 * GCI_UnsupportedType: Wrong type of input, e.g. FLOAT31 or the empty string
 *                      in a type description string. Another reason is an
 *                      internal error since the default sizes for "unsigned"
 *                      and "integer" are not supported.
 * GCI_WrongInput:      Strange characters occur in the input string as the
 *                      bit size of the type.
 * GCI_NumberRange:     Number to small or big to fit into the desired type
 *                      with the desired destbyte-size. This applies to the
 *                      element count of an "ARRAY" or "CONTAINER" type size
 *                      or the bit size of the plain type.
 * GCI_NoBaseType:      The type won't fit the requirements for basic types.
 *
 * And there are numerous other possible errors returned by cb->callback.
 */
static GCI_result parse( callblock *cb,
                         int itemnumber )
{
    GCI_parseinfo pi;
    GCI_str newName;
    static const GCI_parseinfo indirectArray = { GCI_container, 1, 1, 1 };
    GCI_result rc;
    unsigned i;
    int origlen = GCI_strlen( cb->buffer );

    GCI_strfromascii( &newName, NULL, 0 );
    GCI_strcats( cb->buffer, "." );
    GCI_strcats( cb->buffer, cb->prefixChar );
    if ( ( rc = GCI_strcats( cb->buffer, "TYPE" ) ) != GCI_OK )
        return rc;
    if ( ( rc = GCI_readRexx( cb->hidden,
                              cb->buffer,
                              &cb->tempbuf,
                              0,
                              1,
                              NULL ) ) != GCI_OK )
    {
        if ( rc == GCI_MissingValue )
            rc = GCI_MissingName;
        return rc;
    }
    GCI_uppercase( cb->hidden, &cb->tempbuf );

    if ( ( rc = decode( cb->hidden, &cb->tempbuf, &pi, cb->depth, &newName ) )
            != GCI_OK )
        return rc;
    GCI_strsetlen( cb->buffer, origlen );

    if ( GCI_content( &newName ) != NULL ) {
        if (cb->recurCount++ >= 100) {
            GCI_strfree( cb->hidden, &newName );
            return GCI_NestingOverflow;
        }
        GCI_strswap( &newName, cb->buffer );
        origlen = GCI_strlen( cb->buffer );
    }

    /*
     * Alright, we have it, but we have to fetch the number of elements
     * if we parse a container or an array.
     */
    if ( ( pi.type == GCI_container ) || ( pi.type == GCI_array ) )
    {
        if ( ( rc = GCI_strcats( cb->buffer, ".0" ) ) != GCI_OK )
        {
            /*
             * The tmp buffer persists for error displaying, kill the other.
             */
            if ( GCI_content( &newName ) != NULL )
                GCI_strfree( cb->hidden, &newName );
            return rc;
        }
        if ( ( rc = GCI_readRexx( cb->hidden,
                                  cb->buffer,
                                  &cb->tempbuf,
                                  0,
                                  1,
                                  NULL ) ) != GCI_OK )
        {
            if ( rc == GCI_MissingValue )
                rc = GCI_MissingName;
            /*
             * The tmp buffer persists for error displaying, kill the other.
             */
            if ( GCI_content( &newName ) != NULL )
                GCI_strfree( cb->hidden, &newName );
            return rc;
        }

        /*
         * The result shall be a whole, positive number. Lets see...
         */
        if ( ( rc = GCI_string2bin( cb->hidden,
                                    GCI_content( &cb->tempbuf ),
                                    GCI_strlen( &cb->tempbuf ),
                                    &pi.size,
                                    sizeof( pi.size ),
                                    GCI_unsigned ) ) != GCI_OK )
        {
            /*
             * The tmp buffer persists for error displaying, kill the other.
             */
            if ( GCI_content( &newName ) != NULL )
                GCI_strfree( cb->hidden, &newName );
            return rc;
        }
        if ( pi.size == 0 )
        {
            /*
             * The tmp buffer persists for error displaying, kill the other.
             */
            if ( GCI_content( &newName ) != NULL )
                GCI_strfree( cb->hidden, &newName );
            return GCI_NumberRange;
        }
        GCI_strsetlen( cb->buffer, origlen );
    }

    if ( pi.indirect && ( pi.type == GCI_array ) )
    {
        if ( ( rc = cb->callback( cb->depth,
                                  itemnumber,
                                  cb->arg,
                                  &indirectArray) ) != GCI_OK )
            return rc;
        pi.indirect = 0;
        if ( ( rc = cb->callback( cb->depth,
                                  itemnumber,
                                  cb->arg,
                                  &pi) ) != GCI_OK )
            return rc;
        pi.indirect = 1;
    }
    else
    {
        if ( ( rc = cb->callback( cb->depth,
                                  itemnumber,
                                  cb->arg,
                                  &pi) ) != GCI_OK )
        {
            /*
             * The tmp buffer persists for error displaying, kill the other.
             */
            if ( GCI_content( &newName ) != NULL )
                GCI_strfree( cb->hidden, &newName );
            return rc;
        }
    }

    if ( ( pi.type != GCI_container ) && ( pi.type != GCI_array ) )
        return GCI_OK;

    cb->depth++;
    for ( i = 0; i < pi.size; i++ )
    {
        sprintf( cb->helper, ".%u", i + 1 );

        if ( ( rc = GCI_strcats( cb->buffer, cb->helper ) ) != GCI_OK )
        {
            /*
             * The tmp buffer persists for error displaying, kill the other.
             */
            if ( GCI_content( &newName ) != NULL )
                GCI_strfree( cb->hidden, &newName );
            return rc;
        }
        if ( ( rc = parse( cb, i ) ) != GCI_OK )
        {
            /*
             * The tmp buffer persists for error displaying, kill the other.
             */
            if ( GCI_content( &newName ) != NULL )
                GCI_strfree( cb->hidden, &newName );
            return rc;
        }
        GCI_strsetlen( cb->buffer, origlen );

        if ( pi.type == GCI_array )
            break;
    }
    cb->depth--;
    cb->recurCount--;
    if ( GCI_content( &newName ) != NULL )
    {
        GCI_strswap( &newName, cb->buffer );
        GCI_strfree( cb->hidden, &newName );
    }

    if ( pi.indirect && ( pi.type == GCI_array ) )
    {
        pi.indirect = 0;
        if ( ( rc = cb->callback( cb->depth, -1, cb->arg, &pi) ) != GCI_OK )
            return rc;
        return cb->callback( cb->depth, -1, cb->arg, &indirectArray );
    }
    return cb->callback( cb->depth, -1, cb->arg, &pi );
}