S08 * ISIL_GetLine(FILE * fp)
{
	static S08 line[LINE_BUF_LEN];
	S32 i;
	S08 *p;

	while (fgets(line, sizeof (line), fp) != NULL) {
		if (IsEOL(*line))
			continue;
		p = line;
		while (!IsEOL(*p))
			p++;
		/* delete last space */
		while (p >= line && (IsSpace(*p) || IsEOL(*p)))
			p--;
		*(p + 1) = 0;

		/* delete first space */
		p = line;
		while (*p && IsSpace(*p))
			p++;
		/* move */
		i = 0;
		while (*p)
			line[i++] = *p++;
		line[i] = 0;
		if (*line == 0)
			continue;
		return line;
	}
	return NULL;
}
std::string ASStreamIterator::readLine()
{
    m_buffer.clear();

    while (*m_In != 0)
    {
        if (!IsEOL(*m_In))
        {
            m_buffer.push_back(*m_In);
        }

        ++m_In;

        if (IsEOL(*m_In))
        {
            // if CRLF (two chars) peek next char (avoid duplicating empty-lines)
            if (*m_In != *(m_In + 1) && IsEOL(*(m_In + 1)))
            {
                ++m_In;
            }

            break;
        }
    }

    m_buffer.push_back(0);
    ++m_curline;

    return std::string(cbU2C(&m_buffer[0]));
}
Example #3
0
size_t GetStartOfNextLine(const std::vector<wchar_t>& chars, size_t p)
{
    while (p < chars.size() && !IsEOL(chars[p]))
        ++p;
    if (p >= chars.size())
        return UINT_MAX;
    p += IsEOL(chars, p);
    return p;
}
Example #4
0
char* FindStrEnd (
		char* s,
		char* last
		)
{
	while ( (s != last) && !IsEOL(*s) ) s++;

	if ( (s != last) || IsEOL(*s) )
		--s;

	return s;
}
//------------------------------------------------------------------------------
bool FBasicTokenParser::GetRawTokenRespectingQuotes(FBasicToken& Token, TCHAR StopChar/* = TCHAR('\n')*/)
{
	// if the parser is in a bad state, then don't continue parsing (who 
	// knows what will happen!?)
	if (!IsValid())
	{
		return false;
	}

	// Get token after whitespace.
	TCHAR Temp[MAX_STRING_CONST_SIZE];
	int32 Length=0;
	TCHAR c = GetLeadingChar();

	bool bInQuote = false;

	while( !IsEOL(c) && ((c != StopChar) || bInQuote) )
	{
		if( (c=='/' && PeekChar()=='/') || (c=='/' && PeekChar()=='*') )
		{
			break;
		}

		if (c == '"')
		{
			bInQuote = !bInQuote;
		}

		Temp[Length++] = c;
		if( Length >= MAX_STRING_CONST_SIZE )
		{
			Length = ((int32)MAX_STRING_CONST_SIZE) - 1;
			Temp[Length]=0; // needs to happen for the error description below

			FText ErrorDesc = FText::Format(LOCTEXT("IdTooLong", "Identifer ({0}...) exceeds maximum length of {1}"), FText::FromString(Temp), FText::AsNumber((int32)MAX_STRING_CONST_SIZE));
			SetError(FErrorState::ParseError, ErrorDesc);

			c = GetChar(true);
			break;
		}
		c = GetChar(true);
	}
	UngetChar();

	// Get rid of trailing whitespace.
	while( Length>0 && (Temp[Length-1]==' ' || Temp[Length-1]==9 ) )
	{
		Length--;
	}
	Temp[Length]=0;

	if (bInQuote)
	{
		FText ErrorDesc = FText::Format(LOCTEXT("NoClosingQuote", "Unterminated quoted string ({0})"), FText::FromString(Temp));
		SetError(FErrorState::ParseError, ErrorDesc);
	}
	Token.SetConstString(Temp);

	return Length>0 && IsValid();
}
/**
 * Put all text from the current position up to either EOL or the StopToken
 * into Token.  Advances the compiler's current position.
 *
 * @param	Token	[out] will contain the text that was parsed
 * @param	StopChar	stop processing when this character is reached
 *
 * @return	the number of character parsed
 */
