Commit 29613e29 authored by jean-pierre charras's avatar jean-pierre charras

Netlist reader: fix issue when reading an ORCADPCB2 netlist (which fixes also...

Netlist reader: fix issue when reading an ORCADPCB2 netlist (which fixes also bug 1184023) and fix a Cvpcb crash when trying to read an unknown netlist format.
parent 38a5e9af
...@@ -773,9 +773,14 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist() ...@@ -773,9 +773,14 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist()
netlistReader = NETLIST_READER::GetNetlistReader( &m_netlist, netlistReader = NETLIST_READER::GetNetlistReader( &m_netlist,
m_NetlistFileName.GetFullPath(), m_NetlistFileName.GetFullPath(),
compFootprintLinkFileName ); compFootprintLinkFileName );
if( netlistReader != NULL )
{
std::auto_ptr< NETLIST_READER > nlr( netlistReader ); std::auto_ptr< NETLIST_READER > nlr( netlistReader );
netlistReader->LoadNetlist(); netlistReader->LoadNetlist();
} }
else
wxMessageBox( _( "Unknown netlist format" ), wxEmptyString, wxOK | wxICON_ERROR );
}
catch( IO_ERROR& ioe ) catch( IO_ERROR& ioe )
{ {
msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() ); msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() );
......
...@@ -159,14 +159,11 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText ) throw( PARSE_ERRO ...@@ -159,14 +159,11 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText ) throw( PARSE_ERRO
value = FROM_UTF8( text ); value = FROM_UTF8( text );
// Read component name (fifth word) {Lib=C} // Read component name (fifth word) {Lib=C}
if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL ) // This is an optional field (a comment), which does not always exists
if( ( text = strtok( NULL, " ()\t\n" ) ) != NULL )
{ {
msg = _( "Cannot parse name comment in component section of netlist." );
THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(),
m_lineReader->Length() );
}
name = FROM_UTF8( text ).AfterFirst( wxChar( '=' ) ).BeforeLast( wxChar( '}' ) ); name = FROM_UTF8( text ).AfterFirst( wxChar( '=' ) ).BeforeLast( wxChar( '}' ) );
}
COMPONENT* component = new COMPONENT( footprintName, reference, value, timeStamp ); COMPONENT* component = new COMPONENT( footprintName, reference, value, timeStamp );
component->SetName( name ); component->SetName( name );
...@@ -213,7 +210,7 @@ void LEGACY_NETLIST_READER::loadFootprintFilters() throw( IO_ERROR, PARSE_ERROR ...@@ -213,7 +210,7 @@ void LEGACY_NETLIST_READER::loadFootprintFilters() throw( IO_ERROR, PARSE_ERROR
wxArrayString filters; wxArrayString filters;
wxString cmpRef; wxString cmpRef;
char* line; char* line;
COMPONENT* component; COMPONENT* component = NULL; // Suppress compil warning
while( ( line = m_lineReader->ReadLine() ) != NULL ) while( ( line = m_lineReader->ReadLine() ) != NULL )
{ {
......
...@@ -293,10 +293,14 @@ NETLIST_READER::~NETLIST_READER() ...@@ -293,10 +293,14 @@ NETLIST_READER::~NETLIST_READER()
NETLIST_READER::NETLIST_FILE_T NETLIST_READER::GuessNetlistFileType( LINE_READER* aLineReader ) NETLIST_READER::NETLIST_FILE_T NETLIST_READER::GuessNetlistFileType( LINE_READER* aLineReader )
{ {
wxRegEx reOrcad( wxT( "(?i)[ ]*\\({EESchema[ \t]+Netlist[ \t]+" ), wxRE_ADVANCED ); // Orcad Pcb2 netlist format starts by "( {", followed by an unknown comment,
// depending on the tool which created the file
wxRegEx reOrcad( wxT( "(?i)[ ]*\\([ \t]+{+" ), wxRE_ADVANCED );
wxASSERT( reOrcad.IsValid() ); wxASSERT( reOrcad.IsValid() );
// Our legacy netlist format starts by "# EESchema Netlist "
wxRegEx reLegacy( wxT( "(?i)#[ \t]+EESchema[ \t]+Netlist[ \t]+" ), wxRE_ADVANCED ); wxRegEx reLegacy( wxT( "(?i)#[ \t]+EESchema[ \t]+Netlist[ \t]+" ), wxRE_ADVANCED );
wxASSERT( reLegacy.IsValid() ); wxASSERT( reLegacy.IsValid() );
// Our new netlist format starts by "(export (version "
wxRegEx reKicad( wxT( "[ ]*\\(export[ ]+" ), wxRE_ADVANCED ); wxRegEx reKicad( wxT( "[ ]*\\(export[ ]+" ), wxRE_ADVANCED );
wxASSERT( reKicad.IsValid() ); wxASSERT( reKicad.IsValid() );
...@@ -306,12 +310,12 @@ NETLIST_READER::NETLIST_FILE_T NETLIST_READER::GuessNetlistFileType( LINE_READER ...@@ -306,12 +310,12 @@ NETLIST_READER::NETLIST_FILE_T NETLIST_READER::GuessNetlistFileType( LINE_READER
{ {
line = FROM_UTF8( aLineReader->Line() ); line = FROM_UTF8( aLineReader->Line() );
if( reOrcad.Matches( line ) ) if( reLegacy.Matches( line ) )
return ORCAD;
else if( reLegacy.Matches( line ) )
return LEGACY; return LEGACY;
else if( reKicad.Matches( line ) ) else if( reKicad.Matches( line ) )
return KICAD; return KICAD;
else if( reOrcad.Matches( line ) )
return ORCAD;
} }
return UNKNOWN; return UNKNOWN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment