Пример #1
0
void Insert (Item X, int position, List *L) {
	ListNode *p, *q;
	assert(position >= 0);
	assert(position <= L->size);
	
	L->size++;
	q=(ListNode *)malloc(sizeof(ListNode));
	copyItem(&q->item,X);
			 
	if(position==0) {
		q->next=L->first;
		L->first=q;
	}
	else {
		p=moveTo(position-1,L);
		q->next=p->next;
		p->next=q;
	}
	assert(Empty(L) == 0);
	assert(Size(L) == L->size);
	Peek(position, L, &X);
	assert(strcmp(q->item.name, X.name) == 0);
	assert(q->item.grade == X.grade);
	
}
Пример #2
0
size_t BufferedTransformation::Peek(byte &outByte) const
{
	if (AttachedTransformation())
		return AttachedTransformation()->Peek(outByte);
	else
		return Peek(&outByte, 1);
}
Пример #3
0
nsresult nsScanner::ReadUntil(nsScannerSharedSubstring& aString,
                              const nsReadEndCondition& aEndCondition,
                              PRBool addTerminal)
{  
  if (!mSlidingBuffer) {
    return kEOF;
  }

  nsScannerIterator origin, current;
  const PRUnichar* setstart = aEndCondition.mChars;
  const PRUnichar* setcurrent;

  origin = mCurrentPosition;
  current = origin;

  PRUnichar         theChar=0;
  nsresult          result=Peek(theChar);

  if (NS_FAILED(result)) {
    return result;
  }
  
  while (current != mEndPosition) {
    theChar = *current;
    if (theChar == '\0') {
      ReplaceCharacter(current, sInvalid);
      theChar = sInvalid;
    }

    // Filter out completely wrong characters
    // Check if all bits are in the required area
    if(!(theChar & aEndCondition.mFilter)) {
      // They were. Do a thorough check.

      setcurrent = setstart;
      while (*setcurrent) {
        if (*setcurrent == theChar) {
          if(addTerminal)
            ++current;
          AppendUnicodeTo(origin, current, aString);
          SetPosition(current);

          //DoErrTest(aString);

          return NS_OK;
        }
        ++setcurrent;
      }
    }
    
    ++current;
  }

  // If we are here, we didn't find any terminator in the string and
  // current = mEndPosition
  SetPosition(current);
  AppendUnicodeTo(origin, current, aString);
  return FillBuffer();
}
Пример #4
0
/**
 *  Consume characters until you run into space, a '<', a '>', or a '/'.
 *  
 *  @param   aString - receives new data from stream
 *  @return  error code
 */