bool FBaseParser::GetRawToken( FToken& Token, TCHAR StopChar /* = TCHAR('\n') */ )
{
	// Get token after whitespace.
	TCHAR Temp[MAX_STRING_CONST_SIZE];
	int32 Length=0;
	TCHAR c = GetLeadingChar();
	while( !IsEOL(c) && c != StopChar )
	{
		if( (c=='/' && PeekChar()=='/') || (c=='/' && PeekChar()=='*') )
		{
			break;
		}
		Temp[Length++] = c;
		if( Length >= MAX_STRING_CONST_SIZE )
		{
			FError::Throwf(TEXT("Identifier exceeds maximum of %i characters"), (int32)MAX_STRING_CONST_SIZE );
		}
		c = GetChar(true);
	}
	UngetChar();

	// Get rid of trailing whitespace.
	while( Length>0 && (Temp[Length-1]==' ' || Temp[Length-1]==9 ) )
	{
		Length--;
	}
	Temp[Length]=0;

	Token.SetConstString(Temp);

	return Length>0;
}
Example #7
0
char* FindNextStr (
		char* s,
		char* last
		)
{
	if ( s != last )
		s++;

	while ( (s != last) && IsEOL(*s) ) s++;

	return s;
}
Example #8
0
size_t MoveRight(const std::vector<wchar_t>& chars, size_t p)
{
    size_t d = IsEOL(chars, p);
    if (d == 0)
    {
        if (p < chars.size())
            ++p;
    }
    else
        p += d;
    return p;
}
Example #9
0
bool SIMPLEAPI SkipLineEnd(const wchar_t*& p)
{
	if (!IsEOL(p[0]))
		return false;

	if (p[0]==L'\r')
		p++;
	if (p[0]==L'\n')
		p++;

	return true;
}
bool FBaseParser::GetRawTokenRespectingQuotes( FToken& Token, TCHAR StopChar /* = TCHAR('\n') */ )
{
	// Get token after whitespace.
	TCHAR Temp[MAX_STRING_CONST_SIZE];
	int32 Length=0;
	TCHAR c = GetLeadingChar();

	bool bInQuote = false;

	while( !IsEOL(c) && ((c != StopChar) || bInQuote) )
	{
		if( (c=='/' && PeekChar()=='/') || (c=='/' && PeekChar()=='*') )
		{
			break;
		}

		if (c == '"')
		{
			bInQuote = !bInQuote;
		}

		Temp[Length++] = c;
		if( Length >= MAX_STRING_CONST_SIZE )
		{
			FError::Throwf(TEXT("Identifier exceeds maximum of %i characters"), (int32)MAX_STRING_CONST_SIZE );
			c = GetChar(true);
			Length = ((int32)MAX_STRING_CONST_SIZE) - 1;
			break;
		}
		c = GetChar(true);
	}
	UngetChar();

	if (bInQuote)
	{
		FError::Throwf(TEXT("Unterminated quoted string"));
	}

	// Get rid of trailing whitespace.
	while( Length>0 && (Temp[Length-1]==' ' || Temp[Length-1]==9 ) )
	{
		Length--;
	}
	Temp[Length]=0;

	Token.SetConstString(Temp);

	return Length>0;
}
Example #11
0
// getline( char *, int, int ):  This is a variation on the
//  standard getline() functions (which, incidentially, can
//  still be used instead of this function).  The file's
//  current EOL type is used if none is supplied
// Note that the file MUST be in binary mode for this to
//  work correctly; if it isn't not, it will assert.
char * pifstream::getline( char *buffer, unsigned int bufsize,
                           int eoltype ) {
  // Do some legality tests
  if( eoltype == -1 )                  // Handle -1 (current EOL type)
    eoltype = eol;
  else
    assert( IsEOL( eoltype ) );        // Bounds-check EOL  

  assert( buffer != NULL );            // Make sure the buffer isn't NULL

  char         c;
  const char * EOL       = EOLType2String(eoltype);
  int          EOLLength = strlen(EOL);
  int          sofar = 0;

  for( unsigned int i = 0; i < bufsize-1; i++ ) {
    get(c);

    // Test for errors/EOF
    if( !good() )
      break;
    if( eof() )
      break;

    // Add the char to the buffer
    buffer[i] = c; // Store the current char

    // Check for EOL(s)
    if( c == EOL[sofar] )
      sofar++;
    else
      sofar = 0;

    // Exit if we've found our EOL(s)
    if( sofar == EOLLength ) {
      sofar--;
      break;
    }
  }

  // Finish Up
  buffer[ i - sofar ] = '\0';
  return buffer;
}
Example #12
0
size_t MoveWordRight(const std::vector<wchar_t>& chars, size_t p)
{
    size_t d = IsEOL(chars, p);
    if (d > 0)
        p += d;
    else
    {
        if (iswpunct(chars[p])) // TODO Use locale?
            ++p;
        else
            while (p < chars.size() && (iswalnum(chars[p]) || chars[p] == L'_')) // TODO Use locale?
                ++p;
    }

    while (p < chars.size() && isblank(chars[p])) // TODO Use locale?
        ++p;

    return p;
}
//------------------------------------------------------------------------------
bool FBasicTokenParser::GetRawToken(FBasicToken& Token, TCHAR StopChar/* = TCHAR('\n')*/)
{
	// if the parser is in a bad state, then don't continue parsing (who 
	// knows what will happen!?)
	if (!IsValid())
	{
		return false;
	}

	// Get token after whitespace.
	TCHAR Temp[MAX_STRING_CONST_SIZE];
	int32 Length=0;
	TCHAR c = GetLeadingChar();
	while( !IsEOL(c) && c != StopChar )
	{
		if( (c=='/' && PeekChar()=='/') || (c=='/' && PeekChar()=='*') )
		{
			break;
		}
		Temp[Length++] = c;
		if( Length >= MAX_STRING_CONST_SIZE )
		{
			Temp[Length] = 0;

			FText ErrorDesc = FText::Format(LOCTEXT("IdTooLong", "Identifer ({0}...) exceeds maximum length of {1}"), FText::FromString(Temp), FText::AsNumber((int32)MAX_STRING_CONST_SIZE));
			SetError(FErrorState::ParseError, ErrorDesc);
		}
		c = GetChar(true);
	}
	UngetChar();

	// Get rid of trailing whitespace.
	while( Length>0 && (Temp[Length-1]==' ' || Temp[Length-1]==9 ) )
	{
		Length--;
	}
	Temp[Length]=0;

	Token.SetConstString(Temp);

	return Length>0;
}
Example #14
0
S32 ISIL_AppendLine(S08 *fname, S08 *line)
{
	FILE *fp;
	S32 c;

	if (!FileExist(fname))
		fp = fopen(fname, "w+");
	else
		fp = fopen(fname, "r+");
	if (fp == NULL)
		return ISIL_FALSE;
	fseek(fp, -1, 2);	/* to last place */
	c = fgetc(fp);
	if (!IsEOL(c))
		fprintf(fp, "\n");
	fseek(fp, 0, 2);
	fprintf(fp, "%s\n", line);
	fclose(fp);
	return ISIL_TRUE;
}
// Gets the next token from the input stream, advancing the variables which keep track of the current input position and line.
bool FBaseParser::GetToken( FToken& Token, bool bNoConsts/*=false*/, ESymbolParseOption bParseTemplateClosingBracket/*=ESymbolParseOption::Normal*/ )
{
	Token.TokenName	= NAME_None;
	TCHAR c = GetLeadingChar();
	TCHAR p = PeekChar();
	if( c == 0 )
	{
		UngetChar();
		return 0;
	}
	Token.StartPos		= PrevPos;
	Token.StartLine		= PrevLine;
	if( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c=='_') )
	{
		// Alphanumeric token.
		int32 Length=0;
		do
		{
			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				FError::Throwf(TEXT("Identifer length exceeds maximum of %i"), (int32)NAME_SIZE);
				Length = ((int32)NAME_SIZE) - 1;
				break;
			}
			c = GetChar();
		} while( ((c>='A')&&(c<='Z')) || ((c>='a')&&(c<='z')) || ((c>='0')&&(c<='9')) || (c=='_') );
		UngetChar();
		Token.Identifier[Length]=0;

		// Assume this is an identifier unless we find otherwise.
		Token.TokenType = TOKEN_Identifier;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		// If const values are allowed, determine whether the identifier represents a constant
		if ( !bNoConsts )
		{
			// See if the identifier is part of a vector, rotation or other struct constant.
			// boolean true/false
			if( Token.Matches(TEXT("true")) )
			{
				Token.SetConstBool(true);
				return true;
			}
			else if( Token.Matches(TEXT("false")) )
			{
				Token.SetConstBool(false);
				return true;
			}
		}
		return true;
	}

	// if const values are allowed, determine whether the non-identifier token represents a const
	else if ( !bNoConsts && ((c>='0' && c<='9') || ((c=='+' || c=='-') && (p>='0' && p<='9'))) )
	{
		// Integer or floating point constant.
		bool  bIsFloat = 0;
		int32 Length   = 0;
		bool  bIsHex   = 0;
		do
		{
			if( c==TEXT('.') )
			{
				bIsFloat = true;
			}
			if( c==TEXT('X') || c == TEXT('x') )
			{
				bIsHex = true;
			}

			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				FError::Throwf(TEXT("Number length exceeds maximum of %i "), (int32)NAME_SIZE );
				Length = ((int32)NAME_SIZE) - 1;
				break;
			}
			c = FChar::ToUpper(GetChar());
		} while ((c >= TEXT('0') && c <= TEXT('9')) || (!bIsFloat && c == TEXT('.')) || (!bIsHex && c == TEXT('X')) || (bIsHex && c >= TEXT('A') && c <= TEXT('F')));

		Token.Identifier[Length]=0;
		if (!bIsFloat || c != 'F')
		{
			UngetChar();
		}

		if (bIsFloat)
		{
			Token.SetConstFloat( FCString::Atof(Token.Identifier) );
		}
		else if (bIsHex)
		{
			TCHAR* End = Token.Identifier + FCString::Strlen(Token.Identifier);
			Token.SetConstInt( FCString::Strtoi(Token.Identifier,&End,0) );
		}
		else
		{
			Token.SetConstInt( FCString::Atoi(Token.Identifier) );
		}
		return true;
	}
	else if (c == '\'')
	{
		TCHAR ActualCharLiteral = GetChar(/*bLiteral=*/ true);

		if (ActualCharLiteral == '\\')
		{
			ActualCharLiteral = GetChar(/*bLiteral=*/ true);
			switch (ActualCharLiteral)
			{
			case TCHAR('t'):
				ActualCharLiteral = '\t';
				break;
			case TCHAR('n'):
				ActualCharLiteral = '\n';
				break;
			case TCHAR('r'):
				ActualCharLiteral = '\r';
				break;
			}
		}

		c = GetChar(/*bLiteral=*/ true);
		if (c != '\'')
		{
			FError::Throwf(TEXT("Unterminated character constant"));
			UngetChar();
		}

		Token.SetConstChar(ActualCharLiteral);
		return true;
	}
	else if (c == '"')
	{
		// String constant.
		TCHAR Temp[MAX_STRING_CONST_SIZE];
		int32 Length=0;
		c = GetChar(/*bLiteral=*/ true);
		while( (c!='"') && !IsEOL(c) )
		{
			if( c=='\\' )
			{
				c = GetChar(/*bLiteral=*/ true);
				if( IsEOL(c) )
				{
					break;
				}
				else if(c == 'n')
				{
					// Newline escape sequence.
					c = '\n';
				}
			}
			Temp[Length++] = c;
			if( Length >= MAX_STRING_CONST_SIZE )
			{
				FError::Throwf(TEXT("String constant exceeds maximum of %i characters"), (int32)MAX_STRING_CONST_SIZE );
				c = TEXT('\"');
				Length = ((int32)MAX_STRING_CONST_SIZE) - 1;
				break;
			}
			c = GetChar(/*bLiteral=*/ true);
		}
		Temp[Length]=0;

		if( c != '"' )
		{
			FError::Throwf(TEXT("Unterminated string constant: %s"), Temp);
			UngetChar();
		}

		Token.SetConstString(Temp);
		return true;
	}
	else
	{
		// Symbol.
		int32 Length=0;
		Token.Identifier[Length++] = c;

		// Handle special 2-character symbols.
		#define PAIR(cc,dd) ((c==cc)&&(d==dd)) /* Comparison macro for convenience */
		TCHAR d = GetChar();
		if
		(	PAIR('<','<')
		||	(PAIR('>','>') && (bParseTemplateClosingBracket != ESymbolParseOption::CloseTemplateBracket))
		||	PAIR('!','=')
		||	PAIR('<','=')
		||	PAIR('>','=')
		||	PAIR('+','+')
		||	PAIR('-','-')
		||	PAIR('+','=')
		||	PAIR('-','=')
		||	PAIR('*','=')
		||	PAIR('/','=')
		||	PAIR('&','&')
		||	PAIR('|','|')
		||	PAIR('^','^')
		||	PAIR('=','=')
		||	PAIR('*','*')
		||	PAIR('~','=')
		||	PAIR(':',':')
		)
		{
			Token.Identifier[Length++] = d;
			if( c=='>' && d=='>' )
			{
				if( GetChar()=='>' )
					Token.Identifier[Length++] = '>';
				else
					UngetChar();
			}
		}
		else UngetChar();
		#undef PAIR

		Token.Identifier[Length] = 0;
		Token.TokenType = TOKEN_Symbol;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		return true;
	}
}
//
// Skip past all spaces and tabs in the input stream.
//
TCHAR FBaseParser::GetLeadingChar()
{
	TCHAR TrailingCommentNewline = 0;

	for (;;)
	{
		bool MultipleNewlines = false;

		TCHAR c;

		// Skip blanks.
		do
		{
			c = GetChar();

			// Check if we've encountered another newline since the last one
			if (c == TrailingCommentNewline)
			{
				MultipleNewlines = true;
			}
		} while (IsWhitespace(c));

		if (c != TEXT('/') || PeekChar() != TEXT('/'))
		{
			return c;
		}

		// Clear the comment if we've encountered newlines since the last comment
		if (MultipleNewlines)
		{
			ClearComment();
		}

		// Record the first slash.  The first iteration of the loop will get the second slash.
		PrevComment += c;

		do
		{
			c = GetChar(true);
			if (c == 0)
				return c;
			PrevComment += c;
		} while (!IsEOL(c));

		TrailingCommentNewline = c;

		for (;;)
		{
			c = GetChar();
			if (c == 0)
				return c;
			if (c == TrailingCommentNewline || !IsEOL(c))
			{
				UngetChar();
				break;
			}

			PrevComment += c;
		}
	}
}
Example #17
0
// Gets the next token from the input stream, advancing the variables which keep track of the current input position and line.
bool FBaseParser::GetToken( FToken& Token, bool bNoConsts/*=false*/ )
{
	Token.TokenName	= NAME_None;
	TCHAR c = GetLeadingChar();
	TCHAR p = PeekChar();
	if( c == 0 )
	{
		UngetChar();
		return 0;
	}
	Token.StartPos		= PrevPos;
	Token.StartLine		= PrevLine;
	if( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c=='_') )
	{
		// Alphanumeric token.
		int32 Length=0;
		do
		{
			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				FError::Throwf(TEXT("Identifer length exceeds maximum of %i"), (int32)NAME_SIZE);
				Length = ((int32)NAME_SIZE) - 1;
				break;
			}
			c = GetChar();
		} while( ((c>='A')&&(c<='Z')) || ((c>='a')&&(c<='z')) || ((c>='0')&&(c<='9')) || (c=='_') );
		UngetChar();
		Token.Identifier[Length]=0;

		// Assume this is an identifier unless we find otherwise.
		Token.TokenType = TOKEN_Identifier;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		// If const values are allowed, determine whether the identifier represents a constant
		if ( !bNoConsts )
		{
			// See if the identifier is part of a vector, rotation or other struct constant.
			// boolean true/false
			if( Token.Matches(TEXT("true")) )
			{
				Token.SetConstBool(true);
				return true;
			}
			else if( Token.Matches(TEXT("false")) )
			{
				Token.SetConstBool(false);
				return true;
			}
		}
		return true;
	}

	// if const values are allowed, determine whether the non-identifier token represents a const
	else if ( !bNoConsts && ((c>='0' && c<='9') || ((c=='+' || c=='-') && (p>='0' && p<='9'))) )
	{
		// Integer or floating point constant.
		bool  bIsFloat = 0;
		int32 Length   = 0;
		bool  bIsHex   = 0;
		do
		{
			if( c==TEXT('.') )
			{
				bIsFloat = true;
			}
			if( c==TEXT('X') || c == TEXT('x') )
			{
				bIsHex = true;
			}

			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				FError::Throwf(TEXT("Number length exceeds maximum of %i "), (int32)NAME_SIZE );
				Length = ((int32)NAME_SIZE) - 1;
				break;
			}
			c = FChar::ToUpper(GetChar());
		} while ((c >= TEXT('0') && c <= TEXT('9')) || (!bIsFloat && c == TEXT('.')) || (!bIsHex && c == TEXT('X')) || (bIsHex && c >= TEXT('A') && c <= TEXT('F')));

		Token.Identifier[Length]=0;
		if (!bIsFloat || c != 'F')
		{
			UngetChar();
		}

		if (bIsFloat)
		{
			Token.SetConstFloat( FCString::Atof(Token.Identifier) );
		}
		else if (bIsHex)
		{
			TCHAR* End = Token.Identifier + FCString::Strlen(Token.Identifier);
			Token.SetConstInt( FCString::Strtoi(Token.Identifier,&End,0) );
		}
		else
		{
			Token.SetConstInt( FCString::Atoi(Token.Identifier) );
		}
		return true;
	}
