← Back to team overview

kicad-developers team mailing list archive

Re: spaces not allowed in SCH library nicknames

 

Wayne-

Would you object to a patch like the attached?  It reads the name line in
reverse order, allowing spaces in the component name.  If this is an
acceptable approach, I'll make the other required internal changes.

-Seth

2018-01-26 10:22 GMT-08:00 Tomasz Wlostowski <tomasz.wlostowski@xxxxxxx>:

> On 26/01/18 19:18, Wayne Stambaugh wrote:
> > On 1/26/2018 1:01 PM, Tomasz Wlostowski wrote:
> >> Hi all,
> >>
> >> Why are space characters not allowed in the SCH library nicknames, but
> >> are OK for the FP libraries? Is this an overlook on SCH/PCB side?
> >>
> >> I'd like to disable the space check in eeschema, it's very annoying if
> >> the library file names contain spaces.
> >>
> >> Regards,
> >> Tom
> >
> > For the same reason you can have spaces in symbol names, library symbol
> > names are not quoted in the schematic file format.  If you can figure
> > out a way to fix this without changing the schematic file format and
> > breaking anything, then I'm ok with that.  The new schematic file format
> > will use quoted strings for symbol library links (which will only be for
> > reverting or updating since symbols will be embedded in the schematic)
> > so I will remove this restriction once the new file formats are in play.
> >
>
> Hi Wayne,
>
> Now I understand the reason for not allowing spaces. What about the
> slashes?
>
> Tom
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
From 667748dac10166a0f0c04d04937649f75670d981 Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <hillbrand@xxxxxxxxxxx>
Date: Fri, 26 Jan 2018 11:22:09 -0800
Subject: [PATCH] Allowing spaces in SCHEMATIC file Component names

---
 eeschema/sch_legacy_plugin.cpp | 86 +++++++++++++++++++++++++++++++++---------
 1 file changed, 68 insertions(+), 18 deletions(-)

diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp
index 5dab47f2b..4f3102a7c 100644
--- a/eeschema/sch_legacy_plugin.cpp
+++ b/eeschema/sch_legacy_plugin.cpp
@@ -364,6 +364,50 @@ static void parseUnquotedString( wxString& aString, FILE_LINE_READER& aReader,
 
 
 /**
+ * Parse an unquoted utf8 string starting from the end of the input line.
+ *
+ * The parsed string must be a continuous string with no white space.
+ *
+ * @param aString - A reference to the parsed string.
+ * @param aReader - The line reader used to generate exception throw information.
+ * @param aCurrentToken - A pointer the current position in a string.
+ * @param aCanBeEmpty - True if the parsed string is optional.  False if it is mandatory.
+ * @throw IO_ERROR on an unexpected end of line.
+ * @throw PARSE_ERROR if the \a aCanBeEmpty is false and no string was parsed.
+ */
+static void parseUnquotedStringReverse( wxString& aString, FILE_LINE_READER& aReader,
+                                 const char* aCurrentToken, bool aCanBeEmpty = false )
+{
+    if( !*aCurrentToken )
+    {
+        if( aCanBeEmpty )
+            return;
+        else
+            SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aCurrentToken );
+    }
+
+    wxString tmp( aCurrentToken );
+    tmp.Trim();
+
+    size_t pos = tmp.find_last_of( " " );
+
+    if( pos == std::string::npos )
+    {
+        if( aCanBeEmpty )
+            return;
+        else
+            SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aCurrentToken );
+    }
+
+    aString = FROM_UTF8( tmp.substr( pos + 1 ).c_str() );
+
+    if( aString.IsEmpty() && !aCanBeEmpty )
+        SCH_PARSE_ERROR( _( "expected unquoted string" ), aReader, aCurrentToken );
+
+}
+
+
+/**
  * Parse an quoted ASCII utf8 and updates the pointer at \a aOutput if it is not NULL.
  *
  * The parsed string must be contained within a single line.  There are no multi-line
@@ -1388,26 +1432,9 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( FILE_LINE_READER& aReader )
     {
         if( strCompare( "L", line, &line ) )
         {
-            wxString libName;
-
-            parseUnquotedString( libName, aReader, line, &line );
-            libName.Replace( "~", " " );
-
-            LIB_ID libId;
-
-            // Prior to schematic version 4, library IDs did not have a library nickname so
-            // parsing the symbol name with LIB_ID::Parse() would break symbol library links
-            // that contained '/' and ':' characters.
-            if( m_version > 3 )
-                libId.Parse( libName );
-            else
-                libId.SetLibItemName( libName, false );
-
-            component->SetLibId( libId );
-
             wxString refDesignator;
 
-            parseUnquotedString( refDesignator, aReader, line, &line );
+            parseUnquotedStringReverse( refDesignator, aReader, line );
             refDesignator.Replace( "~", " " );
 
             wxString prefix = refDesignator;
@@ -1428,6 +1455,29 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( FILE_LINE_READER& aReader )
                 component->SetPrefix( wxString( "U" ) );
             else
                 component->SetPrefix( prefix );
+
+            wxString libName( line );
+            if( libName.size() <= ( refDesignator.size() + 1 ) )
+                SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
+
+            // Trim the reference designator (plus space)
+            libName.resize( libName.size() - ( refDesignator.size() + 1 ) );
+            libName.Trim( true );
+            libName.Trim( false );
+            libName.Replace( "~", " " );
+
+            LIB_ID libId;
+
+            // Prior to schematic version 4, library IDs did not have a library nickname so
+            // parsing the symbol name with LIB_ID::Parse() would break symbol library links
+            // that contained '/' and ':' characters.
+            if( m_version > 3 )
+                libId.Parse( libName );
+            else
+                libId.SetLibItemName( libName, false );
+
+            component->SetLibId( libId );
+
         }
         else if( strCompare( "U", line, &line ) )
         {
-- 
2.11.0


Follow ups

References