Exemplo n.º 1
0
static void
propident(char *buffer, int size)
{
  if (lookahead == -1 || !_istupper(lookahead)) 
    parse_error("Expected an upper case letter", 0);
  while (lookahead != -1 && _istalpha(lookahead)) {
    if (_istupper(lookahead) && size > 1) {
      *buffer++ = lookahead;
      size--;
    }
    nexttoken();
  }
  *buffer = '\0';
}
Exemplo n.º 2
0
void ShiftAnd::compile(const String &pattern, bool ignoreCase) {
  m_patternLen = (int)pattern.length();
  if(m_patternLen >= 64) {
    throwException(_T("<%s> too long for shiftand-search. max length is 63"), pattern.cstr());
  }
  memset(m_mask, -1, sizeof(m_mask));
  for(int i = 0; i < m_patternLen; i++) {
    const _TUCHAR ch = pattern[i];
    m_mask[ch] &= ~((UINT64)1 << i);
    if (ignoreCase) {
      if (_istlower(ch)) {
        m_mask[_toupper(ch)] &= ~((UINT64)1 << i);
      } else if(_istupper(ch)) {
        m_mask[_tolower(ch)] &= ~((UINT64)1 << i);
      }
    }
  }
  m_s = (UINT64)1 << m_patternLen;
#ifdef _TEST_CLASS
  for(int i = 0; i < ARRAYSIZE(m_mask); i++) {
    const UINT64 mask = m_mask[i];
    if(mask != -1) {
      _tprintf(_T("mask[%c]:%s\n"), i, sprintbin(mask).cstr());
    }
  }
#endif
}
int GetSliderIni( LPCTSTR lpszTargetPath )
{
	TCHAR lpszExeName[ MAX_PATH * 2 ];
	TCHAR lpszExeNameLower[ MAX_PATH * 2 ];

	if( lpszTargetPath == NULL ) return 33;

	const int len = lstrlen( lpszTargetPath );
	int start = 0;
	int i;
	for( i = len - 1; i >= 0; i-- )
	{
		if( lpszTargetPath[ i ] == TEXT( '\\' ) )
		{
			start = i + 1;
			break;
		}
	}

	lstrcpy( lpszExeName, &lpszTargetPath[ start ] );
#if !defined( _UNICODE )
	if( lstrlen( lpszExeName ) >= 19 )
	{
		lpszExeName[ 15 ] = '\0';
		PathToExeEx( lpszExeName, MAX_PATH * 2 );
	}
#endif
	const int len2 = lstrlen( lpszExeName );
	for( i = 0; i < len2; i++ )
	{
		TCHAR c = lpszExeName[ i ];
		if( _istascii( c ) && _istupper( c ) )
		{
			lpszExeNameLower[ i ] = (TCHAR) _totlower( c );
		}
		else
		{
			lpszExeNameLower[ i ] = c;
		}
	}
	lpszExeNameLower[ i ] = TEXT( '\0' );

	TCHAR lpszPath[ MAX_PATH * 2 ];
	GetIniPath( lpszPath );


	// to flushes the cache --- Just in case!
	WritePrivateProfileString(
		NULL,
		NULL,
		NULL,
		lpszPath
	);

	int iSlider = GetPrivateProfileInt( TEXT( "Slider" ), lpszExeNameLower, 33, lpszPath );
	if( iSlider < 0 || iSlider > 99 ) iSlider = 33;
	else if( iSlider == 0 ) iSlider = 1; // for backword compat.
	return iSlider;
}
Exemplo n.º 4
0
static void
node(SGFNodeP n)
{
  SGFPropertyP last = NULL;
  match(';');
  while (lookahead != -1 && _istupper(lookahead))
    last = property(n, last);
}
Exemplo n.º 5
0
ULONG striHash(const TCHAR * const &s) {
  ULONG result = 0;
  for(const _TUCHAR *cp = (const _TUCHAR*)s; *cp; cp++) {
    const _TUCHAR ch = _istupper(*cp) ? _totlower(*cp) : *cp;
    result = (result * 117) ^ ch;
  }
  return result;
}
LPTSTR strToLower(LPTSTR dest, LPCTSTR src)
{
	LPTSTR start = dest;

	while (*dest = *src) {
		if (_istupper(*dest))
			*dest = _tolower(*dest);
		dest++;
		src++;
	}

	return start;
}
Exemplo n.º 7
0
TCHAR * StrLower(TCHAR *pStr)
{
	TCHAR *ret = pStr;

	while (*pStr)
	{
		if (_istupper(*pStr))
			*pStr = _totlower(*pStr);
		pStr++;
	}

	return ret;
}
Exemplo n.º 8
0
size_t KString::AlphabetToValue(TCHAR cChar)
{
	if(_istdigit(cChar))
		return cChar - TEXT('0');

	if(_istupper(cChar))
		return cChar - TEXT('A') + 10;

	if(_istlower(cChar))
		return cChar - TEXT('a') + (10 + 26);

	return UINT_MAX;
}
Exemplo n.º 9
0
TCHAR * StrLower(TCHAR * str)
{
	TCHAR *ret = str;

	while (*str)
	{
		if (_istupper(*str))
		{
			*str = _totlower(*str);
		}
		str++;
	}
	return ret;
}
BOOL SetSliderIni( LPCTSTR lpszString, const int iSlider )
{
	if( iSlider <= 0 || iSlider > 99 || lstrlen( lpszString ) > 1000 ) return FALSE;

	WriteDebugLog( TEXT( "SetSliderIni" ) );
	WriteDebugLog( lpszString );


	TCHAR lpszExeName[ MAX_PATH * 2 ] = _T( "" );
/* - 1.1b7
	int len = lstrlen( lpszTarget );
	int start = -1;
	int end = -1;
	for( int i = len - 1; i >= 5; i-- )
	{
		if(
			lpszTarget[ i ] == TEXT( ' ' ) &&
			( lpszTarget[ i - 1 ] == TEXT( 'e' ) || lpszTarget[ i - 1 ] == TEXT( 'E' ) ) &&
			( lpszTarget[ i - 2 ] == TEXT( 'x' ) || lpszTarget[ i - 2 ] == TEXT( 'X' ) ) &&
			( lpszTarget[ i - 3 ] == TEXT( 'e' ) || lpszTarget[ i - 3 ] == TEXT( 'E' ) ) &&
			lpszTarget[ i - 4 ] == TEXT( '.' )
		)
		{
			end = i;
			break;
		}
	}

	for( ; i >=0; i-- )
	{
		if( lpszTarget[ i ] == TEXT( '\\' ) )
		{
			start = i + 1;
			break;
		}
	}

	if( start == -1 ) start = 0;

	if( end == -1 || end - start <= 0 )
	{
		TCHAR dbg[1000];
		wsprintf( dbg, TEXT("DEBUG: %s %d %d %d"), lpszTarget, start, end, end-start );
		WriteDebugLog( dbg ) ;

		return FALSE;
	}



	lstrcpy( lpszExeName, &lpszTarget[ start ] );
	lpszExeName[ end - start ] = TEXT( '\0' );
*/
// +1.1b7
	PathToExe( lpszString, lpszExeName, MAX_PATH * 2 );


#if !defined( _UNICODE )
	if( lstrlen( lpszExeName ) >= 19 )
	{
		lpszExeName[ 15 ] = '\0';
		PathToExeEx( lpszExeName, MAX_PATH * 2 );
	}
#endif


	TCHAR lpszExeNameLower[ MAX_PATH * 2 ] = _TEXT( "" );
	int len = lstrlen( lpszExeName );
	for( int i = 0; i < len; i++ )
	{
		TCHAR c = lpszExeName[ i ];
		if( _istascii( c ) && _istupper( c ) )
		{
			lpszExeNameLower[ i ] = (TCHAR) _totlower( c );
		}
		else
		{
			lpszExeNameLower[ i ] = c;
		}
	}
	//lpszExeNameLower[ i ] = TEXT( '\0' );



	TCHAR lpszPath[ MAX_PATH * 2 ];
	GetIniPath( lpszPath );

	TCHAR tmpstr[ 100 ];
	wsprintf( tmpstr, TEXT( "%d" ), iSlider );


	WritePrivateProfileString(
		TEXT( "Slider" ), 
		lpszExeNameLower,
		tmpstr,
		lpszPath
	);

	// to flushes the cache
	WritePrivateProfileString(
		NULL,
		NULL,
		NULL,
		lpszPath
	);

	return TRUE;
}
Exemplo n.º 11
0
int isupper( int c ) { return _istupper(c); }
Exemplo n.º 12
0
bool Character::IsCapitalLetter(TCHAR character)
{
	return (_istupper(character) != 0) ? true : false;
}
Exemplo n.º 13
0
/**
 * @brief Compare two buffers byte per byte.
 *
 * This function compares two buffers pointed to by @p ptr0 and @p ptr1.
 * Comparing takes account diffutils options flags given to constructor.
 * Buffer pointers are advanced while comparing so they point to current
 * compare position. End of buffers are given by @p end0 and @p end1, which
 * may point past last valid byte in file. Offset-params tell is how far this
 * buffer is into the file (ie, 0 the first time called).
 * @param [in,out] stats0 Statistics for first side.
 * @param [in,out] stats1 Statistics for second side.
 * @param [in,out] ptr0 Pointer to begin of the first buffer.
 * @param [in,out] ptr1 Pointer to begin of the second buffer.
 * @param [in] end0 Pointer to end of the first buffer.
 * @param [in] end1 Pointer to end of the second buffer.
 * @param [in] eof0 Is first buffers end also end of the file?
 * @param [in] eof1 Is second buffers end also end of the file?
 * @param [in] offset0 Offset of the buffer begin in the first file.
 * @param [in] offset1 Offset of the buffer begin in the second file.
 * @return COMP_RESULT telling result of the compare.
 */