//@TODO: 'z' is a character literal in C++, not a FName like it was in UnrealScript - do we need this code? 
// 	else if( !bNoConsts && c=='\'' )
// 	{
// 		// Name constant.
// 		int32 Length=0;
// 		c = GetChar();
// 		while( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || (c=='_') || (c=='-') || (c==' ') ) //@FIXME: space in names should be illegal!
// 		{
// 			Token.Identifier[Length++] = c;
// 			if( Length >= NAME_SIZE )
// 			{
// 				FError::Throwf(TEXT("Name length exceeds maximum of %i"), (int32)NAME_SIZE );
// 				// trick the error a few lines down
// 				c = TEXT('\'');
// 				Length = ((int32)NAME_SIZE) - 1;
// 				break;
// 			}
// 			c = GetChar();
// 		}
// 		if( c != '\'' )
// 		{
// 			UngetChar();
// 			FError::Throwf(TEXT("Illegal character in name") );
// 		}
// 		Token.Identifier[Length]=0;
// 
// 		// Make constant name.
// 		Token.SetConstName( FName(Token.Identifier) );
// 		return true;
// 	}
	else if( c=='"' )
	{
		// String constant.
		TCHAR Temp[MAX_STRING_CONST_SIZE];
		int32 Length=0;
		c = GetChar(1);
		while( (c!='"') && !IsEOL(c) )
		{
			if( c=='\\' )
			{
				c = GetChar(1);
				if( IsEOL(c) )
				{
					break;
				}
				else if(c == 'n')
				{
					// Newline escape sequence.
					c = '\n';
				}
			}
			Temp[Length++] = c;
			if( Length >= MAX_STRING_CONST_SIZE )
			{
				FError::Throwf(TEXT("String constant exceeds maximum of %i characters"), (int32)MAX_STRING_CONST_SIZE );
				c = TEXT('\"');
				Length = ((int32)MAX_STRING_CONST_SIZE) - 1;
				break;
			}
			c = GetChar(1);
		}
		Temp[Length]=0;

		if( c != '"' )
		{
			FError::Throwf(TEXT("Unterminated string constant: %s"), Temp);
			UngetChar();
		}

		Token.SetConstString(Temp);
		return true;
	}
	else
	{
		// Symbol.
		int32 Length=0;
		Token.Identifier[Length++] = c;

		// Handle special 2-character symbols.
		#define PAIR(cc,dd) ((c==cc)&&(d==dd)) /* Comparison macro for convenience */
		TCHAR d = GetChar();
		if
		(	PAIR('<','<')
		||	PAIR('>','>')
		||	PAIR('!','=')
		||	PAIR('<','=')
		||	PAIR('>','=')
		||	PAIR('+','+')
		||	PAIR('-','-')
		||	PAIR('+','=')
		||	PAIR('-','=')
		||	PAIR('*','=')
		||	PAIR('/','=')
		||	PAIR('&','&')
		||	PAIR('|','|')
		||	PAIR('^','^')
		||	PAIR('=','=')
		||	PAIR('*','*')
		||	PAIR('~','=')
		||	PAIR(':',':')
		)
		{
			Token.Identifier[Length++] = d;
			if( c=='>' && d=='>' )
			{
				if( GetChar()=='>' )
					Token.Identifier[Length++] = '>';
				else
					UngetChar();
			}
		}
		else UngetChar();
		#undef PAIR

		Token.Identifier[Length] = 0;
		Token.TokenType = TOKEN_Symbol;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		return true;
	}
}
//------------------------------------------------------------------------------
bool FBasicTokenParser::GetToken(FBasicToken& Token, bool bNoConsts/* = false*/)
{
	// if the parser is in a bad state, then don't continue parsing (who 
	// knows what will happen!?)
	if (!IsValid())
	{
		return false;
	}

	Token.TokenName	= NAME_None;
	TCHAR c = GetLeadingChar();
	TCHAR p = PeekChar();
	if( c == 0 )
	{
		UngetChar();
		return 0;
	}
	Token.StartPos		= PrevPos;
	Token.StartLine		= PrevLine;
	if( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c=='_') )
	{
		// Alphanumeric token.
		int32 Length=0;
		do
		{
			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				Length = ((int32)NAME_SIZE) - 1;
				Token.Identifier[Length]=0; // need this for the error description

				FText ErrorDesc = FText::Format(LOCTEXT("IdTooLong", "Identifer ({0}...) exceeds maximum length of {1}"), FText::FromString(Token.Identifier), FText::AsNumber((int32)NAME_SIZE));
				SetError(FErrorState::ParseError, ErrorDesc);

				break;
			}
			c = GetChar();
		} while( ((c>='A')&&(c<='Z')) || ((c>='a')&&(c<='z')) || ((c>='0')&&(c<='9')) || (c=='_') );
		UngetChar();
		Token.Identifier[Length]=0;

		// Assume this is an identifier unless we find otherwise.
		Token.TokenType = FBasicToken::TOKEN_Identifier;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		// If const values are allowed, determine whether the identifier represents a constant
		if ( !bNoConsts )
		{
			// See if the identifier is part of a vector, rotation or other struct constant.
			// boolean true/false
			if( Token.Matches(TEXT("true")) )
			{
				Token.SetConstBool(true);
				return true;
			}
			else if( Token.Matches(TEXT("false")) )
			{
				Token.SetConstBool(false);
				return true;
			}
		}

		return IsValid();
	}
	// if const values are allowed, determine whether the non-identifier token represents a const
	else if ( !bNoConsts && ((c>='0' && c<='9') || ((c=='+' || c=='-') && (p>='0' && p<='9'))) )
	{
		// Integer or floating point constant.
		bool  bIsFloat = 0;
		int32 Length   = 0;
		bool  bIsHex   = 0;
		do
		{
			if( c==TEXT('.') )
			{
				bIsFloat = true;
			}
			if( c==TEXT('X') || c == TEXT('x') )
			{
				bIsHex = true;
			}

			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				Length = ((int32)NAME_SIZE) - 1;
				Token.Identifier[Length]=0; // need this for the error description

				FText ErrorDesc = FText::Format(LOCTEXT("IdTooLong", "Identifer ({0}...) exceeds maximum length of {1}"), FText::FromString(Token.Identifier), FText::AsNumber((int32)NAME_SIZE));
				SetError(FErrorState::ParseError, ErrorDesc);

				break;
			}
			c = FChar::ToUpper(GetChar());
		} while ((c >= TEXT('0') && c <= TEXT('9')) || (!bIsFloat && c == TEXT('.')) || (!bIsHex && c == TEXT('X')) || (bIsHex && c >= TEXT('A') && c <= TEXT('F')));

		Token.Identifier[Length]=0;
		if (!bIsFloat || c != 'F')
		{
			UngetChar();
		}

		if (bIsFloat)
		{
			Token.SetConstFloat( FCString::Atof(Token.Identifier) );
		}
		else if (bIsHex)
		{
			TCHAR* End = Token.Identifier + FCString::Strlen(Token.Identifier);
			Token.SetConstInt( FCString::Strtoi(Token.Identifier,&End,0) );
		}
		else
		{
			Token.SetConstInt( FCString::Atoi(Token.Identifier) );
		}
		return IsValid();
	}
	else if( c=='"' )
	{
		// String constant.
		TCHAR Temp[MAX_STRING_CONST_SIZE];
		int32 Length=0;
		c = GetChar(1);
		while( (c!='"') && !IsEOL(c) )
		{
			if( c=='\\' )
			{
				c = GetChar(1);
				if( IsEOL(c) )
				{
					break;
				}
				else if(c == 'n')
				{
					// Newline escape sequence.
					c = '\n';
				}
			}
			Temp[Length++] = c;
			if( Length >= MAX_STRING_CONST_SIZE )
			{
				Length = ((int32)MAX_STRING_CONST_SIZE) - 1;
				Temp[Length]=0; // need this for the error description

				FText ErrorDesc = FText::Format(LOCTEXT("StringConstTooLong", "String constant ({0}...) exceeds maximum of {1} characters"), FText::FromString(Temp), FText::AsNumber((int32)MAX_STRING_CONST_SIZE));
				SetError(FErrorState::ParseError, ErrorDesc);

				c = TEXT('\"');				
				break;
			}
			c = GetChar(1);
		}
		Temp[Length]=0;

		if( c != '"' )
		{
			FText ErrorDesc = FText::Format(LOCTEXT("NoClosingQuote", "Unterminated quoted string ({0})"), FText::FromString(Temp));
			SetError(FErrorState::ParseError, ErrorDesc);

			UngetChar();
		}

		Token.SetConstString(Temp);
		return IsValid();
	}
	else
	{
		// Symbol.
		int32 Length=0;
		Token.Identifier[Length++] = c;

		// Handle special 2-character symbols.
#define PAIR(cc,dd) ((c==cc)&&(d==dd)) /* Comparison macro for convenience */
		TCHAR d = GetChar();
		if
		(	PAIR('<','<')
		||	PAIR('>','>')
		||	PAIR('!','=')
		||	PAIR('<','=')
		||	PAIR('>','=')
		||	PAIR('+','+')
		||	PAIR('-','-')
		||	PAIR('+','=')
		||	PAIR('-','=')
		||	PAIR('*','=')
		||	PAIR('/','=')
		||	PAIR('&','&')
		||	PAIR('|','|')
		||	PAIR('^','^')
		||	PAIR('=','=')
		||	PAIR('*','*')
		||	PAIR('~','=')
		||	PAIR(':',':')
		)
		{
			Token.Identifier[Length++] = d;
			if( c=='>' && d=='>' )
			{
				if( GetChar()=='>' )
					Token.Identifier[Length++] = '>';
				else
					UngetChar();
			}
		}
		else UngetChar();
#undef PAIR

		Token.Identifier[Length] = 0;
		Token.TokenType = FBasicToken::TOKEN_Symbol;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		return true;
	}
}
Example #19
0
static int
ReadSock(struct DccUser *connptr)

