From c4722e0f39620215eefc4c02baf3666c69bf0f19 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sat, 15 Jan 2011 23:11:17 -0600 Subject: [PATCH] StrPurge(), see mailing list --- common/string.cpp | 19 +++++++++---------- pcbnew/librairi.cpp | 12 ++++++++---- pcbnew/loadcmp.cpp | 7 ++++++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/common/string.cpp b/common/string.cpp index ece3be9e78..d4181fce80 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -42,18 +42,17 @@ int ReadDelimitedText( char* dest, char* source, int NbMaxChar ) */ char* StrPurge( char* text ) { - char* ptspace; + const char whitespace[] = " \t\n\r\f\v"; - if( text == NULL ) - return NULL; - - while( ( *text <= ' ' ) && *text ) - text++; - - ptspace = text + strlen( text ) - 1; - while( ( *ptspace <= ' ' ) && *ptspace && ( ptspace >= text ) ) + if( text ) { - *ptspace = 0; ptspace--; + while( strchr( whitespace, *text ) ) + ++text; + + char* cp = text + strlen( text ) - 1; + + while( cp >= text && strchr( whitespace, *cp ) ) + *cp-- = '\0'; } return text; diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index 2cf3c0be21..f6993edf46 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -100,7 +100,6 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( ) Footprint_Is_GPCB_Format = true; else { - fclose( file ); DisplayError( this, _( "Not a module file" ) ); return NULL; } @@ -211,6 +210,7 @@ void WinEDA_ModuleEditFrame::Export_Module( MODULE* aModule, bool aCreateSysLib fputs( "$EndLIBRARY\n", file ); fclose( file ); + SetLocaleTo_Default(); // revert to the current locale msg.Printf( _( "Module exported in file <%s>" ), @@ -238,6 +238,7 @@ void WinEDA_ModuleEditFrame::Delete_Module_In_Library( const wxString& aLibname /* Confirmation */ msg.Printf( _( "Ok to delete module %s in library %s" ), GetChars( CmpName ), GetChars( aLibname ) ); + if( !IsOK( this, msg ) ) return; @@ -587,7 +588,8 @@ int WinEDA_BasePcbFrame::Save_Module_In_Library( const wxString& aLibName, if( !aOverwrite ) /* Do not save the given footprint: an old * one exists */ { - fclose( lib_module ); return 1; + fclose( lib_module ); + return 1; } end = 1; break; } @@ -680,7 +682,8 @@ int WinEDA_BasePcbFrame::Save_Module_In_Library( const wxString& aLibName, fprintf( dest, "$EndLIBRARY\n" ); aModule->m_TimeStamp = tmp; - fclose( dest ); fclose( lib_module ); + fclose( dest ); + fclose( lib_module ); SetLocaleTo_Default(); // revert to the current locale wxEndBusyCursor(); @@ -826,7 +829,8 @@ int WinEDA_ModuleEditFrame::Create_Librairie( const wxString& LibName ) { msg = _( "Create error " ) + LibName; DisplayError( this, msg ); - fclose( lib_module ); return -1; + fclose( lib_module ); + return -1; } fprintf( lib_module, " %s\n", DateAndTime( cbuf ) ); diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index 822e21dacf..092abeef62 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -309,11 +309,16 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module( Line = reader.Line(); if( Line[0] != '$' ) continue; + if( Line[1] != 'M' ) continue; + if( strnicmp( Line, "$MODULE", 7 ) != 0 ) continue; - /* Read module name. */ + + StrPurge( Line + 8 ); + + // Read module name. Name = CONV_FROM_UTF8( Line + 8 ); if( Name.CmpNoCase( aModuleName ) == 0 )