Пример #1
0
// remove whitespace from start and end of a string
//
void strip_whitespace(wxChar *str) {
    size_t n;
    while (1) {
        if (!str[0]) break;
        if (!_istascii(str[0])) break;
        if (!_istspace(str[0])) break;
        strcpy_overlap(str, str+1);
    }
    while (1) {
        n = _tcslen(str);
        if (n == 0) break;
        if (!_istascii(str[n-1])) break;
        if (!_istspace(str[n-1])) break;
        str[n-1] = 0;
    }
}
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;
}
Пример #3
0
String firstLetterToUpperCase(const String &str) { // Return a copy of str, with first non-space letter changed to uppercase.
  String  result(str);
  _TUCHAR *s;
  for(s = (_TUCHAR*)result.cstr(); _istspace(*s); s++);
  if(_istascii(*s) && _istlower(*s)) {
    *s = _totupper(*s);
  }
  return result;
}
Пример #4
0
ZIP_API bool ZipArchiveLib::IsStringAscii(const CZipString& value)
{
	for (int i = 0; i < value.GetLength(); i++)
#if !defined __GNUC__ || defined __MINGW32__
		if (!_istascii(value[i]))
#else
		if (!isascii(value[i]))
#endif
			return false;
	return true;
}
Пример #5
0
/**
 * @brief Convert string to integer.
 * @param [in] str String to convert.
 * @param [out] val Converted integer.
 * @return true if conversion succeeded, false otherwise.
 */
static bool GetAsInt(LPCTSTR str, int & val)
{
	if (str == NULL)
		return false;
	const size_t len = _tcslen(str);
	if (len == 0)
		return false;

	for (int i = 0; i < len; ++i)
	{
		if (!_istascii(str[i]) || !_istdigit(str[i]))
			return false;
	}
	val = _ttoi(str);
	return true;
}
Пример #6
0
bool CCmd_Password::PrepPassword( CString &pwd )
{
    bool bOk = true;

	pwd.TrimLeft();
	pwd.TrimRight();

    // Don't allow non-ascii
    // for MBCS, we look at lead and trail bytes here, not characters,
    // but that's ok since the lead byte will be non-ascii and we'll be done
    for(int i = 0; bOk && i < pwd.GetLength(); i++)
	{
        if(!_istascii(pwd.GetAt(i)))
		{
		    bOk = false;
			break;
		}
	}
    return bOk;
}
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;
}
Пример #8
0
void LoadSettings()
{
	HKEY hkey;
	LONG value;
	ULONG len;
	TCHAR *hugechar = malloc(4096);
	TCHAR *hptr = hugechar;

	if(hugechar == 0)
		return;

	ZeroMemory(hugechar, 4096);

	RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Catch22\\Matrix Screen Saver"), 0,
		_T(""), 0, KEY_READ, NULL, &hkey, NULL);

	len = sizeof value;
	if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("MessageSpeed"), 0, 0, (BYTE *)&value, &len))
	{
		if(value >= MSGSPEED_MIN && value <= MSGSPEED_MAX)
			g_nMessageSpeed = value;
	}

	if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("MatrixSpeed"),  0, 0, (BYTE *)&value, &len))
	{
		if(value >= SPEED_MIN && value <= SPEED_MAX)
			g_nMatrixSpeed  = value;
	}

	if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("Density"),      0, 0, (BYTE *)&value, &len))
	{
		if(value >= DENSITY_MIN && value <= DENSITY_MAX)
			g_nDensity      = value;
	}

	if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("FontSize"),      0, 0, (BYTE *)&value, &len))
	{
		if(value >= FONT_MIN && value <= FONT_MAX)
			g_nFontSize	 = value;
	}

	if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("FontBold"),      0, 0, (BYTE *)&value, &len))
		g_fFontBold = (value == 0 ? FALSE : TRUE);

	if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("Randomize"),      0, 0, (BYTE *)&value, &len))
		g_fRandomizeMessages = (value == 0 ? FALSE : TRUE);

	len = 512;
	if(RegQueryValueEx(hkey, _T("FontName"),  0, 0, (BYTE *)g_szFontName, &len) != ERROR_SUCCESS)
		lstrcpy(g_szFontName, _T("Arial"));

	len = 4096;

	if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("Messages"),      0, 0 , (BYTE *)hugechar, &len))
	{
		while(len > 0 && *hptr && _istascii(*hptr))
		{
			if(lstrlen(hptr) > 0)
			{
				lstrcpyn(g_szMessages[g_nNumMessages], hptr, MAXMSG_LENGTH);
				++g_nNumMessages;
				hptr += lstrlen(hptr) + 1;
			}
		}
	}
	else
	{
		/* built-in coded message for first run */
		lstrcpyn(g_szMessages[0], _T("ReactOS"), MAXMSG_LENGTH);
		++g_nNumMessages;
	}

	RegCloseKey(hkey);
	free(hugechar);
}