Exemplo n.º 1
0
//------------------------------------------------------------------------------
// Parse a NEXUS-style comment
bool Tokeniser::ParseComment ()
{
	bool echo = false;
	comment = "";

	curChar = GetNextChar ();
	echo = (curChar == '!');
	if (echo)
		curChar =  GetNextChar ();

	while ((curChar != '\0') && (curChar != ']'))
	{
		comment += curChar;
		curChar = GetNextChar();
	}

	if (echo)
#if defined __BORLANDC__ && (__BORLANDC__ < 0x0550)
		cout << comment;
#else
		std::cout << comment;
#endif

	return true;
}
void CToken::GetTTString()
{
	int nsLen;

	m_eNextTokenType = ttString;
	m_sNextTokenType = "String";

	nsLen = m_sNextToken.GetLength();
	m_sNextToken.Insert(nsLen, m_cNextChar);

	GetNextChar();
	char cPrevChar='x';
	bool bHasRemnString;
	do
	{
		bHasRemnString = false;

		while(m_cNextChar != '\"')
		{
			nsLen = m_sNextToken.GetLength();
			m_sNextToken.Insert(nsLen, m_cNextChar);
			cPrevChar = m_cNextChar;
			GetNextChar();
		}

		nsLen = m_sNextToken.GetLength();
		m_sNextToken.Insert(nsLen, m_cNextChar);

		if(cPrevChar == '\\')
			bHasRemnString = true;

		GetNextChar();
	}while(bHasRemnString == true);
}
Exemplo n.º 3
0
struct Node_t * T(void)
{
  struct Node_t * ret_node;

  if (last == '(')
  {
    last = GetNextChar();
    ret_node = E();
    last = GetNextChar(); /* preskocit ')' */
    return ret_node;
  }
  free_node->oper = last;
  last = GetNextChar(); /* preskocit terminator */
  return free_node++;
}
Exemplo n.º 4
0
// Parse a string argument.  ASN1 strings can include nulls as valid characters.
void MHParseBinary::ParseString(int endStr, MHOctetString &str)
{
    // TODO: Don't deal with indefinite length at the moment.
    if (endStr == INDEFINITE_LENGTH)
    {
        MHERROR("Indefinite length strings are not implemented");
    }

    int nLength = endStr - m_p;
    unsigned char *stringValue = (unsigned char *)malloc(nLength + 1);
    if (stringValue == NULL)
    {
        MHERROR("Out of memory");
    }

    unsigned char *p = stringValue;

    while (m_p < endStr)
    {
        *p++ = GetNextChar();
    }

    str.Copy(MHOctetString((const char *)stringValue, nLength));
    free(stringValue);
}
Exemplo n.º 5
0
/*----------------------------------------------------------------------------------------------------------------------
|	Reads rest of parenthetical token (starting '(' already input) up to and including the matching ')' character.  All
|	nested parenthetical phrases will be included.
*/
void NxsToken::GetParentheticalToken()
	{
	// Set level to 1 initially.  Every ')' encountered reduces
	// level by one, so that we know we can stop when level becomes 0.
	//
	int level = 1;

	char ch;
	for(;;)
		{
		ch = GetNextChar();
		if (atEOF)
			break;

		if (ch == ')')
			level--;
		else if (ch == '(')
			level++;

		AppendToToken(ch);

		if (level == 0)
			break;
		}
	}
Exemplo n.º 6
0
/*----------------------------------------------------------------------------------------------------------------------
|	Gets remainder of a quoted NEXUS word (the first single quote character was read in already by GetNextToken). This
|	function reads characters until the next single quote is encountered. An exception occurs if two single quotes occur
|	one after the other, in which case the function continues to gather characters until an isolated single quote is
|	found. The tandem quotes are stored as a single quote character in the token NxsString.
*/
void NxsToken::GetQuoted()
	{
	char ch;

	for(;;)
		{
		ch = GetNextChar();
		if (atEOF)
			break;

		if (ch == '\'' && saved == '\'')
			{
			// Paired single quotes, save as one single quote
			//
			AppendToToken(ch);
			saved = '\0';
			}
		else if (ch == '\'' && saved == '\0')
			{
			// Save the single quote to see if it is followed by another
			//
			saved = '\'';
			}
		else if (saved == '\'')
			{
			// Previously read character was single quote but this is something else, save current character so that it will
			// be the first character in the next token read
			//
			saved = ch;
			break;
			}
		else
			AppendToToken(ch);
		}
	}
Exemplo n.º 7
0
// Parse an integer argument.  Also used for bool and enum.
int MHParseBinary::ParseInt(int endInt)
{
    int intVal = 0;
    bool firstByte = true;

    if (endInt == INDEFINITE_LENGTH)
    {
        MHERROR("Indefinite length integers are not implemented");
    }

    while (m_p < endInt)
    {
        unsigned char ch = GetNextChar();

        // Integer values are signed so if the top bit is set in the first byte
        // we need to set the sign bit.
        if (firstByte && ch >= 128)
        {
            intVal = -1;
        }

        firstByte = false;
        intVal = (intVal << 8) | ch;
    }

    return intVal;
}
Exemplo n.º 8
0
void MainObject::ProcessCommands()
{
  char c;
  Q3SocketDevice *udp_command=new Q3SocketDevice(Q3SocketDevice::Datagram);
  char rml[RD_RML_MAX_LENGTH];
  unsigned ptr=0;
  bool active=false;

  while(!GetNextChar(&c)) {
    if(active) {
      if(c=='!') {
	rml[ptr++]=c;
	rml[ptr]=0;
	udp_command->writeBlock(rml,ptr,*dest_addr,dest_port);
	ptr=0;
	active=false;
      }
      else {
	rml[ptr++]=c;
      }
      if(ptr==RD_RML_MAX_LENGTH) {
	fprintf(stderr,"rmlsend: rml command too long\n");
	CloseStream();
	exit(256);
      }
    }
    else {
      if(isalpha(c)) {
	rml[ptr++]=c;
	active=true;
      }
    }
  }
}
Exemplo n.º 9
0
static int IsNextMoveValid(GAME_STATE *ptr, G_GHOST *pGhost)
{
char c;

	c = GetNextChar(ptr, pGhost);
	return Pac_IsOpenArea(c);
}
Exemplo n.º 10
0
extern char *GetNextString( read_file *ch_info ) {

    char                *buffer;
    int                 x = 0;
    int                 current_max = BUFF_INC;
    int                 ch;

    buffer = malloc( BUFF_INC );

    do {
        if ( x >= current_max ) {
            current_max += BUFF_INC;
            buffer = realloc( buffer, current_max );
            if ( !buffer ) {
                puts("Out of memory");
                close( ch_info->file_handle );
                abort();
            }
        }
        ch = GetNextChar( ch_info );
        if ( ch == -1 ) {
            puts("File read error occured");
            close( ch_info->file_handle );
            free( buffer );
            abort();
        }
        buffer[ x ] = ch;
        x++;
    } while ( ch );
    return( buffer );
}
Exemplo n.º 11
0
// write the file (or pipe) to another file
static void _near ListSaveFile( void )
{
	int i, nFH, nMode;
	long lTemp;
	POPWINDOWPTR wn;
	TCHAR szBuffer[ MAXLISTLINE+1 ];
	
	// disable ^C / ^BREAK handling
	HoldSignals();
	
	wn = wOpen( 2, 1, 4, GetScrCols() - 2, nInverse, LIST_SAVE_TITLE, NULL );
	wn->nAttrib = nNormal;
	wClear();
	wWriteListStr( 0, 1, wn, LIST_QUERY_SAVE );
	egets( szBuffer, MAXFILENAME, EDIT_DATA | EDIT_BIOS_KEY );
	
	if ( szBuffer[0] ) {
		
		// save start position
		lTemp = LFile.lViewPtr;
		
		nMode = _O_BINARY;
		
		if (( nFH = _sopen( szBuffer, ( nMode | _O_WRONLY | _O_CREAT | _O_TRUNC ), _SH_DENYNO, _S_IWRITE | _S_IREAD )) >= 0 ) {
			
			// reset to beginning of file

				ListSetCurrent( 0L );
			
			do {
				
				for ( i = 0; ( i < MAXLISTLINE ); i++ ) {
					
					// don't call GetNextChar unless absolutely necessary
					if ( LFile.lpCurrent == LFile.lpEOF )
						break;

					szBuffer[i] = (TCHAR)GetNextChar();
				}

				szBuffer[i] = _TEXT('\0');
				
			} while (( i > 0 ) && ( wwrite( nFH, szBuffer, i ) > 0 ));
			
			_close( nFH );
			
			// restore start position
			LFile.lViewPtr = lTemp;
			ListSetCurrent( LFile.lViewPtr );
			
		} else
			honk();
	}
	
	wRemove( wn );
	
	// enable ^C / ^BREAK handling
	EnableSignals();
}
Exemplo n.º 12
0
/* ¶ÁÈ¡×Ö·û´® */  
bool JsonString::ReadString()  
{  
	char c = 0;  
	while(current_ != end_)  
	{  
		c= GetNextChar();  
		if( c == '\\')  
		{  
			c = GetNextChar();  
		}  
		else if( c == '"')  
		{  
			break;  
		}  
	}  
	return (c == '"');  
}  
Exemplo n.º 13
0
int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) {
  int offset = 0;
  int width = 0;
  while (offset < size) {
    uint32_t charcode = GetNextChar(pString, size, offset);
    width += GetCharWidthF(charcode);
  }
  return width;
}
Exemplo n.º 14
0
void CCSVParser::ParseToOpenQuote (void)

