コード例 #1
0
ファイル: icmask.c プロジェクト: MikeyG/open-watcom-v2
int indirEnvOrFile( char *name, char ***args )
{
    /*
     * Pass nofilenames and analysis of getenv(name) into argc and argv
     * to doScanParams. Return view on usability of data. (true is usable.)
     */
    int                 argc;
    size_t              argvsize;
    size_t              argbufsize;
    const char          *optstring;
    size_t              varlen;         // size to hold name copy.
    char                fbuf[512];

    optstring = getenv( name );
    if( optstring == NULL ) {
        FILE *fh;

        fh = fopen( name, "rt" );
        if( fh == NULL ) {
            *args = NULL;
            return( 0 );
        }
        fgets( fbuf, sizeof( fbuf ), fh );
        fclose( fh );
        optstring = fbuf;
    }
    argc = ParseVariable( optstring, NULL, NULL );  // count parameters.
    argbufsize = strlen( optstring ) + 1 + argc;    // inter-parameter spaces map to 0
    argvsize = argc * sizeof( char * );             // sizeof argv[argc+1]
    varlen = strlen( name ) + 1;                    // Copy taken to detect recursion.
    *args = (char **)malloc( argbufsize + argvsize + varlen );
    ParseVariable( optstring, *args, (char *)( *args + argc ) );
    return( argc );
}
コード例 #2
0
/**
Parse a Float, Vector4, Int or Bool element inside a RenderPath
element (these are global variable definitions.
*/
void U2FrameXmlParser::ParseGlobalVariable(U2Variable::Type dataType, TiXmlElement* elem, 
										   U2Frame* renderPath)
{
	U2ASSERT(elem && renderPath);
	U2Variable* pVar = ParseVariable(dataType, elem);
	renderPath->AddVariable(pVar);
}
コード例 #3
0
ファイル: parse_type.c プロジェクト: davidechiappetta/atalan
void ParseArgList(VarSubmode mode, Type * to_type)
/*
Purpose:
	Parse block with list of arguments.
	  [">" | "<"] assign
	Arguments are added to current context with submode SUBMODE_ARG_*.

	This method is used when parsing procedure or macro argument declaration or structure declaration.
*/
{
	VarSubmode submode = SUBMODE_EMPTY;
	Var * var, * adr;
	Bool out_part = false;

 	EnterBlockWithStop(TOKEN_EQUAL);			// TOKEN_EQUAL

	while (TOK != TOKEN_ERROR && !NextIs(TOKEN_BLOCK_END)) {

		if (!out_part && NextIs(TOKEN_RIGHT_ARROW)) {
			out_part = true;
		}

		submode = mode;

		if (out_part) {
			submode = SUBMODE_ARG_OUT;
		} else {

			if (NextIs(TOKEN_LOWER)) {
				submode = SUBMODE_ARG_IN;
			}
			if (NextIs(TOKEN_HIGHER)) {
				submode = SUBMODE_ARG_OUT;
			}
		}

		// Variables preceded by @ define local variables used in the procedure.
		if (NextIs(TOKEN_ADR)) {
			adr = ParseVariable();
			if (TOK) {
				var = VarAllocScopeTmp(to_type->owner, INSTR_VAR, adr->type);
				var->adr  = adr;
				NextIs(TOKEN_EOL);
				continue;
			}
		}

		if (TOK == TOKEN_ID) {
			ParseAssign(INSTR_VAR, submode, to_type);
			NextIs(TOKEN_COMMA);
			NextIs(TOKEN_EOL);
		} else {
			SyntaxError("Expected variable name");
		}
	}
}
コード例 #4
0
ファイル: parse_type.c プロジェクト: davidechiappetta/atalan
Type * ParseTypeInline() 
/*
Syntax: "+" full_type | "(" full_type ")" | normal_type |  identifier | int ".." exp | "-" int ".." exp
*/{
	Type * type = NULL;
	Var * var;
	UInt16 bookmark;
	BigInt * bi;

	PARSE_INLINE = true;

	if (TOK == TOKEN_OPEN_P || TOK == TOKEN_PLUS) {
		type = ParseType2(INSTR_TYPE);
	} else {
		type = ParseType3();
		if (!TOK) return NULL;
		if (type != NULL) return type;

		if (ParseArg(&var)) {
			type = TypeAllocVar(var);
		} else if (TOK == TOKEN_ID) {
			bookmark = SetBookmark();
			var = ParseVariable();
			if (TOK) {
				if (var->mode == INSTR_TYPE) {
					type = var->type;
				} else if (var->mode == INSTR_VAR && var->type->variant == TYPE_TYPE) {
					type = var->type_value;
				} else {
					ErrArg(var);
					SyntaxErrorBmk("Variable [A] does not define type.", bookmark);
				}
			}
		} else if (TOK == TOKEN_INT || TOK == TOKEN_MINUS) {
			type = TypeAlloc(TYPE_INT);
			bi = ParseIntConstExpression(NULL);
			if (TOK) {
				IntModify(&type->range.min, bi);
				if (NextIs(TOKEN_DOTDOT)) {
					bi = ParseIntConstExpression(NULL);
					if (TOK) {
						IntModify(&type->range.max, bi);
					}
				} else {
					IntModify(&type->range.max, &type->range.min);
				}
			}
		}
	}
	return type;
}
コード例 #5
0
ファイル: Deserializer.cpp プロジェクト: angelorohit/raywatch
// Parses a known variable of the format: <variable> = <value>;
const bool Deserializer::ParseVariable(std::istream &stream, const std::string &variable, std::string &value)
{
    std::string variableRead;
    if( !ParseVariable( stream, variableRead, value ) )
        return false;

    // See if the variable read is what is expected
    if( variableRead.compare( variable ) != 0 )
    {
        std::cout << "Error: Variable '" << variable << "' was expected, but '" << variableRead << "' was found instead." << std::endl;
        return false;
    }

    return true;
}
コード例 #6
0
ファイル: PARSSTMT.CPP プロジェクト: soshimozi/PascalCompiler
void TParser::ParseAssignment(const TSymtabNode *pTargetId)
{
    TType *pTargetType = ParseVariable(pTargetId);

    //-- :=
    Resync(tlColonEqual, tlExpressionStart);
    CondGetTokenAppend(tcColonEqual, errMissingColonEqual);

    //--<expr>
    TType *pExprType = ParseExpression();

    //--Check for assignment compatibility.
    CheckAssignmentTypeCompatible(pTargetType, pExprType,
				  errIncompatibleAssignment);
}
コード例 #7
0
	void SourceTASReader::ParseVariables()
	{
		while (ParseLine())
		{
			if (IsFramesLine())
			{
				break;
			}

			if (!freezeVariables)
				ParseVariable();
		}

		variables.Iteration(searchType);
		variables.PrintState();
	}
