Пример #1
0
/*
 * Parse the command string contained in the current context.
 */
void CmdStringParse( OPT_STORAGE *cmdOpts, int *itemsParsed )
/***********************************************************/
{
    int                 ch;
    char *              filename;

    for( ;; ) {
        /*** Find the start of the next item ***/
        CmdScanWhitespace();
        ch = GetCharContext();
        if( ch == '\0' )  break;
        MarkPosContext();               /* mark start of switch */

        /*** Handle switches, command files, and input files ***/
        if( ch == '-'  ||  ch == '/' ) {        /* switch */
            if( OPT_PROCESS( cmdOpts ) != 0 ) {
                cmd_line_error();
            }
        } else if( ch == '@' ) {                /* command file */
            filename = CmdScanFileNameWithoutQuotes();
            PushContext();
            if( OpenFileContext( filename ) ) {
                FatalError( "Cannot open '%s'.", filename );
            }
            FreeMem( filename );
            CmdStringParse( cmdOpts, itemsParsed );
            PopContext();
        } else if( ch == '"' ) {                /* quoted option or file name */
            ch = GetCharContext();
            if( ch == '-' ) {
                Quoted = 1;
                if( OPT_PROCESS( cmdOpts ) != 0 ) {
                    cmd_line_error();
                }
            } else {
                UngetCharContext();
                UngetCharContext();
                filename = CmdScanFileName();
                AddFile( TYPE_DEFAULT_FILE, filename );
                FreeMem( filename );
            }                
        } else {                                /* input file */
            UngetCharContext();
            filename = CmdScanFileName();
            AddFile( TYPE_DEFAULT_FILE, filename );
            FreeMem( filename );
        }
        (*itemsParsed)++;
    }
    CloseContext();
}
Пример #2
0
static void procOptions(        // PROCESS AN OPTIONS LINE
    OPT_STORAGE *data,          // - options data
    const char *str )           // - scan position in command line
{
    int c;                      // - next character
    char const *fnm;            // - scanned @ name
    char *env;                  // - environment name
    size_t len;                 // - length of file name

    if( indirectionLevel >= MAX_INDIRECTION ) {
        BadCmdLine( ERR_MAX_CMD_INDIRECTION );
    } else if( str != NULL ) {
        ++indirectionLevel;
        CtxSetSwitchAddr( str );
        CmdScanInit( str );
        for(;;) {
            c = CmdScanWhiteSpace();
            if( c == '\0' ) break;
            CmdScanSwitchBegin();
            CmdLnCtxSwitch( CmdScanAddr() - 1 );
            if( c == '-'  ||  c == SwitchChar ) {
                if( OPT_PROCESS( data ) ) {
                    BadCmdLine( ERR_INVALID_OPTION );
                }
            } else if( c == '@' ) {
                CmdScanWhiteSpace();
                CmdScanUngetChar();
                len = CmdScanFilename( &fnm );
                env = get_env( fnm, len );
                if( NULL == env ) {
                    if( openCmdFile( fnm, len ) ) {
                        CmdLnCtxPushCmdFile( SrcFileCurrent() );
                        processCmdFile( data );
                        CmdLnCtxPop();
                    } else {
                        CmdLnCtxPushEnv( fnm );
                        BadCmdLine( ERR_BAD_CMD_INDIRECTION );
                        CmdLnCtxPop();
                    }
                } else {
                    CmdLnCtxPushEnv( fnm );
                    procOptions( data, env );
                    CmdLnCtxPop();
                }
            } else {
                CmdScanUngetChar();
                scanInputFile();
            }
        }
        --indirectionLevel;
    }
}
Пример #3
0
/*
 * Parse the command string contained in the current context.
 */
void CmdStringParse( OPT_STORAGE *cmdOpts, int *itemsParsed )
/***********************************************************/
{
    char                ch;
    char *              filename;
    char *              str;

    for( ;; ) {
        /*** Find the start of the next item ***/
        CmdScanWhitespace();
        ch = GetCharContext();
        if( ch == '\0' )  break;
        MarkPosContext();               /* mark start of switch */

        /*** Handle switches, command files, and input files ***/
        if( ch == '-'  ||  ch == '/' ) {        /* switch */
            if( OPT_PROCESS( cmdOpts ) ) {
                /*
                 * Switch didn't match, if user entered empty switch,
                 * just be silent like MS's nmake does.
                 */

                ch = GetCharContext();
                if( ch != '\0' && !isspace( ch ) ) {
                    cmd_line_error();
                }
            }
        } else if( ch == '@' ) {                /* command file */
            filename = CmdScanFileNameWithoutQuotes();
            PushContext();
            if( OpenFileContext( filename ) ) {
                FatalError( "Cannot open '%s'.", filename );
            }
            FreeMem( filename );
            CmdStringParse( cmdOpts, itemsParsed );
            PopContext();
        } else {                                /* targets and macros */
            UngetCharContext();
            str = CmdScanString();
            add_string( &(cmdOpts->t010101010101_value), str, '\0' );
            cmdOpts->t010101010101 = 1;
        }
        (*itemsParsed)++;
    }
    CloseContext();
}