{
	int length;
	char *ch;
	char *linech;

	if (!connptr)
		return 0;

	length = recv(connptr->socket, buffer, BUFSIZE, 0);

	if ((length == (-1)) && ((errno == EWOULDBLOCK) || (errno == EAGAIN)))
		return 2; /* no error - there's just nothing to read */

	if (length <= 0)
	{
		/* dcc client closed connection */
		return 0;
	}

	/*
	 * recv() may have cut off the line in the middle
	 * if buffer wasn't big enough
	 */
	buffer[length] = '\0';

	if (telnet_check(connptr->socket, buffer))
		return 1;

	ch = buffer;
	linech = connptr->spill + connptr->offset;

	while (*ch)
	{
		char tmp;

		tmp = *ch;
		if (IsEOL(tmp))
		{
			*linech = '\0';

			if (IsEOL(*connptr->spill))
			{
				ch++;
				continue;
			}

			/* process the line */
			if (connptr->flags & SOCK_TCMBOT)
			{
				/* process line from bot */
				if (BotProcess(connptr, connptr->spill))
					return 1;
			}
			else
				/* process line from client */
				DccProcess(connptr, connptr->spill);

			linech = connptr->spill;
			connptr->offset = 0;

			/*
			 * If the line ends in \r\n, advance past the \n
			 */
			if (IsEOL(*(ch + 1)))
				ch++;
		}
		else
		{
			/* make sure we don't overflow spill */
			if (linech < (connptr->spill + (sizeof(connptr->spill) - 1)))
			{
				*linech++ = tmp;
				connptr->offset++;
			}
		}
		ch++;
	}

	return 1;
} /* ReadSock() */
Example #20
0
size_t GetEndOfLine(const std::vector<wchar_t>& chars, size_t p)
{
    while (p < chars.size() && !IsEOL(chars[p]))
        ++p;
    return p;
}
Example #21
0
size_t GetStartOfLine(const std::vector<wchar_t>& chars, size_t p)
{
    while (p > 0 && !IsEOL(chars[p - 1]))
        --p;
    return p;
}
//------------------------------------------------------------------------------
TCHAR FBasicTokenParser::GetLeadingChar()
{
	// if the parser is in a bad state, then don't continue parsing (who 
	// knows what will happen!?)... return a char signaling the end-of-stream
	if (!IsValid())
	{
		return 0;
	}

	TCHAR TrailingCommentNewline = 0;
	for (;;)
	{
		bool MultipleNewlines = false;

		TCHAR c;

		// Skip blanks.
		do
		{
			c = GetChar();

			// Check if we've encountered another newline since the last one
			if (c == TrailingCommentNewline)
			{
				MultipleNewlines = true;
			}
		} while (IsWhitespace(c));

		if (c != TEXT('/') || PeekChar() != TEXT('/'))
		{
			return c;
		}

		// Clear the comment if we've encountered newlines since the last comment
		if (MultipleNewlines)
		{
			ClearCachedComment();
		}

		// Record the first slash.  The first iteration of the loop will get the second slash.
		PrevComment += c;

		do
		{
			c = GetChar(true);
			if (c == 0)
				return c;
			PrevComment += c;
		} while (!IsEOL(c));

		TrailingCommentNewline = c;

		for (;;)
		{
			c = GetChar();
			if (c == 0)
				return c;
			if (c == TrailingCommentNewline || !IsEOL(c))
			{
				UngetChar();
				break;
			}

			PrevComment += c;
		}
	}
}
Example #23
0
static int
ReadHub()

