← Back to team overview

kicad-developers team mailing list archive

[PATCH] Complete str[n]icmp -> str[n]casecmp

 

This also reverses the substitution logic if strcasecmp is missing.
---
 CMakeModules/config.h.cmake            | 8 ++++----
 common/class_bitmap_base.cpp           | 2 +-
 eeschema/sch_legacy_plugin.cpp         | 8 ++++----
 pcb_calculator/datafile_read_write.cpp | 4 ++--
 pcbnew/specctra.cpp                    | 2 +-
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/CMakeModules/config.h.cmake b/CMakeModules/config.h.cmake
index 3e60199..01359cc 100644
--- a/CMakeModules/config.h.cmake
+++ b/CMakeModules/config.h.cmake
@@ -39,12 +39,12 @@
 #include <iso646.h>
 #endif
 
-#if defined( HAVE_STRCASECMP )
-#define stricmp strcasecmp
+#if !defined( HAVE_STRCASECMP )
+#define strcasecmp stricmp
 #endif
 
-#if defined( HAVE_STRNCASECMP )
-#define strnicmp strncasecmp
+#if !defined( HAVE_STRNCASECMP )
+#define strncasecmp strnicmp
 #endif
 
 // Use Posix getc_unlocked() instead of getc() when it's available.
diff --git a/common/class_bitmap_base.cpp b/common/class_bitmap_base.cpp
index 67e9b7a..c563f1f 100644
--- a/common/class_bitmap_base.cpp
+++ b/common/class_bitmap_base.cpp
@@ -174,7 +174,7 @@ bool BITMAP_BASE::LoadData( LINE_READER& aLine, wxString& aErrorMsg )
 
         line = aLine.Line();
 
-        if( strnicmp( line, "EndData", 4 ) == 0 )
+        if( strncasecmp( line, "EndData", 4 ) == 0 )
         {
             // all the PNG date is read.
             // We expect here m_image and m_bitmap are void
diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp
index c7592e2..3790a04 100644
--- a/eeschema/sch_legacy_plugin.cpp
+++ b/eeschema/sch_legacy_plugin.cpp
@@ -72,7 +72,7 @@ const char* delims = " \t\r\n";
 static bool strCompare( const char* aString, const char* aLine, const char** aOutput = NULL )
 {
     size_t len = strlen( aString );
-    bool retv = ( strnicmp( aLine, aString, len ) == 0 ) && isspace( aLine[ len ] );
+    bool retv = ( strncasecmp( aLine, aString, len ) == 0 ) && isspace( aLine[ len ] );
 
     if( retv && aOutput )
     {
@@ -1220,7 +1220,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( FILE_LINE_READER& aReader )
             const char* strCompare = "Path=";
             int         len = strlen( strCompare );
 
-            if( strnicmp( strCompare, line, len ) != 0 )
+            if( strncasecmp( strCompare, line, len ) != 0 )
                 SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
 
             line += len;
@@ -1231,7 +1231,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( FILE_LINE_READER& aReader )
             strCompare = "Ref=";
             len = strlen( strCompare );
 
-            if( strnicmp( strCompare, line, len ) != 0 )
+            if( strncasecmp( strCompare, line, len ) != 0 )
                 SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
 
             line+= len;
@@ -1240,7 +1240,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( FILE_LINE_READER& aReader )
             strCompare = "Part=";
             len = strlen( strCompare );
 
-            if( strnicmp( strCompare, line, len ) != 0 )
+            if( strncasecmp( strCompare, line, len ) != 0 )
                 SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
 
             line+= len;
diff --git a/pcb_calculator/datafile_read_write.cpp b/pcb_calculator/datafile_read_write.cpp
index a058a2a..00b09df 100644
--- a/pcb_calculator/datafile_read_write.cpp
+++ b/pcb_calculator/datafile_read_write.cpp
@@ -255,9 +255,9 @@ void PCB_CALCULATOR_DATAFILE_PARSER::ParseRegulatorDescr( PCB_CALCULATOR_DATAFIL
 
                 case T_reg_type:   // type: normal or 3 terminal reg
                     token = NextTok();
-                   if( stricmp( CurText(), regtype_str[0] ) == 0 )
+                   if( strcasecmp( CurText(), regtype_str[0] ) == 0 )
                         type = 0;
-                    else if( stricmp( CurText(), regtype_str[1] ) == 0 )
+                    else if( strcasecmp( CurText(), regtype_str[1] ) == 0 )
                         type = 1;
                     else
                         Unexpected( CurText() );
diff --git a/pcbnew/specctra.cpp b/pcbnew/specctra.cpp
index ef14eee..39ffb90 100644
--- a/pcbnew/specctra.cpp
+++ b/pcbnew/specctra.cpp
@@ -194,7 +194,7 @@ void SPECCTRA_DB::readTIME( time_t* time_stamp ) throw( IO_ERROR )
     mytime.tm_mon = 0;      // remains if we don't find a month match.
     for( int m=0;  months[m];  ++m )
     {
-        if( !stricmp( months[m], ptok ) )
+        if( !strcasecmp( months[m], ptok ) )
         {
             mytime.tm_mon = m;
             break;

Follow ups