diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index 330b1865b4..b0e57e6ad0 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -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 ) { diff --git a/pcbnew/legacy_netlist_reader.cpp b/pcbnew/legacy_netlist_reader.cpp index ac876d3051..7bd95830e2 100644 --- a/pcbnew/legacy_netlist_reader.cpp +++ b/pcbnew/legacy_netlist_reader.cpp @@ -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 ) { diff --git a/pcbnew/netlist_reader.cpp b/pcbnew/netlist_reader.cpp index 8f127e2d2a..3472164b35 100644 --- a/pcbnew/netlist_reader.cpp +++ b/pcbnew/netlist_reader.cpp @@ -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;