fix bug lp:663929

This commit is contained in:
Dick Hollenbeck 2010-10-20 19:18:42 -05:00
parent 8b4bc768a9
commit c3924e6fc9
3 changed files with 190 additions and 215 deletions

View File

@ -10,26 +10,19 @@
#include "general.h" #include "general.h"
#include "protos.h" #include "protos.h"
#include "class_marker_sch.h" #include "class_marker_sch.h"
#include "richio.h"
/* in read_from_file_schematic_items_description.cpp */ /* in read_from_file_schematic_items_description.cpp */
SCH_ITEM* ReadTextDescr( FILE* aFile, wxString& aMsgDiag, char* aLine, SCH_ITEM* ReadTextDescr( LINE_READER* aLine, wxString& aMsgDiag, int aSchematicFileVersion );
int aBufsize, int* aLineNum,
int aSchematicFileVersion );
extern int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
wxString& aMsgDiag, int* aLineNum,
BASE_SCREEN* Window );
extern bool ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f, bool ReadSchemaDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
wxString& aMsgDiag, int* aLineNum,
BASE_SCREEN* Window );
extern int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, int ReadPartDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
wxString& aMsgDiag, int* aLineNum,
BASE_SCREEN* Window );
static void LoadLayers( FILE* f, int* linecnt ); static void LoadLayers( LINE_READER* aLine );
/** /**
@ -39,7 +32,6 @@ static void LoadLayers( FILE* f, int* linecnt );
bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
const wxString& FullFileName ) const wxString& FullFileName )
{ {
char Line[1024], * SLine;
char Name1[256], char Name1[256],
Name2[256]; Name2[256];
int ii, layer; int ii, layer;
@ -51,10 +43,9 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
SCH_LINE* SegmentStruct; SCH_LINE* SegmentStruct;
SCH_BUS_ENTRY* busEntry; SCH_BUS_ENTRY* busEntry;
SCH_NO_CONNECT* NoConnectStruct; SCH_NO_CONNECT* NoConnectStruct;
int LineCount;
wxString MsgDiag; // Error and log messages wxString MsgDiag; // Error and log messages
FILE* f; #define line ((char*)reader)
if( screen == NULL ) if( screen == NULL )
return FALSE; return FALSE;
@ -67,7 +58,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
// D(printf("LoadOneEEFile:%s\n", CONV_TO_UTF8( FullFileName ) ); ) // D(printf("LoadOneEEFile:%s\n", CONV_TO_UTF8( FullFileName ) ); )
LineCount = 1; FILE* f;
if( ( f = wxFopen( FullFileName, wxT( "rt" ) ) ) == NULL ) if( ( f = wxFopen( FullFileName, wxT( "rt" ) ) ) == NULL )
{ {
MsgDiag = _( "Failed to open " ) + FullFileName; MsgDiag = _( "Failed to open " ) + FullFileName;
@ -75,21 +66,23 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
return FALSE; return FALSE;
} }
// reader now owns the open FILE.
FILE_LINE_READER reader( f, FullFileName );
MsgDiag = _( "Loading " ) + screen->m_FileName; MsgDiag = _( "Loading " ) + screen->m_FileName;
PrintMsg( MsgDiag ); PrintMsg( MsgDiag );
if( fgets( Line, sizeof(Line), f ) == NULL if( !reader.ReadLine()
|| strncmp( Line + 9, SCHEMATIC_HEAD_STRING, || strncmp( line + 9, SCHEMATIC_HEAD_STRING,
sizeof(SCHEMATIC_HEAD_STRING) - 1 ) != 0 ) sizeof(SCHEMATIC_HEAD_STRING) - 1 ) != 0 )
{ {
MsgDiag = FullFileName + _( " is NOT an EESchema file!" ); MsgDiag = FullFileName + _( " is NOT an EESchema file!" );
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
fclose( f );
return FALSE; return FALSE;
} }
// get the file version here. TODO: Support version numbers > 9 // get the file version here. TODO: Support version numbers > 9
char version = Line[9 + sizeof(SCHEMATIC_HEAD_STRING)]; char version = line[9 + sizeof(SCHEMATIC_HEAD_STRING)];
int ver = version - '0'; int ver = version - '0';
if( ver > EESCHEMA_VERSION ) if( ver > EESCHEMA_VERSION )
{ {
@ -110,50 +103,37 @@ again." );
} }
#endif #endif
LineCount++; if( !reader.ReadLine() || strncmp( line, "LIBS:", 5 ) != 0 )
if( fgets( Line, sizeof(Line), f ) == NULL || strncmp( Line, "LIBS:", 5 ) != 0 )
{ {
MsgDiag = FullFileName + _( " is NOT an EESchema file!" ); MsgDiag = FullFileName + _( " is NOT an EESchema file!" );
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
fclose( f );
return FALSE; return FALSE;
} }
// Read the rest of a potentially very long line. fgets() puts a '\n' into LoadLayers( &reader );
// the buffer if the end of line was reached. Read until end of line if
// necessary. while( reader.ReadLine() )
if( Line[ strlen( Line )-1 ] != '\n' )
{ {
int c; char* sline = line;
while( !feof( f ) && (c = fgetc( f )) != '\n' ) while( (*sline != ' ' ) && *sline )
; sline++;
}
LoadLayers( f, &LineCount ); switch( line[0] )
while( !feof( f ) && GetLine( f, Line, &LineCount, sizeof(Line) ) != NULL )
{
SLine = Line;
while( (*SLine != ' ' ) && *SLine )
SLine++;
switch( Line[0] )
{ {
case '$': // identification block case '$': // identification block
if( Line[1] == 'C' ) if( line[1] == 'C' )
Failed = ReadPartDescr( this, Line, f, MsgDiag, &LineCount, screen ); Failed = ReadPartDescr( this, &reader, MsgDiag, screen );
else if( Line[1] == 'S' ) else if( line[1] == 'S' )
Failed = ReadSheetDescr( this, Line, f, MsgDiag, &LineCount, screen ); Failed = ReadSheetDescr( this, &reader, MsgDiag, screen );
else if( Line[1] == 'D' ) else if( line[1] == 'D' )
Failed = ReadSchemaDescr( this, Line, f, MsgDiag, &LineCount, screen ); Failed = ReadSchemaDescr( this, &reader, MsgDiag, screen );
else if( Line[1] == 'T' ) // text part else if( line[1] == 'T' ) // text part
{ {
printf( "**** TEXT PART\n" ); printf( "**** TEXT PART\n" );
SCH_ITEM* Struct; SCH_ITEM* Struct = ReadTextDescr( &reader, MsgDiag, version );
Struct = ReadTextDescr( f, MsgDiag, Line, sizeof(Line), &LineCount, version );
if( Struct ) if( Struct )
{ {
@ -168,15 +148,15 @@ again." );
break; break;
case 'L': // Its a library item. case 'L': // Its a library item.
Failed = ReadPartDescr( this, Line, f, MsgDiag, &LineCount, screen ); Failed = ReadPartDescr( this, &reader, MsgDiag, screen );
break; break;
case 'W': // Its a Segment (WIRE or BUS) item. case 'W': // Its a Segment (WIRE or BUS) item.
if( sscanf( SLine, "%s %s", Name1, Name2 ) != 2 ) if( sscanf( sline, "%s %s", Name1, Name2 ) != 2 )
{ {
MsgDiag.Printf( wxT( "EESchema file segment error at line %d, aborted" ), MsgDiag.Printf( wxT( "EESchema file segment error at line %d, aborted" ),
LineCount ); reader.LineNumber() );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
Failed = true; Failed = true;
break; break;
} }
@ -190,15 +170,14 @@ again." );
SegmentStruct = new SCH_LINE( wxPoint( 0, 0 ), layer ); SegmentStruct = new SCH_LINE( wxPoint( 0, 0 ), layer );
LineCount++; if( !reader.ReadLine()
if( fgets( Line, 256 - 1, f ) == NULL || sscanf( line, "%d %d %d %d ", &SegmentStruct->m_Start.x,
|| sscanf( Line, "%d %d %d %d ", &SegmentStruct->m_Start.x,
&SegmentStruct->m_Start.y, &SegmentStruct->m_End.x, &SegmentStruct->m_Start.y, &SegmentStruct->m_End.x,
&SegmentStruct->m_End.y ) != 4 ) &SegmentStruct->m_End.y ) != 4 )
{ {
MsgDiag.Printf( wxT( "EESchema file Segment struct error at line %d, aborted" ), MsgDiag.Printf( wxT( "EESchema file Segment struct error at line %d, aborted" ),
LineCount ); reader.LineNumber() );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
Failed = true; Failed = true;
SAFE_DELETE( SegmentStruct ); SAFE_DELETE( SegmentStruct );
break; break;
@ -212,11 +191,11 @@ again." );
break; break;
case 'E': // Its a WIRE or BUS item. case 'E': // Its a WIRE or BUS item.
if( sscanf( SLine, "%s %s", Name1, Name2 ) != 2 ) if( sscanf( sline, "%s %s", Name1, Name2 ) != 2 )
{ {
MsgDiag.Printf( wxT( "EESchema file record struct error at line %d, aborted" ), MsgDiag.Printf( wxT( "EESchema file record struct error at line %d, aborted" ),
LineCount ); reader.LineNumber() );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
Failed = true; Failed = true;
break; break;
} }
@ -224,17 +203,16 @@ again." );
ii = WIRE_TO_BUS; ii = WIRE_TO_BUS;
if( Name1[0] == 'B' ) if( Name1[0] == 'B' )
ii = BUS_TO_BUS; ii = BUS_TO_BUS;
busEntry = new SCH_BUS_ENTRY( wxPoint( 0, 0 ), '\\', ii ); busEntry = new SCH_BUS_ENTRY( wxPoint( 0, 0 ), '\\', ii );
LineCount++; if( !reader.ReadLine()
|| sscanf( line, "%d %d %d %d ", &busEntry->m_Pos.x, &busEntry->m_Pos.y,
if( fgets( Line, 256 - 1, f ) == NULL
|| sscanf( Line, "%d %d %d %d ", &busEntry->m_Pos.x, &busEntry->m_Pos.y,
&busEntry->m_Size.x, &busEntry->m_Size.y ) != 4 ) &busEntry->m_Size.x, &busEntry->m_Size.y ) != 4 )
{ {
MsgDiag.Printf( wxT( "EESchema file Bus Entry struct error at line %d, aborted" ), MsgDiag.Printf( wxT( "EESchema file Bus Entry struct error at line %d, aborted" ),
LineCount ); reader.LineNumber() );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
Failed = true; Failed = true;
SAFE_DELETE( busEntry ); SAFE_DELETE( busEntry );
break; break;
@ -250,11 +228,11 @@ again." );
break; break;
case 'P': // Its a polyline item. case 'P': // Its a polyline item.
if( sscanf( SLine, "%s %s %d", Name1, Name2, &ii ) != 3 ) if( sscanf( sline, "%s %s %d", Name1, Name2, &ii ) != 3 )
{ {
MsgDiag.Printf( wxT( "EESchema file polyline struct error at line %d, aborted" ), MsgDiag.Printf( wxT( "EESchema file polyline struct error at line %d, aborted" ),
LineCount ); reader.LineNumber() );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
Failed = true; Failed = true;
break; break;
} }
@ -265,17 +243,17 @@ again." );
layer = LAYER_BUS; layer = LAYER_BUS;
PolylineStruct = new SCH_POLYLINE( layer ); PolylineStruct = new SCH_POLYLINE( layer );
for( unsigned jj = 0; jj < (unsigned)ii; jj++ ) for( unsigned jj = 0; jj < (unsigned)ii; jj++ )
{ {
LineCount++;
wxPoint point; wxPoint point;
if( fgets( Line, 256 - 1, f ) == NULL
|| sscanf( Line, "%d %d", &point.x, &point.y ) != 2 ) if( !reader.ReadLine()
|| sscanf( line, "%d %d", &point.x, &point.y ) != 2 )
{ {
MsgDiag.Printf( wxT( "EESchema file polyline struct error \ MsgDiag.Printf( wxT( "EESchema file polyline struct error at line %d, aborted" ),
at line %d, aborted" ), reader.LineNumber() );
LineCount ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
Failed = true; Failed = true;
SAFE_DELETE( PolylineStruct ); SAFE_DELETE( PolylineStruct );
break; break;
@ -294,13 +272,12 @@ at line %d, aborted" ),
case 'C': // It is a connection item. case 'C': // It is a connection item.
ConnectionStruct = new SCH_JUNCTION( wxPoint( 0, 0 ) ); ConnectionStruct = new SCH_JUNCTION( wxPoint( 0, 0 ) );
if( sscanf( SLine, "%s %d %d", Name1, &ConnectionStruct->m_Pos.x, if( sscanf( sline, "%s %d %d", Name1, &ConnectionStruct->m_Pos.x,
&ConnectionStruct->m_Pos.y ) != 3 ) &ConnectionStruct->m_Pos.y ) != 3 )
{ {
MsgDiag.Printf( wxT( "EESchema file connection struct error \ MsgDiag.Printf( wxT( "EESchema file connection struct error at line %d, aborted" ),
at line %d, aborted" ), reader.LineNumber() );
LineCount ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
Failed = true; Failed = true;
SAFE_DELETE( ConnectionStruct ); SAFE_DELETE( ConnectionStruct );
} }
@ -312,11 +289,11 @@ at line %d, aborted" ),
break; break;
case 'N': // It is a NoConnect item. case 'N': // It is a NoConnect item.
if( sscanf( SLine, "%s %d %d", Name1, &pos.x, &pos.y ) != 3 ) if( sscanf( sline, "%s %d %d", Name1, &pos.x, &pos.y ) != 3 )
{ {
MsgDiag.Printf( wxT( "EESchema file NoConnect struct error at line %d, aborted" ), MsgDiag.Printf( wxT( "EESchema file NoConnect struct error at line %d, aborted" ),
LineCount ); reader.LineNumber() );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
Failed = true; Failed = true;
} }
else else
@ -334,9 +311,7 @@ at line %d, aborted" ),
case 'T': // It is a text item. case 'T': // It is a text item.
{ {
SCH_ITEM* Struct; SCH_ITEM* Struct = ReadTextDescr( &reader, MsgDiag, version);
Struct = ReadTextDescr( f, MsgDiag, Line, sizeof(Line), &LineCount, version);
if( Struct ) if( Struct )
{ {
Struct->SetNext( screen->EEDrawList ); Struct->SetNext( screen->EEDrawList );
@ -350,8 +325,8 @@ at line %d, aborted" ),
default: default:
Failed = true; Failed = true;
MsgDiag.Printf( wxT( "EESchema file undefined object at line %d, aborted" ), MsgDiag.Printf( wxT( "EESchema file undefined object at line %d, aborted" ),
LineCount ); reader.LineNumber() );
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line ); MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
break; break;
} }
@ -378,8 +353,6 @@ at line %d, aborted" ),
screen->Show( 0, std::cout ); screen->Show( 0, std::cout );
#endif #endif
fclose( f );
TestDanglingEnds( screen->EEDrawList, NULL ); TestDanglingEnds( screen->EEDrawList, NULL );
MsgDiag = _( "Done Loading " ) + screen->m_FileName; MsgDiag = _( "Done Loading " ) + screen->m_FileName;
@ -389,17 +362,16 @@ at line %d, aborted" ),
} }
static void LoadLayers( FILE* f, int* linecnt ) static void LoadLayers( LINE_READER* aLine )
{ {
int Number; int Number;
char Line[1024];
//int Mode,Color,Layer; //int Mode,Color,Layer;
char Name[256]; char Name[256];
GetLine( f, Line, linecnt, sizeof(Line) ); /* read line */ aLine->ReadLine();
sscanf( Line, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer ); sscanf( *aLine, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer );
if( strcmp( Name, "EELAYER" ) !=0 ) if( strcmp( Name, "EELAYER" ) !=0 )
{ {
/* error : init par default */ /* error : init par default */
@ -413,9 +385,9 @@ static void LoadLayers( FILE* f, int* linecnt )
g_LayerDescr.NumberOfLayers = Number; g_LayerDescr.NumberOfLayers = Number;
while( GetLine( f, Line, linecnt, sizeof(Line) ) ) while( aLine->ReadLine() )
{ {
if( strnicmp( Line, "EELAYER END", 11 ) == 0 ) if( strnicmp( *aLine, "EELAYER END", 11 ) == 0 )
break; break;
} }
} }

