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.

This commit is contained in:
jean-pierre charras 2013-05-25 12:41:24 +02:00
parent 38a5e9af4b
commit 29613e2974
3 changed files with 19 additions and 13 deletions

View File

@ -773,8 +773,13 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist()
netlistReader = NETLIST_READER::GetNetlistReader( &m_netlist,
m_NetlistFileName.GetFullPath(),
compFootprintLinkFileName );
std::auto_ptr< NETLIST_READER > nlr( netlistReader );
netlistReader->LoadNetlist();
if( netlistReader != NULL )
{
std::auto_ptr< NETLIST_READER > nlr( netlistReader );
netlistReader->LoadNetlist();
}
else
wxMessageBox( _( "Unknown netlist format" ), wxEmptyString, wxOK | wxICON_ERROR );
}
catch( IO_ERROR& ioe )
{

View File

@ -159,15 +159,12 @@ COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText ) throw( PARSE_ERRO
value = FROM_UTF8( text );
// 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->SetName( name );
m_netlist->AddComponent( component );
@ -213,7 +210,7 @@ void LEGACY_NETLIST_READER::loadFootprintFilters() throw( IO_ERROR, PARSE_ERROR
wxArrayString filters;
wxString cmpRef;
char* line;
COMPONENT* component;
COMPONENT* component = NULL; // Suppress compil warning
while( ( line = m_lineReader->ReadLine() ) != NULL )
{

View File

@ -293,10 +293,14 @@ NETLIST_READER::~NETLIST_READER()
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() );
// Our legacy netlist format starts by "# EESchema Netlist "
wxRegEx reLegacy( wxT( "(?i)#[ \t]+EESchema[ \t]+Netlist[ \t]+" ), wxRE_ADVANCED );
wxASSERT( reLegacy.IsValid() );
// Our new netlist format starts by "(export (version "
wxRegEx reKicad( wxT( "[ ]*\\(export[ ]+" ), wxRE_ADVANCED );
wxASSERT( reKicad.IsValid() );
@ -306,12 +310,12 @@ NETLIST_READER::NETLIST_FILE_T NETLIST_READER::GuessNetlistFileType( LINE_READER
{
line = FROM_UTF8( aLineReader->Line() );
if( reOrcad.Matches( line ) )
return ORCAD;
else if( reLegacy.Matches( line ) )
if( reLegacy.Matches( line ) )
return LEGACY;
else if( reKicad.Matches( line ) )
return KICAD;
else if( reOrcad.Matches( line ) )
return ORCAD;
}
return UNKNOWN;