/* * Runs the machine and returns true or false if the machine accepts * the input. * * The token read is saved on token, so it expects that the size is * bigger enough to put the token. (this is not safe, and must be * refactored) */ bool fa_run(FiniteAutomata *m, char *token, BufferedInputStream *in) { state_t state = m->initial_state; int c, j = 0;; mark(in); while (true) { c = read(in); //printf("%c", c); switch (m->actions[state][c]) { case ERROR: //printf(" -> ERROR\n"); token[j++] = c; token[j] = '\0'; reverse1(token); while (j > 0) {/* pushback token consumed */ unread(token[--j], in); token[j] = '\0'; /* cleaning token */ } unmark(in); return false; case MOVEAPPEND: //printf(" -> MOVEAPPEND\n"); state = m->transitions[state][c]; token[j++] = c; break; case MOVENOAPPEND: //printf(" -> MOVENOAPPEND\n"); state = m->transitions[state][c]; break; case HALTAPPEND: //printf(" -> HALTAPPEND\n"); token[j++] = c; token[j] = '\0'; unmark(in); return true; case HALTNOAPPEND: //printf(" -> HALTNOAPPEND\n"); token[j] = '\0'; unmark(in); return true; case HALTREUSE: //printf(" -> HALTREUSE\n"); unread(c, in); token[j] = '\0'; unmark(in); return true; } } }
static boolean factor() { char ch; if(DEBUG) { printf("Looking for a <factor>\n"); } ch = readChar(); if(ch == '(') { if(expr()) { ch = readChar(); if(ch == ')') { return TRUE; } else { // if(ch == ')') printf("<expr> not followed by right parenthesis in <factor>\n"); return FALSE; } } else { // if(expr()) printf("Left parenthesis not followed by <expr> in <factor>\n"); return FALSE; } } else { // if(ch == '(') unread(ch); if(integer()) { return TRUE; } else { printf("<integer> not found in <factor>\n"); return FALSE; } } }
QVariant FeedItem::data(int role) const { switch(role) { case UidRole: return uid(); case TitleRole: return title(); case ContentRole: return content(); case LinkRole: return link(); case UrlRole: return url(); case IconRole: return icon(); case StreamIdRole: return streamId(); case UnreadRole: return unread(); case ReadRole: return read(); case ReadlaterRole: return readlater(); case FreshRole: return fresh(); default: return QVariant(); } }
bool parseSign() // leading whitespace and/or sign { s32 ch; while (true) { ch = read(); if (ch < 0) return die("No number found"); if (isspace(ch)) continue; if (ch == '+') { if (sign < 0) return die("Both - and + signs found"); if (sign > 0) return die("Duplicate + signs found"); sign = 1; continue; } if (ch == '-') { if (sign < 0) return die("Duplicate - signs found"); if (sign > 0) return die("Both + and - signs found"); sign = -1; continue; } // not ws, signs unread(); break; } return true; }
int readOneImpl() { int i; std::deque<unsigned char> cmp; for (i=0; i<m_nextMark.length(); ++i) { int c = qread(); if (c>=0) { cmp.push_front(c); if (c==m_nextMark[i]) { // MB_DPRINTLN("MM> %s", m_nextMark.substr(0, i).c_str()); continue; } } else { // EOF if (cmp.size()<=0) break; } unsigned char ret = cmp.back(); cmp.pop_back(); std::deque<unsigned char>::const_iterator iter = cmp.begin(); std::deque<unsigned char>::const_iterator iend = cmp.end(); for (; iter!=iend; ++iter) unread(*iter); return ret; } m_bReady = false; return -1; }
bool parseBase() // leading 0, 0b, 0x, or 1-9 { s32 val = digitVal(peek()); if (val < 0) { if (sign < 0) return die("No digits found after -"); if (sign > 0) return die("No digits found after +"); return die("No digits found"); } if (val >= 1 && val <= 9) { base = 10; return true; } if (val != 0) return die("No radix prefix (0, 0x, 0b, or 1-9) found"); read(); // discard the '0' s32 ch = read(); if (ch < 0 || ch == 'u') { // Whups, the whole number was 0 or 0u. We check for EOF // after the possible 'u', then return false here to // shortcircuit downstream, even though the conversion is a // success (and the default result is correct). if (read() >= 0) return die("Characters after 'u' in number"); return false; } if (ch == 'x') { base = 16; return true; } if (ch == 'b') { base = 2; return true; } unread(); // maybe we'll get hungry later // Only possibility left is awful octal. if (ch >= '0' && ch <= '7') { base = 8; return true; } // Not 0, 0u, 0x, 0b, or 1-9: FU return die("Illegal character in number"); }
void NotificationsModel::markAsRead() { if (_notifs.isEmpty() || !unread()) return; QString url = "v2/messenger/notifications/read.json"; QString data = QString("last_id=%1").arg(_notifs.first()->id()); auto request = new ApiRequest(url, ApiRequest::AccessTokenRequired | ApiRequest::ShowMessageOnError, QNetworkAccessManager::PostOperation, data); Q_TEST(connect(request, SIGNAL(success(QJsonArray)), this, SLOT(_readSuccess()))); }
void TelnetSocket::processIAC() { QByteArray data = read(bytesAvailable()); while (!data.isEmpty() && IAC == static_cast<uchar>(data[0])) { switch (static_cast<uchar>(data[1])) { case WILL: case WONT: case DO: case DONT: if (data.size() < 3) { unread(data); return; } else data.remove(0, 3); break; case SB: { int p = data.indexOf(QByteArray(subNegotiationEnd, sizeof(subNegotiationEnd))); if (p == -1) { unread(data); return; } else data.remove(0, p + 2); } break; default: break; } } unread(data); }
static boolean integer() { char ch; if(DEBUG) { printf("Looking for an <integer>\n"); } ch = readChar(); if((ch >= '0') && (ch <= '9')) { val = ch-'0'; while(TRUE) { ch = readChar(); if((ch < '0') || (ch > '9')) { unread(ch); return TRUE; } val = val*PLACE_VALUE + ch-'0'; } } else { unread(ch); return FALSE; } }
static boolean additive_op() { char ch; if(DEBUG) { printf("Looking for an <additive-op>\n"); } ch = readChar(); if(ch == '+') { op = OP_ADD; return TRUE; } else if (ch == '-') { op = OP_SUB; return TRUE; } else { unread(ch); return FALSE; } }
static boolean multiplicative_op() { char ch; if(DEBUG) { printf("Looking for a <multiplicative-op>\n"); } ch = readChar(); if(ch == '*') { op = OP_MUL; return TRUE; } else if (ch == '/') { op = OP_DIV; return TRUE; } else if (ch == '%') { op = OP_REM; return TRUE; } else { unread(ch); return FALSE; } }
s32 peek() { s32 ch = read(); if (ch >= 0) unread(); return ch; }