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

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
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -773,9 +773,14 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist()
        netlistReader = NETLIST_READER::GetNetlistReader( &m_netlist,
                                                          m_NetlistFileName.GetFullPath(),
                                                          compFootprintLinkFileName );
        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 )
    {
        msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() );
+4 −7
Original line number Diff line number Diff line
@@ -159,14 +159,11 @@ 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( '}' ) );
    }

    COMPONENT* component = new COMPONENT( footprintName, reference, value, timeStamp );
    component->SetName( name );
@@ -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 )
    {
+8 −4
Original line number Diff line number Diff line
@@ -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;