diff --git a/common/richio.cpp b/common/richio.cpp index b037687b56..621c3ebfc2 100644 --- a/common/richio.cpp +++ b/common/richio.cpp @@ -204,6 +204,46 @@ int OUTPUTFORMATTER::Print( int nestLevel, const char* fmt, ... ) throw( IOError } +const char* OUTPUTFORMATTER::Quoted( std::string* aWrapee ) throw( IOError ) +{ + // derived class's notion of what a quote character is + char quote = *GetQuoteChar( "(" ); + + // Will the string be wrapped based on its interior content? + const char* squote = GetQuoteChar( aWrapee->c_str() ); + + // Search the interior of the string for 'quote' chars + // and replace them as found with duplicated quotes. + // Note that necessarily any string which has internal quotes will + // also be wrapped in quotes later in this function. + for( unsigned i=0; isize(); ++i ) + { + if( (*aWrapee)[i] == quote ) + { + aWrapee->insert( aWrapee->begin()+i, quote ); + ++i; + } + else if( (*aWrapee)[0]=='\r' || (*aWrapee)[0]=='\n' ) + { + // In a desire to maintain accurate line number reporting within DSNLEXER + // a decision was made to make all S-expression strings be on a single + // line. You can embedd \n (human readable) in the text but not + // '\n' which is 0x0a. + throw IOError( _( "S-expression string has newline" ) ); + } + } + + if( *squote ) + { + // wrap the beginning and end of the string in a quote. + aWrapee->insert( aWrapee->begin(), quote ); + aWrapee->insert( aWrapee->end(), quote ); + } + + return aWrapee->c_str(); +} + + //--------------------------------------------------------- void STRING_FORMATTER::write( const char* aOutBuf, int aCount ) throw( IOError ) diff --git a/common/xnode.cpp b/common/xnode.cpp index 43aa806275..b24ee1bf53 100644 --- a/common/xnode.cpp +++ b/common/xnode.cpp @@ -51,18 +51,16 @@ void XNODE::Format( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError ) void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError ) { std::string utf8; - const char* quote; // output attributes first if they exist for( XATTR* attr = (XATTR*) GetAttributes(); attr; attr = (XATTR*) attr->GetNext() ) { utf8 = CONV_TO_UTF8( attr->GetValue() ); // capture the content - quote = out->GetQuoteChar( utf8.c_str() ); - out->Print( 0, " (%s %s%s%s)", + out->Print( 0, " (%s %s)", // attr names should never need quoting, no spaces, we designed the file. CONV_TO_UTF8( attr->GetName() ), - quote, utf8.c_str(), quote ); + out->Quoted( &utf8 ) ); } // we only expect to have used one of two types here: @@ -88,8 +86,7 @@ void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IOError case wxXML_TEXT_NODE: utf8 = CONV_TO_UTF8( GetContent() ); - quote = out->GetQuoteChar( utf8.c_str() ); - out->Print( 0, " %s%s%s", quote, utf8.c_str(), quote ); + out->Print( 0, " %s", out->Quoted( &utf8 ) ); break; default: diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index 7384cae3ba..228275666d 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -629,7 +629,7 @@ static XNODE* node( const wxString& aName, const wxString& aTextualContent = wxE XNODE* EXPORT_HELP::makeGenericDesignHeader() { XNODE* xdesign = node( wxT("design") ); - char date[128]; + char date[128]; DateAndTime( date ); @@ -1010,7 +1010,7 @@ XNODE* EXPORT_HELP::makeGenericComponents() bool EXPORT_HELP::WriteGENERICNetList( WinEDA_SchematicFrame* frame, const wxString& aOutFileName ) { -#if 0 +#if 1 // this code seems to work now, for S-expression support. diff --git a/eeschema/plugins/netlist_form_pads-pcb.xsl b/eeschema/plugins/netlist_form_pads-pcb.xsl index 147a208eda..8708a3026c 100644 --- a/eeschema/plugins/netlist_form_pads-pcb.xsl +++ b/eeschema/plugins/netlist_form_pads-pcb.xsl @@ -11,7 +11,7 @@ - + *PADS-PCB*&nl;*PART*&nl; &nl;*NET*&nl; diff --git a/include/richio.h b/include/richio.h index 45b4d2ff48..86f664da72 100644 --- a/include/richio.h +++ b/include/richio.h @@ -301,7 +301,7 @@ public: /** * Function Quoted - * checks \a aWrappee input string for a need to be quoted + * checks \a aWrapee input string for a need to be quoted * (e.g. contains a ')' character or a space), and for \" double quotes * within the string that need to be doubled up such that the DSNLEXER * will correctly parse the string from a file later. @@ -312,9 +312,11 @@ public: * * @return const char* - useful for passing to printf() style functions that * must output utf8 streams. - virtual const char* Quoted( std::string* aWrapee ); - thinking about using wxCharBuffer* instead. + * @throw IOError, if aWrapee has any \r or \n bytes in it which is + * illegal according to the DSNLEXER who does not ever want them + * within a string. */ + virtual const char* Quoted( std::string* aWrapee ) throw( IOError ); //---------------------------------------------- };