//	ParseToOpenQuote
//
//	Reads characters until we find an open quote.

	{
	while (GetCurChar() != '\"')
		GetNextChar();
	}
void CToken::Skip2EndOfLine()
{
	while(m_cNextChar != cEndOfLine && m_cNextChar != cEndOfFile) //10 = end of line
	{
		//s.Format("%c",m_cNextChar);
		//MessageBox(s);

		GetNextChar();
	}	
}
void CToken::GetTTComments()
{
	int nsLen;

	if(m_cNextChar == '/')
	{
		m_eNextTokenType = ttCPPComments;
		m_sNextTokenType = "CPP's Comments";				

		while(m_cNextChar != 10) // end of line
		{
			nsLen = m_sNextToken.GetLength();
			m_sNextToken.Insert(nsLen, m_cNextChar);
			GetNextChar();
		}				
	}
	else if(m_cNextChar == '*')
	{
		char cPrevChar='x';
		m_eNextTokenType = ttCComments;
		m_sNextTokenType = "C's Comments";				

		//store '*'
		nsLen = m_sNextToken.GetLength();
		m_sNextToken.Insert(nsLen, m_cNextChar);

		GetNextChar();
		while(cPrevChar != '*' && m_cNextChar != '/')
		{
			nsLen = m_sNextToken.GetLength();
			m_sNextToken.Insert(nsLen, m_cNextChar);

			cPrevChar = m_cNextChar;
			GetNextChar();
		}
		// store last '/'
		nsLen = m_sNextToken.GetLength();
		m_sNextToken.Insert(nsLen, m_cNextChar);

		GetNextChar();
	}
}
Exemplo n.º 17
0
extern unsigned long GetNextLong( read_file *ch_info ) {

    char                buffer[4];
    unsigned long       *sptr;
    int                 ch;

    ch = GetNextChar( ch_info );
    if ( ch == -1 ) {
        puts("File read error occured");
        close( ch_info->file_handle );
        abort();
    }
    buffer[0] = ch;
    ch = GetNextChar( ch_info );
    if ( ch == -1 ) {
        puts("File read error occured");
        close( ch_info->file_handle );
        abort();
    }
    buffer[1] = ch;
    ch = GetNextChar( ch_info );
    if ( ch == -1 ) {
        puts("File read error occured");
        close( ch_info->file_handle );
        abort();
    }
    buffer[2] = ch;
    ch = GetNextChar( ch_info );
    if ( ch == -1 ) {
        puts("File read error occured");
        close( ch_info->file_handle );
        abort();
    }
    buffer[3] = ch;

    sptr = (unsigned long *)buffer;
    return( *sptr );
}
void CToken::GetTTNumber()
{
	int nsLen;

	m_eNextTokenType = ttNumber;
	m_sNextTokenType = "Number";

	while(m_cNextChar >= '0' && m_cNextChar <= '9')
	{
		nsLen = m_sNextToken.GetLength();
		m_sNextToken.Insert(nsLen, m_cNextChar);
		GetNextChar();
	}			
}
Exemplo n.º 19
0
/**
 * Find next non-white space character.
 */