{
	int length; /* number of bytes we read */
	char *ch;
	char *linech;
#ifdef EXTREMEDEBUG

	FILE *fp;
#endif

	if (HubSock == NOSOCKET)
		return 0;

	/* read in a line */
	length = recv(HubSock, buffer, BUFSIZE, 0);

	/* hub closed connection */
	if (length == 0)
		return 0;

	/* error in read */
	if (length == -1)
	{
			if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
				/* there's just nothing to read */
				return 2;
			else
			{
				/* the connection was closed */
				putlog(LOG1, "Read error from server: %s",
			       strerror(errno));
				return 0;
			}
	}

	Network->RecvB += length;

	/*
	 * buffer may not be big enough to read the whole last line
	 * so it may contain only part of it
	 */
	buffer[length] = '\0';

#ifdef EXTREMEDEBUG

	if ((fp = fopen("hybserv.hubinfo", "a+")))
	{
		fprintf(fp, "%s", buffer);
		fclose(fp);
	}
#endif

	/*
	 * buffer could possibly contain several lines of info, especially if
	 * this is the inital connect burst, so go through, and record each line
	 * (until we hit a \n) and process it separately
	 */

	ch = buffer;
	linech = spill + offset;

	/*
	 * The following routine works something like this: buffer may contain
	 * several full lines, and then a partial line. If this is the case,
	 * loop through buffer, storing each character in 'spill' until we hit a
	 * \n or \r.  When we do, process the line. When we hit the end of
	 * buffer, spill will contain the partial line that buffer had, and
	 * offset will contain the index of spill where we left off, so the next
	 * time we recv() from the hub, the beginning characters of buffer will
	 * be appended to the end of spill, thus forming a complete line. If
	 * buffer does not contain a partial line, then linech will simply point
	 * to the first index of 'spill' (offset will be zero) after we process
	 * all of buffer's lines, and we can continue normally from there.
	 */

	while (*ch)
	{
		char tmp;
#ifdef DEBUGMODE

		int    ii;
#endif

		tmp = *ch;
		if (IsEOL(tmp))
		{
			*linech = '\0';

			if (nextparam)
			{
				/*
				 * It is possible nextparam will not be NULL here if there is a
				 * line like:
				 * PASS password :TS
				 * where the text after the colon does not have any spaces, so we
				 * reach the \n and do not execute the code below which sets the
				 * next index of param[] to nextparam. Do it here.
				 */
				param[paramc++] = nextparam;
			}

#ifdef DEBUGMODE
			for (ii = 0; ii < paramc; ii++)
				fprintf(stderr, "%s ", param[ii]);
			fprintf(stderr, "\n");
#endif

			/*
			 * Make sure paramc is non-zero, because if the line starts with a
			 * \n, we will immediately come here, without initializing param[0]
			 */
			if (paramc)
			{
				/* process the line */
				ProcessInfo(paramc, param);
			}

			linech = spill;
			offset = 0;
			paramc = 0;
			nextparam = NULL;

			/*
			 * If the line ends in \r\n, then this algorithm would have only
			 * picked up the \r. We don't want an entire other loop to do the
			 * \n, so advance ch here.
			 */
			if (IsEOL(*(ch + 1)))
				ch++;
		}
		else
		{
			/* make sure we don't overflow spill[] */
			if (linech >= (spill + (sizeof(spill) - 1)))
			{
				ch++;
				continue;
			}

			*linech++ = tmp;
			if (tmp == ' ')
			{
				/*
				 * Only set the space character to \0 if this is the very first
				 * parameter, or if nextparam is not NULL. If nextparam is NULL,
				 * then we've hit a parameter that starts with a colon (:), so
				 * leave it as a whole parameter.
				 */
				if (nextparam || (paramc == 0))
					*(linech - 1) = '\0';

				if (paramc == 0)
				{
					/*
					 * Its the first parameter - set it to the beginning of spill
					 */
					param[paramc++] = spill;
					nextparam = linech;
				}
				else
				{
					if (nextparam)
					{
						param[paramc++] = nextparam;
						if (*nextparam == ':')
						{
							/*
							 * We've hit a colon, set nextparam to NULL, so we know not
							 * to set any more spaces to \0
							 */
							nextparam = NULL;

							/*
							 * Unfortunately, the first space has already been set to \0
							 * above, so reset to to a space character
							 */
							*(linech - 1) = ' ';
						}
						else
							nextparam = linech;

						if (paramc >= MAXPARAM)
							nextparam = NULL;
					}
				}
			}
			offset++;
		}

		/*
		 * Advance ch to go to the next letter in the buffer
		 */
		ch++;
	}

	return 1;
} /* ReadHub() */
int LookupStringInFixedSet(const unsigned char* graph,
	size_t length,
	const char* key,
	size_t key_length)
{
	const unsigned char* pos = graph;
	const unsigned char* end = graph + length;
	const unsigned char* offset = pos;
	const char* key_end = key + key_length;
	const char* multibyte_start = 0;

	while (GetNextOffset(&pos, end, &offset)) {
		/*char <char>+ end_char offsets
		 * char <char>+ return value
		 * char end_char offsets
		 * char return value
		 * end_char offsets
		 * return_value
		 */
		int did_consume = 0;

		if (key != key_end && !IsEOL(offset, end)) {
			/* Leading <char> is not a match. Don't dive into this child */
			if (!IsMatch(offset, end, key, multibyte_start))
				continue;
			did_consume = 1;
			NextPos(&offset, &key, &multibyte_start);
			/* Possible matches at this point:
			 * <char>+ end_char offsets
			 * <char>+ return value
			 * end_char offsets
			 * return value
			 */

			/* Remove all remaining <char> nodes possible */
			while (!IsEOL(offset, end) && key != key_end) {
				if (!IsMatch(offset, end, key, multibyte_start))
					return -1;
				NextPos(&offset, &key, &multibyte_start);
			}
		}
		/* Possible matches at this point:
		 * end_char offsets
		 * return_value
		 * If one or more <char> elements were consumed, a failure
		 * to match is terminal. Otherwise, try the next node.
		 */
		if (key == key_end) {
			int return_value;

			if (GetReturnValue(offset, end, multibyte_start, &return_value))
				return return_value;
			/* The DAFSA guarantees that if the first char is a match, all
			 * remaining char elements MUST match if the key is truly present.
			 */
			if (did_consume)
				return -1;
			continue;
		}
		if (!IsEndCharMatch(offset, end, key, multibyte_start)) {
			if (did_consume)
				return -1; /* Unexpected */
			continue;
		}
		NextPos(&offset, &key, &multibyte_start);
		pos = offset; /* Dive into child */
	}

	return -1; /* No match */
}
Example #25
0
//********************************************************************
Bool WordsControl(
		long reason	// См. enum BROWSE_REASON
		)
{
// Слежение за словами и строками
// Вызывается после записи символа или конца строки
// или после иной обработки

	switch(reason)
		{
		case BROWSE_PARAGRAPH_START:
			// Начало абзаца
			gLastEOL = NULL;
			gBegWord = NULL;
			gDefis = NULL;
			gCharBack = NULL;
			break;

		case BROWSE_PARAGRAPH_END:
			// Конец абзаца
			// Обработать конец слова если есть
			if ( gBegWord && !WordEnd() )
				return FALSE;

			gLastEOL = NULL;
			gBegWord = NULL;
			gDefis = NULL;
			gCharBack = NULL;
			break;

		case BROWSE_LINE_END:
			// Конец строки
			// Запоминается адрес до записи конца строки
			// или пробела в начале следующей строки
			if ( gCharBack && IsEOL(*gCharBack) )
				gLastEOL = gCharBack;
			else
				gLastEOL = gMemCur;
			break;

		case BROWSE_LINE_START:
			// Начало строки
			{
			Byte c = *(gMemCur-1);	// Предыдущий символ
			if (gLastEOL &&			// Предыдущая строка
				c &&				// Не кончается нулем
				!IsEOL(c) &&		// Нет конца строки текста
				!(gFormat==ROUT_FMT_HTML && // Нет конца строки HTML
				  !memcmp("<br>",(char*)gMemCur-4,4)
				 ) &&
				c != ' '			// На конце не пробел
				)
				{
				// Вставить пробел перед новой строкой
				*gMemCur++ = ' ';
				}
			}
			break;

		case BROWSE_CHAR:
			// Символ

			// Буква
			if (IS_LETTER(gCharCode))
				{
				// Начало слова
				if(!gBegWord)
					gBegWord = gCharBack;
				}
			// Не буква. А слово есть.
			else if (gBegWord)
				{
				// Дефис
				if (gCharCode == '-')
					{
					Byte c = *(gMemCur-2);	// Предыдущий символ
					if ( c == '-' )
						{
						// Два дефиса подряд это тире
						if ( gDefis == gMemCur-2 )
							gDefis = 0;
						}
					else
						{
						// Скрытый дефис в "мягкой" строке может быть удален
						if ( gEdCharHidden &&
							!(gPreserveLineBreaks || gEdLineHardBreak)
						   )
 							gDefis = gCharBack;
						}
					}

				// Конец слова
				else
					{
					// Обработать конец слова
					if ( !WordEnd() )
						return FALSE;
					}
				}

			break;

		}

	return TRUE;
}
Example #26
0
void
GiveHelp(char *Serv, char *helpnick, char *command, int sockfd)

