bool IC_CmdLineParser::handleChar( wchar_t wc, WideString& cmdName, array<WideString>& args ) { static const wchar_t spaceChar = ( wchar_t )' '; static const wchar_t escapeChar = ( wchar_t )'\\'; static const wchar_t quoteChar = ( wchar_t )'\"'; if ( wc == spaceChar ) { if ( !isQuoted() ) { shoveTmpString( cmdName, args ); } else { tmpString += ( spaceChar ); bShouldAddLast = true; } } else if ( wc == quoteChar ) { if ( isEscaped() ) { tmpString += quoteChar; bShouldAddLast = true; setEscaped( false ); } else if ( isQuoted() ) { shoveTmpString( cmdName, args ); setQuoted( false ); } else { setQuoted( true ); } } else if ( wc == escapeChar ) { if ( isEscaped() ) { tmpString += escapeChar; bShouldAddLast = true; setEscaped( false ); } else { setEscaped( true ); } } else { if ( isEscaped() ) { return false; } tmpString += wc; bShouldAddLast = true; } return true; }
bool IC_CmdLineParser::parse( WideString& cmdName, array<WideString>& args ) { // cout << "Parsing : [" << cmdLine << "]" << endl; static const wchar_t spaceChar = ( wchar_t )' '; args.clear(); cmdName = L""; if ( cmdLine.findFirst( spaceChar ) == -1 ) { cmdName = cmdLine; return true; } setQuoted( false ); setEscaped( false ); setNameDone( false ); bShouldAddLast = true; resetTmpString(); for ( s32 x = 0; x < cmdLine.size(); x++ ) { if ( !handleChar( cmdLine[x], cmdName, args ) ) { return false; } } if ( bShouldAddLast ) { shoveTmpString( cmdLine, args ); } return true; }
bool KernelMessages::generateRandom(int major, int minor) { bool generatedMessage = false; // Scan through the random messages array for (uint msgCtr = 0; msgCtr < _randomMessages.size(); msgCtr++) { // Find currently active random messages if (_randomMessages[msgCtr]._handle < 0) { // Check whether there's any existing 'scrolling in' message bool bad = false; for (uint scanCtr = 0; scanCtr < _randomMessages.size(); ++scanCtr) { if (_randomMessages[scanCtr]._handle >= 0) { if (_entries[_randomMessages[scanCtr]._handle]._flags & KMSG_SCROLL) { bad = true; break; } } } // Do a random check for a new message to appear if (_vm->getRandomNumber(major) <= minor && !bad) { int quoteId; // Pick a random quote to display from the available list do { int quoteIdx = _vm->getRandomNumber(_randomQuotes.size() - 1); quoteId = _randomQuotes[quoteIdx]; // Ensure the quote isn't already in use bad = false; for (uint scanCtr = 0; scanCtr < _randomMessages.size(); ++scanCtr) { if (quoteId == _randomMessages[scanCtr]._quoteId) { bad = true; break; } } } while (bad); // Store the quote Id to be used _randomMessages[msgCtr]._quoteId = quoteId; // Position the message at a random position Common::Point textPos; textPos.x = _vm->getRandomNumber(_randomMessages._bounds.left, _randomMessages._bounds.right); // Figure out Y position, making sure not to be overlapping with // any other on-screen message int abortCounter = 0; do { // Ensure we don't get stuck in an infinite loop if too many messages // are alrady on-screen if (abortCounter++ > 100) goto done; bad = false; // Set potential new Y position textPos.y = _vm->getRandomNumber(_randomMessages._bounds.top, _randomMessages._bounds.bottom); // Ensure it doesn't overlap an existing on-screen message for (uint msgCtr2 = 0; msgCtr2 < _randomMessages.size(); ++msgCtr2) { if (_randomMessages[msgCtr2]._handle >= 0) { int lastY = _entries[_randomMessages[msgCtr2]._handle]._position.y; if ((textPos.y >= (lastY - _randomMessages._randomSpacing)) && (textPos.y <= (lastY + _randomMessages._randomSpacing))) { bad = true; } } } } while (bad); // Add the message _randomMessages[msgCtr]._handle = add(textPos, _randomMessages._color, 0, RANDOM_MESSAGE_TRIGGER + msgCtr, _randomMessages._duration, _vm->_game->getQuote(_randomMessages[msgCtr]._quoteId)); if (_randomMessages._scrollRate > 0) { if (_randomMessages[msgCtr]._handle >= 0) { setQuoted(_randomMessages[msgCtr]._handle, _randomMessages._scrollRate, true); } } generatedMessage = true; break; } } } done: return generatedMessage; }