void Bdecoder::read(QByteArray *buf) { int end = m_buf.indexOf(':', m_pos); if (end <= m_pos || end >= m_len) { setError("buffer overrun"); return; } QByteArray s = m_buf.mid(m_pos, end - m_pos); m_pos = end + 1; if (!validateInt(s)) return; bool ok; int strlen = s.toUInt(&ok, 10); if (!ok) { setError("Invalid string length (%s)", s.constData()); return; } if (strlen + m_pos > m_len) { setError("buffer overrun"); return; } if (buf) *buf = m_buf.mid(m_pos, strlen); m_pos += strlen; }
void Bdecoder::read(qulonglong *value, bool &bSigned) { if (m_pos >= m_len || m_buf[m_pos] != 'i') { setError("expected integer, got %c", char(m_buf[m_pos])); return; } m_pos++; int end = m_buf.indexOf('e', m_pos); if (end <= m_pos || end >= m_len) { setError("buffer overrun"); return; } if (value) { QByteArray s = m_buf.mid(m_pos, end - m_pos); if (!validateInt(s)) return; bool ok; if(bSigned = (s.left(1) == "-")) *value = s.toLongLong(&ok, 10); else *value = s.toULongLong(&ok, 10); if (!ok) { setError("Invalid integer (%s)", s.constData()); return; } } m_pos = end + 1; }
static void ask2Int( int a1, int * n1, int b1, int a2, int * n2, int b2 ) { char c; static char error[MAX_ERR_LEN]; static char buffer[MAX_COM_LEN]; error[0] = 0; do{ clearScreen(); drawText( NULL ); drawPanel( error ); askCommand( buffer ); raiseErrorIf( errorCode() == NOERROR, errorCode(), ); error[0] = 0; if( ( c = sscanf( buffer, " %d %d %c", n1, n2, &c ) ) != 2 && buffer[0] != '\n' ) sprintf( error, "Format error:\nMust be two integers, " "space separated" ); }while( c != 2 || !validateInt( a1, *n1, b1+1, error ) || !validateInt( a2, *n2, b2+1, error ) ); }
static int askInt( int a, int b ) { int sol; char c; static char error[MAX_ERR_LEN]; static char buffer[MAX_COM_LEN]; error[0] = 0; do{ clearScreen(); drawText( NULL ); drawPanel( error ); askCommand( buffer ); raiseErrorIf( errorCode() == NOERROR, errorCode(), -1 ); error[0] = 0; if ( ( c = sscanf( buffer, " %d %c ", &sol, &c ) ) != 1 && buffer[0] != '\n' ) sprintf( error, "Format error:\nMust be an integer" ); }while( c != 1 || !validateInt( a, sol, b+1, error ) ); return sol; }
void ArgParse::validateValue(const ArgParse::ValueType type, const std::string name, const std::string choices, const std::string value) const { switch ( type ) { case INT : validateInt(name, choices, value); break; case FLOAT : validateFloat(name, choices, value); break; case BOOL : validateBool(name, choices, value); break; case STRING : validateString(name, choices, value); break; default: break; } }
void AddNew::processInput(string inputString) { // Holds the value entered by the user for this menu static int menuChoiceInt; static char menuChoiceChar; // Holds whether the entered value is valid static bool isValidInt; static bool isValidChar; isValidInt = validateInt(inputString, &menuChoiceInt); isValidChar = validateChar(inputString, &menuChoiceChar); if(isValidInt) { if(isOption(menuChoiceInt)) { // You need to find a way to associate values with menu selections // This more general than assuming the order that is setup in setActions() //process(); if(menuChoiceInt == 1) { //change(MenuSystem::ENTERDIR); kill(); } else if(menuChoiceInt == 2) { cout << "trying to switch to enter dir..." << endl; change(MenuSystem::ENTERDIR); //kill(); } else if(menuChoiceInt == 3) { //change(MenuSystem::REMOVEDIR); kill(); } else { process(); } } } else if(isValidChar) { if(Menu::isOption(menuChoiceChar)) { MenuSystem::MenuType menuType = getOption(menuChoiceChar)->getValue(); if(menuType == MenuSystem::EXIT) { kill(); } else if(menuType == MenuSystem::ADDREMOVE) { // Assuming there are no more menus for now change(MenuSystem::ADDREMOVE); } } else { printInvalidAndProcess(); } } else { printInvalidAndProcess(); } }