{
	FILE *fp;
	char sendstr[MAXLINE + 1] = "";
	char line[MAXLINE + 1];
	char *final;
	struct Luser *servptr;

	if (!(servptr = GetService(Serv)))
		return;

	if (!command) /* they want general help */
	{
		if (sockfd == NODCC) /* they want /msg commands */
		{
			sendstr[0] = '\0';
			if (servptr == Me.osptr)
				ircsprintf(sendstr, "%s/operserv/index", HelpPath);

#ifdef NICKSERVICES

			else if (servptr == Me.nsptr)
				ircsprintf(sendstr, "%s/nickserv/index", HelpPath);

#ifdef CHANNELSERVICES

			else if (servptr == Me.csptr)
				ircsprintf(sendstr, "%s/chanserv/index", HelpPath);
#endif

#ifdef MEMOSERVICES

			else if (servptr == Me.msptr)
				ircsprintf(sendstr, "%s/memoserv/index", HelpPath);
#endif

#endif /* NICKSERVICES */

#ifdef STATSERVICES

			else if (servptr == Me.ssptr)
				ircsprintf(sendstr, "%s/statserv/index", HelpPath);
#endif /* STATSERVICES */

#ifdef SEENSERVICES

			else if (servptr == Me.esptr)
				ircsprintf(sendstr, "%s/seenserv/index", HelpPath );
#endif /* SEENSERVICES */

#ifdef HELPSERVICES

			else if (servptr == Me.hsptr)
				ircsprintf(sendstr, "%s/helpserv/index", HelpPath);
#endif /* HELPSERVICES */

#ifdef GLOBALSERVICES

			else if (servptr == Me.gsptr)
				ircsprintf(sendstr, "%s/global/index", HelpPath);
#endif /* GLOBALSERVICES */

			if (sendstr[0])
			{
				if ((fp = fopen(sendstr, "r")) == NULL)
				{
					notice(Serv, helpnick, "Unable to open help file");
					return;
				}
			}
			else
				return; /* something got messed up =/ */
		}
		else /* they want dcc commands (OperServ only) */
		{
			if (servptr == Me.osptr)
			{
				ircsprintf(sendstr, "%s/operserv/dcc/index", HelpPath);
				if ((fp = fopen(sendstr, "r")) == NULL)
				{
					hs_notice(n_OperServ, helpnick, sockfd,
					          "Unable to open help file");
					return;
				}
			}
			else
				return; /* no other *Serv's allow dcc chat */
		}

		while (fgets(line, sizeof(line), fp))
		{
			if (IsEOL(*line))
			{
				hs_notice(Serv, helpnick, sockfd, " ");
				continue;
			}
			final = Substitute(helpnick, line, sockfd);
			if (final && (final != (char *) -1))
			{
				hs_notice(Serv, helpnick, sockfd, "%s", final);
				MyFree(final);
			}
		}
		fclose(fp);
	}
nsresult nsPropertiesParser::ParseBuffer(const PRUnichar* aBuffer,
                                         PRUint32 aBufferLength)
{
  const PRUnichar* cur = aBuffer;
  const PRUnichar* end = aBuffer + aBufferLength;

  // points to the start/end of the current key or value
  const PRUnichar* tokenStart = nsnull;

  // if we're in the middle of parsing a key or value, make sure
  // the current token points to the beginning of the current buffer
  if (mState == eParserState_Key ||
      mState == eParserState_Value) {
    tokenStart = aBuffer;
  }

  nsAutoString oldValue;

  while (cur != end) {

    PRUnichar c = *cur;

    switch (mState) {
    case eParserState_AwaitingKey:
      if (c == '#' || c == '!')
        EnterCommentState();

      else if (!IsWhiteSpace(c)) {
        // not a comment, not whitespace, we must have found a key!
        EnterKeyState();
        tokenStart = cur;
      }
      break;

    case eParserState_Key:
      if (c == '=' || c == ':') {
        mKey += Substring(tokenStart, cur);
        WaitForValue();
      }
      break;

    case eParserState_AwaitingValue:
      if (IsEOL(c)) {
        // no value at all! mimic the normal value-ending
        EnterValueState();
        FinishValueState(oldValue);
      }

      // ignore white space leading up to the value
      else if (!IsWhiteSpace(c)) {
        tokenStart = cur;
        EnterValueState();

        // make sure to handle this first character
        if (ParseValueCharacter(c, cur, tokenStart, oldValue))
          cur++;
        // If the character isn't consumed, don't do cur++ and parse
        // the character again. This can happen f.e. for char 'X' in sequence
        // "\u00X". This character can be control character and must be
        // processed again.
        continue;
      }
      break;

    case eParserState_Value:
      if (ParseValueCharacter(c, cur, tokenStart, oldValue))
        cur++;
      // See few lines above for reason of doing this
      continue;

    case eParserState_Comment:
      // stay in this state till we hit EOL
      if (c == '\r' || c== '\n')
        WaitForKey();
      break;
    }

    // finally, advance to the next character
    cur++;
  }

  // if we're still parsing the value and are in eParserSpecial_None, then
  // append whatever we have..
  if (mState == eParserState_Value && tokenStart &&
      mSpecialState == eParserSpecial_None) {
    mValue += Substring(tokenStart, cur);
  }
  // if we're still parsing the key, then append whatever we have..
  else if (mState == eParserState_Key && tokenStart) {
    mKey += Substring(tokenStart, cur);
  }

  return NS_OK;
}
Example #28
0
/*****************************************************************************
	BakSrc()
	This recursive function does a backward search in the edit buffer,
looking for a string which will match the first match construct in the search
buffer.  Basically,  it is the high-speed part of the search algorithm: it
scans the edit buffer looking for the first character in the search string.
	On entry, SStPtr points to the first match construct in the search
buffer.  On exit,  SStPtr points to the last character of the first match
construct in the search buffer.
	SBfPtr points to the character following the last character in
the search string.  This function does not modify SBfPtr.
	On entry,  EBPtr1 points to the place in the edit buffer where
the search starts.  On exit,  if the search was successful,  EBPtr1 will
point to the found character.  If the search was unsuccessful,  EBPtr1 will
be less than EndSAr.
	On entry,  EBPtr2 is undefined.  On exit,  if the search was
successful,  EBPtr2 points to the last character of the found string.  If
the search was unsuccessful,  EBPtr2 is undefined.
	EndSAr points to the end of the search area (where the search ends).
Note that for backwards searches,  EndSAr is less than EBPtr1.  This function
does not modify EndSAr.
	Match constructs are:
	^X		match any character
	^S		match a separator character (not letter or digit)
	^N		match anything but following match construct
	^EA		match any alphabetic
	^EB		match a separator character (not letter or digit)
	^EC		match symbol constituent
	^ED		match any digit
	^EGq		match any character in q-register q
	^EL		match any line terminator (LF, VT, FF)
	^EM		match non-null string of following match construct
	^ER		match any alphanumeric
	^ES		match non-null string of spaces and/or tabs
	^EV		match lowercase alphabetic
	^EW		match uppercase alphabetic
	^EX		match any character
	^E<nnn>		match character with ASCII code nnn (octal)
	^E[x1,x2,...xn]	match any of the match constructs x1, x2, etc.
	else		match the character itself
*****************************************************************************/
#include "zport.h"		/* define portability identifiers */
#include "tecoc.h"		/* define general identifiers */
#include "defext.h"		/* define external global variables */
#include "dchars.h"		/* define identifiers for characters */
#include "chmacs.h"		/* define character processing macros */
#include "deferr.h"		/* define identifiers for error messages */
DEFAULT BakSrc()		/* forward search for 1st search char */
{
    unsigned char Charac;	/* holds a character */
    charptr	LstBeg;		/* beginning of ^E[x1,x2,...] list */
    char	OtCase;		/* "other" case character */
    charptr	QRPtr;		/* pointer into q-register text */
    BOOLEAN	SamChr;		/* same character indicator */
    charptr	SavEP2;		/* temporary holder of EBPtr2 */
    charptr	SavSSP;		/* temporary holder of SStPtr */
    DEFAULT	Status;		/* FindQR() status for ^EGq */
    charptr	TCBfPt;		/* temporary holder of CBfPtr */
    charptr	TCStEn;		/* temporary holder of CStEnd */
    LONG	TmpLng;		/* holds octal number for ^E<nnn> */
#if DEBUGGING
    static char *DbgFNm = "BakSrc";
    sprintf(DbgSBf,"*SStPtr = '%c', *EBPtr1 = '%c'", *SStPtr, *EBPtr1);
    DbgFEn(3,DbgFNm,DbgSBf);
#endif
    switch (*SStPtr) {
	case CTRL_X:	/* ^X match any char */
    	    break;
	case CTRL_S:	/* ^S match separator char */
	    for (; EBPtr1 >= EndSAr; --EBPtr1) {
	        if (!Is_Alnum(*EBPtr1)) {
		    break;
		}
	    }
	    break;
	case CTRL_N:	/* ^Nx match any BUT next match construct */
	    if (++SStPtr == SBfPtr) {
	        ErrMsg(ERR_ISS);		/* illegal search string */
		DBGFEX(3,DbgFNm,"FAILURE, no ^N arg");
		return FAILURE;
	    }
	    SavSSP = SStPtr;
	    for (;EBPtr1>=EndSAr;--EBPtr1) {
	        EBPtr2 = EBPtr1;
		SStPtr = SavSSP;
		if (CMatch(&SamChr) == FAILURE) {
		    DBGFEX(3,DbgFNm,"FAILURE, CMatch failed");
		    return FAILURE;
		}
		if (!SamChr) {
		    break;
		}
	    }
	    break;
	case CTRL_E:	/* ^E match construct */
	    if (++SStPtr == SBfPtr) {
	        ErrMsg(ERR_ICE);	/* ICE = illegal ^E */
		DBGFEX(3,DbgFNm,"FAILURE, no ^E arg");
		return FAILURE;
	    }
	    switch (To_Upper(*SStPtr)) {
	        case 'A':	/* ^EA match any alphabetic */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Alpha(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'B':	/* ^EB match any separator (==^S) */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (!Is_Alnum(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'C':	/* ^EC match symbol constitient */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_SyCon(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'D':	/* ^ED match any digit */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Digit(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'G':	/* ^EGq match any char in Q-reg q */
		    if (++SStPtr == SBfPtr) {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE, no ^EG arg");
			return FAILURE;
		    }
		    TCBfPt = CBfPtr;	/* save CBfPtr */
		    TCStEn = CStEnd;	/* save CStEnd */
		    CBfPtr = SStPtr;
		    CStEnd = SBfPtr;
		    Status = FindQR();
		    SStPtr = CBfPtr;
		    SBfPtr = CStEnd;
		    CBfPtr = TCBfPt;	/* restore CBfPtr */
		    CStEnd = TCStEn;	/* restore CStEnd */
		    if (Status == FAILURE) {
		        DBGFEX(3,DbgFNm,"FAILURE, ^EG FindQR failed");
			    return FAILURE;
		    }	
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        QRPtr = QR->Start;
			while (QRPtr < QR->End_P1) {
			    if (*QRPtr++ == *EBPtr1) {
			        goto kludge;
			    }
			}
		    }
kludge:		    break;
		case 'L':	/* ^EL match line terminator */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (IsEOL(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'M':	/* ^EM match multiple next constructs */
		    if (++SStPtr == SBfPtr) {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE, no ^EM arg");
			return FAILURE;
		    }
		    SavSSP = SStPtr;
		    if (BakSrc() == FAILURE) {
		        DBGFEX(3,DbgFNm,"FAILURE");
			return FAILURE;
		    }
		    if (EBPtr1 < EndSAr) {	/* if not found */
		        break;
		    }
		    SavEP2 = EBPtr2;
		    while (EBPtr1 > EndSAr) {
		        EBPtr1--;
			EBPtr2 = EBPtr1;
			SStPtr = SavSSP;
			if (CMatch(&SamChr) == FAILURE) {
			    DBGFEX(3,DbgFNm,"FAILURE");
			    return FAILURE;
			}
			if (!SamChr) {
			    EBPtr1++;
			    EBPtr2 = SavEP2;
			    break;
			}
		    }
		    DBGFEX(3,DbgFNm,"SUCCESS");
		    return SUCCESS;
		case 'R':	/* ^ER match any alphanumeric */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Alnum(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'S':	/* ^ES match any spaces/tabs */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if ((*EBPtr1 == SPACE) || (*EBPtr1 == TABCHR)) {
			    EBPtr2 = EBPtr1;
			    while (EBPtr1 > EndSAr) {
			        EBPtr1--;
				if ((*EBPtr1 != SPACE) &&
				    (*EBPtr1 != TABCHR)) {
				    EBPtr1++;
				    break;
				}
			    }
			    DBGFEX(3,DbgFNm,"SUCCESS");
			    return SUCCESS;
			}
		    }
		    break;
		case 'V':	/* ^EV match any lowercase char */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Lower(*EBPtr1)) {
			    break;
			}
		    }
		    break;
		case 'W':	/* ^EW match any uppercase character */
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (Is_Upper(*EBPtr1)) {
		            break;
			}
		    }
		    break;
		case 'X':	/* ^EX match any char (==^X) */
		    break;
		case '<':	/* ^E<n> match char w/ASCII octal code n */
		    if (++SStPtr == SBfPtr) {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE, no ^E<> arg");
			return FAILURE;
		    }
		    TmpLng = 0;
		    while (Is_Digit(*SStPtr)) {
		        TmpLng = (TmpLng * 8) + (*SStPtr - '0');
			if (TmpLng > 127) {
			    ErrMsg(ERR_ICE);
			    DBGFEX(3,DbgFNm,"FAILURE");
			    return FAILURE;
			}
			if (++SStPtr == SBfPtr) {
			    ErrMsg(ERR_ICE);
			    DBGFEX(3,DbgFNm,"FAILURE");
			    return FAILURE;
			}
		    }
		    if (*SStPtr != '>') {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE");
			return FAILURE;
		    }
		    Charac = (unsigned char)TmpLng;
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
		        if (*EBPtr1 == Charac) {
			    break;
			}
		    }
		    break;
		case '[':	/* ^E[x1,x2,...] match any one of x1,x2,... */
		    if (++SStPtr == SBfPtr) {
		        ErrMsg(ERR_ICE);
			DBGFEX(3,DbgFNm,"FAILURE, no ^E[] arg");
			return FAILURE;
		    }
		    LstBeg = SStPtr;
		    for (; EBPtr1 >= EndSAr; --EBPtr1) {
			while (*SStPtr != ']') {
		            if (*SStPtr == ',') {
			        if (++SStPtr == SBfPtr) {
			            ErrMsg(ERR_ICE);
				    DBGFEX(3,DbgFNm,"FAILURE");
				    return FAILURE;
				}
			    } else {
			        EBPtr2 = EBPtr1;
				if (CMatch(&SamChr) == FAILURE) {
			            DBGFEX(3,DbgFNm,"FAILURE");
				    return FAILURE;
				}
				if (SamChr) {
			            while (*SStPtr != ']') {
				        if (++SStPtr == SBfPtr) {
				            ErrMsg(ERR_ICE);
					    DBGFEX(3,DbgFNm,"FAILURE");
					    return FAILURE;
					}
				    }
				    EBPtr2 = EBPtr1;
				    DBGFEX(3,DbgFNm,"SUCCESS");
				    return SUCCESS;
				}
				if (++SStPtr == SBfPtr) {
			            ErrMsg(ERR_ICE);
				    DBGFEX(3,DbgFNm,"FAILURE");
				    return FAILURE;
				}
			    }
			}
			SStPtr = LstBeg;
		    }
		    break;
		default:
		    ErrMsg(ERR_ICE);
		    DBGFEX(3,DbgFNm,"FAILURE, bad ^E arg");
		    return FAILURE;
	    } /* end of ^E switch */
	    break;
	default:	/* edit buffer char must match search string char */
	    if (SMFlag) {			/* if case dependence */
	        for (; EBPtr1 >= EndSAr; --EBPtr1) {
		    if (*EBPtr1 == *SStPtr) {
		        break;
		    }
		}
	    } else {			/* else case independence */
	        OtCase = Is_Upper(*SStPtr)
		             ? To_Lower(*SStPtr)
			     : To_Upper(*SStPtr);
		for (; EBPtr1 >= EndSAr; --EBPtr1) {
		    if ((*EBPtr1 == *SStPtr) || (*EBPtr1 == OtCase)) {
		        break;
		    }
		}
	    }
    } /* end of switch */
    EBPtr2 = EBPtr1;
    DBGFEX(3,DbgFNm,"SUCCESS");
    return SUCCESS;
}