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);
}
@ -327,10 +328,12 @@ wxString KIwxExpandEnvVars(const wxString& str)
wxString strResult;
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( '%' ):
#endif // __WINDOWS__
@ -342,11 +345,14 @@ wxString KIwxExpandEnvVars(const wxString& str)
bracket = Bracket_Windows;
else
#endif // __WINDOWS__
if ( n == strlen - 1 ) {
if( n == strlen - 1 )
{
bracket = Bracket_None;
}
else {
switch ( str[n + 1].GetValue() ) {
else
{
switch( str[n + 1].GetValue() )
{
case wxT( '(' ):
bracket = Bracket_Normal;
str_n = str[++n]; // skip the bracket
@ -377,6 +383,7 @@ wxString KIwxExpandEnvVars(const wxString& str)
// set through wxSetEnv may not be read correctly!
bool expanded = false;
wxString tmp;
if( wxGetEnv( strVarName, &tmp ) )
{
strResult += tmp;
@ -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'."),
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 )
strResult << (wxChar)bracket;
str_m = str[++m];
}
}
@ -423,7 +436,8 @@ wxString KIwxExpandEnvVars(const wxString& str)
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.
*/
@ -702,6 +717,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
else if( *m == '?' )
{
m++;
if( !*n++ )
return false;
}
@ -710,6 +726,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
if( *m == '\\' )
{
m++;
/* Quoting "nothing" is a bad thing */
if( !*m )
return false;
@ -723,11 +740,14 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
*/
if( !*n )
return true;
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,6 +756,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
* the NULL of n
*/
just = 0;
if( *m == *n )
{
m++;
@ -744,7 +765,6 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
}
else
{
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.
static wxInt64 EPOCH_OFFSET_IN_MSEC = wxLL(11644473600000);
static void ConvertFileTimeToWx( wxDateTime *dt, const FILETIME &ft )
{
wxLongLong t( ft.dwHighDateTime, ft.dwLowDateTime );
@ -877,5 +898,3 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
return timestamp;
}