Commit bdadac7b authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

FILE_LINE_READER owns open files by default

parent 66566f9b
Loading
Loading
Loading
Loading
+17 −20
Original line number Original line Diff line number Diff line
@@ -80,21 +80,19 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles( )
        }
        }


        FILE_LINE_READER    fileReader( file, libname );
        FILE_LINE_READER    fileReader( file, libname );

        FILTER_READER       reader( fileReader );
        FILTER_READER       reader( fileReader );


        /* Read header. */
        /* Read header. */
        reader.ReadLine();
        reader.ReadLine();
        char * Line = reader.Line();
        char * line = reader.Line();
        StrPurge( Line );
        StrPurge( line );


        if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
        if( strnicmp( line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
        {
        {
            wxString msg;
            wxString msg;
            msg.Printf( _( "<%s> is not a valid Kicad PCB footprint library." ),
            msg.Printf( _( "<%s> is not a valid Kicad PCB footprint library." ),
                        GetChars( libname ) );
                        GetChars( libname ) );
            files_invalid << msg << wxT("\n");
            files_invalid << msg << wxT("\n");
            fclose( file );
            continue;
            continue;
        }
        }


@@ -102,47 +100,46 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles( )
        bool end = false;
        bool end = false;
        while( !end && reader.ReadLine() )
        while( !end && reader.ReadLine() )
        {
        {
            Line = reader.Line();
            line = reader.Line();
            StrPurge( Line );
            StrPurge( line );
            if( strnicmp( Line, "$EndLIBRARY", 11 ) == 0 )
            if( strnicmp( line, "$EndLIBRARY", 11 ) == 0 )
            {
            {
                end = true;
                end = true;
                break;
                break;
            }
            }
            if( strnicmp( Line, "$MODULE", 7 ) == 0 )
            if( strnicmp( line, "$MODULE", 7 ) == 0 )
            {
            {


                Line += 7;
                line += 7;
                FOOTPRINT*  ItemLib = new FOOTPRINT();
                FOOTPRINT*  ItemLib = new FOOTPRINT();
                ItemLib->m_Module = CONV_FROM_UTF8( StrPurge( Line ) );
                ItemLib->m_Module = CONV_FROM_UTF8( StrPurge( line ) );
                ItemLib->m_LibName = libname;
                ItemLib->m_LibName = libname;
                m_footprints.push_back( ItemLib );
                m_footprints.push_back( ItemLib );


                while( reader.ReadLine() )
                while( reader.ReadLine() )
                {
                {
                    Line = reader.Line();
                    line = reader.Line();
                    StrPurge( Line );
                    StrPurge( line );
                    if( strnicmp( Line, "$EndMODULE", 10 ) == 0 )
                    if( strnicmp( line, "$EndMODULE", 10 ) == 0 )
                        break;
                        break;


                    int id = ((Line[0] & 0xFF) << 8) + (Line[1] & 0xFF);
                    int id = ((line[0] & 0xFF) << 8) + (line[1] & 0xFF);
                    switch( id )
                    switch( id )
                    {
                    {
                    /* KeyWords */
                    /* KeyWords */
                    case (('K'<<8) + 'w'):
                    case (('K'<<8) + 'w'):
                        ItemLib->m_KeyWord = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
                        ItemLib->m_KeyWord = CONV_FROM_UTF8( StrPurge( line + 3 ) );
                    break;
                    break;


                    /* Doc */
                    /* Doc */
                    case (('C'<<8) + 'd'):
                    case (('C'<<8) + 'd'):
                        ItemLib->m_Doc = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
                        ItemLib->m_Doc = CONV_FROM_UTF8( StrPurge( line + 3 ) );
                    break;
                    break;
                    }
                    }
                }
                }
            }
            }
        }
        }


        fclose( file );
        if( !end )
        if( !end )
        {
        {
            files_invalid << libname << _(" (Unexpected end of file)") << wxT("\n");
            files_invalid << libname << _(" (Unexpected end of file)") << wxT("\n");