static TCHAR
FindNonWhiteSpace(XML::Parser *pXML)
{
  assert(pXML);

    // Iterate through characters in the string until we find a NULL or a
  // non-white space character
  TCHAR ch;
  while ((ch = GetNextChar(pXML)) != 0) {
    if (!IsWhitespaceOrNull(ch))
      return ch;
  }
  return 0;
}
void CToken::GetTTNames()
{
	int nsLen;	

	m_eNextTokenType = ttNames;
	m_sNextTokenType = "variable/constant/class etc";

	while(m_cNextChar >= 'A' && m_cNextChar <= 'Z'
	   || m_cNextChar >= 'a' && m_cNextChar <= 'z'
	   || m_cNextChar == '_'
	   || m_cNextChar >= '0' && m_cNextChar <= '9')
	{
		nsLen = m_sNextToken.GetLength();
		m_sNextToken.Insert(nsLen, m_cNextChar);
		GetNextChar();
	}
	while(m_cNextChar == ' ')
		GetNextChar();
	if(m_cNextChar == '(')
	{
		m_eNextTokenType = ttFunction;
		m_sNextTokenType = "Function Name";
	}
}
Exemplo n.º 21
0
struct Node_t * Fc(struct Node_t * left)
{
  struct Node_t * node;

  if ((last == '*') || (last == '/'))
  {
    node = free_node++;
    node->oper = last;
    last = GetNextChar();
    node->left = left;
    node->right = T();
    return Fc(node);
  }
  return left;
}
void RedBufferInput::SkipWhitespace(void)
{
    RedChar cChar;

    // look ahead to the next character
    cChar = PreviewNextChar();
    while (cChar.IsWhiteSpace())
    {
        // if the next character is a whitespace, read it (and throw it away).
        cChar = GetNextChar();
        
        // preview the next character for the next while evaluation
        cChar = PreviewNextChar();
    }
}
Exemplo n.º 23
0
static int tryBackSlashNewLine( void )
{
    int nc;

    // CurrChar is '\\' and SrcFile->column is up to date
    Blank1Count = 0;
    Blank2Count = 0;
    Tab1Count = 0;
    nc = getTestCharFromFile();
    if( CompFlags.extensions_enabled ) {
        while( nc == ' ' ) {
            ++Blank1Count;
            nc = getTestCharFromFile();
        }
        while( nc == '\t' ) {
            ++Tab1Count;
            nc = getTestCharFromFile();
        }
        while( nc == ' ' ) {
            ++Blank2Count;
            nc = getTestCharFromFile();
        }
    }
    if( nc == '\r' ) {
        nc = getTestCharFromFile();
    }
    if( nc == '\n' ) {
        if( CompFlags.scanning_cpp_comment && NestLevel == SkipLevel ) {
            CWarn1( WARN_SPLICE_IN_CPP_COMMENT, ERR_SPLICE_IN_CPP_COMMENT );
        }
        if( CompFlags.cpp_output ) {            /* 30-may-95 */
            if( CompFlags.in_pragma ) {
                CppPrtChar( '\\' );
                CppPrtChar( '\n' );
            } else if( CompFlags.cpp_line_wanted ) {
                CppPrtChar( '\n' );
            }
        }
        SrcFile->src_line_cnt++;
        SrcFile->src_loc.line++;
        SrcFileLoc = SrcFile->src_loc;
//      SrcFile->column = 0;
        return( GetNextChar() );
    }
    LastChar = nc;
    NextChar = getCharAfterBackSlash;
    return( '\\' );
}
Exemplo n.º 24
0
//------------------------------------------------------------------------------
bool Tokeniser::ParseString ()
{
	bool done = false;
	 char lastChar = '\0';
	token = "";

  	while (!done && !atEOF)
	{
		curChar = GetNextChar ();

		if (curChar=='\'')
		{
			if (lastChar == '\0')		// first time we've encountered a quote
				lastChar = '\'';
			else if (lastChar == '\'')	// second single quote
			{
				token += curChar;
				lastChar = '\0';
			}
	    }
	    else
	    {
		    if (lastChar == '\'')
		    {
				// end of quoted string indicated by single quote that doesn't
		        // follow another single quote
		        done = true;
			}
			else
			{
				lastChar = '\0';
				if (curChar == '_')
					token += ' ';
				else
					token += curChar;
			}
		}
	}
#ifdef __MWERKS__
	putBuffer = curChar;
#else

	putBackChar = curChar;
	//in.putback (curChar);
#endif
 	filecol--;
	return (done);
}
Exemplo n.º 25
0
/*----------------------------------------------------------------------------------------------------------------------
|	Gets remainder of a double-quoted NEXUS word (the first double quote character was read in already by GetNextToken).
|	This function reads characters until the next double quote is encountered. Tandem double quotes within a 
|	double-quoted NEXUS word are not allowed and will be treated as the end of the first word and the beginning of the 
|	next double-quoted NEXUS word. Tandem single quotes inside a double-quoted NEXUS word are saved as two separate 
|	single quote characters; to embed a single quote inside a double-quoted NEXUS word, simply use the single quote by 
|	itself (not paired with another tandem single quote).
*/
void NxsToken::GetDoubleQuotedToken()
	{
	char ch;

	for(;;)
		{
		ch = GetNextChar();
		if (atEOF)
			break;

		if (ch == '\"')
			break;
		else
			AppendToToken(ch);
		}
	}