コード例 #8
0
ファイル: Deserializer.cpp プロジェクト: angelorohit/raywatch
Serializable *const Deserializer::Read(std::istream &stream)
{
    Serializable *pSerializable = 0;

    BEGIN_CODE_BLOCK
    {
        // Read the first Object's type
        std::string objectType;
        if( !ParseVariable( stream, "begin", objectType ) )
            break;

        // Create the object
        pSerializable = ObjectFactory<Serializable>::Create( objectType );
        if( !pSerializable )
        {
            std::cout << "Error: Unknown Object found: " << objectType << std::endl;
            EXIT_CODE_BLOCK;
        }

        // Load the object
        if( !pSerializable->Read( stream ) )
        {
            SAFE_DELETE_SCALAR( pSerializable );
            EXIT_CODE_BLOCK;
        }

        // Restore all pointers
        if( !RestoreAllPointers() )
        {
            SAFE_DELETE_SCALAR( pSerializable );
            EXIT_CODE_BLOCK;
        }
    }
    END_CODE_BLOCK;

    return pSerializable;
}
コード例 #9
0
ファイル: parser.c プロジェクト: NVIDIA/winex_lgpl
/*******************************************************************
 *         ParseOrdinal
 *
 * Parse an ordinal definition.
 */
static void ParseOrdinal(int ordinal)
{
    const char *token;

    ORDDEF *odp = xmalloc( sizeof(*odp) );
    memset( odp, 0, sizeof(*odp) );
    EntryPoints[nb_entry_points++] = odp;

    token = GetToken(0);

    for (odp->type = 0; odp->type < TYPE_NBTYPES; odp->type++)
        if (TypeNames[odp->type] && !strcmp( token, TypeNames[odp->type] ))
            break;

    if (odp->type >= TYPE_NBTYPES)
        fatal_error( "Expected type after ordinal, found '%s' instead\n", token );

    token = GetToken(0);
    if (*token == '-') token = ParseFlags( odp );

    odp->name = xstrdup( token );
    odp->export_name = xstrdup( token );
    fix_export_name( odp->name );
    odp->lineno = current_line;
    odp->ordinal = ordinal;

    switch(odp->type)
    {
    case TYPE_VARIABLE:
        ParseVariable( odp );
        break;
    case TYPE_PASCAL_16:
    case TYPE_PASCAL:
    case TYPE_STDCALL:
    case TYPE_VARARGS:
    case TYPE_CDECL:
        ParseExportFunction( odp );
        break;
    case TYPE_ABS:
        ParseEquate( odp );
        break;
    case TYPE_STUB:
        ParseStub( odp );
        break;
    case TYPE_EXTERN:
        ParseExtern( odp );
        break;
    case TYPE_FORWARD:
        ParseForward( odp );
        break;
    default:
        assert( 0 );
    }

#ifndef __i386__
    if (odp->flags & FLAG_I386)
    {
        /* ignore this entry point on non-Intel archs */
        EntryPoints[--nb_entry_points] = NULL;
        free( odp );
        return;
    }
#endif

    if (ordinal != -1)
    {
        if (ordinal >= MAX_ORDINALS) fatal_error( "Ordinal number %d too large\n", ordinal );
        if (ordinal > Limit) Limit = ordinal;
        if (ordinal < Base) Base = ordinal;
        odp->ordinal = ordinal;
        Ordinals[ordinal] = odp;
    }

    if (!strcmp( odp->name, "@" ))
    {
        if (ordinal == -1)
            fatal_error( "Nameless function needs an explicit ordinal number\n" );
        if (SpecType != SPEC_WIN32)
            fatal_error( "Nameless functions not supported for Win16\n" );
        odp->name[0] = 0;
    }
    else Names[nb_names++] = odp;
}
コード例 #10
0
ファイル: wcpp.c プロジェクト: ArmstrongJ/open-watcom-v2
static bool scanEnvVarOrFile( const char *name )
/**********************************************/
{
    /*
     * Pass nofilenames and analysis of getenv(name) into argc and argv
     * to doScanParams. Return view on usability of data. (true is usable.)
     *
     * Recursion is supported but circularity is rejected.
     */
    typedef struct VarInfo {
        struct VarInfo      *next;
        char                *name;
        char                **argv; /* points into buf */
        char                buf[1]; /* dynamic array */
    } VarInfo;

    int                 argc;
    VarInfo             *info;
    static VarInfo      *stack = NULL;  // Needed to detect recursion.
    size_t              argvsize;
    size_t              argbufsize;
    const char          *optstring;
    size_t              varlen;         // size to hold name copy.
    bool                result;         // doScanParams Result.
    char                fbuf[512];

    optstring = PP_GetEnv( name );
    if( optstring == NULL ) {
        FILE *fh;

        fh = fopen( name, "rt" );
        if( fh == NULL ) {
//            RcWarning( ERR_ENV_VAR_NOT_FOUND, name );
            return( true );
        }
        fgets( fbuf, sizeof( fbuf ), fh );
        fclose( fh );
        optstring = fbuf;
    }
    // This used to cause stack overflow: set foo=@foo && wrc @foo.
    for( info = stack; info != NULL; info = info->next ) {
#if defined( __UNIX__ )
        if( strcmp( name, info->name ) == 0 ) {     // Case-sensitive
#else
        if( stricmp( name, info->name ) == 0 ) {    // Case-insensitive
#endif
//            RcFatalError( ERR_RCVARIABLE_RECURSIVE, name );
        }
    }
    argc = ParseVariable( optstring, NULL, NULL );  // count parameters.
    argbufsize = strlen( optstring ) + 1 + argc;    // inter-parameter spaces map to 0
    argvsize = argc * sizeof( char * );             // sizeof argv[argc+1]
    varlen = strlen( name ) + 1;                    // Copy taken to detect recursion.
    info = malloc( sizeof( *info ) + argbufsize + argvsize + varlen );
    info->next = stack;
    stack = info;                                   // push info on stack
    info->argv = (char **)info->buf;
    ParseVariable( optstring, info->argv, info->buf + argvsize );
    info->name = info->buf + argvsize + argbufsize;
    strcpy( info->name, name );
    result = doScanParams( argc, info->argv );

    stack = info->next;                             // pop stack
    free( info );
    return( result );
}

static bool doScanParams( int argc, char *argv[] )
/************************************************/
{
    const char  *arg;
    int         switchchar;
    bool        contok;         /* continue with main execution */
    int         currarg;

    contok = true;
    switchchar = _dos_switch_char();
    for( currarg = 0; currarg < argc && contok; currarg++ ) {
        arg = argv[currarg];
        if( *arg == switchchar || *arg == '-' ) {
            contok = ScanOptionsArg( arg + 1 ) && contok;
        } else if( *arg == '@' ) {
            contok = scanEnvVarOrFile( arg + 1 ) && contok;
        } else if( *arg == '?' ) {
            wcpp_quit( usageMsg, NULL );
//            contok = false;
        } else {
            filenames = realloc( (void *)filenames, ( nofilenames + 1 ) * sizeof( char * ) );
            filenames[nofilenames++] = my_strdup( arg );
        }
    }
    return( contok );
}

int main( int argc, char *argv[] )
{
    int         ch;
    int         i;
    int         j;
    int         rc;
    FILE        *fo;

    if( argc < 2 ) {
        wcpp_quit( usageMsg, "No filename specified\n" );
    } else if( argc == 2 ) {
        if( !strcmp( argv[1], "?" ) ) {
            wcpp_quit( usageMsg, NULL );
        }
    }

    PP_IncludePathInit();

    rc = EXIT_FAILURE;
    if( doScanParams( argc - 1, argv + 1 ) && nofilenames != 0 ) {
        PP_Init( '#' );
        fo = stdout;
        if( out_filename != NULL ) {
            fo = fopen( out_filename, "wb" );
        }
        rc = EXIT_SUCCESS;
        for( i = 0; i < nofilenames; ++i ) {
            if( PP_FileInit( filenames[i], flags, NULL ) != 0 ) {
                fprintf( stderr, "Unable to open '%s'\n", filenames[i] );
                rc = EXIT_FAILURE;
                break;
            }
            for( j = 0; j < numdefs; j++ ) {
                PP_Define( defines[j] );
            }
            for( ;; ) {
                ch = PP_Char();
                if( ch == EOF )
                    break;
#ifndef __UNIX__
                if( ch == '\n' )
                    fputc( '\r', fo );
#endif
                fputc( ch, fo );
            }
            PP_FileFini();
        }
        if( fo == stdout ) {
            fflush( fo );
        } else if( fo != NULL ) {
            fclose( fo );
        }
        PP_Fini();
    }

    if( out_filename != NULL ) {
        free( out_filename );
    }
    for( i = 0; i < nofilenames; ++i ) {
        free( filenames[i] );
    }
    free( (void *)filenames );
    for( i = 0; i < numdefs; i++ ) {
        free( defines[i] );
    }
    free( (void *)defines );

    PP_IncludePathFini();

    if( rc == EXIT_FAILURE && nofilenames == 0 ) {
        wcpp_quit( usageMsg, "No filename specified\n" );
    }

    return( rc );
}