diff --git a/eeschema/bom_plugins.cpp b/eeschema/bom_plugins.cpp index 581ef9e864..5b84e59aef 100644 --- a/eeschema/bom_plugins.cpp +++ b/eeschema/bom_plugins.cpp @@ -48,24 +48,28 @@ BOM_PLUGIN::BOM_PLUGIN( const wxString& aFile ) if( extension == "xsl" ) { m_info = readHeader( "-->" ); - m_cmd = wxString::Format( "xsltproc -o \"%%O\" \"%s\" \"%%I\"", m_file.GetFullPath() ); + m_cmd = wxString::Format( "xsltproc -o \"%%O%s\" \"%s\" \"%%I\"", + getOutputExtension( m_info ), m_file.GetFullPath() ); } else if( extension == "py" ) { m_info = readHeader( "\"\"\"" ); #ifdef __WINDOWS__ - m_cmd = wxString::Format( "python \"%s/%s\" \"%%I\" \"%%O\"", - m_file.GetPath(), m_file.GetFullName() ); + m_cmd = wxString::Format( "python \"%s/%s\" \"%%I\" \"%%O%s\"", + m_file.GetPath(), m_file.GetFullName(), + getOutputExtension( m_info ) ); #else - m_cmd = wxString::Format( "python \"%s\" \"%%I\" \"%%O\"", m_file.GetFullPath() ); + m_cmd = wxString::Format( "python \"%s\" \"%%I\" \"%%O%s\"", m_file.GetFullPath(), + getOutputExtension( m_info ) ); #endif } #ifdef __WINDOWS__ else if( extension == "pyw" ) { m_info = readHeader( "\"\"\"" ); - m_cmd = wxString::Format( "pythonw \"%s/%s\" \"%%I\" \"%%O\"", - m_file.GetPath(),m_file.GetFullName() ); + m_cmd = wxString::Format( "pythonw \"%s/%s\" \"%%I\" \"%%O%s\"", + m_file.GetPath(), m_file.GetFullName(), + getOutputExtension( m_info ) ); } #endif /* __WINDOWS__ */ else // fallback @@ -112,7 +116,7 @@ wxString BOM_PLUGIN::readHeader( const wxString& aEndSection ) strstart += header.Length(); int strend = data.find( aEndSection, strstart ); - if( strend == wxNOT_FOUND) + if( strend == wxNOT_FOUND ) return wxEmptyString; // Remove empty line if any @@ -121,3 +125,24 @@ wxString BOM_PLUGIN::readHeader( const wxString& aEndSection ) return data.SubString( strstart, strend - 1 ); } + + +wxString BOM_GENERATOR_HANDLER::getOutputExtension( const wxString& aHeader ) +{ + // search header for extension after %O (extension includes '.') + // looks for output argument of the form `"%O.extension"` + const wxString outputarg( "\"%O" ); + + int strstart = aHeader.Find( outputarg ); + + if( strstart == wxNOT_FOUND ) + return wxEmptyString; + + strstart += outputarg.Length(); + int strend = aHeader.find( "\"", strstart ); + + if( strend == wxNOT_FOUND ) + return wxEmptyString; + + return aHeader.SubString( strstart, strend - 1 ); +} diff --git a/eeschema/bom_plugins.h b/eeschema/bom_plugins.h index 18efefe575..a73108fa06 100644 --- a/eeschema/bom_plugins.h +++ b/eeschema/bom_plugins.h @@ -121,6 +121,14 @@ protected: */ wxString readHeader( const wxString& aEndSection ); + /** + * Extracts the output BOM file's extension, including the '.', from the + * plugin file header. If the output extension cannot be determined from + * the plugin header, returns wxEmptyString. + * @param aHeader is the plugin file's header, as returned by readHeader() + **/ + static wxString getOutputExtension( const wxString& aHeader ); + ///> true if the plugin is working (i.e. if the plugin file exists and was read bool m_isOk;