View File

@ -11,24 +11,18 @@
#include "program.h" #include "program.h"
#include "general.h" #include "general.h"
#include "protos.h" #include "protos.h"
#include "richio.h"
#define line ((char*)(*aLine))
SCH_ITEM* ReadTextDescr( FILE* aFile, SCH_ITEM* ReadTextDescr( LINE_READER* aLine, wxString& aMsgDiag, int aSchematicFileVersion )
wxString& aMsgDiag,
char* aLine,
int aBufsize,
int* aLineNum,
int aSchematicFileVersion )
{ {
/** /**
* Function ReadTextDescr * Function ReadTextDescr
* Reads the data structures for a Text (Comment, label, Hlabel and Hlabel * Reads the data structures for a Text (Comment, label, Hlabel and Hlabel
* from a FILE in "*.sch" format. * from a FILE in "*.sch" format.
* @param aFile The FILE to read. * @param aLine is a LINE_READER to use.
* @param aLine The buffer used to read the first line of description. * @return a pointer to the new created object if success reading else NULL.
* @param aBufsize The size of aLine.
* @param aLineNum a pointer to the line count.
* @return a poiner to the new created object if success reading else NULL.
*/ */
SCH_ITEM* Struct = NULL; SCH_ITEM* Struct = NULL;
char Name1[256]; char Name1[256];
@ -37,35 +31,37 @@ SCH_ITEM* ReadTextDescr( FILE* aFile,
int thickness = 0, size = 0, orient = 0; int thickness = 0, size = 0, orient = 0;
wxPoint pos; wxPoint pos;
char* SLine = aLine;
while( (*SLine != ' ' ) && *SLine )
SLine++;
// SLine points the start of parameters
Name1[0] = 0; Name2[0] = 0; Name3[0] = 0; Name1[0] = 0; Name2[0] = 0; Name3[0] = 0;
int ii = sscanf( SLine, "%s %d %d %d %d %s %s %d", Name1, &pos.x, &pos.y,
char* sline = line;
while( (*sline != ' ' ) && *sline )
sline++;
// sline points the start of parameters
int ii = sscanf( sline, "%s %d %d %d %d %s %s %d", Name1, &pos.x, &pos.y,
&orient, &size, Name2, Name3, &thickness ); &orient, &size, Name2, Name3, &thickness );
if( ii < 4 ) if( ii < 4 )
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "EESchema file text struct error line %d, aborted" ), wxT( "EESchema file text struct error line %d, aborted" ),
*aLineNum ); aLine->LineNumber() );
return NULL; return NULL;
} }
if( feof( aFile ) || GetLine( aFile, aLine, aLineNum, aBufsize ) == NULL ) if( !aLine->ReadLine() )
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "EESchema file text struct error line %d (No text), aborted" ), wxT( "EESchema file text struct error line %d (No text), aborted" ),
*aLineNum ); aLine->LineNumber() );
return NULL; return NULL;
} }
if( size == 0 ) if( size == 0 )
size = DEFAULT_SIZE_TEXT; size = DEFAULT_SIZE_TEXT;
char* text = strtok( aLine, "\n\r" );
char* text = strtok( line, "\n\r" );
if( text == NULL ) if( text == NULL )
return NULL; return NULL;
@ -168,6 +164,7 @@ SCH_ITEM* ReadTextDescr( FILE* aFile,
if( strnicmp( Name2, "Italic", 6 ) == 0 ) if( strnicmp( Name2, "Italic", 6 ) == 0 )
TextStruct->m_Italic = 1; TextStruct->m_Italic = 1;
Struct = TextStruct; Struct = TextStruct;
} }
@ -178,8 +175,7 @@ SCH_ITEM* ReadTextDescr( FILE* aFile,
/* Function used by LoadEEFile(). /* Function used by LoadEEFile().
* Get the lines for a description of a piece of hierarchy. * Get the lines for a description of a piece of hierarchy.
*/ */
int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag, int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
int* aLineNum, BASE_SCREEN* Window )
{ {
int ii, fieldNdx, size; int ii, fieldNdx, size;
char Name1[256], Char1[256], Char2[256]; char Name1[256], Char1[256], Char2[256];
@ -198,10 +194,9 @@ int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
// must be a duplicate, references just work for a two-layer structure. // must be a duplicate, references just work for a two-layer structure.
// this is accomplished through the Sync() function. // this is accomplished through the Sync() function.
if( Line[0] == '$' ) /* Line should be "$Sheet" */ if( line[0] == '$' ) // line should be "$Sheet"
{ {
*aLineNum++; if( !aLine->ReadLine() )
if( fgets( Line, 256 - 1, f ) == 0 )
{ {
aMsgDiag.Printf( wxT( "Read File Errror" ) ); aMsgDiag.Printf( wxT( "Read File Errror" ) );
return TRUE; return TRUE;
@ -210,15 +205,16 @@ int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
/* Next line: must be "S xx yy nn mm" with xx, yy = sheet position /* Next line: must be "S xx yy nn mm" with xx, yy = sheet position
* ( upper left corner ) et nn,mm = sheet size */ * ( upper left corner ) et nn,mm = sheet size */
if( (sscanf( &Line[1], "%d %d %d %d", if( (sscanf( &line[1], "%d %d %d %d",
&SheetStruct->m_Pos.x, &SheetStruct->m_Pos.y, &SheetStruct->m_Pos.x, &SheetStruct->m_Pos.y,
&SheetStruct->m_Size.x, &SheetStruct->m_Size.y ) != 4) &SheetStruct->m_Size.x, &SheetStruct->m_Size.y ) != 4)
|| (Line[0] != 'S' ) ) || (line[0] != 'S' ) )
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( " ** EESchema file sheet struct error at line %d, aborted\n" ), wxT( " ** EESchema file sheet struct error at line %d, aborted\n" ),
*aLineNum ); aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( Line );
aMsgDiag << CONV_FROM_UTF8( line );
Failed = TRUE; Failed = TRUE;
return Failed; return Failed;
} }
@ -226,19 +222,21 @@ int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
/* Read fields */ /* Read fields */
for( ; ; ) /* Analysis of lines "Fn" text. */ for( ; ; ) /* Analysis of lines "Fn" text. */
{ {
*aLineNum++; if( !aLine->ReadLine() )
if( fgets( Line, 256 - 1, f ) == NULL )
return TRUE; return TRUE;
if( Line[0] == 'U' )
if( line[0] == 'U' )
{ {
sscanf( Line + 1, "%lX", &(SheetStruct->m_TimeStamp) ); sscanf( line + 1, "%lX", &SheetStruct->m_TimeStamp );
if( SheetStruct->m_TimeStamp == 0 ) //zero is not unique! if( SheetStruct->m_TimeStamp == 0 ) // zero is not unique!
SheetStruct->m_TimeStamp = GetTimeStamp(); SheetStruct->m_TimeStamp = GetTimeStamp();
continue; continue;
} }
if( Line[0] != 'F' )
if( line[0] != 'F' )
break; break;
sscanf( Line + 1, "%d", &fieldNdx );
sscanf( line + 1, "%d", &fieldNdx );
/* Read the field: /* Read the field:
@ -246,32 +244,36 @@ int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
* If F0 "text" for SheetName * If F0 "text" for SheetName
* F1 and "text" for filename * F1 and "text" for filename
*/ */
ptcar = Line; while( *ptcar && ( *ptcar != '"' ) ) ptcar = line;
while( *ptcar && ( *ptcar != '"' ) )
ptcar++; ptcar++;
if( *ptcar != '"' ) if( *ptcar != '"' )
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "EESchema file sheet label F%d at line %d, aborted\n" ), wxT( "EESchema file sheet label F%d at line %d, aborted\n" ),
fieldNdx, *aLineNum ); fieldNdx, aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( Line ); aMsgDiag << CONV_FROM_UTF8( line );
return TRUE; return TRUE;
} }
for( ptcar++, ii = 0; ; ii++, ptcar++ ) for( ptcar++, ii = 0; ; ii++, ptcar++ )
{ {
Name1[ii] = *ptcar; Name1[ii] = *ptcar;
if( *ptcar == 0 ) if( *ptcar == 0 )
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "EESchema file sheet field F at line %d, aborted\n" ), wxT( "EESchema file sheet field F at line %d, aborted\n" ),
*aLineNum ); aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( Line ); aMsgDiag << CONV_FROM_UTF8( line );
return TRUE; return TRUE;
} }
if( *ptcar == '"' ) if( *ptcar == '"' )
{ {
Name1[ii] = 0; ptcar++; Name1[ii] = 0;
ptcar++;
break; break;
} }
} }
@ -280,14 +282,15 @@ int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
{ {
if( sscanf( ptcar, "%d", &size ) != 1 ) if( sscanf( ptcar, "%d", &size ) != 1 )
{ {
aMsgDiag.Printf( wxT( "EESchema file sheet Label Caract \ aMsgDiag.Printf( wxT( "EESchema file sheet Label Caract error line %d, aborted\n" ),
error line %d, aborted\n" ), aLine->LineNumber() );
*aLineNum );
aMsgDiag << CONV_FROM_UTF8( Line ); aMsgDiag << CONV_FROM_UTF8( line );
DisplayError( frame, aMsgDiag ); DisplayError( frame, aMsgDiag );
} }
if( size == 0 ) if( size == 0 )
size = DEFAULT_SIZE_TEXT; size = DEFAULT_SIZE_TEXT;
if( fieldNdx == 0 ) if( fieldNdx == 0 )
{ {
SheetStruct->m_SheetName = CONV_FROM_UTF8( Name1 ); SheetStruct->m_SheetName = CONV_FROM_UTF8( Name1 );
@ -311,8 +314,8 @@ error line %d, aborted\n" ),
if( sscanf( ptcar, "%s %s %d %d %d", Char1, Char2, &x, &y, &size ) != 5 ) if( sscanf( ptcar, "%s %s %d %d %d", Char1, Char2, &x, &y, &size ) != 5 )
{ {
aMsgDiag.Printf( wxT( "EESchema file sheet label error at line %d, ignoring.\n" ), aMsgDiag.Printf( wxT( "EESchema file sheet label error at line %d, ignoring.\n" ),
*aLineNum ); aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( Line ); aMsgDiag << CONV_FROM_UTF8( line );
DisplayError( frame, aMsgDiag ); DisplayError( frame, aMsgDiag );
continue; continue;
} }
@ -322,6 +325,7 @@ error line %d, aborted\n" ),
if( size == 0 ) if( size == 0 )
size = DEFAULT_SIZE_TEXT; size = DEFAULT_SIZE_TEXT;
SheetLabelStruct->m_Size.x = SheetLabelStruct->m_Size.y = size; SheetLabelStruct->m_Size.x = SheetLabelStruct->m_Size.y = size;
SheetLabelStruct->m_Pos.x=x; //to readjust x of first label if vertical SheetLabelStruct->m_Pos.x=x; //to readjust x of first label if vertical
switch( Char1[0] ) switch( Char1[0] )
@ -367,13 +371,14 @@ error line %d, aborted\n" ),
} }
} }
if( strnicmp( "$End", Line, 4 ) != 0 ) if( strnicmp( "$End", line, 4 ) != 0 )
{ {
aMsgDiag.Printf( wxT( "**EESchema file end_sheet struct error at line %d, aborted\n" ), aMsgDiag.Printf( wxT( "**EESchema file end_sheet struct error at line %d, aborted\n" ),
*aLineNum ); aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( Line ); aMsgDiag << CONV_FROM_UTF8( line );
Failed = TRUE; Failed = TRUE;
} }
if( !Failed ) if( !Failed )
{ {
SheetStruct->SetNext( Window->EEDrawList ); SheetStruct->SetNext( Window->EEDrawList );
@ -386,8 +391,7 @@ error line %d, aborted\n" ),
/* Read the schematic header. */ /* Read the schematic header. */
bool ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag, bool ReadSchemaDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
int* aLineNum, BASE_SCREEN* Window )
{ {
char Text[256], buf[1024]; char Text[256], buf[1024];
int ii; int ii;
@ -400,7 +404,7 @@ bool ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
}; };
wxSize PageSize; wxSize PageSize;
sscanf( Line, "%s %s %d %d", Text, Text, &PageSize.x, &PageSize.y ); sscanf( line, "%s %s %d %d", Text, Text, &PageSize.x, &PageSize.y );
wxString pagename = CONV_FROM_UTF8( Text ); wxString pagename = CONV_FROM_UTF8( Text );
for( ii = 0; SheetFormatList[ii] != NULL; ii++ ) for( ii = 0; SheetFormatList[ii] != NULL; ii++ )
@ -421,8 +425,8 @@ bool ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
{ {
aMsgDiag.Printf( wxT( "EESchema file dimension definition error \ aMsgDiag.Printf( wxT( "EESchema file dimension definition error \
line %d, \aAbort reading file.\n" ), line %d, \aAbort reading file.\n" ),
*aLineNum ); aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( Line ); aMsgDiag << CONV_FROM_UTF8( line );
DisplayError( frame, aMsgDiag ); DisplayError( frame, aMsgDiag );
} }
@ -430,67 +434,68 @@ line %d, \aAbort reading file.\n" ),
for( ; ; ) for( ; ; )
{ {
if( GetLine( f, Line, aLineNum, 1024 ) == NULL ) if( !aLine->ReadLine() )
return TRUE; return TRUE;
if( strnicmp( Line, "$End", 4 ) == 0 )
if( strnicmp( line, "$End", 4 ) == 0 )
break; break;
if( strnicmp( Line, "Sheet", 2 ) == 0 ) if( strnicmp( line, "Sheet", 2 ) == 0 )
sscanf( Line + 5, " %d %d", sscanf( line + 5, " %d %d",
&Window->m_ScreenNumber, &Window->m_NumberOfScreen ); &Window->m_ScreenNumber, &Window->m_NumberOfScreen );
if( strnicmp( Line, "Title", 2 ) == 0 ) if( strnicmp( line, "Title", 2 ) == 0 )
{ {
ReadDelimitedText( buf, Line, 256 ); ReadDelimitedText( buf, line, 256 );
Window->m_Title = CONV_FROM_UTF8( buf ); Window->m_Title = CONV_FROM_UTF8( buf );
continue; continue;
} }
if( strnicmp( Line, "Date", 2 ) == 0 ) if( strnicmp( line, "Date", 2 ) == 0 )
{ {
ReadDelimitedText( buf, Line, 256 ); ReadDelimitedText( buf, line, 256 );
Window->m_Date = CONV_FROM_UTF8( buf ); Window->m_Date = CONV_FROM_UTF8( buf );
continue; continue;
} }
if( strnicmp( Line, "Rev", 2 ) == 0 ) if( strnicmp( line, "Rev", 2 ) == 0 )
{ {
ReadDelimitedText( buf, Line, 256 ); ReadDelimitedText( buf, line, 256 );
Window->m_Revision = CONV_FROM_UTF8( buf ); Window->m_Revision = CONV_FROM_UTF8( buf );
continue; continue;
} }
if( strnicmp( Line, "Comp", 4 ) == 0 ) if( strnicmp( line, "Comp", 4 ) == 0 )
{ {
ReadDelimitedText( buf, Line, 256 ); ReadDelimitedText( buf, line, 256 );
Window->m_Company = CONV_FROM_UTF8( buf ); Window->m_Company = CONV_FROM_UTF8( buf );
continue; continue;
} }
if( strnicmp( Line, "Comment1", 8 ) == 0 ) if( strnicmp( line, "Comment1", 8 ) == 0 )
{ {
ReadDelimitedText( buf, Line, 256 ); ReadDelimitedText( buf, line, 256 );
Window->m_Commentaire1 = CONV_FROM_UTF8( buf ); Window->m_Commentaire1 = CONV_FROM_UTF8( buf );
continue; continue;
} }
if( strnicmp( Line, "Comment2", 8 ) == 0 ) if( strnicmp( line, "Comment2", 8 ) == 0 )
{ {
ReadDelimitedText( buf, Line, 256 ); ReadDelimitedText( buf, line, 256 );
Window->m_Commentaire2 = CONV_FROM_UTF8( buf ); Window->m_Commentaire2 = CONV_FROM_UTF8( buf );
continue; continue;
} }
if( strnicmp( Line, "Comment3", 8 ) == 0 ) if( strnicmp( line, "Comment3", 8 ) == 0 )
{ {
ReadDelimitedText( buf, Line, 256 ); ReadDelimitedText( buf, line, 256 );
Window->m_Commentaire3 = CONV_FROM_UTF8( buf ); Window->m_Commentaire3 = CONV_FROM_UTF8( buf );
continue; continue;
} }
if( strnicmp( Line, "Comment4", 8 ) == 0 ) if( strnicmp( line, "Comment4", 8 ) == 0 )
{ {
ReadDelimitedText( buf, Line, 256 ); ReadDelimitedText( buf, line, 256 );
Window->m_Commentaire4 = CONV_FROM_UTF8( buf ); Window->m_Commentaire4 = CONV_FROM_UTF8( buf );
continue; continue;
} }
@ -503,8 +508,8 @@ line %d, \aAbort reading file.\n" ),
/* Function used by LoadEEFile (). /* Function used by LoadEEFile ().
* Get the lines for a description of a schematic component. * Get the lines for a description of a schematic component.
*/ */
int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
int* aLineNum, BASE_SCREEN* Window ) int ReadPartDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
{ {
int ii; int ii;
char Name1[256], Name2[256], char Name1[256], Name2[256],
@ -518,20 +523,20 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
component->m_Convert = 1; component->m_Convert = 1;
if( Line[0] == '$' ) if( line[0] == '$' )
{ {
newfmt = 1; newfmt = 1;
*aLineNum++;
if( fgets( Line, 256 - 1, f ) == 0 ) if( !aLine->ReadLine() )
return TRUE; return TRUE;
} }
if( sscanf( &Line[1], "%s %s", Name1, Name2 ) != 2 ) if( sscanf( &line[1], "%s %s", Name1, Name2 ) != 2 )
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "EESchema Component descr error at line %d, aborted" ), wxT( "EESchema Component descr error at line %d, aborted" ),
*aLineNum ); aLine->LineNumber() );
aMsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line ); aMsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
Failed = TRUE; Failed = TRUE;
return Failed; return Failed;
} }
@ -608,19 +613,18 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
*/ */
for( ; ; ) for( ; ; )
{ {
*aLineNum++; if( !aLine->ReadLine() )
if( fgets( Line, 256 - 1, f ) == NULL )
return TRUE; return TRUE;
if( Line[0] == 'U' ) if( line[0] == 'U' )
{ {
sscanf( Line + 1, "%d %d %lX", sscanf( line + 1, "%d %d %lX",
&component->m_Multi, &component->m_Convert, &component->m_Multi, &component->m_Convert,
&component->m_TimeStamp ); &component->m_TimeStamp );
} }
else if( Line[0] == 'P' ) else if( line[0] == 'P' )
{ {
sscanf( Line + 1, "%d %d", sscanf( line + 1, "%d %d",
&component->m_Pos.x, &component->m_Pos.y ); &component->m_Pos.x, &component->m_Pos.y );
// Set fields position to a default position (that is the // Set fields position to a default position (that is the
@ -632,7 +636,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
component->GetField( i )->m_Pos = component->m_Pos; component->GetField( i )->m_Pos = component->m_Pos;
} }
} }
else if( Line[0] == 'A' && Line[1] == 'R' ) else if( line[0] == 'A' && line[1] == 'R' )
{ {
/* format: /* format:
* AR Path="/9086AF6E/67452AA0" Ref="C99" Part="1" * AR Path="/9086AF6E/67452AA0" Ref="C99" Part="1"
@ -641,7 +645,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
* C99 is the reference given this path. * C99 is the reference given this path.
*/ */
int ii; int ii;
ptcar = Line + 2; ptcar = line + 2;
//copy the path. //copy the path.
ii = ReadDelimitedText( Name1, ptcar, 255 ); ii = ReadDelimitedText( Name1, ptcar, 255 );
@ -663,7 +667,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
component->AddHierarchicalReference( path, ref, multi ); component->AddHierarchicalReference( path, ref, multi );
component->GetField( REFERENCE )->m_Text = ref; component->GetField( REFERENCE )->m_Text = ref;
} }
else if( Line[0] == 'F' ) else if( line[0] == 'F' )
{ {
int fieldNdx; int fieldNdx;
@ -673,7 +677,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
FieldUserName[0] = 0; FieldUserName[0] = 0;
ptcar = Line; ptcar = line;
while( *ptcar && (*ptcar != '"') ) while( *ptcar && (*ptcar != '"') )
ptcar++; ptcar++;
@ -682,7 +686,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "EESchema file lib field F at line %d, aborted" ), wxT( "EESchema file lib field F at line %d, aborted" ),
*aLineNum ); aLine->LineNumber() );
return TRUE; return TRUE;
} }
@ -693,7 +697,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "Component field F at line %d, aborted" ), wxT( "Component field F at line %d, aborted" ),
*aLineNum ); aLine->LineNumber() );
return TRUE; return TRUE;
} }
@ -705,7 +709,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
} }
} }
fieldNdx = atoi( Line + 2 ); fieldNdx = atoi( line + 2 );
ReadDelimitedText( FieldUserName, ptcar, sizeof(FieldUserName) ); ReadDelimitedText( FieldUserName, ptcar, sizeof(FieldUserName) );
@ -749,7 +753,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "Component Field error line %d, aborted" ), wxT( "Component Field error line %d, aborted" ),
*aLineNum ); aLine->LineNumber() );
DisplayError( frame, aMsgDiag ); DisplayError( frame, aMsgDiag );
continue; continue;
} }
@ -796,39 +800,38 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
break; break;
} }
if( sscanf( Line, "%d %d %d", &component->m_Multi, if( sscanf( line, "%d %d %d", &component->m_Multi,
&component->m_Pos.x, &component->m_Pos.y ) != 3 ) &component->m_Pos.x, &component->m_Pos.y ) != 3 )
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "Component unit & pos error at line %d, aborted" ), wxT( "Component unit & pos error at line %d, aborted" ),
*aLineNum ); aLine->LineNumber() );
Failed = TRUE; Failed = TRUE;
return Failed; return Failed;
} }
*aLineNum++; if( !aLine->ReadLine() ||
if( ( fgets( Line, 256 - 1, f ) == NULL ) sscanf( line, "%d %d %d %d",
|| ( sscanf( Line, "%d %d %d %d",
&component->m_Transform.x1, &component->m_Transform.x1,
&component->m_Transform.y1, &component->m_Transform.y1,
&component->m_Transform.x2, &component->m_Transform.x2,
&component->m_Transform.y2 ) != 4 ) ) &component->m_Transform.y2 ) != 4 )
{ {
aMsgDiag.Printf( wxT( "Component orient error at line %d, aborted" ), *aLineNum ); aMsgDiag.Printf( wxT( "Component orient error at line %d, aborted" ), aLine->LineNumber() );
Failed = TRUE; Failed = TRUE;
return Failed; return Failed;
} }
if( newfmt ) if( newfmt )
{ {
*aLineNum++; if( !aLine->ReadLine() )
if( fgets( Line, 256 - 1, f ) == NULL )
return TRUE; return TRUE;
if( strnicmp( "$End", Line, 4 ) != 0 )
if( strnicmp( "$End", line, 4 ) != 0 )
{ {
aMsgDiag.Printf( aMsgDiag.Printf(
wxT( "Component End expected at line %d, aborted" ), wxT( "Component End expected at line %d, aborted" ),
*aLineNum ); aLine->LineNumber() );
Failed = TRUE; Failed = TRUE;
} }
} }

View File

@ -115,7 +115,7 @@ public:
* of lines of text. The returned string is useful for reporting error * of lines of text. The returned string is useful for reporting error
* messages. * messages.
*/ */
const wxString& GetSource() const wxString& GetSource() const
{ {
return source; return source;
} }
@ -135,7 +135,7 @@ public:
* returns the line number of the last line read from this LINE_READER. Lines * returns the line number of the last line read from this LINE_READER. Lines
* start from 1. * start from 1.
*/ */
int LineNumber() int LineNumber() const
{ {
return lineNum; return lineNum;
} }
@ -144,7 +144,7 @@ public:
* Function Length * Function Length
* returns the number of bytes in the last line read from this LINE_READER. * returns the number of bytes in the last line read from this LINE_READER.
*/ */
unsigned Length() unsigned Length() const
{ {
return length; return length;
} }