nsresult nsScanner::ReadTagIdentifier(nsScannerSharedSubstring& aString) {

  if (!mSlidingBuffer) {
    return kEOF;
  }

  PRUnichar         theChar=0;
  nsresult          result=Peek(theChar);
  nsScannerIterator current, end;
  PRBool            found=PR_FALSE;  
  
  current = mCurrentPosition;
  end = mEndPosition;

  // Loop until we find an illegal character. Everything is then appended
  // later.
  while(current != end && !found) {
    theChar=*current;

    switch(theChar) {
      case '\n':
      case '\r':
      case ' ' :
      case '\t':
      case '\v':
      case '\f':
      case '<':
      case '>':
      case '/':
        found = PR_TRUE;
        break;

      case '\0':
        ReplaceCharacter(current, sInvalid);
        break;

      default:
        break;
    }

    if (!found) {
      ++current;
    }
  }

  // Don't bother appending nothing.
  if (current != mCurrentPosition) {
    AppendUnicodeTo(mCurrentPosition, current, aString);
  }

  SetPosition(current);  
  if (current == end) {
    result = FillBuffer();
  }

  //DoErrTest(aString);

  return result;
}
Пример #5
0
int BuildSignatureDatabaseSearchMachine(signature_db* SignatureDatabase)
{
  if (!SignatureDatabase)
    return -1;

  if (!SignatureDatabase->Trie && BuildSignatureDatabaseTrie(SignatureDatabase) != 0)
    return -1;

  InitializeSearchMachine(SignatureDatabase->SearchMachine, SignatureDatabase->Trie);

  search_machine* SM = SignatureDatabase->SearchMachine;

  // Phase 2
  queue* Queue = xcalloc(1, sizeof(queue));
  InitializeQueue(Queue);

  for (size_t AlphabetIndex = 0; AlphabetIndex < UNIT_CARDINALITY; ++AlphabetIndex)
  {
    trie* Node = SM->Goto[ROOT_IDENTIFIER][AlphabetIndex];
    //if (Node && Node->Identifier != ROOT_IDENTIFIER)
    if (!Node || Node->Identifier != ROOT_IDENTIFIER)
    {
      SM->Fail[Node->Identifier] = SM->Trie;
      Enqueue(Queue, Node);
    }
  }

  while (Peek(Queue) != NULL)
  {
    trie* R = Dequeue(Queue);

    for (size_t AlphabetIndex = 0; AlphabetIndex < UNIT_CARDINALITY; ++AlphabetIndex)
    {
      trie* S = SM->Goto[R->Identifier][AlphabetIndex];

      // Not 100% about this
      if (S)
      {
        Enqueue(Queue, S);
        trie* ST = SM->Fail[R->Identifier];

        // Not 100% about this
        while (!SM->Goto[ST->Identifier][AlphabetIndex])
        {
          ST = SM->Fail[ST->Identifier];
        }

        SM->Fail[S->Identifier] = SM->Goto[ST->Identifier][AlphabetIndex];

        // out(u) = out(u) UNION out(fail(u))
        SM->Out[S->Identifier] = UniqExtendList(SM->Out[S->Identifier], SM->Out[SM->Fail[S->Identifier]->Identifier]);
      }
    }
  }

  FreeQueue(Queue);
  Queue = NULL;
  return 0;
}
Пример #6
0
/**
 * Scan an AtKeyword token.  Also handles production of Symbol when
 * an '@' is not followed by an identifier.
 */
