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 // revert to the user locale
setlocale( LC_NUMERIC, m_user_locale.c_str() ); setlocale( LC_NUMERIC, m_user_locale.c_str() );
#if defined( _WIN32 ) && defined( DEBUG ) #if defined( _WIN32 ) && defined( DEBUG )
// Enaable wxWidgets alerts // Enable wxWidgets alerts
wxSetDefaultAssertHandler(); wxSetDefaultAssertHandler();
#endif #endif
} }
@ -171,6 +171,7 @@ void SelectReferenceNumber( wxTextEntry* aTextEntry )
{ {
if( !isdigit( num.Last() ) ) if( !isdigit( num.Last() ) )
num.RemoveLast(); num.RemoveLast();
if( !isdigit( num.GetChar ( 0 ) ) ) if( !isdigit( num.GetChar ( 0 ) ) )
num = num.Right( num.Length() - 1); num = num.Right( num.Length() - 1);
} }
@ -327,10 +328,12 @@ wxString KIwxExpandEnvVars(const wxString& str)
wxString strResult; 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]; wxUniChar str_n = str[n];
switch ( str_n.GetValue() ) { switch( str_n.GetValue() )
{
#ifdef __WINDOWS__ #ifdef __WINDOWS__
case wxT( '%' ): case wxT( '%' ):
#endif // __WINDOWS__ #endif // __WINDOWS__
@ -342,11 +345,14 @@ wxString KIwxExpandEnvVars(const wxString& str)
bracket = Bracket_Windows; bracket = Bracket_Windows;
else else
#endif // __WINDOWS__ #endif // __WINDOWS__
if ( n == strlen - 1 ) { if( n == strlen - 1 )
{
bracket = Bracket_None; bracket = Bracket_None;
} }
else { else
switch ( str[n + 1].GetValue() ) { {
switch( str[n + 1].GetValue() )
{
case wxT( '(' ): case wxT( '(' ):
bracket = Bracket_Normal; bracket = Bracket_Normal;
str_n = str[++n]; // skip the bracket str_n = str[++n]; // skip the bracket
@ -377,6 +383,7 @@ wxString KIwxExpandEnvVars(const wxString& str)
// set through wxSetEnv may not be read correctly! // set through wxSetEnv may not be read correctly!
bool expanded = false; bool expanded = false;
wxString tmp; wxString tmp;
if( wxGetEnv( strVarName, &tmp ) ) if( wxGetEnv( strVarName, &tmp ) )
{ {
strResult += tmp; strResult += tmp;
@ -391,27 +398,33 @@ wxString KIwxExpandEnvVars(const wxString& str)
#endif #endif
if ( bracket != Bracket_None ) if ( bracket != Bracket_None )
strResult << str[n - 1]; strResult << str[n - 1];
strResult << str_n << strVarName; strResult << str_n << strVarName;
} }
// check the closing bracket // check the closing bracket
if ( bracket != Bracket_None ) { if( bracket != Bracket_None )
if ( m == strlen || str_m != (wxChar)bracket ) { {
if( m == strlen || str_m != (wxChar)bracket )
{
// under MSW it's common to have '%' characters in the registry // under MSW it's common to have '%' characters in the registry
// and it's annoying to have warnings about them each time, so // 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 // under Unix, OTOH, this warning could be useful for the user to
// understand why isn't the variable expanded as intended // understand why isn't the variable expanded as intended
#ifndef __WINDOWS__ #ifndef __WINDOWS__
wxLogWarning(_("Environment variables expansion failed: missing '%c' at position %u in '%s'."), wxLogWarning( _( "Environment variables expansion failed: missing '%c' "
"at position %u in '%s'." ),
(char)bracket, (unsigned int) (m + 1), str.c_str() ); (char)bracket, (unsigned int) (m + 1), str.c_str() );
#endif // __WINDOWS__ #endif // __WINDOWS__
} }
else { else
{
// skip closing bracket unless the variables wasn't expanded // skip closing bracket unless the variables wasn't expanded
if( !expanded ) if( !expanded )
strResult << (wxChar)bracket; strResult << (wxChar)bracket;
str_m = str[++m]; str_m = str[++m];
} }
} }
@ -423,7 +436,8 @@ wxString KIwxExpandEnvVars(const wxString& str)
case wxT( '\\' ): case wxT( '\\' ):
// backslash can be used to suppress special meaning of % and $ // 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]; str_n = str[++n];
strResult += str_n; strResult += str_n;
@ -449,8 +463,7 @@ const wxString ExpandEnvVarSubstitutions( const wxString& aString )
MUTLOCK lock( getenv_mutex ); MUTLOCK lock( getenv_mutex );
// We reserve the right to do this another way, by providing our own member // We reserve the right to do this another way, by providing our own member function.
// function.
return KIwxExpandEnvVars( aString ); return KIwxExpandEnvVars( aString );
} }
@ -459,6 +472,7 @@ const wxString ResolveUriByEnvVars( const wxString& aUri )
{ {
// URL-like URI: return as is. // URL-like URI: return as is.
wxURL url( aUri ); wxURL url( aUri );
if( url.GetError() == wxURL_NOERR ) if( url.GetError() == wxURL_NOERR )
return aUri; return aUri;
@ -531,7 +545,7 @@ wxString GetOSXKicadUserDataDir()
// Since appname is different if started via launcher or standalone binary // Since appname is different if started via launcher or standalone binary
// map all to "kicad" here // map all to "kicad" here
udir.RemoveLastDir(); udir.RemoveLastDir();
udir.AppendDir( wxT( "kicad" ) ); udir.AppendDir( "kicad" );
return udir.GetPath(); return udir.GetPath();
} }
@ -568,6 +582,7 @@ wxString GetOSXKicadDataDir()
} }
#endif #endif
// add this only if it is not in wxWidgets (for instance before 3.1.0) // add this only if it is not in wxWidgets (for instance before 3.1.0)
#ifdef USE_KICAD_WXSTRING_HASH #ifdef USE_KICAD_WXSTRING_HASH
size_t std::hash<wxString>::operator()( const wxString& s ) const 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. * Performance enhancements to file and directory operations.
* *
* Note: while it's annoying to have to make copies of wxWidgets stuff and then * 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. * SIGNIFICANT performance benefits.
*/ */
@ -702,6 +717,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
else if( *m == '?' ) else if( *m == '?' )
{ {
m++; m++;
if( !*n++ ) if( !*n++ )
return false; return false;
} }
@ -710,6 +726,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
if( *m == '\\' ) if( *m == '\\' )
{ {
m++; m++;
/* Quoting "nothing" is a bad thing */ /* Quoting "nothing" is a bad thing */
if( !*m ) if( !*m )
return false; return false;
@ -723,11 +740,14 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
*/ */
if( !*n ) if( !*n )
return true; return true;
if( just ) if( just )
return true; return true;
just = 0; just = 0;
goto not_matched; goto not_matched;
} }
/* /*
* We could check for *n == NULL at this point, but * We could check for *n == NULL at this point, but
* since it's more common to have a character there, * since it's more common to have a character there,
@ -736,6 +756,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
* the NULL of n * the NULL of n
*/ */
just = 0; just = 0;
if( *m == *n ) if( *m == *n )
{ {
m++; m++;
@ -744,7 +765,6 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
} }
else else
{ {
not_matched: not_matched:
/* /*
@ -782,6 +802,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
// This is the offset between FILETIME epoch and the Unix/wxDateTime Epoch. // This is the offset between FILETIME epoch and the Unix/wxDateTime Epoch.
static wxInt64 EPOCH_OFFSET_IN_MSEC = wxLL(11644473600000); 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 );
@ -877,5 +898,3 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
return timestamp; return timestamp;
} }