void CommandLineParser::Process ( const StringStore& commandArgs ) { if ( commandArgs.empty() ) { return; } commandLine_ = commandArgs[0]; if ( commandArgs.size() > 1 ) { StringStore::const_iterator current = commandArgs.begin(); StringStore::const_iterator end = commandArgs.end(); while( current != end ) { std::string param( *current ); if ( helpSwitch == param || helpSwitchLong == param ) { showHelp_ = true; } else if ( noHeaderSwitch == param || noHeaderSwitchLong == param ) { showHeader_ = false; } else if ( listTestsSwitch == param || listTestsSwitchLong == param ) { listTests_ = true; } else if ( listTestSetsSwitch == param || listTestSetsSwitchLong == param ) { listTestSets_ = true; } else if ( ( testSwitch == param || testSwitchLong == param ) && GetNextParam( current, end, param ) ) { tests_.push_back( param ); } else if ( ( testSetSwitch == param || testSetSwitchLong == param ) && GetNextParam( current, end, param ) ) { testSets_.push_back( param ); } else if ( ( reportSwitch == param || reportSwitchLong == param ) && GetNextParam( current, end, param ) ) { report_ = param; } if ( current != end ) { ++current; } } } }
// parse command line parameters and set results to static variables void ParseCommandLine(CTString strCmd) { cmd_strOutput = ""; cmd_strOutput+=CTString(0, TRANS("Command line: '%s'\n"), strCmd); // if no command line if (strlen(strCmd) == 0) { // do nothing return; } _strCmd = strCmd; FOREVER { CTString strWord = GetNextParam(); if (strWord=="") { cmd_strOutput+="\n"; return; } else if (strWord=="+level") { cmd_strWorld = GetNextParam(); } else if (strWord=="+server") { cmd_bServer = TRUE; } else if (strWord=="+quickjoin") { cmd_bQuickJoin = TRUE; } else if (strWord=="+game") { CTString strMod = GetNextParam(); if (strMod!="SeriousSam") { // (we ignore default mod - always use base dir in that case) _fnmMod = "Mods\\"+strMod+"\\"; } } else if (strWord=="+cdpath") { _fnmCDPath = GetNextParam(); } else if (strWord=="+password") { cmd_strPassword = GetNextParam(); } else if (strWord=="+connect") { cmd_strServer = GetNextParam(); const char *pcColon = strchr(cmd_strServer, ':'); if (pcColon!=NULL) { CTString strServer; CTString strPort; cmd_strServer.Split(pcColon-cmd_strServer, strServer, strPort); cmd_strServer = strServer; strPort.ScanF(":%d", &cmd_iPort); } } else if (strWord=="+script") { cmd_strScript = GetNextParam(); } else if (strWord=="+goto") { GetNextParam().ScanF("%d", &cmd_iGoToMarker); } else if (strWord=="+logfile") { _strLogFile = GetNextParam(); } else { cmd_strOutput+=CTString(0, TRANS(" Unknown option: '%s'\n"), strWord); } } }
/* the function determines only two parameters */ void GetCommandParams(char * buf, char * fparam, char * sparam) { char * start = buf; /* cut out command itself, for example "DWH: " substring */ if (buf[3] == ':' && (buf[4] == 0x20 || buf[4] == 0x09)) start = &buf[5]; /* cut out prefixed whitespaces */ while (start[0] == 0x20 || start[0] == 0x09) ++start; /* reset parameter strings */ fparam[0] = 0x00; sparam[0] = 0x00; /* determine the first parameter */ if (start = GetNextParam(start, fparam)) { /* determine the second parameter */ GetNextParam(start, sparam); } }
// parse command line parameters and set results to static variables void ParseCommandLine(CTString strCmd) { cmd_strOutput = ""; cmd_strOutput+=CTString(0, TRANS("Command line: '%s'\n"), strCmd); // if no command line if (strlen(strCmd) == 0) { // do nothing return; } _strCmd = strCmd; FOREVER { CTString strWord = GetNextParam(); if (strWord=="") { cmd_strOutput+="\n"; return; } else if (strWord=="+level") { cmd_strWorld = GetNextParam(); } else if (strWord=="+server") { cmd_bServer = TRUE; } else if (strWord=="+player") { cmd_strPlayer = GetNextParam(); } else if (strWord=="+quickjoin") { cmd_bQuickJoin = TRUE; } else if (strWord=="+game") { CTString strMod = GetNextParam(); #if _SE_DEMO if (strMod!="SeriousSam" && strMod!="Warped") { FatalError(TRANS("This MOD is not allowed in demo version!")); return; } #endif if (strMod!="SeriousSam") { // (we ignore default mod - always use base dir in that case) _fnmMod = "Mods\\"+strMod+"\\"; } } else if (strWord=="+cdpath") { _fnmCDPath = GetNextParam(); } else if (strWord=="+password") { cmd_strPassword = GetNextParam(); } else if (strWord=="+connect") { cmd_strServer = GetNextParam(); const char *pcColon = strchr(cmd_strServer, ':'); if (pcColon!=NULL) { CTString strServer; CTString strPort; cmd_strServer.Split(pcColon-cmd_strServer, strServer, strPort); cmd_strServer = strServer; strPort.ScanF(":%d", &cmd_iPort); } } else if (strWord=="+windowpos") { CTString strWinPos = GetNextParam(); const char *pcColon = strchr(strWinPos, ':'); if (pcColon!=NULL) { CTString strLeft; CTString strTop; strWinPos.Split(pcColon-strWinPos, strLeft, strTop); strLeft.ScanF("%d", &cmd_iWindowLeft); strTop.ScanF(":%d", &cmd_iWindowTop); } } else if (strWord=="+script") { cmd_strScript = GetNextParam(); } else if (strWord=="+goto") { GetNextParam().ScanF("%d", &cmd_iGoToMarker); } else if (strWord=="+logfile") { _strLogFile = GetNextParam(); } else { cmd_strOutput+=CTString(0, TRANS(" Unknown option: '%s'\n"), strWord); } } }