void CToken::GetTTComments()
{
	int nsLen;

	//if(m_cNextChar == '\'')
	//{
	m_eNextTokenType = ttVBComments;
	m_sNextTokenType = "VB's Comments";				
	while(m_cNextChar != '\n' && m_cNextChar != EOF) // end of line
	{
		nsLen = m_sNextToken.GetLength();
		m_sNextToken.Insert(nsLen, m_cNextChar);
		GetNextChar();
	}
	//}
} // GetTTComments()
Exemplo n.º 27
0
int main(void)
{
  struct Node_t * node;
  int n;

  scanf("%d\n", &n);
  while (n--)
  {
    last = GetNextChar();
    free_node = nodes;
    node = E();
    Print(node, 4);
    printf("\n");
/*printf("###########done############(posledni znak \'%c\')\n", last);*/
  }
  return 0;
}
Exemplo n.º 28
0
	char GetLookAheadChar()
	{
		LexerState prevLexerState;
		CopyLexerState(&prevLexerState, &compiler.currLexerState);

		char currentChar;
		while (TRUE)
		{
			currentChar = GetNextChar();
			if (!IsCharWhiteSpace_CL(currentChar))
				break;
		}

		CopyLexerState(&compiler.currLexerState, &prevLexerState);

		return currentChar;
	}
Exemplo n.º 29
0
struct Node_t * Ec(struct Node_t * left)
{
  struct Node_t * node;

  if ((last == '+') || (last == '-'))
  {
    node = free_node++;
    node->oper = last;
    last = GetNextChar();
    node->left = left;
    node->right = F();
    return Ec(node);
  }
  node = Fc(left);
  if ((last == '+') || (last == '-'))
    return Ec(node);
  return node;
}
Exemplo n.º 30
0
/**
 * Find next non-white space character.
 */
static TCHAR
FindNonWhiteSpace(XML::Parser *pXML)
{
  assert(pXML);

    // Iterate through characters in the string until we find a NULL or a
  // non-white space character
  TCHAR ch;
  while ((ch = GetNextChar(pXML)) != 0) {
    switch (ch) {
    // Ignore white space
    case _T('\n'):
    case _T(' '):
    case _T('\t'):
    case _T('\r'):
      continue;
    default:
      return ch;
    }
  }
  return 0;
}