BOOL messageValidate(PTR_MESSAGE msg) { BOOL result; result = false; switch(msg->type) { case LoginRequest: result = checkLoginRequest(msg); break; case LoginResponseOK: result = checkLoginResponseOK(msg); break; case CatalogRequest: result = checkCatalogRequest(msg); break; case CatalogResponse: result = checkCatalogResponse(msg); break; case CatalogChange: result = checkCatalogChange(msg); break; case PlayerList: result = checkPlayerList(msg); break; case StartGame: result = checkStartGame(msg); break; case QuestionRequest: result = checkQuestionRequest(msg); break; case QUestion: result = checkQuestion(msg); break; case QuestionAnswered: result = checkQuestionAnswered(msg); break; case QuestionResult: result = checkQuestionResult(msg); break; case GameOver: result = checkGameOver(msg); break; case ErrorWarning: result = checkErrorWarning(msg); break; } return result; }
PTR_MESSAGE generateQuestion(uint8_t type, uint16_t length, char* content) { PTR_MESSAGE msg; uint16_t* forHons; msg = generateMsg(type, length, content); if(checkQuestion(msg) == true) { forHons = (uint16_t *) &msg->content[length-2]; *forHons = htons(*forHons); return msg; } else { free(msg); return NULL; } }
Token* RegxParser::parseFactor() { Token* tok = parseAtom(); switch(fState) { case REGX_T_STAR: return processStar(tok); case REGX_T_PLUS: return processPlus(tok); case REGX_T_QUESTION: return processQuestion(tok); case REGX_T_CHAR: if (fCharData == chOpenCurly && fOffset < fStringLen) { int min = 0; int max = -1; XMLInt32 ch = fString[fOffset++]; if (ch >= chDigit_0 && ch <= chDigit_9) { min = ch - chDigit_0; while (fOffset < fStringLen && (ch = fString[fOffset++]) >= chDigit_0 && ch <= chDigit_9) { min = min*10 + ch - chDigit_0; } if (min < 0) ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier5, fString, fMemoryManager); } else { ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier1, fString, fMemoryManager); } max = min; if (ch == chComma) { if (fOffset >= fStringLen) { ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier3, fString, fMemoryManager); } else if ((ch = fString[fOffset++]) >= chDigit_0 && ch <= chDigit_9) { max = ch - chDigit_0; while (fOffset < fStringLen && (ch = fString[fOffset++]) >= chDigit_0 && ch <= chDigit_9) { max = max*10 + ch - chDigit_0; } if (max < 0) ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier5, fString, fMemoryManager); else if (min > max) ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier4, fString, fMemoryManager); } else { max = -1; } } if (ch != chCloseCurly) { ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier2, fString, fMemoryManager); } if (checkQuestion(fOffset)) { tok = fTokenFactory->createClosure(tok, true); fOffset++; } else { tok = fTokenFactory->createClosure(tok); } tok->setMin(min); tok->setMax(max); processNext(); } break; default: break; } return tok; }