예제 #1
0
bool RequestQueue::PeekNextPiece(bt_index_t *pidx, bt_offset_t *poff,
  bt_length_t *plen) const
{
  const PIECE *piece;

  if( !m_peek ) return PeekNext(pidx, poff, plen);

  if( !(piece = FindPiece(m_peek->index)) ) return false;
  piece = piece->next;
  m_peek = piece ? piece->slices : (SLICE *)0;
  if( m_peek ){
    if( pidx ) *pidx = m_peek->index;
    if( poff ) *poff = m_peek->offset;
    if( plen ) *plen = m_peek->length;
  }
  return m_peek ? true : false;
}
예제 #2
0
int UDFParser::GetTok() {
  // Skip any whitespace.
  while (isspace(last_char_)) {
    last_char_ = GetNextChar();
  }

  if (isalpha(last_char_)) {  // identifier: [a-zA-Z][a-zA-Z0-9]*
    identifier_str_ = last_char_;

    while (isalnum((last_char_ = GetNextChar()))) {
      identifier_str_ += last_char_;
    }

    if (identifier_str_ == "BEGIN" || identifier_str_ == "begin") {
      return tok_begin;
    } else if (identifier_str_ == "IF" || identifier_str_ == "if") {
      return tok_if;
    } else if (identifier_str_ == "THEN" || identifier_str_ == "then") {
      return tok_then;
    } else if (identifier_str_ == "ELSE" || identifier_str_ == "else") {
      return tok_else;
    } else if (identifier_str_ == "END" || identifier_str_ == "end") {
      return tok_end;
    } else if (identifier_str_ == "RETURN" || identifier_str_ == "return") {
      return tok_return;
    }
    return tok_identifier;
  }

  /*
  TODO(PP): Do better error-handling for digits
  */
  if (isdigit(last_char_) || last_char_ == '.') {  // Number: [0-9.]+
    std::string num_str;
    do {
      num_str += last_char_;
      last_char_ = GetNextChar();
    } while (isdigit(last_char_) || last_char_ == '.');

    num_val_ = strtod(num_str.c_str(), nullptr);
    return tok_number;
  }

  // Semicolon
  if (last_char_ == ';') {
    last_char_ = GetNextChar();
    return tok_semicolon;
  }

  if (last_char_ == ',') {
    last_char_ = GetNextChar();
    return tok_comma;
  }

  // Handles single line comments
  // (May not enter, since everything is flattened into one line)
  if (last_char_ == '-') {
    int nextChar = PeekNext();
    if (nextChar == '-') {
      last_char_ = GetNextChar();
      // Comment until end of line.
      do {
        last_char_ = GetNextChar();
      } while (last_char_ != EOF && last_char_ != '\n' && last_char_ != '\r');

      if (last_char_ != EOF) {
        return GetTok();
      }
    }
  }

  // Check for end of file.  Don't eat the EOF.
  if (last_char_ == EOF) {
    return tok_eof;
  }

  // Otherwise, just return the character as its ascii value.
  int this_char = last_char_;
  last_char_ = GetNextChar();
  return this_char;
}