/* Without priorities yet */ AST* ParseCondition(ParserState* parser) { if(parser->currentToken.type == TOKEN_NOT) { AST* notCond = CreateASTNode(SEM_NOT, VALUE_EMPTY); Match(parser, TOKEN_NOT); AddASTChild(notCond, ParseLogicalExpression(parser)); return notCond; } else { AST* lexp = ParseLogicalExpression(parser); AST* rhs; enum TokenType type = parser->currentToken.type; if(type == TOKEN_AND || type == TOKEN_OR) { Match(parser, type); rhs = ParseCondition(parser); AST *log_node = CreateASTNode(type == TOKEN_AND ? SEM_AND : SEM_OR, VALUE_EMPTY); AddASTChild(log_node, lexp); AddASTChild(log_node, rhs); return log_node; } return lexp; } }
void CParser::ParseStatementIf(int nTabs) { CString sToken = m_oToken.GetCurrentToken(); m_sProgress = m_sProgress + GetTabs(nTabs) + "ParseStatemenIf " + sToken + "\r\n"; /* If condition Then [statements] [ElseIf condition-n Then [elseifstatements] ... [Else [elsestatements]] End If */ m_oToken.GetNextToken(); //skip current if token ParseCondition(nTabs+1); ParseStatementIfThen(nTabs+1); ParseStatementList(nTabs+1); //temp code to reach end (of if) //while(sToken != "End" && sToken !="") //sToken = m_oToken.GetNextToken(); //skip end if //m_oToken.GetNextToken(); //skip end ParseStatementEnd(nTabs); m_oToken.GetNextToken(); //skip if //parse then //parse statement list //parse else if list (do it only if time possible) //parse end if }
void CParser::ParseStatementWhile(int nTabs) { CString sToken = m_oToken.GetCurrentToken(); m_sProgress = m_sProgress + GetTabs(nTabs) + "ParseStatemenWhile " + sToken + "\r\n"; m_oToken.GetNextToken(); //skip current while token ParseCondition(nTabs+1); ParseStatementList(nTabs+1); ParseStatementWend(nTabs); }
shared_ptr<Predicate<EdgeId>> ParseConjunction(size_t& min_length_bound, double& min_coverage_bound) { shared_ptr<Predicate<EdgeId>> answer = make_shared<AlwaysTrue<EdgeId>>(); VERIFY(next_token_ == "{"); ReadNext(); while (next_token_ != "}") { answer = make_shared<AndOperator<EdgeId>>( answer, ParseCondition(min_length_bound, min_coverage_bound)); ReadNext(); } return answer; }
AST* ParseWhileCycle(ParserState* parser) { Match(parser, TOKEN_WHILE); AST* whileNode = CreateASTNode(SEM_WHILE_CYCLE, VALUE_EMPTY); AST* condition = ParseCondition(parser); Match(parser, TOKEN_DO); AST* op = ParseOperator(parser); AddASTChild(whileNode, condition); AddASTChild(whileNode, op); return whileNode; }
AST* ParseIfStatement(ParserState* parser) { Match(parser, TOKEN_IF); AST* ifNode = CreateASTNode(SEM_IF_STATEMENT, VALUE_EMPTY); AST* condition = ParseCondition(parser); Match(parser, TOKEN_THEN); AST* thenOp = ParseOperator(parser); AddASTChild(ifNode, condition); AddASTChild(ifNode, thenOp); if(parser->currentToken.type == TOKEN_ELSE) { Match(parser, TOKEN_ELSE); AST* elseOp = ParseOperator(parser); AddASTChild(ifNode, elseOp); } return ifNode; }
asCScriptNode *asCParser::ParseAssignment() { asCScriptNode *node = new asCScriptNode(snAssignment); node->AddChildLast(ParseCondition()); if( isSyntaxError ) return node; sToken t; GetToken(&t); RewindTo(&t); if( IsAssignOperator(t.type) ) { node->AddChildLast(ParseAssignOperator()); if( isSyntaxError ) return node; node->AddChildLast(ParseAssignment()); if( isSyntaxError ) return node; } return node; }
nsresult nsAbQueryStringToExpression::ParseExpression ( const char** index, nsISupports** expression) { nsresult rv; if (**index != '(') return NS_ERROR_FAILURE; const char* indexBracket = *index + 1; while (*indexBracket && *indexBracket != '(' && *indexBracket != ')') indexBracket++; // Case: End of string if (*indexBracket == 0) return NS_ERROR_FAILURE; // Case: "((" or "()" if (indexBracket == *index + 1) { return NS_ERROR_FAILURE; } // Case: "(*(" else if (*indexBracket == '(') { // printf ("Case: (*(: %s\n", *index); nsCString operation; rv = ParseOperationEntry ( *index, indexBracket, getter_Copies (operation)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIAbBooleanExpression> e; rv = CreateBooleanExpression(operation.get(), getter_AddRefs(e)); NS_ENSURE_SUCCESS(rv, rv); // Case: "(*)(*)....(*))" *index = indexBracket; rv = ParseExpressions (index, e); NS_ENSURE_SUCCESS(rv, rv); NS_IF_ADDREF(*expression = e); } // Case" "(*)" else if (*indexBracket == ')') { // printf ("Case: (*): %s\n", *index); nsCOMPtr<nsIAbBooleanConditionString> conditionString; rv = ParseCondition (index, indexBracket, getter_AddRefs(conditionString)); NS_ENSURE_SUCCESS(rv, rv); NS_IF_ADDREF(*expression = conditionString); } if (**index != ')') return NS_ERROR_FAILURE; (*index)++; return NS_OK; }
nsresult nsMsgFilterList::LoadTextFilters(nsIInputStream *aStream) { nsresult err = NS_OK; uint64_t bytesAvailable; nsCOMPtr<nsIInputStream> bufStream; err = NS_NewBufferedInputStream(getter_AddRefs(bufStream), aStream, 10240); NS_ENSURE_SUCCESS(err, err); nsMsgFilterFileAttribValue attrib; nsCOMPtr<nsIMsgRuleAction> currentFilterAction; // We'd really like to move lot's of these into the objects that they refer to. do { nsAutoCString value; nsresult intToStringResult; char curChar; curChar = LoadAttrib(attrib, bufStream); if (curChar == (char) -1) //reached eof break; err = LoadValue(value, bufStream); if (NS_FAILED(err)) break; switch(attrib) { case nsIMsgFilterList::attribNone: if (m_curFilter) m_curFilter->SetUnparseable(true); break; case nsIMsgFilterList::attribVersion: m_fileVersion = value.ToInteger(&intToStringResult); if (NS_FAILED(intToStringResult)) { attrib = nsIMsgFilterList::attribNone; NS_ASSERTION(false, "error parsing filter file version"); } break; case nsIMsgFilterList::attribLogging: m_loggingEnabled = StrToBool(value); m_unparsedFilterBuffer.Truncate(); //we are going to buffer each filter as we read them, make sure no garbage is there m_startWritingToBuffer = true; //filters begin now break; case nsIMsgFilterList::attribName: //every filter starts w/ a name { if (m_curFilter) { int32_t nextFilterStartPos = m_unparsedFilterBuffer.RFind("name"); nsAutoCString nextFilterPart; nextFilterPart = Substring(m_unparsedFilterBuffer, nextFilterStartPos, m_unparsedFilterBuffer.Length()); m_unparsedFilterBuffer.SetLength(nextFilterStartPos); bool unparseableFilter; m_curFilter->GetUnparseable(&unparseableFilter); if (unparseableFilter) { m_curFilter->SetUnparsedBuffer(m_unparsedFilterBuffer); m_curFilter->SetEnabled(false); //disable the filter because we don't know how to apply it } m_unparsedFilterBuffer = nextFilterPart; } nsMsgFilter *filter = new nsMsgFilter; if (filter == nullptr) { err = NS_ERROR_OUT_OF_MEMORY; break; } filter->SetFilterList(static_cast<nsIMsgFilterList*>(this)); if (m_fileVersion == k45Version) { nsAutoString unicodeStr; err = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(), value, unicodeStr); if (NS_FAILED(err)) break; filter->SetFilterName(unicodeStr); } else { // ### fix me - this is silly. PRUnichar *unicodeString = nsTextFormatter::smprintf(unicodeFormatter, value.get()); filter->SetFilterName(nsDependentString(unicodeString)); nsTextFormatter::smprintf_free(unicodeString); } m_curFilter = filter; m_filters.AppendElement(filter); } break; case nsIMsgFilterList::attribEnabled: if (m_curFilter) m_curFilter->SetEnabled(StrToBool(value)); break; case nsIMsgFilterList::attribDescription: if (m_curFilter) m_curFilter->SetFilterDesc(value); break; case nsIMsgFilterList::attribType: if (m_curFilter) { // Older versions of filters didn't have the ability to turn on/off the // manual filter context, so default manual to be on in that case int32_t filterType = value.ToInteger(&intToStringResult); if (m_fileVersion < kManualContextVersion) filterType |= nsMsgFilterType::Manual; m_curFilter->SetType((nsMsgFilterTypeType) filterType); } break; case nsIMsgFilterList::attribScriptFile: if (m_curFilter) m_curFilter->SetFilterScript(&value); break; case nsIMsgFilterList::attribAction: if (m_curFilter) { nsMsgRuleActionType actionType = nsMsgFilter::GetActionForFilingStr(value); if (actionType == nsMsgFilterAction::None) m_curFilter->SetUnparseable(true); else { err = m_curFilter->CreateAction(getter_AddRefs(currentFilterAction)); NS_ENSURE_SUCCESS(err, err); currentFilterAction->SetType(actionType); m_curFilter->AppendAction(currentFilterAction); } } break; case nsIMsgFilterList::attribActionValue: if (m_curFilter && currentFilterAction) { nsMsgRuleActionType type; currentFilterAction->GetType(&type); if (type == nsMsgFilterAction::MoveToFolder || type == nsMsgFilterAction::CopyToFolder) err = m_curFilter->ConvertMoveOrCopyToFolderValue(currentFilterAction, value); else if (type == nsMsgFilterAction::ChangePriority) { nsMsgPriorityValue outPriority; nsresult res = NS_MsgGetPriorityFromString(value.get(), outPriority); if (NS_SUCCEEDED(res)) currentFilterAction->SetPriority(outPriority); else NS_ASSERTION(false, "invalid priority in filter file"); } else if (type == nsMsgFilterAction::Label) { // upgrade label to corresponding tag/keyword nsresult res; int32_t labelInt = value.ToInteger(&res); if (NS_SUCCEEDED(res)) { nsAutoCString keyword("$label"); keyword.Append('0' + labelInt); currentFilterAction->SetType(nsMsgFilterAction::AddTag); currentFilterAction->SetStrValue(keyword); } } else if (type == nsMsgFilterAction::JunkScore) { nsresult res; int32_t junkScore = value.ToInteger(&res); if (NS_SUCCEEDED(res)) currentFilterAction->SetJunkScore(junkScore); } else if (type == nsMsgFilterAction::Forward || type == nsMsgFilterAction::Reply || type == nsMsgFilterAction::AddTag || type == nsMsgFilterAction::Custom) { currentFilterAction->SetStrValue(value); } } break; case nsIMsgFilterList::attribCondition: if (m_curFilter) { if (m_fileVersion == k45Version) { nsAutoString unicodeStr; err = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(), value, unicodeStr); if (NS_FAILED(err)) break; char *utf8 = ToNewUTF8String(unicodeStr); value.Assign(utf8); nsMemory::Free(utf8); } err = ParseCondition(m_curFilter, value.get()); if (err == NS_ERROR_INVALID_ARG) err = m_curFilter->SetUnparseable(true); NS_ENSURE_SUCCESS(err, err); } break; case nsIMsgFilterList::attribCustomId: if (m_curFilter && currentFilterAction) { err = currentFilterAction->SetCustomId(value); NS_ENSURE_SUCCESS(err, err); } break; } } while (NS_SUCCEEDED(bufStream->Available(&bytesAvailable))); if (m_curFilter) { bool unparseableFilter; m_curFilter->GetUnparseable(&unparseableFilter); if (unparseableFilter) { m_curFilter->SetUnparsedBuffer(m_unparsedFilterBuffer); m_curFilter->SetEnabled(false); //disable the filter because we don't know how to apply it } } return err; }
bool CTaskMgr::Init() { const char* str = NULL; bool r = CSysSettingMgr::GetInstance()->GetStringValue("Chapter_Map_Born_Point", str); ASSERT(r && str); CHECK_FALSE_RETURN_FALSE(r && str); split_string_2i(std::string(str), m_CharpterMapBornPoint, "|"); //1. 读配置 组织基本map //2. 组织各个查询map,并且一旦有问题 就报错!! MYSQL* con = CDBMgr::GetInstance()->GetConnection(); //解析task表! char* sql = SELECT_TASK; int code = CDBMgr::Query(con, sql, (unsigned int)strlen(sql)); if (0 != code) //非0查询失败 { printf("query failed! [%s]\n", sql); return false; } MYSQL_RES* res = mysql_store_result(con); //保存查询结果 { //检查表结构是否有改变 //string task_need_fields[] = {"id", "task_id", "type", "name", "desc", "mappoint_id", "priority", "has_enter_condition", "prize_element_type", "prize_element_id", "prize_element_num", "img", "unlock_mappoint_id", "hidden"}; string need_fields[] = {"id", "task_id", "type", "name", "desc", "mappoint_id", "priority", "total_enter_num_per_day", "enter_condition_arr", "prize_element_type_id_num_arr", "unlock_mappoint_id_arr", "background_img", "hidden"}; std::vector<std::string> v_task_need_field(need_fields, need_fields + sizeof(need_fields)/sizeof(need_fields[0])); ASSERT(CDBMgr::check_fields(res, v_task_need_field)); } MYSQL_ROW row; CMapMgr* pMapMgr = CMapMgr::GetInstance(); while (row = mysql_fetch_row(res)) { int col = 1; CTask *pTask = new CTask(); pTask->iTaskID = atoi(row[col++]); pTask->eType = (CTask::ETASKTYPE)atoi(row[col++]); ASSERT( pTask->eType > CTask::ETASKTYPE_MIN && pTask->eType < CTask::ETASKTYPE_MAX); char* pBuf = UTF8ToANSI(row[col++]); int len = strlen(pBuf); ASSERT( len <= MAXLEN_TASKNAME); memcpy(pTask->strName, pBuf, len); free(pBuf); pBuf = UTF8ToANSI(row[col++]); len = strlen(pBuf); ASSERT( len <= MAXLEN_TASKDESC); memcpy(pTask->strDesc, pBuf, len); free(pBuf); pTask->iMapPointID = atoi(row[col++]); ASSERT(CMapMgr::GetInstance()->GetMapPointByID(pTask->iMapPointID));//验证所属据点存在 pTask->iPriority = atoi(row[col++]); pTask->iTotalEnterNumPerDay = atoi(row[col++]); //解析显示条件配置 <--服务器已经去掉这个设定 //解析进入条件配置! pBuf = UTF8ToANSI(row[col++]); bool r = ParseCondition(pBuf, pTask->enterConditions); free(pBuf); pBuf = UTF8ToANSI(row[col++]); //len = strlen(pBuf); //ASSERT( len <= MAXNUM_TASKPRIZE_STRLEN); //分割字符串 vector<string> prizes; split_string(string(pBuf), prizes, "|"); free(pBuf); int i = 0; //ASSERT(prizes.size()<= MAXNUM_TASKPRIZE_NUM); for (vector<string>::iterator it = prizes.begin() ; it != prizes.end() ; ++it){ vector<int> aprize; split_string_2i(*it, aprize, "-"); ASSERT(aprize.size() == 3); pTask->prizes.push_back(stGameElement((EELEMENTTYPE)aprize[0], aprize[1], 0, stGameElement::INCREASE, aprize[2])); IsElementValid(pTask->prizes[i]); ++i; } //pTask->iPrizeElementType = (EELEMENTTYPE)atoi(row[8]); //ASSERT(pTask->iPrizeElementType < EELEMENTTYPE::EELEMENTTYPE_MAX); //pTask->iPrizeElementID = atoi(row[9]); //pTask->iPrizeElementNum = atoi(row[10]); pBuf = UTF8ToANSI(row[col++]); len = strlen(pBuf); ASSERT( len <= MAXLEN_TASKIMG); memcpy(pTask->strImg, pBuf, len); free(pBuf); //pTask->iUnlockMappointID = atoi(row[12]); //ASSERT(CMapMgr::GetInstance()->GetMapPointByID(pTask->iUnlockMappointID));//验证所属据点存在 pBuf = UTF8ToANSI(row[col++]); //len = strlen(pBuf); vector<int> mappoints; split_string_2i(string(pBuf), mappoints, "|"); ASSERT(mappoints.size() <= MAXNUM_JOINEDMAPPOINT); i = 0; for (vector<int>::iterator it = mappoints.begin() ; it != mappoints.end() ;++it) { UINT32 iMappointID = *it; ASSERT(pMapMgr->GetMapPointByID(iMappointID)); pTask->iUnlockMappointID[i++] = iMappointID; } free(pBuf); pTask->bHidden = (bool)atoi(row[col]); ASSERT(AddTask(pTask)); } mysql_free_result(res); sql = SELECT_SUBTASK; code = CDBMgr::Query(con, sql, (unsigned int)strlen(sql)); if (0 != code) //非0查询失败 { printf("query failed! [%s]\n", sql); return false; } res = mysql_store_result(con); //保存查询结果 //检查表结构是否有改变 //, "battle_id_difficulty_time_arr"去掉这个配置! 《-还是保留了 { string need_fields[] = {"id", "sub_task_id", "task_id", "priority", "spend_health", "total_enter_num_per_day", "normal_packet_id", "auto_battle_packet_id", "extra_packet_id", "extra_packet_time"}; std::vector<std::string> v_subtask_need_field(need_fields, need_fields + sizeof(need_fields)/sizeof(need_fields[0])); ASSERT(CDBMgr::check_fields(res, v_subtask_need_field)); } while (row = mysql_fetch_row(res)) { stSubTask *pSubTask = new stSubTask(); memset(pSubTask, 0, sizeof stSubTask); int col = 1;//忽略主键id pSubTask->iSubTaskID = atoi(row[col++]); pSubTask->iTaskID = atoi(row[col++]); ASSERT(GetTaskByTaskID(pSubTask->iTaskID) && "子任务初始化有问题 其父任务不存在!"); pSubTask->iPriority = atoi(row[col++]); pSubTask->iSpendHealth = atoi(row[col++]); pSubTask->iTotalEnterNumPerDay = atoi(row[col++]); pSubTask->iBurstPacketID = atoi(row[col++]); ASSERT(CBurstMgr::GetInstance()->GetPacketByPacketID(pSubTask->iBurstPacketID)); pSubTask->iAutoBattleBurstPacketID = atoi(row[col++]); ASSERT(CBurstMgr::GetInstance()->GetPacketByPacketID(pSubTask->iAutoBattleBurstPacketID)); pSubTask->iExtraPacketID = atoi(row[col++]); if (pSubTask->iExtraPacketID){ ASSERT(CBurstMgr::GetInstance()->GetPacketByPacketID(pSubTask->iExtraPacketID)); //解析额外掉落包条件配置! char* pBuf = UTF8ToANSI(row[col++]); bool r = ParseTimeCondition(pBuf, pSubTask->ExtraPacketCondition); free(pBuf); } //char* pBuf = UTF8ToANSI(row[col++]); ////len = strlen(pBuf); ////ASSERT( len <= MAXLEN_TASKIMG); //vector<string> battlecontrols; //split_string(string(pBuf), battlecontrols, "|"); //free(pBuf); //int i = 0; //ASSERT(battlecontrols.size()<= MAXNUM_TASKBATTLE); //for (vector<string>::iterator it = battlecontrols.begin() ; it != battlecontrols.end() ; ++it) //{ // vector<int> aBattle; // split_string_2i(*it, aBattle, "-"); // ASSERT(aBattle.size() == 2); // ASSERT(CFightMgr::GetInstance()->GetBattleByID(aBattle[0])); // pSubTask->battles[i].iBattleID = aBattle[0]; // //pSubTask->battles[i].iDifficulty = aBattle[1]; // //pSubTask->battles[i].iTimeLimit = aBattle[2]; // pSubTask->battles[i].iTimeLimit = aBattle[1]; // ++i; //} bool r = AddSubTask(pSubTask); ASSERT(r); } sql = SELECT_SUB_TASK_MAIN_BRANCH_ID; code = CDBMgr::Query(con, sql, (unsigned int)strlen(sql)); if (0 != code) { printf("query failed! [%s]\n", sql); return false; } res = mysql_store_result(con); { string need_fields[] = {"chapter_id", "sub_task_id"}; std::vector<std::string> v_subtask_need_field(need_fields, need_fields + sizeof(need_fields)/sizeof(need_fields[0])); ASSERT(CDBMgr::check_fields(res, v_subtask_need_field)); } while (row = mysql_fetch_row(res)) { m_mapChapterID2MainBranchSubTaskIDs; int col = 0; UINT32 iChapterID = atoi(row[col++]); UINT32 iSubTaskID = atoi(row[col++]); m_mapChapterID2MainBranchSubTaskIDs[iChapterID].push_back(iSubTaskID); } mysql_free_result(res); return true; }
Chapter::Chapter(const int chapter_number) : m_ball_game_chapter{*this}, m_bye_text{}, m_consequence{}, m_chapter_number{chapter_number}, m_chapter_type{ChapterType::normal}, m_dice_game_chapter{*this}, m_fighting_chapter{FightingChapter(*this)}, m_game_lost_chapter{this}, m_game_won_chapter{this}, m_luck_chapter(*this), m_observer{nullptr}, m_options_chapter{}, m_pawn_shop_chapter(this), m_pill_game_chapter{*this}, m_shop_chapter{this}, m_skill_chapter{*this}, m_text{}, m_verbose{false} { if (m_verbose) { std::clog << __func__ << std::endl; } Helper h; if (m_verbose) { std::clog << __func__ << std::endl; } #ifdef USE_TEXT_FILES_FOR_INPUT const std::string filename{h.GetFilesFolder() + h.ToStr(chapter_number) + ".txt"}; if (!h.IsRegularFile(filename)) { std::stringstream msg; msg << __func__ << ": ERROR: File " << filename << " does not exist"; Helper().Cout(msg.str()); throw std::runtime_error(msg.str()); } const std::vector<std::string> lines{h.FileToVector(filename)}; #else const std::vector<std::string> lines(1,GetFile(h.ToStr(chapter_number))); #endif std::stringstream s; std::copy(std::begin(lines),std::end(lines),std::ostream_iterator<std::string>(s," ")); m_text = h.ReadText(s); m_chapter_type = ReadChapterType(s); switch (m_chapter_type) { case ChapterType::game_lost: return; case ChapterType::game_won: return; default: break; } while (!s.eof()) { const std::string str{h.ReadString(s)}; if (str.empty()) { break; } else if (str == "Bye" || str == "bye") { m_bye_text = h.ReadText(s); } else if (str == "Change" || str == "change") { m_consequence.Add(ParseConsequence(s)); } else if (str == "Escape" || str == "escape") { GetFighting().SetRoundsToEscape(h.ReadInt(s)); GetFighting().SetEscapeToChapter(h.ReadInt(s)); } else if (str == "Fight_both" || str == "fight_both") { GetFighting().SetFightSequentially(false); } else if (str == "Luck" || str == "luck") { assert(this->m_chapter_type == ChapterType::test_your_luck); const std::string luck_text{h.ReadText(s)}; assert(!luck_text.empty()); GetLuck().SetLuckText(luck_text); const std::string goto_str{h.ReadString(s)}; assert(goto_str == "goto"); const int luck_chapter{h.ReadInt(s)}; assert(luck_chapter > 1); GetLuck().SetLuckChapter(luck_chapter); } else if (str == "Monster" || str == "monster") { this->m_chapter_type = ChapterType::fight; const Monster monster{ParseMonster(s)}; GetFighting().AddMonster(monster); } else if (str == "Next_chapter" || str == "goto") { m_consequence.SetNextChapter(h.ReadInt(s)); } else if (str == "No_luck" || str == "no_luck") { assert(this->m_chapter_type == ChapterType::test_your_luck); //s << std::noskipws; //Obligatory //Parse(s,' '); //You expect a space after a word const std::string no_luck_text{h.ReadText(s)}; assert(!no_luck_text.empty()); GetLuck().SetNoLuckText(no_luck_text); const std::string then{h.ReadString(s)}; if (then == "change") { const Consequence no_luck_consequence{ParseConsequence(s)}; GetLuck().SetNoLuckConsequence(no_luck_consequence); const std::string goto_str{h.ReadString(s)}; assert(goto_str == "goto"); } else { assert(then == "goto"); } const int no_luck_chapter{h.ReadInt(s)}; assert(no_luck_chapter > 1); GetLuck().SetNoLuckChapter(no_luck_chapter); } else if (str == "No_skill" || str == "no_skill") { assert(this->m_chapter_type == ChapterType::test_your_skill); //Parse(s,' '); //You expect a space after a word const std::string no_skill_text{h.ReadText(s)}; assert(!no_skill_text.empty()); GetSkill().SetNoSkillText(no_skill_text); const std::string then_str{h.ReadString(s)}; Consequence consequence; if (then_str == "goto") { consequence.SetNextChapter(h.ReadInt(s)); } else if (then_str == "change") { consequence = ParseConsequence(s); //Also read goto const std::string goto_str{h.ReadString(s)}; assert(goto_str == "goto"); consequence.SetNextChapter(h.ReadInt(s)); } else { assert(!"Should not get here"); } GetSkill().SetNoSkillConsequence(consequence); } else if (str == "Option" || str == "option") { const std::string option_text{h.ReadText(s)}; const std::string t{h.ReadString(s)}; if (t == "if") { const Condition condition{ParseCondition(s)}; const std::string then_str{h.ReadString(s)}; Consequence consequence; if (then_str == "goto") { consequence.SetNextChapter(h.ReadInt(s)); } else if (then_str == "change") { consequence = ParseConsequence(s); //Also read goto const std::string goto_str{h.ReadString(s)}; assert(goto_str == "goto"); consequence.SetNextChapter(h.ReadInt(s)); } else { assert(!"Should not get here"); } Option option(option_text,consequence); option.SetCondition(condition); GetOptions().AddOption(option); } else if (t == "ifnot") { Condition condition; const std::string what{h.ReadString(s)}; if (IsItem(what)) { const Item item_not_needed{ToItem(what)}; condition.AddItemNotNeeded(item_not_needed); } else { std::cerr << "Unknown item " << what << " in chapter " << chapter_number << std::endl; assert(!"Should not get here"); } const std::string str_goto{h.ReadString(s)}; assert(str_goto == "goto"); Consequence consequence; consequence.SetNextChapter(h.ReadInt(s)); Option option(option_text,consequence); option.SetCondition(condition); GetOptions().AddOption(option); } else if (t == "goto") { Consequence consequence; consequence.SetNextChapter(h.ReadInt(s)); const Option option(option_text,consequence); GetOptions().AddOption(option); } else if (h.IsInt(t)) { std::clog << "WARNING: goto omitted in chapter " << chapter_number << std::endl; //If no goto, just parse the number Consequence consequence; consequence.SetNextChapter(h.ToInt(t)); const Option option(option_text,consequence); GetOptions().AddOption(option); } else { std::cerr << "Unknown option " << t << " in chapter " << chapter_number <<std::endl; assert(!"Should not get here"); } } else if (str == "Random_monsters" || str == "random_monsters") { std::vector<Monster> monsters{ParseMonsters(s)}; m_chapter_type = ChapterType::fight; const int which_monster_index{Dice::Get()->Throw() - 1}; assert(which_monster_index >= 0); assert(which_monster_index < static_cast<int>(monsters.size())); const Monster monster{monsters[which_monster_index]}; m_fighting_chapter.AddMonster(monster); } else if (str == "Sell_items" || str == "sell_items") { assert(this->m_chapter_type == ChapterType::pawn_shop); //m_chapter_type = ChapterType::pawn_shop; m_pawn_shop_chapter = ParsePawnShopChapter(s,this); } else if (str == "Shop_items" || str == "shop_items") { assert(this->m_chapter_type == ChapterType::shop); //m_chapter_type = ChapterType::shop; m_shop_chapter = ParseShopChapter(s,this); } else if (str == "Skill" || str == "skill") { assert(this->m_chapter_type == ChapterType::test_your_skill); this->m_chapter_type = ChapterType::test_your_skill; //Parse(s,' '); //You expect a space after a word const std::string skill_text{h.ReadText(s)}; assert(!skill_text.empty()); GetSkill().SetSkillText(skill_text); const std::string then_str{h.ReadString(s)}; Consequence consequence; if (then_str == "goto") { consequence.SetNextChapter(h.ReadInt(s)); } else if (then_str == "change") { consequence = ParseConsequence(s); //Also read goto const std::string goto_str{h.ReadString(s)}; assert(goto_str == "goto"); consequence.SetNextChapter(h.ReadInt(s)); } else { assert(!"Should not get here"); } GetSkill().SetSkillConsequence(consequence); } else { std::cerr << "Chapter cannot parse chapter " << chapter_number << '\n' << "Unknown string: " << str << '\n' ; assert(!"Should not get here"); } } }
//----------------------------------------------------------------------------- bool HoneDumpcap::ParseArgs(void) { QStringList errors; bool haveInterface = false; bool ok = false; bool printInterfaces = false; bool printLinkLayerTypes = false; int index; for (index = 1; index < m_args.size(); index++) { if (m_args.at(index) == "-a") { if (index+1 >= m_args.size()) { errors.append(QString("You must supply a condition with the %1 option").arg(m_args.at(index))); } index++; if (!ParseCondition(m_args.at(index), m_autoStopMilliseconds, m_autoStopFileSize, m_autoStopFileCount)) { errors.append(QString("Invalid condition %1 with the %2 option").arg(m_args.at(index), m_args.at(index-1))); } } else if (m_args.at(index) == "-b") { if (index+1 >= m_args.size()) { errors.append(QString("You must supply a condition with the %1 option").arg(m_args.at(index))); } index++; if (!ParseCondition(m_args.at(index), m_autoRotateMilliseconds, m_autoRotateFileSize, m_autoRotateFileCount)) { errors.append(QString("Invalid condition %1 with the %2 option").arg(m_args.at(index), m_args.at(index-1))); } m_autoRotateFiles = true; } else if (m_args.at(index) == "-c") { if (index+1 >= m_args.size()) { errors.append(QString("You must supply a packet count with the %1 option").arg(m_args.at(index))); } index++; m_autoStopPacketCount = m_args.at(index).toUInt(&ok); if (!ok) { errors.append(QString("Invalid packet count %1 with the %2 option").arg(m_args.at(index), m_args.at(index-1))); } } else if (m_args.at(index) == "-D") { printInterfaces = true; } else if (m_args.at(index) == "-i") { if (index+1 >= m_args.size()) { errors.append(QString("You must supply an interface with the %1 option").arg(m_args.at(index))); } index++; if ((m_args.at(index) == "Hone") || (m_args.at(index) == "1")) { m_haveHoneInterface = true; } else { // Fixup interface index before passing to original dumpcap quint32 val = m_args.at(index).toUInt(&ok); if (ok && (val > 1)) { val--; m_args[index] = QString::number(val); } } haveInterface = true; } else if (m_args.at(index) == "-L") { printLinkLayerTypes = true; } else if (m_args.at(index) == "-M") { m_machineReadable = true; } else if (m_args.at(index) == "-s") { if (index+1 >= m_args.size()) { errors.append(QString("You must supply a snap length with the %1 option").arg(m_args.at(index))); } index++; m_snapLen = m_args.at(index).toUInt(&ok); if (!ok) { errors.append(QString("Invalid snap length %1 with the %2 option").arg(m_args.at(index), m_args.at(index-1))); } } else if (m_args.at(index) == "-w") { if (index+1 >= m_args.size()) { errors.append(QString("You must supply a file name with the %1 option").arg(m_args.at(index))); } index++; m_captureFileName = m_args.at(index); } else if (m_args.at(index) == "-Z") { if (index+1 >= m_args.size()) { errors.append(QString("You must supply a PID or \"none\" with the %1 option").arg(m_args.at(index))); } index++; m_parentPid = m_args.at(index); } else if (m_args.at(index) == "-h") { return Usage(m_args.at(0)); } else { // Silently ignore unknown options for now //Log(QString("Ignoring unknown option %1").arg(m_args.at(index))); } } if (!haveInterface) { m_haveHoneInterface = true; } // Check options if (printInterfaces && printLinkLayerTypes) { errors.append("The '-D' and '-L' options are mutually exclusive"); } if (printInterfaces) { m_operation = OperationPrintInterfaces; } else if (printLinkLayerTypes) { m_operation = OperationPrintLinkLayerTypes; } if (!errors.isEmpty()) { return Usage(m_args.at(0), errors.join("\n")); } return true; }