← Back to team overview

kicad-developers team mailing list archive

[PATCH] Fix 1485352: proejct_rescue invalid library file for projects with space in name

 

Hi,

project_rescue creates invalid library files for projects with 
whitespace in the name (I mistakenly thought that these would be escaped 
on export). Here's a patch to find and replace whitespace.

--
Chris

commit 66f634e13576ac682ae20c2d90851ad18aba030b
Author: Chris Pavlina <cpavlin1@xxxxxxxxxxxxxx>
Date:   Mon Aug 17 16:41:50 2015 -0400

    Fix 1485352: rescue creates invalid file for project with spaces

diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp
index 6d3371d..1b3aeb4 100644
--- a/eeschema/project_rescue.cpp
+++ b/eeschema/project_rescue.cpp
@@ -33,6 +33,7 @@
 #include <schframe.h>
 #include <wildcards_and_files_ext.h>
 
+#include <cctype>
 #include <boost/foreach.hpp>
 #include <map>
 
@@ -331,7 +332,7 @@ public:
         typedef std::map<wxString, RESCUE_CACHE_CANDIDATE> candidate_map_t;
         candidate_map_t candidate_map;
 
-        wxString part_name_suffix = wxT( "-RESCUE-" ) + aRescuer.GetPrj()->GetProjectName();
+        wxString part_name_suffix = aRescuer.GetPartNameSuffix();
 
         BOOST_FOREACH( SCH_COMPONENT* each_component, *( aRescuer.GetComponents() ) )
         {
@@ -497,6 +498,23 @@ void RESCUER::UndoRescues()
 }
 
 
+wxString RESCUER::GetPartNameSuffix()
+{
+    wxString suffix = wxT( "-RESCUE-" );
+    wxString pname = GetPrj()->GetProjectName();
+    for( size_t i = 0; i < pname.Len(); ++i )
+    {
+        if( isspace( pname[i].GetValue() ) ) {
+            suffix.Append( '_' );
+        } else {
+            suffix.Append( pname[i] );
+        }
+    }
+
+    return suffix;
+}
+
+
 bool SCH_EDIT_FRAME::RescueProject( bool aRunningOnDemand )
 {
     RESCUER rescuer( *this, Prj() );
diff --git a/eeschema/project_rescue.h b/eeschema/project_rescue.h
index a179914..4ba538f 100644
--- a/eeschema/project_rescue.h
+++ b/eeschema/project_rescue.h
@@ -162,6 +162,12 @@ public:
     PROJECT* GetPrj() { return m_prj; }
 
     /**
+     * Function GetPartNameSuffix
+     * Return the suffix to add to rescued parts.
+     */
+    wxString GetPartNameSuffix();
+
+    /**
      * Function InvokeDialog
      * Display a dialog to allow the user to select rescues.
      * @param aAskShowAgain - whether the "Never Show Again" button should be visible

Follow ups