static MEPTR defineStringMacro( // DEFINE A MACRO NAME const char *name ) // - name of macro { MEPTR mptr; char const *save = CmdScanAddr(); CmdScanInit( name ); mptr = DefineCmdLineMacro( false ); CmdScanInit( save ); return( mptr ); }
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; } }
size_t CmdScanNumber( // SCAN A NUMBER unsigned *pvalue ) // - addr( return value ) { char const *p; // - scan position char const *str_beg; // - start of string unsigned value; // - base 10 value str_beg = CmdScanAddr(); value = 0; for( p = str_beg; isdigit(*p); ++p ) { value *= 10; value += *p - '0'; } cmd.curr_ptr = p; *pvalue = value; return( p - str_beg ); }
static CTX_CL* cmdLnCtxAlloc( // ALLOCATE NEW CONTEXT CTX_CLTYPE type ) // - type of context { CTX_CL* entry; entry = VstkPush( &cmdLnContexts ); entry->base.ctx_type = type; entry->base.sw_ptr = NULL; if( type == CTX_CLTYPE_PGM ) { entry->base.cmd_line = NULL; entry->base.cmd_scan = NULL; } else { entry->base.cmd_line = CmdScanAddr(); entry->base.cmd_scan = CtxGetSwitchAddr(); } return entry; }
void CmdLnCtxInfo( // PRINT CONTEXT INFO void ) { CTX_CL* entry; // - current entry VBUF buf; // - buffer VbufInit( &buf ); for( entry = VstkTop( &cmdLnContexts ) ; entry != NULL ; entry = VstkNext( &cmdLnContexts, entry ) ) { VbufRewind( &buf ); switch( entry->base.ctx_type ) { case CTX_CLTYPE_ENV : VbufConcChr( &buf, '@' ); VbufConcStr( &buf, entry->env.var ); break; case CTX_CLTYPE_FC : VbufConcStr( &buf, "batch file of commands, line " ); VbufConcDecimal( &buf, CompInfo.fc_file_line ); break; case CTX_CLTYPE_PGM : VbufConcStr( &buf, "command line" ); break; case CTX_CLTYPE_FILE : VbufConcStr( &buf, SrcFileFullName( entry->file.source ) ); break; DbgDefault( "bad command-line context" ); } if( entry->base.sw_ptr != NULL ) { size_t size; char const * not_used; char const* old = CmdScanAddr(); CmdScanInit( entry->base.sw_ptr ); CmdScanChar(); size = CmdScanOption( ¬_used ) + 1; CmdScanInit( old ); VbufConcStr( &buf, ", switch: " ); for( old = entry->base.sw_ptr; size > 0; ++old, --size ) { VbufConcChr( &buf, *old ); } } InfMsgPtr( INF_SWITCH, VbufString( &buf ) ); } VbufFree( &buf ); }