ByteComparator::COMP_RESULT ByteComparator::CompareBuffers(
	FileTextStats & stats0, FileTextStats & stats1, const char* &ptr0, const char* &ptr1,
	const char* end0, const char* end1, bool eof0, bool eof1, int64_t offset0, int64_t offset1)
{
	ByteComparator::COMP_RESULT result = RESULT_SAME;

	// First, update file text statistics by doing a full scan
	// for 0s and all types of line delimiters
	TextScan(stats0, ptr0, end0, eof0, m_cr0, offset0);
	TextScan(stats1, ptr1, end1, eof1, m_cr1, offset1);

	const char *orig0 = ptr0;
	const char *orig1 = ptr1;

	// cycle through buffer data performing actual comparison
	while (true)
	{
		if (m_ignore_all_space)
		{
			// Skip over any whitespace on either side
			// skip over all whitespace
			while (ptr0 < end0 && iswsch(*ptr0))
			{
				m_bol0 = false;
				++ptr0;
			}
			// skip over all whitespace
			while (ptr1 < end1 && iswsch(*ptr1))
			{
				m_bol1 = false;
				++ptr1;
			}
			if ((ptr0 == end0 && !eof0) || (ptr1 == end1 && !eof1))
			{
				goto need_more;
			}
		}
		if (m_ignore_space_change)
		{
			// Skip over whitespace change
			// Also skip whitespace on one side if
			//  either end of line or end of file on other

			// Handle case of whitespace on side0
			// (First four cases)
			if (ptr0 < end0 && iswsch(*ptr0))
			{
				// Whitespace on side0

				if (ptr1 < end1)
				{
					if (iswsch(*ptr1))
					{
						// whitespace on both sides
						m_wsflag = true;
						m_bol0 = false;
						++ptr0;
						m_bol1 = false;
						++ptr1;
					}
					else if (iseolch(*ptr1))
					{
						// whitespace on side 0 (end of line on side 1)
						m_wsflag = true;
						m_bol0 = false;
						++ptr0;
					}
				}
				else // ptr1 == end1
				{
					if (!eof1)
					{
						// Whitespace on side0, don't know what is on side1
						// Cannot tell if matching whitespace yet
						goto need_more;
					}
					else // eof1
					{
						// Whitespace on side0, eof on side1
						m_wsflag = true;
						m_bol0 = false;
						++ptr0;
					}
				}
			}
			else
			{
				// Handle case of whitespace on side1
				// but not whitespace on side0 (that was handled above)
				// (Remaining three cases)
				if (ptr1 < end1 && iswsch(*ptr1))
				{
					// Whitespace on side1

					if (ptr0 < end0)
					{
						// "whitespace on both sides"
						// should not come here, it should have been
						// handled above
						assert(!iswsch(*ptr0));

						if (iseolch(*ptr0))
						{
							// whitespace on side 1 (eol on side 0)
							m_wsflag = true;
							m_bol1 = false;
							++ptr1;
						}
					}
					else // ptr0 == end0
					{
						if (!eof0)
						{
							// Whitespace on side1, don't know what is on side0
							// Cannot tell if matching whitespace yet
							goto need_more;
						}
						else // eof0
						{
							// Whitespace on side1, eof on side0
							m_wsflag = true;
							m_bol1 = false;
							++ptr1;
						}
					}
				}
			}

			if (m_wsflag)
			{
				// skip over consecutive whitespace
				while (ptr0 < end0 && iswsch(*ptr0))
				{
					m_bol0 = false;
					++ptr0;
				}
				// skip over consecutive whitespace
				while (ptr1 < end1 && iswsch(*ptr1))
				{
					m_bol1 = false;
					++ptr1;
				}
				if ((ptr0 == end0 && !eof0) || (ptr1 == end1 && !eof1))
				{
					// if run out of buffer on either side
					// must fetch more, to continue skipping whitespace
					m_wsflag = true;
					goto need_more;
				}
			}
			m_wsflag = false;
		}
		if (m_ignore_eol_diff)
		{
			if (m_ignore_blank_lines)
			{
				// skip over any line delimiters on either side
				while (ptr0 < end0 && iseolch(*ptr0))
				{
					// m_bol0 not used because m_ignore_eol_diff
					++ptr0;
				}
				while (ptr1 < end1 && iseolch(*ptr1))
				{
					// m_bol1 not used because m_ignore_eol_diff
					++ptr1;
				}
				if ((ptr0 == end0 && !eof0) || (ptr1 == end1 && !eof1))
				{
					goto need_more;
				}
			}
			else // don't skip blank lines, but still ignore eol difference
			{
				HandleSide0Eol((char **) &ptr0, end0, eof0);
				HandleSide1Eol((char **) &ptr1, end1, eof1);

				if (m_cr0 || m_cr1)
				{
					// these flags mean possible split CR/LF
					goto need_more;
				}
				if (m_eol0 || m_eol1)
				{
					if ((!m_eol0 || !m_eol1) && (orig0 == end0 || orig1 == end1))
					{
						// one side had an end-of-line, but the other didn't
						return RESULT_DIFF;
					}
					if (ptr0 != end0 && ptr1 != end1)
						// This continue statement is needed to handle blank lines
						continue;
				}
			}
		}
		else
		{ // do not ignore eol differences
			if (m_ignore_blank_lines)
			{
				if (m_bol0)
				{
					while (ptr0 < end0 && iseolch(*ptr0))
					{
						++ptr0;
					}
				}
				if (m_bol1)
				{
					while (ptr1 < end1 && iseolch(*ptr1))
					{
						++ptr1;
					}
				}
				if ((ptr0 == end0 && !eof0) || (ptr1 == end1 && !eof1))
				{
					goto need_more;
				}
			}
		}

		if (ptr0 == end0 || ptr1 == end1)
		{
			if (ptr0 == end0 && ptr1 == end1)
			{
				if (!eof0 || !eof1)
					goto need_more;
				else
					return RESULT_SAME;
			}
			else
			{
				// we are at the end on one side?
				if ((!(ptr0 == end0 && eof0) && !(ptr1 == end1 && eof1)) && (orig0 != end0 && orig1 != end1))
				{
					goto need_more;
				}
				else
					return RESULT_DIFF;
			}
		}

		TCHAR c0 = *ptr0, c1 = *ptr1;
		if (m_ignore_case)
		{
			c0 = _istupper(c0) ? _totlower(c0) : c0;
			c1 = _istupper(c1) ? _totlower(c1) : c1;
		}
		if (c0 != c1)
			return RESULT_DIFF; // buffers are different
		if (ptr0 < end0 && ptr1 < end1)
		{
			m_bol0 = iseolch(c0);
			m_bol1 = iseolch(c1);
			++ptr0;
			++ptr1;
			continue;
		}
		goto need_more;
	}

need_more:
	if (ptr0 - 1 >= orig0 && *(ptr0 - 1) == '\r')
		m_cr0 = true;
	else
		m_cr0 = false;
	if (ptr1 - 1 >= orig1 && *(ptr1 - 1) == '\r')
		m_cr1 = true;
	else
		m_cr1 = false;
	if (ptr0 == end0 && !eof0)
	{
		if (ptr1 == end1 && !eof1)
			return NEED_MORE_BOTH;
		else
			return NEED_MORE_0;
	}
	else if (ptr1 == end1 && !eof1)
	{
		return NEED_MORE_1;
	}
	else
	{
		return result;
	}
}