bool
nsCSSScanner::ScanAtKeyword(nsCSSToken& aToken)
{
  MOZ_ASSERT(Peek() == '@', "should not have been called");

  // Fall back for when '@' isn't followed by an identifier.
  aToken.mSymbol = '@';
  Advance();

  int32_t ch = Peek();
  if (StartsIdent(ch, Peek(1))) {
    if (GatherText(IS_IDCHAR, aToken.mIdent)) {
       aToken.mType = eCSSToken_AtKeyword;
     }
  }
  return true;
}
Пример #7
0
static void showListContent (List *L) {
	int i;
	Student S;
	for(i=0;i<Size(L);i++) {
		Peek(i,L,&S);
		printf("\t%s %d%%\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
	}
}
Пример #8
0
// <bool_term>       ::= <bool_not_factor> [<and_op> <bool_not_factor]*
void Term(CPU *cpu, Files file){
    NotFactor(cpu, file);
    while(Peek("&&", file)){
        Match("&&", file);
        NotFactor(cpu, file);
        cpu->PopValue();
        cpu->BooleanAnd();
    }
}
Пример #9
0
// <bool_expression> ::= <bool_term> [<or_op> <bool_term]*
void Expression(CPU *cpu, Files file){
    Term(cpu, file);
    while(Peek("||", file)){
        Match("||", file);
        Term(cpu, file);
        cpu->PopValue();
        cpu->BooleanOr();
    }
}
Пример #10
0
const Token *TokenStream::PeekIf(const TokenTypeSet &typeSet) const
{
	const Token *token = Peek();
	if (typeSet.Contains(token->GetTokenType()))
	{
		return token;
	}
	return nullptr;
}
Пример #11
0
const Token *TokenStream::PeekIf(Token::TokenType type) const
{
	const Token *token = Peek();
	if (token->GetTokenType() == type)
	{
		return token;
	}
	return nullptr;
}
bool Tokenizer::CondRead(SYMBOL kind) {
  const Token* T = Peek();
  if (T->kind() == kind) {
    Get( );
    return true;
  } else {
    return false;
  }
}
double basisfield::PeekWide(int i, int j, int k, FieldIndex fi)
{
  if (!(i<0 || j<0 || k<0 || static_cast<unsigned int>(i)>=FieldSz_x() || static_cast<unsigned int>(j)>=FieldSz_y() || static_cast<unsigned int>(k)>=FieldSz_z())) {  // Inside "valid" FOV
    return(Peek(static_cast<unsigned int>(i),static_cast<unsigned int>(j),static_cast<unsigned int>(k),fi));
  }
  else {
    return(peek_outside_fov(i,j,k,fi));
  }
}
Пример #14
0
	bool Compare(BufferedLineReader &other) {
		if (Peek(0) != other.Peek(0)) {
			return false;
		}

		Skip(1);
		other.Skip(1);
		return true;
	}
Пример #15
0
int LuaBinding::ActorPhysicsSetVelocity()
{
    int actorId = 0;
    Vector2f velocity;
    if (!Peek(1, &actorId) || !Peek(2, &velocity))
    {
        return ERROR_TYPE_PARAMETER;
    }

    const boost::shared_ptr<ActorPropertyPhysics> property = LuaBinding::GetActorProperty<ActorPropertyPhysics>(actorId);
    if (!property)
    {
        return ERROR_TYPE_STATE;
    }

    property->SetVelocity(velocity);
    return 0;
}
Пример #16
0
int LuaBinding::ActorSetPosition()
{
    int actorId = 0;
    Vector2i position;
    if (!Peek(1, &actorId) || !Peek(2, &position))
    {
        return ERROR_TYPE_PARAMETER;
    }

    const boost::shared_ptr<Actor> actor = GetActor(actorId);
    if (!actor)
    {
        return ERROR_TYPE_STATE;
    }

    actor->SetPosition(position);
    return 0;
}
Пример #17
0
int LuaBinding::ActorSetLayer()
{
    int actorId = 0;
    int actorLayer = ACTOR_LAYER_COUNT;
    if (!Peek(1, &actorId) || !Peek(2, &actorLayer) || actorLayer >= ACTOR_LAYER_COUNT)
    {
        return ERROR_TYPE_PARAMETER;
    }

    const boost::shared_ptr<Actor> actor = GetActor(actorId);
    if (!actor)
    {
        return ERROR_TYPE_STATE;
    }

    actor->SetLayer(static_cast<ActorLayer>(actorLayer));
    return 0;
}
Пример #18
0
int LuaBinding::ActorIsShapeEnabled()
{
    int actorId = 0;
    int actorShapeType = ACTOR_SHAPE_TYPE_COUNT;
    if (!Peek(1, &actorId) || !Peek(2, &actorShapeType) || actorShapeType >= ACTOR_SHAPE_TYPE_COUNT)
    {
        return ERROR_TYPE_PARAMETER;
    }

    const boost::shared_ptr<Actor> actor = GetActor(actorId);
    if (!actor)
    {
        return ERROR_TYPE_STATE;
    }

    Push(actor->IsShapeEnabled(static_cast<ActorShapeType>(actorShapeType)));
    return 1;
}
Пример #19
0
int LuaBinding::ActorHasProperty()
{
    int actorId = 0;
    int actorPropertyType = ACTOR_PROPERTY_TYPE_COUNT;
    if (!Peek(1, &actorId) || !Peek(2, &actorPropertyType) || actorPropertyType >= ACTOR_PROPERTY_TYPE_COUNT)
    {
        return ERROR_TYPE_PARAMETER;
    }

    const boost::shared_ptr<Actor> actor = GetActor(actorId);
    if (!actor)
    {
        return ERROR_TYPE_STATE;
    }

    Push(actor->HasProperty(static_cast<ActorPropertyType>(actorPropertyType)));
    return 1;
}
Пример #20
0
void Parser::assignments(MethodGenerationContext* mgenc, list<StdString>& l) {
    if (symIsIdentifier()) {
        l.push_back(assignment(mgenc));
        Peek();
        
        if (nextSym == Assign)
            assignments(mgenc, l);
    }
}
Пример #21
0
/*****************************************************************************
 * GetLine: Internal function used to dup a line of string from the buffer
 *****************************************************************************/
static char* GetLine( demux_t *p_demux, int *p_pos )
{
    demux_sys_t *p_sys = p_demux->p_sys;
    const uint8_t *p_buf;
    int         i_size;
    int         i;
    char        *p_line;

    while( *p_pos >= p_sys->i_data_peeked )
    {
        if( ! Peek( p_demux, false ) )
        {
            return NULL;
        }
    }
    p_buf = p_sys->p_peek + *p_pos;
    i_size = p_sys->i_data_peeked - *p_pos;
    i = 0;
    while( p_buf[i] != '\n' )
    {
        i++;
        if( i == i_size )
        {
            if( ! Peek( p_demux, false ) )
            {
                return NULL;
            }
            p_buf = p_sys->p_peek + *p_pos;
            i_size = p_sys->i_data_peeked - *p_pos;
        }
    }
    *p_pos += ( i + 1 );
    if( i > 0 && '\r' == p_buf[i - 1] )
    {
        i--;
    }
    p_line = malloc( i + 1 );
    if( p_line == NULL )
        return NULL;
    strncpy ( p_line, (char*)p_buf, i );
    p_line[i] = '\0';
//    msg_Dbg( p_demux, "i = %d, pos = %d, %s", i, *p_pos, p_line );
    return p_line;
}
Пример #22
0
ExecutionLexer::Token ExecutionLexer::PullSql()
{
  int start = pos;

  do {
    int c = Take();

    if (c < 0) {
      return Token(Token::SQL, start, pos - start);
    }

    // note that dollar-quoting takes priority over *everything* (except end of input of course)

    if (c == '$')
      PassDollarQuote();
    else if (quoteStack.empty()) {
      if (c == '\'')
        PassSingleQuotedString(false); // FIXME handle E'...' flag for escape syntax
      else if (c == '\"')
      PassDoubleQuotedString();
      else if (c == ';') {
        // inclusive end character
        int end = ++pos;
        PassWhitespace();
        return Token(Token::SQL, start, end - start);
      }
      else if (c == '-') {
        if (Peek() == '-') {
          PassSingleLineComment();
        }
      }
      else if (c == '/') {
        if (Peek() == '*') {
          PassBlockComment();
        }
      }
      else if (c == '\\') {
        // exclusive end character
        BackUp();
        return Token(Token::SQL, start, pos - start);
      }
    }
  } while (true);
}
Пример #23
0
void ParseScopedName()
{
  if(Token==TOK_SCOPE && (Peek()==TOK_NAME || Peek()==TOK_TYPE))
  {
    Match();
    Match();
  }
  else if(Token==TOK_NAME || Token==TOK_TYPE)
    Match();

  while(Token==TOK_SCOPE)
  {
    Match();
    if(Token==TOK_NAME || Token==TOK_TYPE)
      Match();
    else
      Error("scoped name error");
  }
}
Пример #24
0
int LuaBinding::ActorSetShape()
{
    int actorId = 0;
    int actorShapeType = ACTOR_SHAPE_TYPE_COUNT;
    ActorShape actorShape;
    if (!Peek(1, &actorId) || !Peek(2, &actorShapeType) || !Peek(3, &actorShape) || actorShapeType >= ACTOR_SHAPE_TYPE_COUNT)
    {
        return ERROR_TYPE_PARAMETER;
    }

    const boost::shared_ptr<Actor> actor = GetActor(actorId);
    if (!actor)
    {
        return ERROR_TYPE_STATE;
    }

    actor->SetShape(static_cast<ActorShapeType>(actorShapeType), actorShape);
    return 1;
}
Пример #25
0
bool BufferedTransformation::AnyRetrievable() const
{
	if (AttachedTransformation())
		return AttachedTransformation()->AnyRetrievable();
	else
	{
		byte b;
		return Peek(b) != 0;
	}
}
Пример #26
0
/*
 * Function    TakeOff
 *
 * Takes the instantiated drone struct and adds it to the takeoff_queue.
 * After that it waits to take off and updates the state to inflight.
 *
 * Drone *d: current drone struct.

 */
void TakeOff(Drone *d) {
  Enqueue(d->q, d);
  set_drone_state(d, TAKEOFF_QUEUE);
  Drone *e = Peek(d->q);
  while (strcmp(d->drone_id, e->drone_id) != 0) {
    printf("%s: %s \n", d->drone_id, get_drone_state(d));
    e = Peek(d->q);
    sleep(QUEUE_SLEEP);
  }
  set_drone_state(d, TAKING_OFF);
  int i = TAKEOFF_TIME;
  while(i > 0) {
    printf("%s: %s - %d \n", d->drone_id, get_drone_state(d), i);
    i--;
    sleep(1);
  }
  Dequeue(d->q);
  set_drone_state(d, IN_FLIGHT);
}
bool GenericXMLParser::ParseTag(String &tag, Anything &tagAttributes)
{
	StartTrace(GenericXMLParser.ParseTag);
	tag = ParseName();
	Trace("tag = " << tag);
	while (!IsEof()) {
		SkipWhitespace();
		int c = Peek();
		switch (c) {
			case '>': // done with tag
				c = Get();
				return true;//lint !e438
			case '/': // an empty tag? i.e. <br />
				c = Get();
				if ('>' == Peek()) {
					c = Get();
					return false;//lint !e438
				}
				// an error occured, ignore '/' silently
				PutBack(c);
			default: {//lint !e616
				String name;
				String value;
				if (ParseAttribute(name, value)) {
					tagAttributes[name] = value;
				} else {
					// non-well formed XML...no value given
					if (name.Length() > 0) {
						tagAttributes.Append(name);
					} else {
						String msg("Unexpected character <");
						c = Get();
						msg.AppendAsHex((unsigned char)c).Append("> near ").Append(tag);
						Error(msg);
						tagAttributes.Append(String(char(c)));
					}
				}
			}
		}
	}
	Error("unexpected EOF in Tag");
	return false; // no body to expect
}
Пример #28
0
void _READ_STRING(unsigned char* &MEM) {
	aint DLUG=0;
	astr DAT_S="";

	DLUG=Peek(MEM); MEM++;															//	   DLUG=Peek(MEM) : Inc MEM
	DAT_S=Peek_S(MEM,DLUG);															//	   DAT$=Peek$(MEM,DLUG)
	MEM+=DLUG;																					//	   Add MEM,DLUG
																											//	   Return
	Param_S=DAT_S;																			//
}
Пример #29
0
bool CAccountConnector::__AnalyzeVarSizePacket(UINT uHeader, bool (CAccountConnector::*pfnDispatchPacket)(int))
{
	BYTE bHeader;
	if (!Peek(sizeof(bHeader), &bHeader))
		return true;

	if (bHeader!=uHeader)
		return true;

	TDynamicSizePacketHeader dynamicHeader;

	if (!Peek(sizeof(dynamicHeader), &dynamicHeader))
		return true;

	if (!Peek(dynamicHeader.size))
		return true;

	return (this->*pfnDispatchPacket)(dynamicHeader.size);
}
Пример #30
0
/*****************************************************************************
 * GetLine: Internal function used to dup a line of string from the buffer
 *****************************************************************************/
static char* GetLine( demux_t *p_demux, int *p_pos )
{
    demux_sys_t *p_sys = p_demux->p_sys;
    const uint8_t *p_buf;
    int         i_size;
    int         i;
    char        *p_line;

    while( *p_pos >= p_sys->i_data_peeked )
    {
        if( ! Peek( p_demux, false ) )
        {
            return NULL;
        }
    }
    p_buf = p_sys->p_peek + *p_pos;
    i_size = p_sys->i_data_peeked - *p_pos;
    i = 0;
    while( p_buf[i] != '\n' )
    {
        i++;
        if( i == i_size )
        {
            if( ! Peek( p_demux, false ) )
            {
                return NULL;
            }
            p_buf = p_sys->p_peek + *p_pos;
            i_size = p_sys->i_data_peeked - *p_pos;
        }
    }
    *p_pos += i + 1;
    if( i > 0 && p_buf[i - 1] == '\r' )
    {
        i--;
    }
    p_line = (char *)malloc( i + 1 );			// sunqueen modify
    if( unlikely( p_line == NULL ) )
        return NULL;
    strncpy ( p_line, (char*)p_buf, i );
    p_line[i] = '\0';
    return p_line;
}