Coding policy fixes in common/common.cpp.

This commit is contained in:
Wayne Stambaugh 2019-01-15 12:23:26 -05:00
parent 72c885797e
commit 47492f9452
1 changed files with 74 additions and 55 deletions

View File

@ -104,7 +104,7 @@ LOCALE_IO::~LOCALE_IO()
// revert to the user locale
setlocale( LC_NUMERIC, m_user_locale.c_str() );
#if defined( _WIN32 ) && defined( DEBUG )
// Enaable wxWidgets alerts
// Enable wxWidgets alerts
wxSetDefaultAssertHandler();
#endif
}
@ -171,6 +171,7 @@ void SelectReferenceNumber( wxTextEntry* aTextEntry )
{
if( !isdigit( num.Last() ) )
num.RemoveLast();
if( !isdigit( num.GetChar ( 0 ) ) )
num = num.Right( num.Length() - 1);
}
@ -325,34 +326,39 @@ wxString KIwxExpandEnvVars(const wxString& str)
size_t strlen = str.length();
wxString strResult;
strResult.Alloc(strlen);
strResult.Alloc( strlen );
for ( size_t n = 0; n < strlen; n++ ) {
for( size_t n = 0; n < strlen; n++ )
{
wxUniChar str_n = str[n];
switch ( str_n.GetValue() ) {
switch( str_n.GetValue() )
{
#ifdef __WINDOWS__
case wxT('%'):
case wxT( '%' ):
#endif // __WINDOWS__
case wxT('$'):
case wxT( '$' ):
{
Bracket bracket;
#ifdef __WINDOWS__
if ( str_n == wxT('%') )
if( str_n == wxT( '%' ) )
bracket = Bracket_Windows;
else
#endif // __WINDOWS__
if ( n == strlen - 1 ) {
if( n == strlen - 1 )
{
bracket = Bracket_None;
}
else {
switch ( str[n + 1].GetValue() ) {
case wxT('('):
else
{
switch( str[n + 1].GetValue() )
{
case wxT( '(' ):
bracket = Bracket_Normal;
str_n = str[++n]; // skip the bracket
break;
case wxT('{'):
case wxT( '{' ):
bracket = Bracket_Curly;
str_n = str[++n]; // skip the bracket
break;
@ -365,10 +371,10 @@ wxString KIwxExpandEnvVars(const wxString& str)
size_t m = n + 1;
wxUniChar str_m = str[m];
while ( m < strlen && (wxIsalnum(str_m) || str_m == wxT('_')) )
while( m < strlen && ( wxIsalnum( str_m ) || str_m == wxT( '_' ) ) )
str_m = str[++m];
wxString strVarName(str.c_str() + n + 1, m - n - 1);
wxString strVarName( str.c_str() + n + 1, m - n - 1 );
#ifdef __WXWINCE__
const bool expanded = false;
@ -377,7 +383,8 @@ wxString KIwxExpandEnvVars(const wxString& str)
// set through wxSetEnv may not be read correctly!
bool expanded = false;
wxString tmp;
if (wxGetEnv(strVarName, &tmp))
if( wxGetEnv( strVarName, &tmp ) )
{
strResult += tmp;
expanded = true;
@ -391,27 +398,33 @@ wxString KIwxExpandEnvVars(const wxString& str)
#endif
if ( bracket != Bracket_None )
strResult << str[n - 1];
strResult << str_n << strVarName;
}
// check the closing bracket
if ( bracket != Bracket_None ) {
if ( m == strlen || str_m != (wxChar)bracket ) {
if( bracket != Bracket_None )
{
if( m == strlen || str_m != (wxChar)bracket )
{
// under MSW it's common to have '%' characters in the registry
// and it's annoying to have warnings about them each time, so
// ignroe them silently if they are not used for env vars
// ignore them silently if they are not used for env vars
//
// under Unix, OTOH, this warning could be useful for the user to
// understand why isn't the variable expanded as intended
#ifndef __WINDOWS__
wxLogWarning(_("Environment variables expansion failed: missing '%c' at position %u in '%s'."),
(char)bracket, (unsigned int) (m + 1), str.c_str());
wxLogWarning( _( "Environment variables expansion failed: missing '%c' "
"at position %u in '%s'." ),
(char)bracket, (unsigned int) (m + 1), str.c_str() );
#endif // __WINDOWS__
}
else {
else
{
// skip closing bracket unless the variables wasn't expanded
if ( !expanded )
if( !expanded )
strResult << (wxChar)bracket;
str_m = str[++m];
}
}
@ -421,9 +434,10 @@ wxString KIwxExpandEnvVars(const wxString& str)
}
break;
case wxT('\\'):
case wxT( '\\' ):
// backslash can be used to suppress special meaning of % and $
if ( n != strlen - 1 && (str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) {
if( n != strlen - 1 && (str[n + 1] == wxT( '%' ) || str[n + 1] == wxT( '$' )) )
{
str_n = str[++n];
strResult += str_n;
@ -449,8 +463,7 @@ const wxString ExpandEnvVarSubstitutions( const wxString& aString )
MUTLOCK lock( getenv_mutex );
// We reserve the right to do this another way, by providing our own member
// function.
// We reserve the right to do this another way, by providing our own member function.
return KIwxExpandEnvVars( aString );
}
@ -459,6 +472,7 @@ const wxString ResolveUriByEnvVars( const wxString& aUri )
{
// URL-like URI: return as is.
wxURL url( aUri );
if( url.GetError() == wxURL_NOERR )
return aUri;
@ -531,7 +545,7 @@ wxString GetOSXKicadUserDataDir()
// Since appname is different if started via launcher or standalone binary
// map all to "kicad" here
udir.RemoveLastDir();
udir.AppendDir( wxT( "kicad" ) );
udir.AppendDir( "kicad" );
return udir.GetPath();
}
@ -568,6 +582,7 @@ wxString GetOSXKicadDataDir()
}
#endif
// add this only if it is not in wxWidgets (for instance before 3.1.0)
#ifdef USE_KICAD_WXSTRING_HASH
size_t std::hash<wxString>::operator()( const wxString& s ) const
@ -592,7 +607,7 @@ bool std::less<wxPoint>::operator()( const wxPoint& aA, const wxPoint& aB ) cons
* Performance enhancements to file and directory operations.
*
* Note: while it's annoying to have to make copies of wxWidgets stuff and then
* add platform-specific performance optimizations, the following routies offer
* add platform-specific performance optimizations, the following routines offer
* SIGNIFICANT performance benefits.
*/
@ -669,7 +684,7 @@ long long WX_FILENAME::GetTimestamp()
*/
bool matchWild( const char* pat, const char* text, bool dot_special )
{
if ( !*text )
if( !*text )
{
/* Match if both are empty. */
return !*pat;
@ -683,51 +698,56 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
acount = 0,
count = 0;
if (dot_special && (*n == '.'))
if( dot_special && (*n == '.') )
{
/* Never match so that hidden Unix files
* are never found. */
return false;
}
for (;;)
for(;;)
{
if (*m == '*')
if( *m == '*' )
{
ma = ++m;
na = n;
just = 1;
acount = count;
}
else if (*m == '?')
else if( *m == '?' )
{
m++;
if (!*n++)
if( !*n++ )
return false;
}
else
{
if (*m == '\\')
if( *m == '\\' )
{
m++;
/* Quoting "nothing" is a bad thing */
if (!*m)
if( !*m )
return false;
}
if (!*m)
if( !*m )
{
/*
* If we are out of both strings or we just
* saw a wildcard, then we can say we have a
* match
*/
if (!*n)
if( !*n )
return true;
if (just)
if( just )
return true;
just = 0;
goto not_matched;
}
/*
* We could check for *n == NULL at this point, but
* since it's more common to have a character there,
@ -736,7 +756,8 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
* the NULL of n
*/
just = 0;
if (*m == *n)
if( *m == *n )
{
m++;
count++;
@ -744,19 +765,18 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
}
else
{
not_matched:
/*
* If there are no more characters in the
* string, but we still need to find another
* character (*m != NULL), then it will be
* impossible to match it
*/
if (!*n)
* If there are no more characters in the
* string, but we still need to find another
* character (*m != NULL), then it will be
* impossible to match it
*/
if( !*n )
return false;
if (ma)
if( ma )
{
m = ma;
n = ++na;
@ -782,13 +802,14 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
// This is the offset between FILETIME epoch and the Unix/wxDateTime Epoch.
static wxInt64 EPOCH_OFFSET_IN_MSEC = wxLL(11644473600000);
static void ConvertFileTimeToWx(wxDateTime *dt, const FILETIME &ft)
static void ConvertFileTimeToWx( wxDateTime *dt, const FILETIME &ft )
{
wxLongLong t(ft.dwHighDateTime, ft.dwLowDateTime);
wxLongLong t( ft.dwHighDateTime, ft.dwLowDateTime );
t /= 10000; // Convert hundreds of nanoseconds to milliseconds.
t -= EPOCH_OFFSET_IN_MSEC;
*dt = wxDateTime(t);
*dt = wxDateTime( t );
}
#endif // wxUSE_DATETIME && __WIN32__
@ -807,7 +828,7 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
{
long long timestamp = 0;
#if defined(__WIN32__)
#if defined( __WIN32__ )
// Win32 version.
// Save time by not searching for each path twice: once in wxDir.GetNext() and once in
// wxFileName.GetModificationTime(). Also cuts out wxWidgets' string-matching and case
@ -828,7 +849,7 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
ConvertFileTimeToWx( &lastModDate, findData.ftLastWriteTime );
timestamp += lastModDate.GetValue().GetValue();
}
while ( FindNextFile( fileHandle, &findData ) != 0);
while ( FindNextFile( fileHandle, &findData ) != 0 );
}
FindClose( fileHandle );
@ -877,5 +898,3 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
return timestamp;
}