コード例 #1
0
ファイル: env.c プロジェクト: ErisBlastar/osfree
static int SetFromFile( char *szLine, char *pchList, int fRemove )
{
    char *arg;
    char szBuffer[CMDBUFSIZ];
    int i, n, rval = 0;

    for ( i = 0; (( rval == 0 ) && (( arg = ntharg( szLine, i )) != NULL )); i++ ) {

        mkfname( arg, 0 );

        if (( gnGFH = _sopen( arg, (O_RDONLY | O_BINARY), SH_DENYWR )) < 0 )
            return ( error( _doserrno, arg ));

        for ( arg = szBuffer; (( rval == 0 ) && ( getline( gnGFH, arg, CMDBUFSIZ-((arg-szBuffer)+1), EDIT_DATA ) > 0 )); ) {

            // remove leading white space
            strip_leading( arg, WHITESPACE );

            // if last char is escape character, append
            //   the next line
            n = strlen( arg ) - 1;
            if (( arg[0] ) && ( arg[n] == gpIniptr->EscChr )) {
                arg += n;
                continue;
            }

            // skip blank lines & comments
            arg = szBuffer;
            if (( *arg ) && ( *arg != ':' )) {

                if ( fRemove ) {
                    // delete variable
                    for ( n = 0; (( szBuffer[n] ) && ( szBuffer[n++] != '=' )); )
                        ;
                    szBuffer[n] = '\0';
                }

                // create/modify a variable or alias
                rval = add_list( arg, pchList );
            }
        }

        gnGFH = _close( gnGFH );
    }

    return rval;
}
コード例 #2
0
/*
 * Recursively parse a type hint.  Return FALSE if the parse failed.
 */
static int parseTypeHintNode(sipSpec *pt, int out, int top_level, char *start,
        char *end, typeHintNodeDef **thnp)
{
    char *cp, *name_start, *name_end;
    int have_brackets = FALSE;
    typeHintNodeDef *node, *children = NULL;

    /* Assume there won't be a node. */
    *thnp = NULL;

    /* Find the name and any opening and closing bracket. */
    strip_leading(&start, end);
    name_start = start;

    strip_trailing(start, &end);
    name_end = end;

    for (cp = start; cp < end; ++cp)
        if (*cp == '[')
        {
            typeHintNodeDef **tail = &children;

            /* The last character must be a closing bracket. */
            if (end[-1] != ']')
                return FALSE;

            /* Find the end of any name. */
            name_end = cp;
            strip_trailing(name_start, &name_end);

            for (;;)
            {
                char *pp;
                int depth;

                /* Skip the opening bracket or comma. */
                ++cp;

                /* Find the next comma, if any. */
                depth = 0;

                for (pp = cp; pp < end; ++pp)
                    if (*pp == '[')
                    {
                        ++depth;
                    }
                    else if (*pp == ']' && depth != 0)
                    {
                        --depth;
                    }
                    else if ((*pp == ',' || *pp == ']') && depth == 0)
                    {
                        typeHintNodeDef *child;

                        /* Recursively parse this part. */
                        if (!parseTypeHintNode(pt, out, FALSE, cp, pp, &child))
                            return FALSE;

                        if (child != NULL)
                        {
                            /*
                             * Append the child to the list of children.  There
                             * might not be a child if we have detected a
                             * recursive definition.
                             */
                            *tail = child;
                            tail = &child->next;
                        }

                        cp = pp;
                        break;
                    }

                if (pp == end)
                    break;
            }

            have_brackets = TRUE;

            break;
        }

    /* We must have a name unless we have empty brackets. */
    if (name_start == name_end)
    {
        if (top_level && have_brackets && children == NULL)
            return FALSE;

        /* Return the representation of empty brackets. */
        node = sipMalloc(sizeof (typeHintNodeDef));
        node->type = brackets_node;
    }
    else
    {
        char saved;
        const char *typing;

        /* Isolate the name. */
        saved = *name_end;
        *name_end = '\0';

        /* See if it is an object in the typing module. */
        if ((typing = typingModule(name_start)) != NULL)
        {
            if (strcmp(typing, "Union") == 0)
            {
                /*
                 * If there are no children assume it is because they have been
                 * omitted.
                 */
                if (children == NULL)
                    return TRUE;

                children = flatten_unions(children);
            }

            node = sipMalloc(sizeof (typeHintNodeDef));
            node->type = typing_node;
            node->u.name = typing;
            node->children = children;
        }
        else
        {
            /* Search for the type. */
            node = lookupType(pt, name_start, out);
        }

        *name_end = saved;

        /* Only objects from the typing module can have brackets. */
        if (typing == NULL && have_brackets)
            return FALSE;
    }

    *thnp = node;

    return TRUE;
}
コード例 #3
0
ファイル: env.c プロジェクト: CivilPol/sdcboot
static int SetFromFile( LPTSTR pszLine, TCHAR _far *pchList, long fFlags )
{
	static TCHAR szDelimiters[] = _TEXT("%[^= \t]");
	register LPTSTR pszArg;
	TCHAR szBuffer[CMDBUFSIZ];
	int i, n, nError = 0, nEditFlags = EDIT_DATA, nFH = -1;


	if (( *pszLine == _TEXT('\0') ) && ( QueryIsConsole( STDIN ) == 0 )) {
		pszLine = CONSOLE;
		nFH = STDIN;
	}

	for ( i = 0; (( nError == 0 ) && (( pszArg = ntharg( pszLine, i )) != NULL )); i++ ) {

		if ( nFH != STDIN ) {
			mkfname( pszArg, 0 );
			if (( nFH = _sopen( pszArg, _O_RDONLY | _O_BINARY, _SH_DENYWR )) < 0 )
				return ( error( _doserrno, pszArg ));
		}

		if ( setjmp( cv.env ) == -1 ) {
			if ( nFH > 0 ) {
				_close( nFH );
				nFH = -1;
			}
            return CTRLC;
		}

		for ( pszArg = szBuffer; (( nError == 0 ) && ( getline( nFH, pszArg, CMDBUFSIZ - (UINT)(( pszArg - szBuffer ) + 1 ), nEditFlags ) > 0 )); ) {

			// remove leading white space
			strip_leading( pszArg, WHITESPACE );

			// if last char is escape character, append the next line
			n = strlen( pszArg ) - 1;
			if (( pszArg[0] ) && ( pszArg[n] == gpIniptr->EscChr )) {
				pszArg += n;
				continue;
			}

			// skip blank lines & comments
			pszArg = szBuffer;
			if (( *pszArg ) && ( *pszArg != _TEXT(':') )) {

				// delete variable
				if ( fFlags & 1 ) {
					// an UNSET requires a '=' delimiter; it's optional elsewhere
					szDelimiters[4] = (( pchList == glpEnvironment ) ? _TEXT('\0') : _TEXT(' '));
					sscanf( szBuffer, szDelimiters, szBuffer );
				}

				// create/modify a variable or alias
				nError = add_list( pszArg, pchList );
			}
		}

		if ( nFH != STDIN ) {
			 _close( nFH );
			 nFH = -1;
		}
	}

	return nError;
}