Commit e79b5963 authored by Marco Mattila's avatar Marco Mattila

Add FILTER_READER class. Introduce FILE_LINE_READER into pcbnew.

parent 6113bbf6
...@@ -50,6 +50,7 @@ set(COMMON_SRCS ...@@ -50,6 +50,7 @@ set(COMMON_SRCS
edaappl.cpp edaappl.cpp
eda_dde.cpp eda_dde.cpp
eda_doc.cpp eda_doc.cpp
filter_reader.cpp
gestfich.cpp gestfich.cpp
gr_basic.cpp gr_basic.cpp
hotkeys_basic.cpp hotkeys_basic.cpp
......
/*
* 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;
}
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "protos.h" #include "protos.h"
#include "cvstruct.h" #include "cvstruct.h"
#include "class_DisplayFootprintsFrame.h" #include "class_DisplayFootprintsFrame.h"
#include "richio.h"
#include "filter_reader.h"
/** /**
...@@ -27,9 +29,10 @@ ...@@ -27,9 +29,10 @@
*/ */
MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& CmpName ) MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& CmpName )
{ {
int LineNum, Found = 0; int Found = 0;
unsigned ii; unsigned ii;
char Line[1024], Name[255]; char* Line;
char Name[255];
wxString tmp, msg; wxString tmp, msg;
wxFileName fn; wxFileName fn;
MODULE* Module = NULL; MODULE* Module = NULL;
...@@ -61,9 +64,13 @@ found in the default search paths." ), ...@@ -61,9 +64,13 @@ found in the default search paths." ),
continue; continue;
} }
FILE_LINE_READER fileReader( file, tmp );
FILTER_READER reader( fileReader );
/* Read header. */ /* Read header. */
LineNum = 0; reader.ReadLine();
GetLine( file, Line, &LineNum ); 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 )
...@@ -76,15 +83,17 @@ found in the default search paths." ), ...@@ -76,15 +83,17 @@ found in the default search paths." ),
} }
Found = 0; Found = 0;
while( !Found && GetLine( file, Line, &LineNum ) ) while( !Found && reader.ReadLine() )
{ {
Line = reader.Line();
if( strncmp( Line, "$MODULE", 6 ) == 0 ) if( strncmp( Line, "$MODULE", 6 ) == 0 )
break; break;
if( strnicmp( Line, "$INDEX", 6 ) == 0 ) if( strnicmp( Line, "$INDEX", 6 ) == 0 )
{ {
while( GetLine( file, Line, &LineNum ) ) while( reader.ReadLine() )
{ {
Line = reader.Line();
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
break; break;
...@@ -98,8 +107,9 @@ found in the default search paths." ), ...@@ -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] != '$' ) if( Line[0] != '$' )
continue; continue;
...@@ -117,15 +127,13 @@ found in the default search paths." ), ...@@ -117,15 +127,13 @@ found in the default search paths." ),
// Switch the locale to standard C (needed to print floating // Switch the locale to standard C (needed to print floating
// point numbers like 1.3) // point numbers like 1.3)
SetLocaleTo_C_standard(); SetLocaleTo_C_standard();
Module->ReadDescr( file, &LineNum ); Module->ReadDescr( &reader );
SetLocaleTo_Default(); // revert to the current locale SetLocaleTo_Default(); // revert to the current locale
Module->SetPosition( wxPoint( 0, 0 ) ); Module->SetPosition( wxPoint( 0, 0 ) );
fclose( file );
return Module; return Module;
} }
} }
fclose( file );
file = NULL; file = NULL;
} }
......
/*
* 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 <wx/wx.h>
#include <string.h> #include "richio.h"
/** /**
...@@ -24,17 +50,7 @@ public: ...@@ -24,17 +50,7 @@ public:
{ {
} }
unsigned ReadLine() throw( IO_ERROR ) unsigned ReadLine() throw( IO_ERROR );
{
unsigned ret;
while( ( ret = reader.ReadLine() ) != 0 )
{
if( !strchr( "#\n\r", reader[0] ) )
break;
}
return ret;
}
const wxString& GetSource() const const wxString& GetSource() const
{ {
...@@ -57,3 +73,4 @@ public: ...@@ -57,3 +73,4 @@ public:
} }
}; };
#endif // FILTER_READER_H_
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "wxstruct.h" #include "wxstruct.h"
#include "base_struct.h" #include "base_struct.h"
#include "richio.h"
#ifndef PCB_INTERNAL_UNIT #ifndef PCB_INTERNAL_UNIT
#define PCB_INTERNAL_UNIT 10000 #define PCB_INTERNAL_UNIT 10000
...@@ -121,15 +122,14 @@ public: ...@@ -121,15 +122,14 @@ public:
public: public:
// Read/write functions: // Read/write functions:
EDA_ITEM* ReadDrawSegmentDescr( FILE* File, int* LineNum ); EDA_ITEM* ReadDrawSegmentDescr( LINE_READER* aReader );
int ReadListeSegmentDescr( FILE* File, int ReadListeSegmentDescr( LINE_READER* aReader,
TRACK* PtSegm, TRACK* PtSegm,
int StructType, int StructType,
int* LineNum,
int NumSegm ); int NumSegm );
int ReadSetup( FILE* File, int* LineNum ); int ReadSetup( LINE_READER* aReader );
int ReadGeneralDescrPcb( FILE* File, int* LineNum ); int ReadGeneralDescrPcb( LINE_READER* aReader );
/** /**
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base_struct.h" #include "base_struct.h"
#include "param_config.h" #include "param_config.h"
#include "class_layerchoicebox.h" #include "class_layerchoicebox.h"
#include "richio.h"
#ifndef PCB_INTERNAL_UNIT #ifndef PCB_INTERNAL_UNIT
#define PCB_INTERNAL_UNIT 10000 #define PCB_INTERNAL_UNIT 10000
...@@ -594,7 +595,7 @@ public: ...@@ -594,7 +595,7 @@ public:
* the file else all items of the board file are added to the * the file else all items of the board file are added to the
* existing board * existing board
*/ */
int ReadPcbFile( FILE* File, bool Append ); int ReadPcbFile( LINE_READER* aReader, bool Append );
bool SavePcbFile( const wxString& FileName ); bool SavePcbFile( const wxString& FileName );
int SavePcbFormatAscii( FILE* File ); int SavePcbFormatAscii( FILE* File );
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "colors_selection.h" #include "colors_selection.h"
#include "kicad_string.h" #include "kicad_string.h"
#include "protos.h" #include "protos.h"
#include "richio.h"
DIMENSION::DIMENSION( BOARD_ITEM* aParent ) : DIMENSION::DIMENSION( BOARD_ITEM* aParent ) :
BOARD_ITEM( aParent, TYPE_DIMENSION ) BOARD_ITEM( aParent, TYPE_DIMENSION )
...@@ -100,12 +101,14 @@ void DIMENSION::Copy( DIMENSION* source ) ...@@ -100,12 +101,14 @@ void DIMENSION::Copy( DIMENSION* source )
} }
bool DIMENSION::ReadDimensionDescr( FILE* File, int* LineNum ) bool DIMENSION::ReadDimensionDescr( LINE_READER* aReader )
{ {
char Line[2048], Text[2048]; char* Line;
char Text[2048];
while( GetLine( File, Line, LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "$EndDIMENSION", 4 ) == 0 ) if( strnicmp( Line, "$EndDIMENSION", 4 ) == 0 )
return TRUE; return TRUE;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#define DIMENSION_H #define DIMENSION_H
#include "base_struct.h" #include "base_struct.h"
#include "richio.h"
class DIMENSION : public BOARD_ITEM class DIMENSION : public BOARD_ITEM
{ {
...@@ -47,7 +48,7 @@ public: ...@@ -47,7 +48,7 @@ public:
*/ */
void AdjustDimensionDetails( bool aDoNotChangeText = false); void AdjustDimensionDetails( bool aDoNotChangeText = false);
bool ReadDimensionDescr( FILE* File, int* LineNum ); bool ReadDimensionDescr( LINE_READER* aReader );
/** /**
* Function Save * Function Save
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "trigo.h" #include "trigo.h"
#include "protos.h" #include "protos.h"
#include "richio.h"
/* DRAWSEGMENT: constructor */ /* DRAWSEGMENT: constructor */
DRAWSEGMENT::DRAWSEGMENT( BOARD_ITEM* aParent, KICAD_T idtype ) : DRAWSEGMENT::DRAWSEGMENT( BOARD_ITEM* aParent, KICAD_T idtype ) :
...@@ -113,16 +114,17 @@ out: ...@@ -113,16 +114,17 @@ out:
/******************************************************************/ /******************************************************************/
bool DRAWSEGMENT::ReadDrawSegmentDescr( FILE* File, int* LineNum ) bool DRAWSEGMENT::ReadDrawSegmentDescr( LINE_READER* aReader )
/******************************************************************/ /******************************************************************/
/* Read a DRAWSEGMENT from a file /* Read a DRAWSEGMENT from a file
*/ */
{ {
char Line[2048]; char* Line;
while( GetLine( File, Line, LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "$End", 4 ) == 0 ) if( strnicmp( Line, "$End", 4 ) == 0 )
return TRUE; /* End of description */ return TRUE; /* End of description */
if( Line[0] == 'P' ) if( Line[0] == 'P' )
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CLASS_DRAWSEGMENT_H #ifndef CLASS_DRAWSEGMENT_H
#define CLASS_DRAWSEGMENT_H #define CLASS_DRAWSEGMENT_H
#include "PolyLine.h" #include "PolyLine.h"
#include "richio.h"
class DRAWSEGMENT : public BOARD_ITEM class DRAWSEGMENT : public BOARD_ITEM
{ {
...@@ -59,7 +60,7 @@ public: ...@@ -59,7 +60,7 @@ public:
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
bool ReadDrawSegmentDescr( FILE* File, int* LineNum ); bool ReadDrawSegmentDescr( LINE_READER* aReader );
void Copy( DRAWSEGMENT* source ); void Copy( DRAWSEGMENT* source );
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "pcbnew.h" #include "pcbnew.h"
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "richio.h"
#define MAX_WIDTH 10000 /* Thickness (in 1 / 10000 ") of maximum reasonable #define MAX_WIDTH 10000 /* Thickness (in 1 / 10000 ") of maximum reasonable
* features, text... */ * features, text... */
...@@ -381,12 +382,14 @@ bool EDGE_MODULE::Save( FILE* aFile ) const ...@@ -381,12 +382,14 @@ bool EDGE_MODULE::Save( FILE* aFile ) const
* - Polygon * - Polygon
* *
*/ */
int EDGE_MODULE::ReadDescr( char* Line, FILE* File, int EDGE_MODULE::ReadDescr( LINE_READER* aReader )
int* LineNum )
{ {
int ii; int ii;
int error = 0; int error = 0;
char Buf[1024]; char* Buf;
char* Line;
Line = aReader->Line();
switch( Line[1] ) switch( Line[1] )
{ {
...@@ -439,13 +442,13 @@ int EDGE_MODULE::ReadDescr( char* Line, FILE* File, ...@@ -439,13 +442,13 @@ int EDGE_MODULE::ReadDescr( char* Line, FILE* File,
&m_End0.x, &m_End0.y, &m_End0.x, &m_End0.y,
&pointCount, &m_Width, &m_Layer ); &pointCount, &m_Width, &m_Layer );
(*LineNum)++;
m_PolyPoints.clear(); m_PolyPoints.clear();
m_PolyPoints.reserve( pointCount ); m_PolyPoints.reserve( pointCount );
for( ii = 0; ii<pointCount; ii++ ) for( ii = 0; ii<pointCount; ii++ )
{ {
if( GetLine( File, Buf, LineNum, sizeof(Buf) - 1 ) != NULL ) if( aReader->ReadLine() )
{ {
Buf = aReader->Line();
if( strncmp( Buf, "Dl", 2 ) != 0 ) if( strncmp( Buf, "Dl", 2 ) != 0 )
{ {
error = 1; error = 1;
...@@ -457,8 +460,6 @@ int EDGE_MODULE::ReadDescr( char* Line, FILE* File, ...@@ -457,8 +460,6 @@ int EDGE_MODULE::ReadDescr( char* Line, FILE* File,
sscanf( Buf + 3, "%d %d\n", &x, &y ); sscanf( Buf + 3, "%d %d\n", &x, &y );
m_PolyPoints.push_back( wxPoint( x, y ) ); m_PolyPoints.push_back( wxPoint( x, y ) );
(*LineNum)++;
} }
else else
{ {
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
/* class_edge_module.h : EDGE_MODULE class definition. */ /* class_edge_module.h : EDGE_MODULE class definition. */
/*******************************************************/ /*******************************************************/
#include "richio.h"
class Pcb3D_GLCanvas; class Pcb3D_GLCanvas;
...@@ -53,7 +55,7 @@ public: ...@@ -53,7 +55,7 @@ public:
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
int ReadDescr( char* Line, FILE* File, int* LineNum = NULL ); int ReadDescr( LINE_READER* aReader );
void SetDrawCoord(); void SetDrawCoord();
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "colors_selection.h" #include "colors_selection.h"
#include "trigo.h" #include "trigo.h"
#include "protos.h" #include "protos.h"
#include "richio.h"
MIREPCB::MIREPCB( BOARD_ITEM* aParent ) : MIREPCB::MIREPCB( BOARD_ITEM* aParent ) :
...@@ -41,12 +42,13 @@ void MIREPCB::Copy( MIREPCB* source ) ...@@ -41,12 +42,13 @@ void MIREPCB::Copy( MIREPCB* source )
/* Read the description from the PCB file. /* Read the description from the PCB file.
*/ */
bool MIREPCB::ReadMirePcbDescr( FILE* File, int* LineNum ) bool MIREPCB::ReadMirePcbDescr( LINE_READER* aReader )
{ {
char Line[256]; char* Line;
while( GetLine( File, Line, LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "$End", 4 ) == 0 ) if( strnicmp( Line, "$End", 4 ) == 0 )
return TRUE; return TRUE;
if( Line[0] == 'P' ) if( Line[0] == 'P' )
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#define MIRE_H #define MIRE_H
#include "base_struct.h" #include "base_struct.h"
#include "richio.h"
class MIREPCB : public BOARD_ITEM class MIREPCB : public BOARD_ITEM
...@@ -61,7 +62,7 @@ public: ...@@ -61,7 +62,7 @@ public:
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
bool ReadMirePcbDescr( FILE* File, int* LineNum ); bool ReadMirePcbDescr( LINE_READER* aReader );
void Copy( MIREPCB* source ); void Copy( MIREPCB* source );
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "3d_struct.h" #include "3d_struct.h"
#include "protos.h" #include "protos.h"
#include "richio.h"
/*********************************************/ /*********************************************/
...@@ -409,9 +410,9 @@ int MODULE::Write_3D_Descr( FILE* File ) const ...@@ -409,9 +410,9 @@ int MODULE::Write_3D_Descr( FILE* File ) const
* The 1st line of descr ($MODULE) is assumed to be already read * The 1st line of descr ($MODULE) is assumed to be already read
* Returns 0 if OK * Returns 0 if OK
*/ */
int MODULE::Read_3D_Descr( FILE* File, int* LineNum ) int MODULE::Read_3D_Descr( LINE_READER* aReader )
{ {
char Line[1024]; char* Line = aReader->Line();
char* text = Line + 3; char* text = Line + 3;
S3D_MASTER* t3D = m_3D_Drawings; S3D_MASTER* t3D = m_3D_Drawings;
...@@ -425,8 +426,9 @@ int MODULE::Read_3D_Descr( FILE* File, int* LineNum ) ...@@ -425,8 +426,9 @@ int MODULE::Read_3D_Descr( FILE* File, int* LineNum )
t3D = n3D; t3D = n3D;
} }
while( GetLine( File, Line, LineNum, sizeof(Line) - 1 ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
switch( Line[0] ) switch( Line[0] )
{ {
case '$': case '$':
...@@ -476,13 +478,15 @@ int MODULE::Read_3D_Descr( FILE* File, int* LineNum ) ...@@ -476,13 +478,15 @@ int MODULE::Read_3D_Descr( FILE* File, int* LineNum )
* The first description line ($MODULE) is already read * The first description line ($MODULE) is already read
* @return 0 if no error * @return 0 if no error
*/ */
int MODULE::ReadDescr( FILE* File, int* LineNum ) int MODULE::ReadDescr( LINE_READER* aReader )
{ {
char Line[256], BufLine[256], BufCar1[128], * PtLine; char* Line;
int itmp1, itmp2; char BufLine[256], BufCar1[128], * PtLine;
int itmp1, itmp2;
while( GetLine( File, Line, LineNum, sizeof(Line) - 1 ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( Line[0] == '$' ) if( Line[0] == '$' )
{ {
if( Line[1] == 'E' ) if( Line[1] == 'E' )
...@@ -490,7 +494,7 @@ int MODULE::ReadDescr( FILE* File, int* LineNum ) ...@@ -490,7 +494,7 @@ int MODULE::ReadDescr( FILE* File, int* LineNum )
if( Line[1] == 'P' ) if( Line[1] == 'P' )
{ {
D_PAD* pad = new D_PAD( this ); D_PAD* pad = new D_PAD( this );
pad->ReadDescr( File, LineNum ); pad->ReadDescr( aReader );
RotatePoint( &pad->m_Pos, m_Orient ); RotatePoint( &pad->m_Pos, m_Orient );
pad->m_Pos.x += m_Pos.x; pad->m_Pos.x += m_Pos.x;
pad->m_Pos.y += m_Pos.y; pad->m_Pos.y += m_Pos.y;
...@@ -499,7 +503,7 @@ int MODULE::ReadDescr( FILE* File, int* LineNum ) ...@@ -499,7 +503,7 @@ int MODULE::ReadDescr( FILE* File, int* LineNum )
continue; continue;
} }
if( Line[1] == 'S' ) if( Line[1] == 'S' )
Read_3D_Descr( File, LineNum ); Read_3D_Descr( aReader );
} }
if( strlen( Line ) < 4 ) if( strlen( Line ) < 4 )
...@@ -584,14 +588,14 @@ int MODULE::ReadDescr( FILE* File, int* LineNum ) ...@@ -584,14 +588,14 @@ int MODULE::ReadDescr( FILE* File, int* LineNum )
textm = new TEXTE_MODULE( this ); textm = new TEXTE_MODULE( this );
m_Drawings.PushBack( textm ); m_Drawings.PushBack( textm );
} }
textm->ReadDescr( Line, File, LineNum ); textm->ReadDescr( aReader );
break; break;
case 'D': /* read a drawing item */ case 'D': /* read a drawing item */
EDGE_MODULE * edge; EDGE_MODULE * edge;
edge = new EDGE_MODULE( this ); edge = new EDGE_MODULE( this );
m_Drawings.PushBack( edge ); m_Drawings.PushBack( edge );
edge->ReadDescr( Line, File, LineNum ); edge->ReadDescr( aReader );
edge->SetDrawCoord(); edge->SetDrawCoord();
break; break;
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
class Pcb3D_GLCanvas; class Pcb3D_GLCanvas;
class S3D_MASTER; class S3D_MASTER;
#include "richio.h"
/************************************/ /************************************/
/* Modules (footprints) description */ /* Modules (footprints) description */
/* pad are in class_pad.xx */ /* pad are in class_pad.xx */
...@@ -210,7 +212,7 @@ public: ...@@ -210,7 +212,7 @@ public:
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
int Write_3D_Descr( FILE* File ) const; int Write_3D_Descr( FILE* File ) const;
int ReadDescr( FILE* File, int* LineNum = NULL ); int ReadDescr( LINE_READER* aReader );
/** /**
* Function Read_GPCB_Descr * Function Read_GPCB_Descr
...@@ -220,7 +222,7 @@ public: ...@@ -220,7 +222,7 @@ public:
* @return bool - true if success reading else false. * @return bool - true if success reading else false.
*/ */
bool Read_GPCB_Descr( const wxString& CmpFullFileName ); bool Read_GPCB_Descr( const wxString& CmpFullFileName );
int Read_3D_Descr( FILE* File, int* LineNum = NULL ); int Read_3D_Descr( LINE_READER* aReader );
/* drawing functions */ /* drawing functions */
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "kicad_string.h" #include "kicad_string.h"
#include "pcbnew.h" #include "pcbnew.h"
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "richio.h"
// Current design settings (used also to read configs): // Current design settings (used also to read configs):
extern BOARD_DESIGN_SETTINGS boardDesignSettings; extern BOARD_DESIGN_SETTINGS boardDesignSettings;
...@@ -332,15 +333,16 @@ void NETCLASS::Show( int nestLevel, std::ostream& os ) ...@@ -332,15 +333,16 @@ void NETCLASS::Show( int nestLevel, std::ostream& os )
bool NETCLASS::ReadDescr( FILE* aFile, int* aLineNum ) bool NETCLASS::ReadDescr( LINE_READER* aReader )
{ {
bool result = false; bool result = false;
char Line[1024]; char* Line;
char Buffer[1024]; char Buffer[1024];
wxString netname; wxString netname;
while( GetLine( aFile, Line, aLineNum, 1024 ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "AddNet", 6 ) == 0 ) if( strnicmp( Line, "AddNet", 6 ) == 0 )
{ {
ReadDelimitedText( Buffer, Line + 6, sizeof(Buffer) ); ReadDelimitedText( Buffer, Line + 6, sizeof(Buffer) );
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <set> #include <set>
#include <map> #include <map>
#include "richio.h"
/** /**
* Class NETCLASS * Class NETCLASS
...@@ -205,12 +205,11 @@ public: ...@@ -205,12 +205,11 @@ public:
/** /**
* Function ReadDescr * Function ReadDescr
* reads the data structures for this object from a FILE in "*.brd" format. * reads the data structures for this object from a LINE_READER in "*.brd" format.
* @param aFile The FILE to read to. * @param aReader is a pointer to a LINE_READER to read from.
* @param aLineNum a pointer to a line number counter
* @return bool - true if success reading else false. * @return bool - true if success reading else false.
*/ */
bool ReadDescr( FILE* aFile, int* aLineNum ); bool ReadDescr( LINE_READER* aReader );
#if defined(DEBUG) #if defined(DEBUG)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define __CLASSES_NETINFO__ #define __CLASSES_NETINFO__
#include "class_netclass.h" #include "class_netclass.h"
#include "richio.h"
class NETINFO_ITEM; class NETINFO_ITEM;
...@@ -317,7 +318,7 @@ public: ...@@ -317,7 +318,7 @@ public:
#endif #endif
/* Reading and writing data on files */ /* Reading and writing data on files */
int ReadDescr( FILE* File, int* LineNum ); int ReadDescr( LINE_READER* aReader );
/** /**
* Function Save * Function Save
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "pcbnew.h" #include "pcbnew.h"
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "colors_selection.h" #include "colors_selection.h"
#include "richio.h"
/*********************************************************/ /*********************************************************/
/* class NETINFO_ITEM: handle data relative to a given net */ /* class NETINFO_ITEM: handle data relative to a given net */
...@@ -42,13 +42,15 @@ NETINFO_ITEM::~NETINFO_ITEM() ...@@ -42,13 +42,15 @@ NETINFO_ITEM::~NETINFO_ITEM()
* Returns 0 if OK * Returns 0 if OK
* 1 if incomplete reading * 1 if incomplete reading
*/ */
int NETINFO_ITEM::ReadDescr( FILE* File, int* LineNum ) int NETINFO_ITEM::ReadDescr( LINE_READER* aReader )
{ {
char Line[1024], Ltmp[1024]; char* Line;
int tmp; char Ltmp[1024];
int tmp;
while( GetLine( File, Line, LineNum ) ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "$End", 4 ) == 0 ) if( strnicmp( Line, "$End", 4 ) == 0 )
return 0; return 0;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "trigo.h" #include "trigo.h"
#include "pcbnew_id.h" // ID_TRACK_BUTT #include "pcbnew_id.h" // ID_TRACK_BUTT
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "richio.h"
int D_PAD::m_PadSketchModePenSize = 0; // Pen size used to draw pads in sketch mode int D_PAD::m_PadSketchModePenSize = 0; // Pen size used to draw pads in sketch mode
...@@ -355,14 +356,16 @@ wxSize D_PAD::GetSolderPasteMargin() ...@@ -355,14 +356,16 @@ wxSize D_PAD::GetSolderPasteMargin()
* Po 6000 -6000 * Po 6000 -6000
* $EndPAD * $EndPAD
*/ */
int D_PAD::ReadDescr( FILE* File, int* LineNum ) int D_PAD::ReadDescr( LINE_READER* aReader )
{ {
char Line[1024], BufLine[1024], BufCar[256]; char* Line;
char BufLine[1024], BufCar[256];
char* PtLine; char* PtLine;
int nn, ll, dx, dy; int nn, ll, dx, dy;
while( GetLine( File, Line, LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( Line[0] == '$' ) if( Line[0] == '$' )
return 0; return 0;
......
...@@ -6,6 +6,7 @@ class Pcb3D_GLCanvas; ...@@ -6,6 +6,7 @@ class Pcb3D_GLCanvas;
#include "pad_shapes.h" #include "pad_shapes.h"
#include "PolyLine.h" #include "PolyLine.h"
#include "richio.h"
/* Default layers used for pads, according to the pad type. /* Default layers used for pads, according to the pad type.
* this is default values only, they can be changed for a given pad * this is default values only, they can be changed for a given pad
...@@ -218,7 +219,7 @@ public: ...@@ -218,7 +219,7 @@ public:
wxSize GetSolderPasteMargin(); wxSize GetSolderPasteMargin();
/* Reading and writing data on files */ /* Reading and writing data on files */
int ReadDescr( FILE* File, int* LineNum = NULL ); int ReadDescr( LINE_READER* aReader );
/** /**
* Function Save * Function Save
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "colors_selection.h" #include "colors_selection.h"
#include "trigo.h" #include "trigo.h"
#include "protos.h" #include "protos.h"
#include "richio.h"
/*******************/ /*******************/
...@@ -77,13 +78,15 @@ void TEXTE_PCB::Copy( TEXTE_PCB* source ) ...@@ -77,13 +78,15 @@ void TEXTE_PCB::Copy( TEXTE_PCB* source )
* $EndTEXTPCB * $EndTEXTPCB
* Nl "line nn" is a line added to the current text * Nl "line nn" is a line added to the current text
*/ */
int TEXTE_PCB::ReadTextePcbDescr( FILE* File, int* LineNum ) int TEXTE_PCB::ReadTextePcbDescr( LINE_READER* aReader )
{ {
char text[1024], Line[1024]; char* Line;
char style[256]; char text[1024];
char style[256];
while( GetLine( File, Line, LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "$EndTEXTPCB", 11 ) == 0 ) if( strnicmp( Line, "$EndTEXTPCB", 11 ) == 0 )
return 0; return 0;
if( strncmp( Line, "Te", 2 ) == 0 ) /* Text line (first line for multi line texts */ if( strncmp( Line, "Te", 2 ) == 0 ) /* Text line (first line for multi line texts */
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base_struct.h" #include "base_struct.h"
#include "PolyLine.h" #include "PolyLine.h"
#include "richio.h"
class TEXTE_PCB : public BOARD_ITEM, public EDA_TextStruct class TEXTE_PCB : public BOARD_ITEM, public EDA_TextStruct
{ {
...@@ -57,7 +58,7 @@ public: ...@@ -57,7 +58,7 @@ public:
const wxPoint& offset = ZeroOffset ); const wxPoint& offset = ZeroOffset );
// File Operations: // File Operations:
int ReadTextePcbDescr( FILE* File, int* LineNum ); int ReadTextePcbDescr( LINE_READER* aReader );
/** /**
* Function Save * Function Save
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "pcbcommon.h" #include "pcbcommon.h"
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "colors_selection.h" #include "colors_selection.h"
#include "richio.h"
/*******************************************************************/ /*******************************************************************/
/* Class TEXTE_MODULE base class type of text elements in a module */ /* Class TEXTE_MODULE base class type of text elements in a module */
...@@ -100,12 +101,15 @@ bool TEXTE_MODULE::Save( FILE* aFile ) const ...@@ -100,12 +101,15 @@ bool TEXTE_MODULE::Save( FILE* aFile ) const
* @param aLineNum a point to the line count (currently not used). * @param aLineNum a point to the line count (currently not used).
* @return int - > 0 if success reading else 0. * @return int - > 0 if success reading else 0.
*/ */
int TEXTE_MODULE::ReadDescr( char* aLine, FILE* aFile, int* aLineNum ) int TEXTE_MODULE::ReadDescr( LINE_READER* aReader )
{ {
int success = true; int success = true;
int type; int type;
int layer; int layer;
char BufCar1[128], BufCar2[128], BufCar3[128], BufLine[256]; char BufCar1[128], BufCar2[128], BufCar3[128], BufLine[256];
char *aLine;
aLine = aReader->Line();
layer = SILKSCREEN_N_FRONT; layer = SILKSCREEN_N_FRONT;
BufCar1[0] = 0; BufCar1[0] = 0;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#ifndef TEXT_MODULE_H #ifndef TEXT_MODULE_H
#define TEXT_MODULE_H #define TEXT_MODULE_H
#include "richio.h"
#define TEXT_is_REFERENCE 0 #define TEXT_is_REFERENCE 0
#define TEXT_is_VALUE 1 #define TEXT_is_VALUE 1
...@@ -81,13 +82,10 @@ public: TEXTE_MODULE( MODULE* parent, int text_type = TEXT_is_DIVERS ); ...@@ -81,13 +82,10 @@ public: TEXTE_MODULE( MODULE* parent, int text_type = TEXT_is_DIVERS );
/** /**
* Function ReadDescr * Function ReadDescr
* Read description from a given line in "*.brd" format. * Read description from a given line in "*.brd" format.
* @param aLine The current line which contains the first line of * @param aReader is a pointer to a LINE_READER to read from.
* description.
* @param aFile The FILE to read next lines (currently not used).
* @param aLineNum a point to the line count (currently not used).
* @return int - > 0 if success reading else 0. * @return int - > 0 if success reading else 0.
*/ */
int ReadDescr( char* aLine, FILE* aFile, int* aLineNum = NULL ); int ReadDescr( LINE_READER* aReader );
/* drawing functions */ /* drawing functions */
void Draw( WinEDA_DrawPanel* panel, void Draw( WinEDA_DrawPanel* panel,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "colors_selection.h" #include "colors_selection.h"
#include "protos.h" #include "protos.h"
#include "richio.h"
/************************/ /************************/
/* class ZONE_CONTAINER */ /* class ZONE_CONTAINER */
...@@ -215,26 +216,20 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const ...@@ -215,26 +216,20 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const
/**********************************************************/ /**********************************************************/
int ZONE_CONTAINER::ReadDescr( FILE* aFile, int* aLineNum ) int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader )
/**********************************************************/ /**********************************************************/
/**
* Function ReadDescr
* @param aFile = opened file
* @param aLineNum = pointer on a line number counter (can be NULL or missing)
* @return 1 if ok or 0
*/
{ {
char Line[1024], * text; char* Line, * text;
char netname_buffer[1024]; char netname_buffer[1024];
int ret; int ret;
int n_corner_item = 0; int n_corner_item = 0;
int outline_hatch = CPolyLine::NO_HATCH; int outline_hatch = CPolyLine::NO_HATCH;
bool error = false, has_corner = false; bool error = false, has_corner = false;
netname_buffer[0] = 0; netname_buffer[0] = 0;
while( GetLine( aFile, Line, aLineNum, sizeof(Line) - 1 ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "ZCorner", 7 ) == 0 ) // new corner found if( strnicmp( Line, "ZCorner", 7 ) == 0 ) // new corner found
{ {
int x; int x;
...@@ -382,8 +377,9 @@ int ZONE_CONTAINER::ReadDescr( FILE* aFile, int* aLineNum ) ...@@ -382,8 +377,9 @@ int ZONE_CONTAINER::ReadDescr( FILE* aFile, int* aLineNum )
else if( strnicmp( Line, "$POLYSCORNERS", 13 ) == 0 ) // Read the PolysList (polygons used for fill areas in the zone) else if( strnicmp( Line, "$POLYSCORNERS", 13 ) == 0 ) // Read the PolysList (polygons used for fill areas in the zone)
{ {
while( GetLine( aFile, Line, aLineNum, sizeof(Line) - 1 ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "$endPOLYSCORNERS", 4 ) == 0 ) if( strnicmp( Line, "$endPOLYSCORNERS", 4 ) == 0 )
break; break;
CPolyPt corner; CPolyPt corner;
...@@ -401,8 +397,9 @@ int ZONE_CONTAINER::ReadDescr( FILE* aFile, int* aLineNum ) ...@@ -401,8 +397,9 @@ int ZONE_CONTAINER::ReadDescr( FILE* aFile, int* aLineNum )
else if( strnicmp( Line, "$FILLSEGMENTS", 13) == 0 ) else if( strnicmp( Line, "$FILLSEGMENTS", 13) == 0 )
{ {
SEGMENT segm; SEGMENT segm;
while( GetLine( aFile, Line, aLineNum, sizeof(Line) - 1 ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "$endFILLSEGMENTS", 4 ) == 0 ) if( strnicmp( Line, "$endFILLSEGMENTS", 4 ) == 0 )
break; break;
ret = sscanf( Line, "%d %d %d %d", &segm.m_Start.x, &segm.m_Start.y, &segm.m_End.x, &segm.m_End.y ); ret = sscanf( Line, "%d %d %d %d", &segm.m_Start.x, &segm.m_Start.y, &segm.m_End.x, &segm.m_End.y );
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "gr_basic.h" #include "gr_basic.h"
#include "PolyLine.h" #include "PolyLine.h"
#include "richio.h"
/* a small class used when filling areas with segments */ /* a small class used when filling areas with segments */
class SEGMENT class SEGMENT
...@@ -66,7 +67,14 @@ public: ...@@ -66,7 +67,14 @@ public:
~ZONE_CONTAINER(); ~ZONE_CONTAINER();
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
int ReadDescr( FILE* aFile, int* aLineNum = NULL );
/**
* Function ReadDescr
* reads the data structures for this object from a LINE_READER in "*.brd" format.
* @param aReader is a pointer to a LINE_READER to read from.
* @return int - 1 if success, 0 if not.
*/
int ReadDescr( LINE_READER* aReader );
/** virtual function GetPosition /** virtual function GetPosition
* @return a wxPoint, position of the first point of the outline * @return a wxPoint, position of the first point of the outline
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "protos.h" #include "protos.h"
#include "pcbnew_id.h" #include "pcbnew_id.h"
#include "3d_viewer.h" #include "3d_viewer.h"
#include "richio.h"
#include "filter_reader.h"
#define BACKUP_FILE_EXT wxT( "000" ) #define BACKUP_FILE_EXT wxT( "000" )
...@@ -134,10 +136,8 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event ) ...@@ -134,10 +136,8 @@ void WinEDA_PcbFrame::Files_io( wxCommandEvent& event )
bool WinEDA_PcbFrame::LoadOnePcbFile( const wxString& aFileName, bool aAppend, bool WinEDA_PcbFrame::LoadOnePcbFile( const wxString& aFileName, bool aAppend,
bool aForceFileDialog ) bool aForceFileDialog )
{ {
int ii;
FILE* source; FILE* source;
wxString msg; wxString msg;
char cbuf[1024];
ActiveScreen = GetScreen(); ActiveScreen = GetScreen();
...@@ -198,18 +198,20 @@ the changes?" ) ) ) ...@@ -198,18 +198,20 @@ the changes?" ) ) )
return false; return false;
} }
FILE_LINE_READER fileReader( source, GetScreen()->m_FileName );
FILTER_READER reader( fileReader );
/* Read header and TEST if it is a PCB file format */ /* Read header and TEST if it is a PCB file format */
GetLine( source, cbuf, &ii ); reader.ReadLine();
if( strncmp( cbuf, "PCBNEW-BOARD", 12 ) != 0 ) if( strncmp( reader.Line(), "PCBNEW-BOARD", 12 ) != 0 )
{ {
fclose( source );
DisplayError( this, wxT( "Unknown file type" ) ); DisplayError( this, wxT( "Unknown file type" ) );
return false; return false;
} }
int ver; int ver;
sscanf(cbuf, "PCBNEW-BOARD Version %d date", &ver ); sscanf( reader.Line() , "PCBNEW-BOARD Version %d date", &ver );
if ( ver > g_CurrentVersionPCB ) if ( ver > g_CurrentVersionPCB )
{ {
DisplayInfoMessage( this, _( "This file was created by a more recent \ DisplayInfoMessage( this, _( "This file was created by a more recent \
...@@ -225,7 +227,7 @@ this file again." ) ); ...@@ -225,7 +227,7 @@ this file again." ) );
// Reload the corresponding configuration file: // Reload the corresponding configuration file:
wxSetWorkingDirectory( wxPathOnly( GetScreen()->m_FileName ) ); wxSetWorkingDirectory( wxPathOnly( GetScreen()->m_FileName ) );
if( aAppend ) if( aAppend )
ReadPcbFile( source, true ); ReadPcbFile( &reader, true );
else else
{ {
// Update the option toolbar // Update the option toolbar
...@@ -235,12 +237,10 @@ this file again." ) ); ...@@ -235,12 +237,10 @@ this file again." ) );
m_DisplayPadFill = DisplayOpt.DisplayPadFill; m_DisplayPadFill = DisplayOpt.DisplayPadFill;
m_DisplayViaFill = DisplayOpt.DisplayViaFill; m_DisplayViaFill = DisplayOpt.DisplayViaFill;
ReadPcbFile( source, false ); ReadPcbFile( &reader, false );
LoadProjectSettings( GetScreen()->m_FileName ); LoadProjectSettings( GetScreen()->m_FileName );
} }
fclose( source );
GetScreen()->ClrModify(); GetScreen()->ClrModify();
/* If append option: change the initial board name to <oldname>-append.brd */ /* If append option: change the initial board name to <oldname>-append.brd */
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
#include "kicad_string.h" #include "kicad_string.h"
#include "pcbnew.h" #include "pcbnew.h"
#include "trigo.h" #include "trigo.h"
#include "richio.h"
#include "filter_reader.h"
/* read parameters from a line, and return all params in a wxArrayString /* read parameters from a line, and return all params in a wxArrayString
* each param is in one wxString, and double quotes removed if exists * each param is in one wxString, and double quotes removed if exists
...@@ -155,8 +156,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) ...@@ -155,8 +156,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName )
double conv_unit = NEW_GPCB_UNIT_CONV; // GPCB unit = 0.01 mils and pcbnew 0.1 double conv_unit = NEW_GPCB_UNIT_CONV; // GPCB unit = 0.01 mils and pcbnew 0.1
// Old version unit = 1 mil, so conv_unit is 10 or 0.1 // Old version unit = 1 mil, so conv_unit is 10 or 0.1
bool success = true; bool success = true;
char Line[1024]; char* Line;
int NbLine = 0;
long ibuf[100]; long ibuf[100];
EDGE_MODULE* DrawSegm; EDGE_MODULE* DrawSegm;
D_PAD* Pad; D_PAD* Pad;
...@@ -166,7 +166,13 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) ...@@ -166,7 +166,13 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName )
if( ( cmpfile = wxFopen( CmpFullFileName, wxT( "rt" ) ) ) == NULL ) if( ( cmpfile = wxFopen( CmpFullFileName, wxT( "rt" ) ) ) == NULL )
return false; return false;
GetLine( cmpfile, Line, &NbLine ); FILE_LINE_READER fileReader( cmpfile, CmpFullFileName );
FILTER_READER reader( fileReader );
reader.ReadLine();
Line = reader.Line();
params.Clear(); params.Clear();
Extract_Parameters( params, Line ); Extract_Parameters( params, Line );
...@@ -176,7 +182,6 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) ...@@ -176,7 +182,6 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName )
if( params[iprmcnt].CmpNoCase( wxT( "Element" ) ) != 0 ) if( params[iprmcnt].CmpNoCase( wxT( "Element" ) ) != 0 )
{ {
fclose( cmpfile );
return false; return false;
} }
...@@ -232,8 +237,9 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) ...@@ -232,8 +237,9 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName )
m_Value->m_Size = m_Reference->m_Size; m_Value->m_Size = m_Reference->m_Size;
m_Value->m_Thickness = m_Reference->m_Thickness; m_Value->m_Thickness = m_Reference->m_Thickness;
while( GetLine( cmpfile, Line, &NbLine, sizeof(Line) - 1 ) != NULL ) while( reader.ReadLine() )
{ {
Line = reader.Line();
params.Clear(); params.Clear();
Extract_Parameters( params, Line ); Extract_Parameters( params, Line );
if( params.GetCount() > 3 ) // Test units value for a string line param (more than 3 params : ident [ xx ] ) if( params.GetCount() > 3 ) // Test units value for a string line param (more than 3 params : ident [ xx ] )
...@@ -409,8 +415,6 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) ...@@ -409,8 +415,6 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName )
} }
} }
fclose( cmpfile );
if( m_Value->m_Text.IsEmpty() ) if( m_Value->m_Text.IsEmpty() )
m_Value->m_Text = wxT( "Val**" ); m_Value->m_Text = wxT( "Val**" );
if( m_Reference->m_Text.IsEmpty() ) if( m_Reference->m_Text.IsEmpty() )
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "build_version.h" #include "build_version.h"
#include "pcbnew_id.h" #include "pcbnew_id.h"
#include "richio.h"
/* ASCII format of structures: /* ASCII format of structures:
* *
...@@ -80,42 +81,50 @@ int NbDraw, NbTrack, NbZone, NbMod, NbNets; ...@@ -80,42 +81,50 @@ int NbDraw, NbTrack, NbZone, NbMod, NbNets;
/** Read a list of segments (Tracks, zones) /** Read a list of segments (Tracks, zones)
* @return items count or - count if no end block ($End...) found. * @return items count or - count if no end block ($End...) found.
*/ */
int WinEDA_BasePcbFrame::ReadListeSegmentDescr( FILE* File, int WinEDA_BasePcbFrame::ReadListeSegmentDescr( LINE_READER* aReader,
TRACK* insertBeforeMe, TRACK* insertBeforeMe,
int StructType, int StructType,
int* LineNum,
int NumSegm ) int NumSegm )
{ {
int shape, width, drill, layer, type, flags, net_code; int shape, width, drill, layer, type, flags, net_code;
int tempStartX, tempStartY;
int tempEndX, tempEndY;
int ii = 0; int ii = 0;
char line1[256]; char* line;
char line2[256];
TRACK* newTrack; TRACK* newTrack;
while( GetLine( File, line1, LineNum ) ) while( aReader->ReadLine() )
{ {
line = aReader->Line();
int makeType; int makeType;
unsigned long timeStamp; unsigned long timeStamp;
if( line1[0] == '$' ) if( line[0] == '$' )
{ {
return ii; /* end of segmentlist: OK */ return ii; /* end of segmentlist: OK */
} }
int arg_count = sscanf( line + 2, " %d %d %d %d %d %d %d", &shape,
&tempStartX, &tempStartY,
&tempEndX, &tempEndY, &width,
&drill );
// Read the 2nd line to determine the exact type, one of: // Read the 2nd line to determine the exact type, one of:
// TYPE_TRACK, TYPE_VIA, or TYPE_ZONE. The type field in 2nd line // TYPE_TRACK, TYPE_VIA, or TYPE_ZONE. The type field in 2nd line
// differentiates between TYPE_TRACK and TYPE_VIA. With virtual // differentiates between TYPE_TRACK and TYPE_VIA. With virtual
// functions in use, it is critical to instantiate the TYPE_VIA // functions in use, it is critical to instantiate the TYPE_VIA
// exactly. // exactly.
if( GetLine( File, line2, LineNum ) == NULL ) if( !aReader->ReadLine() )
break; break;
if( line2[0] == '$' ) line = aReader->Line();
if( line[0] == '$' )
break; break;
// parse the 2nd line first to determine the type of object // parse the 2nd line first to determine the type of object
sscanf( line2 + 2, " %d %d %d %lX %X", &layer, &type, &net_code, sscanf( line + 2, " %d %d %d %lX %X", &layer, &type, &net_code,
&timeStamp, &flags ); &timeStamp, &flags );
if( StructType==TYPE_TRACK && type==1 ) if( StructType==TYPE_TRACK && type==1 )
...@@ -145,10 +154,10 @@ int WinEDA_BasePcbFrame::ReadListeSegmentDescr( FILE* File, ...@@ -145,10 +154,10 @@ int WinEDA_BasePcbFrame::ReadListeSegmentDescr( FILE* File,
newTrack->m_TimeStamp = timeStamp; newTrack->m_TimeStamp = timeStamp;
int arg_count = sscanf( line1 + 2, " %d %d %d %d %d %d %d", &shape, newTrack->m_Start.x = tempStartX;
&newTrack->m_Start.x, &newTrack->m_Start.y, newTrack->m_Start.y = tempStartY;
&newTrack->m_End.x, &newTrack->m_End.y, &width, newTrack->m_End.x = tempEndX;
&drill ); newTrack->m_End.y = tempEndY;
newTrack->m_Width = width; newTrack->m_Width = width;
newTrack->m_Shape = shape; newTrack->m_Shape = shape;
...@@ -176,12 +185,13 @@ int WinEDA_BasePcbFrame::ReadListeSegmentDescr( FILE* File, ...@@ -176,12 +185,13 @@ int WinEDA_BasePcbFrame::ReadListeSegmentDescr( FILE* File,
} }
int WinEDA_BasePcbFrame::ReadGeneralDescrPcb( FILE* File, int* LineNum ) int WinEDA_BasePcbFrame::ReadGeneralDescrPcb( LINE_READER* aReader )
{ {
char Line[1024], * data; char* Line, * data;
while( GetLine( File, Line, LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
data = strtok( Line, " =\n\r" ); data = strtok( Line, " =\n\r" );
if( strnicmp( data, "$EndGENERAL", 10 ) == 0 ) if( strnicmp( data, "$EndGENERAL", 10 ) == 0 )
break; break;
...@@ -294,15 +304,16 @@ int WinEDA_BasePcbFrame::ReadGeneralDescrPcb( FILE* File, int* LineNum ) ...@@ -294,15 +304,16 @@ int WinEDA_BasePcbFrame::ReadGeneralDescrPcb( FILE* File, int* LineNum )
} }
int WinEDA_BasePcbFrame::ReadSetup( FILE* File, int* LineNum ) int WinEDA_BasePcbFrame::ReadSetup( LINE_READER* aReader )
{ {
char Line[1024]; char* Line;
char* data; char* data;
NETCLASS* netclass_default = GetBoard()->m_NetClasses.GetDefault(); NETCLASS* netclass_default = GetBoard()->m_NetClasses.GetDefault();
while( GetLine( File, Line, LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
strtok( Line, " =\n\r" ); strtok( Line, " =\n\r" );
data = strtok( NULL, " =\n\r" ); data = strtok( NULL, " =\n\r" );
...@@ -802,12 +813,13 @@ bool WriteSheetDescr( BASE_SCREEN* screen, FILE* File ) ...@@ -802,12 +813,13 @@ bool WriteSheetDescr( BASE_SCREEN* screen, FILE* File )
} }
static bool ReadSheetDescr( BASE_SCREEN* screen, FILE* File, int* LineNum ) static bool ReadSheetDescr( BASE_SCREEN* screen, LINE_READER* aReader )
{ {
char Line[1024], buf[1024], * text; char* Line, buf[1024], * text;
while( GetLine( File, Line, LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
if( strnicmp( Line, "$End", 4 ) == 0 ) if( strnicmp( Line, "$End", 4 ) == 0 )
return TRUE; return TRUE;
...@@ -899,10 +911,9 @@ static bool ReadSheetDescr( BASE_SCREEN* screen, FILE* File, int* LineNum ) ...@@ -899,10 +911,9 @@ static bool ReadSheetDescr( BASE_SCREEN* screen, FILE* File, int* LineNum )
} }
int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) int WinEDA_PcbFrame::ReadPcbFile( LINE_READER* aReader, bool Append )
{ {
char Line[1024]; char* Line;
int LineNum = 0;
wxBusyCursor dummy; wxBusyCursor dummy;
...@@ -922,8 +933,9 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -922,8 +933,9 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
// string. // string.
#define TESTLINE( x ) (strncmp( Line, "$" x, sizeof("$" x) - 1 ) == 0) #define TESTLINE( x ) (strncmp( Line, "$" x, sizeof("$" x) - 1 ) == 0)
while( GetLine( File, Line, &LineNum ) != NULL ) while( aReader->ReadLine() )
{ {
Line = aReader->Line();
// put the more frequent ones at the top // put the more frequent ones at the top
if( TESTLINE( "MODULE" ) ) if( TESTLINE( "MODULE" ) )
...@@ -934,7 +946,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -934,7 +946,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
continue; continue;
board->Add( Module, ADD_APPEND ); board->Add( Module, ADD_APPEND );
Module->ReadDescr( File, &LineNum ); Module->ReadDescr( aReader );
continue; continue;
} }
...@@ -942,7 +954,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -942,7 +954,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
{ {
DRAWSEGMENT* DrawSegm = new DRAWSEGMENT( board ); DRAWSEGMENT* DrawSegm = new DRAWSEGMENT( board );
board->Add( DrawSegm, ADD_APPEND ); board->Add( DrawSegm, ADD_APPEND );
DrawSegm->ReadDrawSegmentDescr( File, &LineNum ); DrawSegm->ReadDrawSegmentDescr( aReader );
continue; continue;
} }
...@@ -950,7 +962,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -950,7 +962,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
{ {
NETINFO_ITEM* net = new NETINFO_ITEM( board ); NETINFO_ITEM* net = new NETINFO_ITEM( board );
board->m_NetInfo->AppendNet( net ); board->m_NetInfo->AppendNet( net );
net->ReadDescr( File, &LineNum ); net->ReadDescr( aReader );
continue; continue;
} }
...@@ -958,7 +970,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -958,7 +970,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
{ {
TEXTE_PCB* pcbtxt = new TEXTE_PCB( board ); TEXTE_PCB* pcbtxt = new TEXTE_PCB( board );
board->Add( pcbtxt, ADD_APPEND ); board->Add( pcbtxt, ADD_APPEND );
pcbtxt->ReadTextePcbDescr( File, &LineNum ); pcbtxt->ReadTextePcbDescr( aReader );
continue; continue;
} }
...@@ -966,8 +978,8 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -966,8 +978,8 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
{ {
#ifdef PCBNEW #ifdef PCBNEW
TRACK* insertBeforeMe = Append ? NULL : board->m_Track.GetFirst(); TRACK* insertBeforeMe = Append ? NULL : board->m_Track.GetFirst();
ReadListeSegmentDescr( File, insertBeforeMe, TYPE_TRACK, ReadListeSegmentDescr( aReader, insertBeforeMe, TYPE_TRACK,
&LineNum, NbTrack ); NbTrack );
#endif #endif
continue; continue;
} }
...@@ -978,7 +990,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -978,7 +990,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
NETCLASS* netclass = new NETCLASS( board, wxEmptyString ); NETCLASS* netclass = new NETCLASS( board, wxEmptyString );
// fill it from the *.brd file, and establish its name. // fill it from the *.brd file, and establish its name.
netclass->ReadDescr( File, &LineNum ); netclass->ReadDescr( aReader );
if( !board->m_NetClasses.Add( netclass ) ) if( !board->m_NetClasses.Add( netclass ) )
{ {
...@@ -996,7 +1008,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -996,7 +1008,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
if( TESTLINE( "CZONE_OUTLINE" ) ) if( TESTLINE( "CZONE_OUTLINE" ) )
{ {
ZONE_CONTAINER* zone_descr = new ZONE_CONTAINER( board ); ZONE_CONTAINER* zone_descr = new ZONE_CONTAINER( board );
zone_descr->ReadDescr( File, &LineNum ); zone_descr->ReadDescr( aReader );
if( zone_descr->GetNumCorners() > 2 ) // should always occur if( zone_descr->GetNumCorners() > 2 ) // should always occur
board->Add( zone_descr ); board->Add( zone_descr );
else else
...@@ -1008,7 +1020,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -1008,7 +1020,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
{ {
DIMENSION* Dimension = new DIMENSION( board ); DIMENSION* Dimension = new DIMENSION( board );
board->Add( Dimension, ADD_APPEND ); board->Add( Dimension, ADD_APPEND );
Dimension->ReadDimensionDescr( File, &LineNum ); Dimension->ReadDimensionDescr( aReader );
continue; continue;
} }
...@@ -1016,7 +1028,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -1016,7 +1028,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
{ {
MIREPCB* Mire = new MIREPCB( board ); MIREPCB* Mire = new MIREPCB( board );
board->Add( Mire, ADD_APPEND ); board->Add( Mire, ADD_APPEND );
Mire->ReadMirePcbDescr( File, &LineNum ); Mire->ReadMirePcbDescr( aReader );
continue; continue;
} }
...@@ -1025,21 +1037,21 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -1025,21 +1037,21 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
#ifdef PCBNEW #ifdef PCBNEW
SEGZONE* insertBeforeMe = Append ? NULL : board->m_Zone.GetFirst(); SEGZONE* insertBeforeMe = Append ? NULL : board->m_Zone.GetFirst();
ReadListeSegmentDescr( File, insertBeforeMe, TYPE_ZONE, ReadListeSegmentDescr( aReader, insertBeforeMe, TYPE_ZONE,
&LineNum, NbZone ); NbZone );
#endif #endif
continue; continue;
} }
if( TESTLINE( "GENERAL" ) ) if( TESTLINE( "GENERAL" ) )
{ {
ReadGeneralDescrPcb( File, &LineNum ); ReadGeneralDescrPcb( aReader );
continue; continue;
} }
if( TESTLINE( "SHEETDESCR" ) ) if( TESTLINE( "SHEETDESCR" ) )
{ {
ReadSheetDescr( GetScreen(), File, &LineNum ); ReadSheetDescr( GetScreen(), aReader );
continue; continue;
} }
...@@ -1047,13 +1059,15 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append ) ...@@ -1047,13 +1059,15 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
{ {
if( !Append ) if( !Append )
{ {
ReadSetup( File, &LineNum ); ReadSetup( aReader );
} }
else else
{ {
while( GetLine( File, Line, &LineNum ) != NULL ) while( aReader->ReadLine() ) {
Line = aReader->Line();
if( TESTLINE( "EndSETUP" ) ) if( TESTLINE( "EndSETUP" ) )
break; break;
}
} }
continue; continue;
} }
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "wxPcbStruct.h" #include "wxPcbStruct.h"
#include "module_editor_frame.h" #include "module_editor_frame.h"
#include "dialog_helpers.h" #include "dialog_helpers.h"
#include "richio.h"
#include "filter_reader.h"
/* /*
* Module library header format: * Module library header format:
...@@ -47,8 +49,7 @@ static bool CreateDocLibrary( const wxString& LibName ); ...@@ -47,8 +49,7 @@ static bool CreateDocLibrary( const wxString& LibName );
*/ */
MODULE* WinEDA_ModuleEditFrame::Import_Module( ) MODULE* WinEDA_ModuleEditFrame::Import_Module( )
{ {
int NbLine = 0; char* Line;
char Line[1024];
FILE* file; FILE* file;
MODULE* module = NULL; MODULE* module = NULL;
bool Footprint_Is_GPCB_Format = false; bool Footprint_Is_GPCB_Format = false;
...@@ -76,6 +77,10 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( ) ...@@ -76,6 +77,10 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( )
return NULL; return NULL;
} }
FILE_LINE_READER fileReader( file, dlg.GetPath() );
FILTER_READER reader( fileReader );
if( Config ) // Save file path if( Config ) // Save file path
{ {
LastOpenedPathForLoading = wxPathOnly( dlg.GetPath() ); LastOpenedPathForLoading = wxPathOnly( dlg.GetPath() );
...@@ -87,7 +92,8 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( ) ...@@ -87,7 +92,8 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( )
SetLocaleTo_C_standard(); SetLocaleTo_C_standard();
/* Read header and test file type */ /* Read header and test file type */
GetLine( file, Line, &NbLine ); reader.ReadLine();
Line = reader.Line();
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 ) if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{ {
if( strnicmp( Line, "Element", 7 ) == 0 ) if( strnicmp( Line, "Element", 7 ) == 0 )
...@@ -103,7 +109,7 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( ) ...@@ -103,7 +109,7 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( )
/* Read file: Search the description starting line (skip lib header)*/ /* Read file: Search the description starting line (skip lib header)*/
if( !Footprint_Is_GPCB_Format ) if( !Footprint_Is_GPCB_Format )
{ {
while( GetLine( file, Line, &NbLine ) != NULL ) while( reader.ReadLine() )
{ {
if( strnicmp( Line, "$MODULE", 7 ) == 0 ) if( strnicmp( Line, "$MODULE", 7 ) == 0 )
break; break;
...@@ -114,13 +120,11 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( ) ...@@ -114,13 +120,11 @@ MODULE* WinEDA_ModuleEditFrame::Import_Module( )
if( Footprint_Is_GPCB_Format ) if( Footprint_Is_GPCB_Format )
{ {
fclose( file );
module->Read_GPCB_Descr( dlg.GetPath() ); module->Read_GPCB_Descr( dlg.GetPath() );
} }
else else
{ {
module->ReadDescr( file, &NbLine ); module->ReadDescr( &reader );
fclose( file );
} }
SetLocaleTo_Default(); // revert to the current locale SetLocaleTo_Default(); // revert to the current locale
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "wxPcbStruct.h" #include "wxPcbStruct.h"
#include "module_editor_frame.h" #include "module_editor_frame.h"
#include "dialog_helpers.h" #include "dialog_helpers.h"
#include "richio.h"
#include "filter_reader.h"
class ModList class ModList
{ {
...@@ -213,9 +215,9 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module( ...@@ -213,9 +215,9 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module(
const wxString& aModuleName, const wxString& aModuleName,
bool aDisplayMessageError ) bool aDisplayMessageError )
{ {
int LineNum, Found = 0; int Found = 0;
wxFileName fn; wxFileName fn;
char Line[512]; char* Line;
wxString Name; wxString Name;
wxString msg, tmp; wxString msg, tmp;
MODULE* NewModule; MODULE* NewModule;
...@@ -256,12 +258,16 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module( ...@@ -256,12 +258,16 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module(
continue; continue;
} }
FILE_LINE_READER fileReader( file, tmp );
FILTER_READER reader( fileReader );
msg.Printf( _( "Scan Lib: %s" ), GetChars( tmp ) ); msg.Printf( _( "Scan Lib: %s" ), GetChars( tmp ) );
Affiche_Message( msg ); Affiche_Message( msg );
/* Reading header ENTETE_LIBRAIRIE */ /* Reading header ENTETE_LIBRAIRIE */
LineNum = 0; reader.ReadLine();
GetLine( file, Line, &LineNum ); 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 )
{ {
...@@ -269,20 +275,21 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module( ...@@ -269,20 +275,21 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module(
GetChars( tmp ) ); GetChars( tmp ) );
wxMessageBox( msg, _( "Library Load Error" ), wxMessageBox( msg, _( "Library Load Error" ),
wxOK | wxICON_ERROR, this ); wxOK | wxICON_ERROR, this );
fclose( file );
return NULL; return NULL;
} }
/* Reading the list of modules in the library. */ /* Reading the list of modules in the library. */
Found = 0; Found = 0;
while( !Found && GetLine( file, Line, &LineNum ) ) while( !Found && reader.ReadLine() )
{ {
Line = reader.Line();
if( strnicmp( Line, "$MODULE", 6 ) == 0 ) if( strnicmp( Line, "$MODULE", 6 ) == 0 )
break; break;
if( strnicmp( Line, "$INDEX", 6 ) == 0 ) if( strnicmp( Line, "$INDEX", 6 ) == 0 )
{ {
while( GetLine( file, Line, &LineNum ) ) while( reader.ReadLine() )
{ {
Line = reader.Line();
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
break; break;
StrPurge( Line ); StrPurge( Line );
...@@ -297,8 +304,9 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module( ...@@ -297,8 +304,9 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module(
} }
/* Read library. */ /* Read library. */
while( Found && GetLine( file, Line, &LineNum ) ) while( Found && reader.ReadLine() )
{ {
Line = reader.Line();
if( Line[0] != '$' ) if( Line[0] != '$' )
continue; continue;
if( Line[1] != 'M' ) if( Line[1] != 'M' )
...@@ -315,16 +323,14 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module( ...@@ -315,16 +323,14 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module(
// Switch the locale to standard C (needed to print // Switch the locale to standard C (needed to print
// floating point numbers like 1.3) // floating point numbers like 1.3)
SetLocaleTo_C_standard(); SetLocaleTo_C_standard();
NewModule->ReadDescr( file, &LineNum ); NewModule->ReadDescr( &reader );
SetLocaleTo_Default(); // revert to the current locale SetLocaleTo_Default(); // revert to the current locale
GetBoard()->Add( NewModule, ADD_APPEND ); GetBoard()->Add( NewModule, ADD_APPEND );
fclose( file );
Affiche_Message( wxEmptyString ); Affiche_Message( wxEmptyString );
return NewModule; return NewModule;
} }
} }
fclose( file );
if( one_lib ) if( one_lib )
break; break;
} }
...@@ -358,9 +364,8 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( WinEDA_DrawFrame* aWind ...@@ -358,9 +364,8 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( WinEDA_DrawFrame* aWind
const wxString& aMask, const wxString& aMask,
const wxString& aKeyWord ) const wxString& aKeyWord )
{ {
int LineNum;
unsigned ii; unsigned ii;
char Line[1024]; char* Line;
wxFileName fn; wxFileName fn;
static wxString OldName; /* Save the name of the last module loaded. */ static wxString OldName; /* Save the name of the last module loaded. */
wxString CmpName, tmp; wxString CmpName, tmp;
...@@ -412,13 +417,17 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( WinEDA_DrawFrame* aWind ...@@ -412,13 +417,17 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( WinEDA_DrawFrame* aWind
continue; continue;
} }
FILE_LINE_READER fileReader( file, tmp );
FILTER_READER reader( fileReader );
// Statusbar library loaded message // Statusbar library loaded message
msg = _( "Library " ) + fn.GetFullPath() + _( " loaded" ); msg = _( "Library " ) + fn.GetFullPath() + _( " loaded" );
Affiche_Message( msg ); Affiche_Message( msg );
/* Read header. */ /* Read header. */
LineNum = 0; reader.ReadLine();
GetLine( file, Line, &LineNum, sizeof(Line) - 1 ); Line = reader.Line();
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 ) if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{ {
...@@ -426,21 +435,22 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( WinEDA_DrawFrame* aWind ...@@ -426,21 +435,22 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( WinEDA_DrawFrame* aWind
GetChars( tmp ) ); GetChars( tmp ) );
wxMessageBox( msg, _( "Library Load Error" ), wxMessageBox( msg, _( "Library Load Error" ),
wxOK | wxICON_ERROR, this ); wxOK | wxICON_ERROR, this );
fclose( file );
continue; continue;
} }
/* Read library. */ /* Read library. */
while( GetLine( file, Line, &LineNum, sizeof(Line) - 1 ) ) while( reader.ReadLine() )
{ {
Line = reader.Line();
if( Line[0] != '$' ) if( Line[0] != '$' )
continue; continue;
if( strnicmp( Line, "$MODULE", 6 ) == 0 ) if( strnicmp( Line, "$MODULE", 6 ) == 0 )
break; break;
if( strnicmp( Line, "$INDEX", 6 ) == 0 ) if( strnicmp( Line, "$INDEX", 6 ) == 0 )
{ {
while( GetLine( file, Line, &LineNum ) ) while( reader.ReadLine() )
{ {
Line = reader.Line();
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
break; break;
strupper( Line ); strupper( Line );
...@@ -454,7 +464,6 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( WinEDA_DrawFrame* aWind ...@@ -454,7 +464,6 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( WinEDA_DrawFrame* aWind
} }
/* End read library. */ /* End read library. */
fclose( file );
file = NULL; file = NULL;
if( !aLibraryFullFilename.IsEmpty() ) if( !aLibraryFullFilename.IsEmpty() )
...@@ -538,7 +547,7 @@ static void DisplayCmpDoc( wxString& Name ) ...@@ -538,7 +547,7 @@ static void DisplayCmpDoc( wxString& Name )
static void ReadDocLib( const wxString& ModLibName ) static void ReadDocLib( const wxString& ModLibName )
{ {
ModList* NewMod; ModList* NewMod;
char Line[1024]; char* Line;
FILE* LibDoc; FILE* LibDoc;
wxFileName fn = ModLibName; wxFileName fn = ModLibName;
...@@ -547,12 +556,18 @@ static void ReadDocLib( const wxString& ModLibName ) ...@@ -547,12 +556,18 @@ static void ReadDocLib( const wxString& ModLibName )
if( ( LibDoc = wxFopen( fn.GetFullPath(), wxT( "rt" ) ) ) == NULL ) if( ( LibDoc = wxFopen( fn.GetFullPath(), wxT( "rt" ) ) ) == NULL )
return; return;
GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 ); FILE_LINE_READER fileReader( LibDoc, fn.GetFullPath() );
FILTER_READER reader( fileReader );
reader.ReadLine();
Line = reader.Line();
if( strnicmp( Line, ENTETE_LIBDOC, L_ENTETE_LIB ) != 0 ) if( strnicmp( Line, ENTETE_LIBDOC, L_ENTETE_LIB ) != 0 )
return; return;
while( GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 ) ) while( reader.ReadLine() )
{ {
Line = reader.Line();
if( Line[0] != '$' ) if( Line[0] != '$' )
continue; continue;
if( Line[1] == 'E' ) if( Line[1] == 'E' )
...@@ -562,8 +577,9 @@ static void ReadDocLib( const wxString& ModLibName ) ...@@ -562,8 +577,9 @@ static void ReadDocLib( const wxString& ModLibName )
NewMod = new ModList(); NewMod = new ModList();
NewMod->Next = MList; NewMod->Next = MList;
MList = NewMod; MList = NewMod;
while( GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 ) ) while( reader.ReadLine() )
{ {
Line = reader.Line();
if( Line[0] == '$' ) /* $EndMODULE */ if( Line[0] == '$' ) /* $EndMODULE */
break; break;
...@@ -585,7 +601,6 @@ static void ReadDocLib( const wxString& ModLibName ) ...@@ -585,7 +601,6 @@ static void ReadDocLib( const wxString& ModLibName )
} /* End read 1 module. */ } /* End read 1 module. */
} }
fclose( LibDoc );
} }
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "protos.h" #include "protos.h"
#include "dialog_helpers.h" #include "dialog_helpers.h"
#include "richio.h"
#include "filter_reader.h"
#define COEFF_COUNT 6 #define COEFF_COUNT 6
static double* PolyEdges; static double* PolyEdges;
...@@ -835,7 +836,7 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ...@@ -835,7 +836,7 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
wxString FullFileName; wxString FullFileName;
wxString ext, mask; wxString ext, mask;
FILE* File; FILE* File;
char Line[1024]; char* Line;
double unitconv = 10000; double unitconv = 10000;
char* param1, * param2; char* param1, * param2;
int bufsize; int bufsize;
...@@ -862,14 +863,17 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ...@@ -862,14 +863,17 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
return; return;
} }
FILE_LINE_READER fileReader( File, FullFileName );
FILTER_READER reader( fileReader );
bufsize = 100; bufsize = 100;
ptbuf = PolyEdges = (double*) MyZMalloc( bufsize * 2 * sizeof(double) ); ptbuf = PolyEdges = (double*) MyZMalloc( bufsize * 2 * sizeof(double) );
SetLocaleTo_C_standard(); SetLocaleTo_C_standard();
int LineNum = 0; while( reader.ReadLine() )
while( GetLine( File, Line, &LineNum, sizeof(Line) - 1 ) != NULL )
{ {
Line = reader.Line();
param1 = strtok( Line, " =\n\r" ); param1 = strtok( Line, " =\n\r" );
param2 = strtok( NULL, " \t\n\r" ); param2 = strtok( NULL, " \t\n\r" );
...@@ -884,8 +888,9 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ...@@ -884,8 +888,9 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
break; break;
if( strnicmp( param1, "$COORD", 6 ) == 0 ) if( strnicmp( param1, "$COORD", 6 ) == 0 )
{ {
while( GetLine( File, Line, &LineNum, sizeof(Line) - 1 ) != NULL ) while( reader.ReadLine() )
{ {
Line = reader.Line();
param1 = strtok( Line, " \t\n\r" ); param1 = strtok( Line, " \t\n\r" );
param2 = strtok( NULL, " \t\n\r" ); param2 = strtok( NULL, " \t\n\r" );
if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 ) if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 )
...@@ -921,7 +926,6 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ...@@ -921,7 +926,6 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
free( PolyEdges ); free( PolyEdges );
PolyEdges = NULL; PolyEdges = NULL;
} }
fclose( File );
SetLocaleTo_Default(); // revert to the current locale SetLocaleTo_Default(); // revert to the current locale
ShapeScaleX *= unitconv; ShapeScaleX *= unitconv;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment