Commit e79b5963 authored by Marco Mattila's avatar Marco Mattila
Browse files

Add FILTER_READER class. Introduce FILE_LINE_READER into pcbnew.

parent 6113bbf6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ set(COMMON_SRCS
    edaappl.cpp
    eda_dde.cpp
    eda_doc.cpp
    filter_reader.cpp
    gestfich.cpp
    gr_basic.cpp
    hotkeys_basic.cpp
+40 −0
Original line number Diff line number Diff line

/*
 * This program source code file is part of KICAD, a free EDA CAD application.
 *
 * Copyright (C) 2007-2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include <string.h>
#include "richio.h"
#include "filter_reader.h"

unsigned FILTER_READER::ReadLine() throw( IO_ERROR )
{
    unsigned ret;

    while( ( ret = reader.ReadLine() ) != 0 )
    {
        if( !strchr( "#\n\r", reader[0] ) )
            break;
    }
    return ret;
}
+18 −10
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
#include "protos.h"
#include "cvstruct.h"
#include "class_DisplayFootprintsFrame.h"
#include "richio.h"
#include "filter_reader.h"


/**
@@ -27,9 +29,10 @@
 */
MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& CmpName )
{
    int        LineNum, Found = 0;
    int        Found = 0;
    unsigned   ii;
    char       Line[1024], Name[255];
    char*      Line;
    char       Name[255];
    wxString   tmp, msg;
    wxFileName fn;
    MODULE*    Module = NULL;
@@ -61,9 +64,13 @@ found in the default search paths." ),
            continue;
        }

        FILE_LINE_READER fileReader( file, tmp );

        FILTER_READER reader( fileReader );

        /* Read header. */
        LineNum = 0;
        GetLine( file, Line, &LineNum );
        reader.ReadLine();
        Line = reader.Line();
        StrPurge( Line );

        if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
@@ -76,15 +83,17 @@ found in the default search paths." ),
        }

        Found = 0;
        while( !Found && GetLine( file, Line, &LineNum ) )
        while( !Found && reader.ReadLine() )
        {
            Line = reader.Line();
            if( strncmp( Line, "$MODULE", 6 ) == 0 )
                break;

            if( strnicmp( Line, "$INDEX", 6 ) == 0 )
            {
                while( GetLine( file, Line, &LineNum ) )
                while( reader.ReadLine() )
                {
                    Line = reader.Line();
                    if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
                        break;

@@ -98,8 +107,9 @@ found in the default search paths." ),
            }
        }

        while( Found && GetLine( file, Line, &LineNum ) )
        while( Found && reader.ReadLine() )
        {
            Line = reader.Line();
            if( Line[0] != '$' )
                continue;

@@ -117,15 +127,13 @@ found in the default search paths." ),
                // Switch the locale to standard C (needed to print floating
                // point numbers like 1.3)
                SetLocaleTo_C_standard();
                Module->ReadDescr( file, &LineNum );
                Module->ReadDescr( &reader );
                SetLocaleTo_Default();       // revert to the current locale
                Module->SetPosition( wxPoint( 0, 0 ) );
                fclose( file );
                return Module;
            }
        }

        fclose( file );
        file = NULL;
    }

+30 −13
Original line number Diff line number Diff line

/*
 * This program source code file is part of KICAD, a free EDA CAD application.
 *
 * Copyright (C) 2007-2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#ifndef FILTER_READER_H_
#define FILTER_READER_H_

#include <richio.h>
#include <string.h>
#include <wx/wx.h>
#include "richio.h"


/**
@@ -24,17 +50,7 @@ public:
    {
    }

    unsigned ReadLine() throw( IO_ERROR )
    {
        unsigned ret;

        while( ( ret = reader.ReadLine() ) != 0 )
        {
            if( !strchr( "#\n\r", reader[0] ) )
                break;
        }
        return ret;
    }
    unsigned ReadLine() throw( IO_ERROR );

    const wxString& GetSource() const
    {
@@ -57,3 +73,4 @@ public:
    }
};

#endif // FILTER_READER_H_
+5 −5
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@

#include "wxstruct.h"
#include "base_struct.h"
#include "richio.h"

#ifndef PCB_INTERNAL_UNIT
#define PCB_INTERNAL_UNIT 10000
@@ -121,15 +122,14 @@ public:
public:

    // Read/write functions:
    EDA_ITEM* ReadDrawSegmentDescr( FILE* File, int* LineNum );
    int             ReadListeSegmentDescr( FILE*  File,
    EDA_ITEM* ReadDrawSegmentDescr( LINE_READER* aReader );
    int             ReadListeSegmentDescr( LINE_READER* aReader,
                                           TRACK* PtSegm,
                                           int    StructType,
                                           int*   LineNum,
                                           int    NumSegm );

    int             ReadSetup( FILE* File, int* LineNum );
    int             ReadGeneralDescrPcb( FILE* File, int* LineNum );
    int             ReadSetup( LINE_READER* aReader );
    int             ReadGeneralDescrPcb( LINE_READER* aReader );


    /**
Loading