Coding policy fixes in common/common.cpp.
This commit is contained in:
parent
72c885797e
commit
47492f9452
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -325,34 +326,39 @@ wxString KIwxExpandEnvVars(const wxString& str)
|
||||||
size_t strlen = str.length();
|
size_t strlen = str.length();
|
||||||
|
|
||||||
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__
|
||||||
case wxT('$'):
|
case wxT( '$' ):
|
||||||
{
|
{
|
||||||
Bracket bracket;
|
Bracket bracket;
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
if ( str_n == wxT('%') )
|
if( str_n == wxT( '%' ) )
|
||||||
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() ) {
|
{
|
||||||
case wxT('('):
|
switch( str[n + 1].GetValue() )
|
||||||
|
{
|
||||||
|
case wxT( '(' ):
|
||||||
bracket = Bracket_Normal;
|
bracket = Bracket_Normal;
|
||||||
str_n = str[++n]; // skip the bracket
|
str_n = str[++n]; // skip the bracket
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxT('{'):
|
case wxT( '{' ):
|
||||||
bracket = Bracket_Curly;
|
bracket = Bracket_Curly;
|
||||||
str_n = str[++n]; // skip the bracket
|
str_n = str[++n]; // skip the bracket
|
||||||
break;
|
break;
|
||||||
|
@ -365,10 +371,10 @@ wxString KIwxExpandEnvVars(const wxString& str)
|
||||||
size_t m = n + 1;
|
size_t m = n + 1;
|
||||||
wxUniChar str_m = str[m];
|
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];
|
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__
|
#ifdef __WXWINCE__
|
||||||
const bool expanded = false;
|
const bool expanded = false;
|
||||||
|
@ -377,7 +383,8 @@ 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;
|
||||||
expanded = true;
|
expanded = true;
|
||||||
|
@ -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' "
|
||||||
(char)bracket, (unsigned int) (m + 1), str.c_str());
|
"at position %u in '%s'." ),
|
||||||
|
(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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,9 +434,10 @@ wxString KIwxExpandEnvVars(const wxString& str)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -669,7 +684,7 @@ long long WX_FILENAME::GetTimestamp()
|
||||||
*/
|
*/
|
||||||
bool matchWild( const char* pat, const char* text, bool dot_special )
|
bool matchWild( const char* pat, const char* text, bool dot_special )
|
||||||
{
|
{
|
||||||
if ( !*text )
|
if( !*text )
|
||||||
{
|
{
|
||||||
/* Match if both are empty. */
|
/* Match if both are empty. */
|
||||||
return !*pat;
|
return !*pat;
|
||||||
|
@ -683,51 +698,56 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
|
||||||
acount = 0,
|
acount = 0,
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
if (dot_special && (*n == '.'))
|
if( dot_special && (*n == '.') )
|
||||||
{
|
{
|
||||||
/* Never match so that hidden Unix files
|
/* Never match so that hidden Unix files
|
||||||
* are never found. */
|
* are never found. */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
if (*m == '*')
|
if( *m == '*' )
|
||||||
{
|
{
|
||||||
ma = ++m;
|
ma = ++m;
|
||||||
na = n;
|
na = n;
|
||||||
just = 1;
|
just = 1;
|
||||||
acount = count;
|
acount = count;
|
||||||
}
|
}
|
||||||
else if (*m == '?')
|
else if( *m == '?' )
|
||||||
{
|
{
|
||||||
m++;
|
m++;
|
||||||
if (!*n++)
|
|
||||||
|
if( !*n++ )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
if (!*m)
|
if( !*m )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* If we are out of both strings or we just
|
* If we are out of both strings or we just
|
||||||
* saw a wildcard, then we can say we have a
|
* saw a wildcard, then we can say we have a
|
||||||
* match
|
* match
|
||||||
*/
|
*/
|
||||||
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,7 +756,8 @@ 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++;
|
||||||
count++;
|
count++;
|
||||||
|
@ -744,7 +765,6 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
not_matched:
|
not_matched:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -753,10 +773,10 @@ bool matchWild( const char* pat, const char* text, bool dot_special )
|
||||||
* character (*m != NULL), then it will be
|
* character (*m != NULL), then it will be
|
||||||
* impossible to match it
|
* impossible to match it
|
||||||
*/
|
*/
|
||||||
if (!*n)
|
if( !*n )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (ma)
|
if( ma )
|
||||||
{
|
{
|
||||||
m = ma;
|
m = ma;
|
||||||
n = ++na;
|
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.
|
// 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 );
|
||||||
t /= 10000; // Convert hundreds of nanoseconds to milliseconds.
|
t /= 10000; // Convert hundreds of nanoseconds to milliseconds.
|
||||||
t -= EPOCH_OFFSET_IN_MSEC;
|
t -= EPOCH_OFFSET_IN_MSEC;
|
||||||
|
|
||||||
*dt = wxDateTime(t);
|
*dt = wxDateTime( t );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_DATETIME && __WIN32__
|
#endif // wxUSE_DATETIME && __WIN32__
|
||||||
|
@ -807,7 +828,7 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
|
||||||
{
|
{
|
||||||
long long timestamp = 0;
|
long long timestamp = 0;
|
||||||
|
|
||||||
#if defined(__WIN32__)
|
#if defined( __WIN32__ )
|
||||||
// Win32 version.
|
// Win32 version.
|
||||||
// Save time by not searching for each path twice: once in wxDir.GetNext() and once in
|
// 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
|
// 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 );
|
ConvertFileTimeToWx( &lastModDate, findData.ftLastWriteTime );
|
||||||
timestamp += lastModDate.GetValue().GetValue();
|
timestamp += lastModDate.GetValue().GetValue();
|
||||||
}
|
}
|
||||||
while ( FindNextFile( fileHandle, &findData ) != 0);
|
while ( FindNextFile( fileHandle, &findData ) != 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
FindClose( fileHandle );
|
FindClose( fileHandle );
|
||||||
|
@ -877,5 +898,3 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec )
|
||||||
|
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue