pgn::Ply* pgn::Parser::getPly(std::string::const_iterator &itr1, const std::string::const_iterator &itr2) { std::string::const_iterator local_itr = itr1; skipBlanks(local_itr, itr2); while (!isspace(*local_itr)) local_itr++; pgn::Ply *p = new pgn::Ply(std::string(itr1, local_itr)); skipBlanks(local_itr, itr2); itr1 = local_itr; pgn::CommentText comment; if (getComment(local_itr, itr2, comment)) { skipBlanks(local_itr, itr2); itr1 = local_itr; p->bindComment(comment); } checkForVariations(local_itr, itr2); itr1 = local_itr; checkForGlyphs(local_itr, itr2); itr1 = local_itr; plyCount_++; return p; }
pgn::Move* pgn::Parser::getMove(std::string::const_iterator &itr1, const std::string::const_iterator &itr2) { std::string::const_iterator local_itr = itr1; // looking for move number std::string movenumber; int dotsCount; if (! getMoveNumber(local_itr, itr2, movenumber, dotsCount)) return 0; itr1 = local_itr; // possibilita`: // // <move_number><dots> <ply> <result> // <move_number><dots> <ply> <move_number> // <move_number><dots> <ply> <ply> <result> // <move_number><dots> <ply> <ply> <move_number> // looking for first ply (mandatory) skipBlanks(local_itr, itr2); pgn::Ply *firstPly=0; if ((firstPly = getPly(local_itr, itr2)) == 0) throw std::runtime_error("Error parsing move"); skipBlanks(local_itr, itr2); pgn::Ply *secondPly=0; // second ply, game result or another move number? // a ply always begins with an uppercase or lowercase alphabetic char. // digits and '*' have lesser ascii values. // if we meet a "[" that's owned by the next game, so game result is // missing if (*local_itr > '9' && *local_itr != '[') { // looking for second ply (optional) secondPly = getPly(local_itr, itr2); skipBlanks(local_itr, itr2); } itr1 = local_itr; pgn::Move *m = new pgn::Move(firstPly, secondPly, atoi(movenumber.c_str())); delete firstPly; delete secondPly; moveCount_++; return m; }
bool UtlXMLStream::readBeginOfArrayElement(std::string sType) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } std::string sReadType; if (!readString( getInputStream(), sReadType)) if (sReadType!=sType) return false; std::string sValue; if (!readString( getInputStream(), sValue)) return false; iChar=readChar( getInputStream() ); if (iChar != ' ') { return false; } if (strcmp(sValue.c_str(),"value") ) return false; return true; }
bool UtlXMLStream::readAttribute(std::string& sName, bool& bValue) { skipBlanks( getInputStream() ); if (!readName(sName)) return false; if (!readBeginningOfAttribute()) return false; std::string sXMLText; if (!readString( getInputStream() , sXMLText)) return false; if (stricmp(sXMLText.c_str(),"TRUE")) bValue=true; if (stricmp(sXMLText.c_str(),"FALSE")) bValue=false; else return false; if (!readEndOfAttribute()) return false; return true; }
bool UtlXMLStream::readAttribute(std::string& sName, std::string& sValue) { skipBlanks( getInputStream() ); if (!readName(sName)) return false; // if (!readBeginningOfAttribute()) // return false; // std::string sXMLText; // if (!readName( sXMLText)) // return false; int iChar=readChar( getInputStream() ); if (iChar != '=') { return false; } std::string sXMLText; if (!readString( getInputStream(), sXMLText)) return false; sValue=convertXMLTextToClassicText( sXMLText ); // if (!readEndOfAttribute()) // return false; return true; }
bool pgn::Parser::getMoveNumber(std::string::const_iterator &itr1, const std::string::const_iterator &itr2, std::string &out, int &dotsCount) { std::string::const_iterator local_itr = itr1; if (!isdigit(*local_itr)) return false; // looking for number std::string movenumber; while (isdigit(*local_itr) && local_itr != itr2) { movenumber += *local_itr++; } skipBlanks(local_itr, itr2); if (*local_itr != '.') { // maybe reading game result '1-0'. return false; } // skipping and counting dots dotsCount=0; while ((*local_itr == '.') && (local_itr != itr2)) { local_itr++; dotsCount++; } itr1 = local_itr; out = movenumber; return true; }
void getToken(void) { skipBlanks(); tokenp = tokenString; switch (calcCharCode(curChar)) { case CHR_LETTER: getWord(); break; case CHR_DIGIT: getNumber(); break; case CHR_DQUOTE: getString(); break; case CHR_EOF: curToken = TKN_EOF; break; default: getSpecial(); break; } if (blockFlag) crunchToken(); }
bool UtlXMLStream::readKeyOfHashTable(std::string& sKey) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } std::string sTrash; if (!readString( getInputStream() , sTrash)) return false; if (strcmp(sTrash.c_str(),"pair")) return false; std::string sKeyTag; if (!readAttribute( sKeyTag , sKey)) return false; if (strcmp(sKeyTag.c_str(),"key")) return false; return true; }
bool UtlXMLStream::readEndOfAssociation(std::string& sOwnerClass, std::string& sName) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } iChar=readChar( getInputStream() ); if (iChar != '/') { return false; } // Read a string, search '_' and split the string in two std::string sCompletWord,sDebut,sFin; if (!readWord( getInputStream(), sCompletWord )) return false; if (!splitString( sCompletWord, '_', sOwnerClass, sName)) return false; iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } return true; }
void cmd_miner(IMP) { USHORT what; /* find out what they want to do */ if (reqChoice(IS, &what, "list\0program\0update\0empty\0refuel\0", "Request miner (empty/list/program/refuel/update)")) { (void) skipBlanks(IS); switch (what) { case 0: minerList(IS); break; case 1: minerProgram(IS); break; case 2: updateAllMiners(IS); break; case 3: minerEmpty(IS); break; case 4: minerRefuel(IS); break; } } }
inline bool ConsumerParser::beginCapture(std::string tag) { if (_skipBlank) skipBlanks(); _captures[tag] = _rwHeader; return (true); }
static char *skipToNextArg( char * cmd ) { char string_open = 0; while( *cmd != '\0' ) { if( *cmd == '\\' ) { cmd++; if( *cmd != '\0' ) { if( !string_open && iswsOrOpt( *cmd ) ) { break; } cmd++; } } else { if( *cmd == '\"' ) { string_open = !string_open; cmd++; } else { if( !string_open && iswsOrOpt( *cmd ) ) { break; } cmd++; } } } cmd = skipBlanks( cmd ); return( cmd ); }
bool UtlXMLStream::readEndTag(std::string& sTag) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } iChar=readChar( getInputStream() ); if (iChar != '/') { return false; } if (!readWord( getInputStream(), sTag )) return false; iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } return true; }
bool UtlXMLStream::readEndOfAttributes() { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } return true; }
inline bool ConsumerParser::readChar(char c) { if (_skipBlank) skipBlanks(); if (peekChar(c)) // He'll call addData() { _rwHeader++; return (true); } return (false); }
bool UtlXMLStream::readName(std::string& sName) { skipBlanks( getInputStream() ); std::string sNonNormaliseName; if (!readWord( getInputStream(), sNonNormaliseName )) return false; sName = normalizeAttributeName(sNonNormaliseName); return true; }
inline bool ConsumerParser::peekChar(char c) { if (_skipBlank) skipBlanks(); if (_rwHeader == _inputData.end() && !addData()) { return (false); } if (*_rwHeader == c) return (true); return (false); }
bool UtlXMLStream::readArrayElement(int& iValue) { skipBlanks( getInputStream() ); if (!readBeginOfArrayElement("int")) return false; if (!readInt( getInputStream() , iValue)) return false; if (!readEndOfArrayElement()) return false; return true; }
// End of Queue routines // ------------------------------------------------------------------- void Scanner::nextTokenInternal() { // check if a token has been pushed back into the token stream, if so use it first // I think I should get rid of this code, use queue methods instead if (previousToken.tokenCode != CodeTypes::tEmptyToken) { ftoken = previousToken.tokenCode; tokenString = previousToken.tokenString; tokenDouble = previousToken.tokenDouble; tokenInteger = previousToken.tokenInteger; previousToken.tokenCode = CodeTypes::tEmptyToken; return; } // Check if there is anything in the token queue, if so get the item // from the queue and exit. If not, read as normal from the stream. // Checking the queue before reading from the stream can be turned off and on // by setting the FromQueue Flag. if(FromQueue) { if(!IsQueueEmpty()) { getTokenFromQueue(); return; } } skipBlanks(); tokenString = ""; TCharCode::TCharCode code = FCharTable[fch]; switch(code) { case TCharCode::cLETTER: case TCharCode::cUNDERSCORE: getWord(); break; case TCharCode::cDIGIT: getNumber(); break; case TCharCode::cDOUBLEQUOTE: getString(); break; case TCharCode::cETX: ftoken = CodeTypes::tEndOfStreamToken; break; default: getSpecial(); break; } }
bool UtlXMLStream::readArrayElement(double& dValue) { skipBlanks( getInputStream() ); if (!readBeginOfArrayElement("double")) return false; if (!readDouble( getInputStream() , dValue)) return false; if (!readEndOfArrayElement()) return false; return true; }
void minerProgram(IMP) { register Ship_t *rsh; ULONG mineNum; USHORT what, curLevel; /* get the number of the miner */ if (reqShip(IS, &mineNum, "Miner to program")) { rsh = &IS->is_request.rq_u.ru_ship; (void) skipBlanks(IS); server(IS, rt_readShip, mineNum); if (rsh->sh_owner != IS->is_player.p_number) { err(IS, "you don't own that miner"); return; } /* make sure the ship is a miner */ if (rsh->sh_type != st_m) { err(IS, "that ship is not a miner"); return; } /* make sure the ship is not on a planet */ if (rsh->sh_planet != NO_ITEM) { err(IS, "miner is on the surface of a planet"); return; } if (rsh->sh_dragger == NO_ITEM) { err(IS, "miner is not on a ship - alert system owner!"); return; } if (reqChoice(IS, &what, "ore\0messages\0gold\0", "Request miner (gold/messages/ore)")) { curLevel = rsh->sh_weapon[what]; if (repLevel(IS, &curLevel)) { server(IS, rt_lockShip, mineNum); rsh->sh_weapon[what] = curLevel; server(IS, rt_unlockShip, mineNum); /* put out the dirty ship number */ feShDirty(IS, mineNum); } } } }
bool UtlXMLStream::readArrayElement(UtlDate& myValue) { skipBlanks( getInputStream() ); if (!readBeginOfArrayElement("date")) return false; struct tm tmValue; if (!readDate( getInputStream() , tmValue)) return false; myValue=UtlDate( tmValue.tm_year, tmValue.tm_mon, tmValue.tm_mday, 0, 0, 0); if (!readEndOfArrayElement()) return false; return true; }
bool UtlXMLStream::readAttribute(std::string& sName, double& dValue) { skipBlanks( getInputStream() ); if (!readName(sName)) return false; if (!readBeginningOfAttribute()) return false; if (!readDouble( getInputStream() , dValue)) return false; if (!readEndOfAttribute()) return false; return true; }
bool UtlXMLStream::readEndOfArrayElement() { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '/') { return false; } iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } return true; }
bool UtlXMLStream::readBeginningOfObject(std::string& sTypeName) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } if (!readWord( getInputStream(), sTypeName )) return false; return true; }
bool UtlXMLStream::readBeginningOfAttribute() { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '=') { return false; } iChar=readChar( getInputStream() ); if (iChar != '\"') { return false; } return true; }
bool UtlXMLStream::readArrayElement(std::string& sValue) { skipBlanks( getInputStream() ); if (!readBeginOfArrayElement("string")) return false; std::string sXMLText; if (!readString( getInputStream() , sXMLText)) return false; sValue=convertXMLTextToClassicText( sXMLText ); if (!readEndOfArrayElement()) return false; return true; }
bool UtlXMLStream::readHashtableEntry(std::string& sKey, std::vector<double>& listOfValues) { int iChar; skipBlanks( getInputStream() ); if (!readKeyOfHashTable(sKey)) return false; iChar=readChar( getInputStream() ); if (iChar != ' ') { return false; } iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } bool bAtLeastOne=false; bool bContinue=true; listOfValues.clear(); while (bContinue) { double dValue; int iPos = getInputStream().tellg(); bContinue=readArrayElement(dValue); if (bContinue) { listOfValues.push_back(dValue); bAtLeastOne=true; } else { getInputStream().seekg(iPos); } } if (!bAtLeastOne) { return false; } if (!readEndOfHashTable()) return false; return true; }
bool pgn::Parser::getComment(std::string::const_iterator &itr1, const std::string::const_iterator &itr2, pgn::CommentText &out) { std::string::const_iterator local_itr = itr1; std::string comment; if (*local_itr != '{') return false; local_itr++; // skipping '{' while ((*local_itr != '}') && (local_itr != itr2)) { comment += *local_itr++; } local_itr++; // skipping '}' skipBlanks(local_itr, itr2); itr1 = local_itr; out = pgn::CommentText(comment); return true; }
bool pgn::Parser::getMoveList(std::string::const_iterator &itr1, const std::string::const_iterator &itr2, pgn::MoveList &out) { std::string::const_iterator local_itr = itr1; pgn::MoveList ml; skipBlanks(local_itr, itr2); pgn::Move *move; while (move = getMove(local_itr, itr2)) { itr1 = local_itr; ml.insert(*move); delete move; } itr1 = local_itr; out = ml; return true; }