fix bug lp:663929
This commit is contained in:
parent
8b4bc768a9
commit
c3924e6fc9
|
@ -10,26 +10,19 @@
|
|||
#include "general.h"
|
||||
#include "protos.h"
|
||||
#include "class_marker_sch.h"
|
||||
#include "richio.h"
|
||||
|
||||
|
||||
/* in read_from_file_schematic_items_description.cpp */
|
||||
SCH_ITEM* ReadTextDescr( FILE* aFile, wxString& aMsgDiag, char* aLine,
|
||||
int aBufsize, int* aLineNum,
|
||||
int aSchematicFileVersion );
|
||||
SCH_ITEM* ReadTextDescr( LINE_READER* aLine, wxString& aMsgDiag, int aSchematicFileVersion );
|
||||
|
||||
extern int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f,
|
||||
wxString& aMsgDiag, int* aLineNum,
|
||||
BASE_SCREEN* Window );
|
||||
int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
|
||||
|
||||
extern bool ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f,
|
||||
wxString& aMsgDiag, int* aLineNum,
|
||||
BASE_SCREEN* Window );
|
||||
bool ReadSchemaDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
|
||||
|
||||
extern 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 );
|
||||
|
||||
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,
|
||||
const wxString& FullFileName )
|
||||
{
|
||||
char Line[1024], * SLine;
|
||||
char Name1[256],
|
||||
Name2[256];
|
||||
int ii, layer;
|
||||
|
@ -51,10 +43,9 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
|
|||
SCH_LINE* SegmentStruct;
|
||||
SCH_BUS_ENTRY* busEntry;
|
||||
SCH_NO_CONNECT* NoConnectStruct;
|
||||
int LineCount;
|
||||
wxString MsgDiag; // Error and log messages
|
||||
|
||||
FILE* f;
|
||||
#define line ((char*)reader)
|
||||
|
||||
if( screen == NULL )
|
||||
return FALSE;
|
||||
|
@ -67,7 +58,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
|
|||
|
||||
// D(printf("LoadOneEEFile:%s\n", CONV_TO_UTF8( FullFileName ) ); )
|
||||
|
||||
LineCount = 1;
|
||||
FILE* f;
|
||||
if( ( f = wxFopen( FullFileName, wxT( "rt" ) ) ) == NULL )
|
||||
{
|
||||
MsgDiag = _( "Failed to open " ) + FullFileName;
|
||||
|
@ -75,21 +66,23 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
// reader now owns the open FILE.
|
||||
FILE_LINE_READER reader( f, FullFileName );
|
||||
|
||||
MsgDiag = _( "Loading " ) + screen->m_FileName;
|
||||
PrintMsg( MsgDiag );
|
||||
|
||||
if( fgets( Line, sizeof(Line), f ) == NULL
|
||||
|| strncmp( Line + 9, SCHEMATIC_HEAD_STRING,
|
||||
if( !reader.ReadLine()
|
||||
|| strncmp( line + 9, SCHEMATIC_HEAD_STRING,
|
||||
sizeof(SCHEMATIC_HEAD_STRING) - 1 ) != 0 )
|
||||
{
|
||||
MsgDiag = FullFileName + _( " is NOT an EESchema file!" );
|
||||
DisplayError( this, MsgDiag );
|
||||
fclose( f );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 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';
|
||||
if( ver > EESCHEMA_VERSION )
|
||||
{
|
||||
|
@ -110,50 +103,37 @@ again." );
|
|||
}
|
||||
#endif
|
||||
|
||||
LineCount++;
|
||||
if( fgets( Line, sizeof(Line), f ) == NULL || strncmp( Line, "LIBS:", 5 ) != 0 )
|
||||
if( !reader.ReadLine() || strncmp( line, "LIBS:", 5 ) != 0 )
|
||||
{
|
||||
MsgDiag = FullFileName + _( " is NOT an EESchema file!" );
|
||||
DisplayError( this, MsgDiag );
|
||||
fclose( f );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Read the rest of a potentially very long line. fgets() puts a '\n' into
|
||||
// the buffer if the end of line was reached. Read until end of line if
|
||||
// necessary.
|
||||
if( Line[ strlen( Line )-1 ] != '\n' )
|
||||
LoadLayers( &reader );
|
||||
|
||||
while( reader.ReadLine() )
|
||||
{
|
||||
int c;
|
||||
while( !feof( f ) && (c = fgetc( f )) != '\n' )
|
||||
;
|
||||
}
|
||||
char* sline = line;
|
||||
while( (*sline != ' ' ) && *sline )
|
||||
sline++;
|
||||
|
||||
LoadLayers( f, &LineCount );
|
||||
|
||||
while( !feof( f ) && GetLine( f, Line, &LineCount, sizeof(Line) ) != NULL )
|
||||
{
|
||||
SLine = Line;
|
||||
while( (*SLine != ' ' ) && *SLine )
|
||||
SLine++;
|
||||
|
||||
switch( Line[0] )
|
||||
switch( line[0] )
|
||||
{
|
||||
case '$': // identification block
|
||||
if( Line[1] == 'C' )
|
||||
Failed = ReadPartDescr( this, Line, f, MsgDiag, &LineCount, screen );
|
||||
if( line[1] == 'C' )
|
||||
Failed = ReadPartDescr( this, &reader, MsgDiag, screen );
|
||||
|
||||
else if( Line[1] == 'S' )
|
||||
Failed = ReadSheetDescr( this, Line, f, MsgDiag, &LineCount, screen );
|
||||
else if( line[1] == 'S' )
|
||||
Failed = ReadSheetDescr( this, &reader, MsgDiag, screen );
|
||||
|
||||
else if( Line[1] == 'D' )
|
||||
Failed = ReadSchemaDescr( this, Line, f, MsgDiag, &LineCount, screen );
|
||||
else if( line[1] == 'D' )
|
||||
Failed = ReadSchemaDescr( this, &reader, MsgDiag, screen );
|
||||
|
||||
else if( Line[1] == 'T' ) // text part
|
||||
else if( line[1] == 'T' ) // text part
|
||||
{
|
||||
printf( "**** TEXT PART\n" );
|
||||
SCH_ITEM* Struct;
|
||||
Struct = ReadTextDescr( f, MsgDiag, Line, sizeof(Line), &LineCount, version );
|
||||
SCH_ITEM* Struct = ReadTextDescr( &reader, MsgDiag, version );
|
||||
|
||||
if( Struct )
|
||||
{
|
||||
|
@ -168,15 +148,15 @@ again." );
|
|||
break;
|
||||
|
||||
case 'L': // Its a library item.
|
||||
Failed = ReadPartDescr( this, Line, f, MsgDiag, &LineCount, screen );
|
||||
Failed = ReadPartDescr( this, &reader, MsgDiag, screen );
|
||||
break;
|
||||
|
||||
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" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = true;
|
||||
break;
|
||||
}
|
||||
|
@ -190,15 +170,14 @@ again." );
|
|||
|
||||
SegmentStruct = new SCH_LINE( wxPoint( 0, 0 ), layer );
|
||||
|
||||
LineCount++;
|
||||
if( fgets( Line, 256 - 1, f ) == NULL
|
||||
|| sscanf( Line, "%d %d %d %d ", &SegmentStruct->m_Start.x,
|
||||
if( !reader.ReadLine()
|
||||
|| sscanf( line, "%d %d %d %d ", &SegmentStruct->m_Start.x,
|
||||
&SegmentStruct->m_Start.y, &SegmentStruct->m_End.x,
|
||||
&SegmentStruct->m_End.y ) != 4 )
|
||||
{
|
||||
MsgDiag.Printf( wxT( "EESchema file Segment struct error at line %d, aborted" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = true;
|
||||
SAFE_DELETE( SegmentStruct );
|
||||
break;
|
||||
|
@ -212,11 +191,11 @@ again." );
|
|||
break;
|
||||
|
||||
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" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = true;
|
||||
break;
|
||||
}
|
||||
|
@ -224,17 +203,16 @@ again." );
|
|||
ii = WIRE_TO_BUS;
|
||||
if( Name1[0] == 'B' )
|
||||
ii = BUS_TO_BUS;
|
||||
|
||||
busEntry = new SCH_BUS_ENTRY( wxPoint( 0, 0 ), '\\', ii );
|
||||
|
||||
LineCount++;
|
||||
|
||||
if( fgets( Line, 256 - 1, f ) == NULL
|
||||
|| sscanf( Line, "%d %d %d %d ", &busEntry->m_Pos.x, &busEntry->m_Pos.y,
|
||||
if( !reader.ReadLine()
|
||||
|| sscanf( line, "%d %d %d %d ", &busEntry->m_Pos.x, &busEntry->m_Pos.y,
|
||||
&busEntry->m_Size.x, &busEntry->m_Size.y ) != 4 )
|
||||
{
|
||||
MsgDiag.Printf( wxT( "EESchema file Bus Entry struct error at line %d, aborted" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = true;
|
||||
SAFE_DELETE( busEntry );
|
||||
break;
|
||||
|
@ -250,11 +228,11 @@ again." );
|
|||
break;
|
||||
|
||||
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" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = true;
|
||||
break;
|
||||
}
|
||||
|
@ -265,17 +243,17 @@ again." );
|
|||
layer = LAYER_BUS;
|
||||
|
||||
PolylineStruct = new SCH_POLYLINE( layer );
|
||||
|
||||
for( unsigned jj = 0; jj < (unsigned)ii; jj++ )
|
||||
{
|
||||
LineCount++;
|
||||
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 \
|
||||
at line %d, aborted" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
MsgDiag.Printf( wxT( "EESchema file polyline struct error at line %d, aborted" ),
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = true;
|
||||
SAFE_DELETE( PolylineStruct );
|
||||
break;
|
||||
|
@ -294,13 +272,12 @@ at line %d, aborted" ),
|
|||
case 'C': // It is a connection item.
|
||||
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 )
|
||||
{
|
||||
MsgDiag.Printf( wxT( "EESchema file connection struct error \
|
||||
at line %d, aborted" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
MsgDiag.Printf( wxT( "EESchema file connection struct error at line %d, aborted" ),
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = true;
|
||||
SAFE_DELETE( ConnectionStruct );
|
||||
}
|
||||
|
@ -312,11 +289,11 @@ at line %d, aborted" ),
|
|||
break;
|
||||
|
||||
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" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = true;
|
||||
}
|
||||
else
|
||||
|
@ -334,9 +311,7 @@ at line %d, aborted" ),
|
|||
|
||||
case 'T': // It is a text item.
|
||||
{
|
||||
SCH_ITEM* Struct;
|
||||
Struct = ReadTextDescr( f, MsgDiag, Line, sizeof(Line), &LineCount, version);
|
||||
|
||||
SCH_ITEM* Struct = ReadTextDescr( &reader, MsgDiag, version);
|
||||
if( Struct )
|
||||
{
|
||||
Struct->SetNext( screen->EEDrawList );
|
||||
|
@ -350,8 +325,8 @@ at line %d, aborted" ),
|
|||
default:
|
||||
Failed = true;
|
||||
MsgDiag.Printf( wxT( "EESchema file undefined object at line %d, aborted" ),
|
||||
LineCount );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
reader.LineNumber() );
|
||||
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -378,8 +353,6 @@ at line %d, aborted" ),
|
|||
screen->Show( 0, std::cout );
|
||||
#endif
|
||||
|
||||
fclose( f );
|
||||
|
||||
TestDanglingEnds( screen->EEDrawList, NULL );
|
||||
|
||||
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;
|
||||
char Line[1024];
|
||||
|
||||
//int Mode,Color,Layer;
|
||||
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 )
|
||||
{
|
||||
/* error : init par default */
|
||||
|
@ -413,9 +385,9 @@ static void LoadLayers( FILE* f, int* linecnt )
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,24 +11,18 @@
|
|||
#include "program.h"
|
||||
#include "general.h"
|
||||
#include "protos.h"
|
||||
#include "richio.h"
|
||||
|
||||
#define line ((char*)(*aLine))
|
||||
|
||||
SCH_ITEM* ReadTextDescr( FILE* aFile,
|
||||
wxString& aMsgDiag,
|
||||
char* aLine,
|
||||
int aBufsize,
|
||||
int* aLineNum,
|
||||
int aSchematicFileVersion )
|
||||
SCH_ITEM* ReadTextDescr( LINE_READER* aLine, wxString& aMsgDiag, int aSchematicFileVersion )
|
||||
{
|
||||
/**
|
||||
* Function ReadTextDescr
|
||||
* Reads the data structures for a Text (Comment, label, Hlabel and Hlabel
|
||||
* from a FILE in "*.sch" format.
|
||||
* @param aFile The FILE to read.
|
||||
* @param aLine The buffer used to read the first line of description.
|
||||
* @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.
|
||||
* @param aLine is a LINE_READER to use.
|
||||
* @return a pointer to the new created object if success reading else NULL.
|
||||
*/
|
||||
SCH_ITEM* Struct = NULL;
|
||||
char Name1[256];
|
||||
|
@ -37,35 +31,37 @@ SCH_ITEM* ReadTextDescr( FILE* aFile,
|
|||
int thickness = 0, size = 0, orient = 0;
|
||||
wxPoint pos;
|
||||
|
||||
char* SLine = aLine;
|
||||
|
||||
while( (*SLine != ' ' ) && *SLine )
|
||||
SLine++;
|
||||
|
||||
// SLine points the start of parameters
|
||||
|
||||
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 );
|
||||
|
||||
if( ii < 4 )
|
||||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "EESchema file text struct error line %d, aborted" ),
|
||||
*aLineNum );
|
||||
aLine->LineNumber() );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( feof( aFile ) || GetLine( aFile, aLine, aLineNum, aBufsize ) == NULL )
|
||||
if( !aLine->ReadLine() )
|
||||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "EESchema file text struct error line %d (No text), aborted" ),
|
||||
*aLineNum );
|
||||
aLine->LineNumber() );
|
||||
return NULL;
|
||||
}
|
||||
if( size == 0 )
|
||||
|
||||
if( size == 0 )
|
||||
size = DEFAULT_SIZE_TEXT;
|
||||
char* text = strtok( aLine, "\n\r" );
|
||||
|
||||
char* text = strtok( line, "\n\r" );
|
||||
if( text == NULL )
|
||||
return NULL;
|
||||
|
||||
|
@ -168,6 +164,7 @@ SCH_ITEM* ReadTextDescr( FILE* aFile,
|
|||
|
||||
if( strnicmp( Name2, "Italic", 6 ) == 0 )
|
||||
TextStruct->m_Italic = 1;
|
||||
|
||||
Struct = TextStruct;
|
||||
}
|
||||
|
||||
|
@ -178,8 +175,7 @@ SCH_ITEM* ReadTextDescr( FILE* aFile,
|
|||
/* Function used by LoadEEFile().
|
||||
* Get the lines for a description of a piece of hierarchy.
|
||||
*/
|
||||
int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
||||
int* aLineNum, BASE_SCREEN* Window )
|
||||
int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
|
||||
{
|
||||
int ii, fieldNdx, size;
|
||||
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.
|
||||
// this is accomplished through the Sync() function.
|
||||
|
||||
if( Line[0] == '$' ) /* Line should be "$Sheet" */
|
||||
if( line[0] == '$' ) // line should be "$Sheet"
|
||||
{
|
||||
*aLineNum++;
|
||||
if( fgets( Line, 256 - 1, f ) == 0 )
|
||||
if( !aLine->ReadLine() )
|
||||
{
|
||||
aMsgDiag.Printf( wxT( "Read File Errror" ) );
|
||||
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
|
||||
* ( 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_Size.x, &SheetStruct->m_Size.y ) != 4)
|
||||
|| (Line[0] != 'S' ) )
|
||||
|| (line[0] != 'S' ) )
|
||||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( " ** EESchema file sheet struct error at line %d, aborted\n" ),
|
||||
*aLineNum );
|
||||
aMsgDiag << CONV_FROM_UTF8( Line );
|
||||
aLine->LineNumber() );
|
||||
|
||||
aMsgDiag << CONV_FROM_UTF8( line );
|
||||
Failed = TRUE;
|
||||
return Failed;
|
||||
}
|
||||
|
@ -226,19 +222,21 @@ int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
/* Read fields */
|
||||
for( ; ; ) /* Analysis of lines "Fn" text. */
|
||||
{
|
||||
*aLineNum++;
|
||||
if( fgets( Line, 256 - 1, f ) == NULL )
|
||||
if( !aLine->ReadLine() )
|
||||
return TRUE;
|
||||
if( Line[0] == 'U' )
|
||||
|
||||
if( line[0] == 'U' )
|
||||
{
|
||||
sscanf( Line + 1, "%lX", &(SheetStruct->m_TimeStamp) );
|
||||
if( SheetStruct->m_TimeStamp == 0 ) //zero is not unique!
|
||||
sscanf( line + 1, "%lX", &SheetStruct->m_TimeStamp );
|
||||
if( SheetStruct->m_TimeStamp == 0 ) // zero is not unique!
|
||||
SheetStruct->m_TimeStamp = GetTimeStamp();
|
||||
continue;
|
||||
}
|
||||
if( Line[0] != 'F' )
|
||||
|
||||
if( line[0] != 'F' )
|
||||
break;
|
||||
sscanf( Line + 1, "%d", &fieldNdx );
|
||||
|
||||
sscanf( line + 1, "%d", &fieldNdx );
|
||||
|
||||
|
||||
/* Read the field:
|
||||
|
@ -246,32 +244,36 @@ int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
* If F0 "text" for SheetName
|
||||
* F1 and "text" for filename
|
||||
*/
|
||||
ptcar = Line; while( *ptcar && ( *ptcar != '"' ) )
|
||||
ptcar = line;
|
||||
while( *ptcar && ( *ptcar != '"' ) )
|
||||
ptcar++;
|
||||
|
||||
if( *ptcar != '"' )
|
||||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "EESchema file sheet label F%d at line %d, aborted\n" ),
|
||||
fieldNdx, *aLineNum );
|
||||
aMsgDiag << CONV_FROM_UTF8( Line );
|
||||
fieldNdx, aLine->LineNumber() );
|
||||
aMsgDiag << CONV_FROM_UTF8( line );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
for( ptcar++, ii = 0; ; ii++, ptcar++ )
|
||||
{
|
||||
Name1[ii] = *ptcar;
|
||||
|
||||
if( *ptcar == 0 )
|
||||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "EESchema file sheet field F at line %d, aborted\n" ),
|
||||
*aLineNum );
|
||||
aMsgDiag << CONV_FROM_UTF8( Line );
|
||||
aLine->LineNumber() );
|
||||
aMsgDiag << CONV_FROM_UTF8( line );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if( *ptcar == '"' )
|
||||
{
|
||||
Name1[ii] = 0; ptcar++;
|
||||
Name1[ii] = 0;
|
||||
ptcar++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -280,14 +282,15 @@ int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
{
|
||||
if( sscanf( ptcar, "%d", &size ) != 1 )
|
||||
{
|
||||
aMsgDiag.Printf( wxT( "EESchema file sheet Label Caract \
|
||||
error line %d, aborted\n" ),
|
||||
*aLineNum );
|
||||
aMsgDiag << CONV_FROM_UTF8( Line );
|
||||
aMsgDiag.Printf( wxT( "EESchema file sheet Label Caract error line %d, aborted\n" ),
|
||||
aLine->LineNumber() );
|
||||
|
||||
aMsgDiag << CONV_FROM_UTF8( line );
|
||||
DisplayError( frame, aMsgDiag );
|
||||
}
|
||||
if( size == 0 )
|
||||
size = DEFAULT_SIZE_TEXT;
|
||||
|
||||
if( fieldNdx == 0 )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
aMsgDiag.Printf( wxT( "EESchema file sheet label error at line %d, ignoring.\n" ),
|
||||
*aLineNum );
|
||||
aMsgDiag << CONV_FROM_UTF8( Line );
|
||||
aLine->LineNumber() );
|
||||
aMsgDiag << CONV_FROM_UTF8( line );
|
||||
DisplayError( frame, aMsgDiag );
|
||||
continue;
|
||||
}
|
||||
|
@ -322,6 +325,7 @@ error line %d, aborted\n" ),
|
|||
|
||||
if( size == 0 )
|
||||
size = DEFAULT_SIZE_TEXT;
|
||||
|
||||
SheetLabelStruct->m_Size.x = SheetLabelStruct->m_Size.y = size;
|
||||
SheetLabelStruct->m_Pos.x=x; //to readjust x of first label if vertical
|
||||
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" ),
|
||||
*aLineNum );
|
||||
aMsgDiag << CONV_FROM_UTF8( Line );
|
||||
aLine->LineNumber() );
|
||||
aMsgDiag << CONV_FROM_UTF8( line );
|
||||
Failed = TRUE;
|
||||
}
|
||||
|
||||
if( !Failed )
|
||||
{
|
||||
SheetStruct->SetNext( Window->EEDrawList );
|
||||
|
@ -386,8 +391,7 @@ error line %d, aborted\n" ),
|
|||
|
||||
|
||||
/* Read the schematic header. */
|
||||
bool ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
||||
int* aLineNum, BASE_SCREEN* Window )
|
||||
bool ReadSchemaDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
|
||||
{
|
||||
char Text[256], buf[1024];
|
||||
int ii;
|
||||
|
@ -400,7 +404,7 @@ bool ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
};
|
||||
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 );
|
||||
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 \
|
||||
line %d, \aAbort reading file.\n" ),
|
||||
*aLineNum );
|
||||
aMsgDiag << CONV_FROM_UTF8( Line );
|
||||
aLine->LineNumber() );
|
||||
aMsgDiag << CONV_FROM_UTF8( line );
|
||||
DisplayError( frame, aMsgDiag );
|
||||
}
|
||||
|
||||
|
@ -430,67 +434,68 @@ line %d, \aAbort reading file.\n" ),
|
|||
|
||||
for( ; ; )
|
||||
{
|
||||
if( GetLine( f, Line, aLineNum, 1024 ) == NULL )
|
||||
if( !aLine->ReadLine() )
|
||||
return TRUE;
|
||||
if( strnicmp( Line, "$End", 4 ) == 0 )
|
||||
|
||||
if( strnicmp( line, "$End", 4 ) == 0 )
|
||||
break;
|
||||
|
||||
if( strnicmp( Line, "Sheet", 2 ) == 0 )
|
||||
sscanf( Line + 5, " %d %d",
|
||||
if( strnicmp( line, "Sheet", 2 ) == 0 )
|
||||
sscanf( line + 5, " %d %d",
|
||||
&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 );
|
||||
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 );
|
||||
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 );
|
||||
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 );
|
||||
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 );
|
||||
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 );
|
||||
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 );
|
||||
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 );
|
||||
continue;
|
||||
}
|
||||
|
@ -503,8 +508,8 @@ line %d, \aAbort reading file.\n" ),
|
|||
/* Function used by LoadEEFile ().
|
||||
* 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;
|
||||
char Name1[256], Name2[256],
|
||||
|
@ -518,20 +523,20 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
|
||||
component->m_Convert = 1;
|
||||
|
||||
if( Line[0] == '$' )
|
||||
if( line[0] == '$' )
|
||||
{
|
||||
newfmt = 1;
|
||||
*aLineNum++;
|
||||
if( fgets( Line, 256 - 1, f ) == 0 )
|
||||
|
||||
if( !aLine->ReadLine() )
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if( sscanf( &Line[1], "%s %s", Name1, Name2 ) != 2 )
|
||||
if( sscanf( &line[1], "%s %s", Name1, Name2 ) != 2 )
|
||||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "EESchema Component descr error at line %d, aborted" ),
|
||||
*aLineNum );
|
||||
aMsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
||||
aLine->LineNumber() );
|
||||
aMsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( line );
|
||||
Failed = TRUE;
|
||||
return Failed;
|
||||
}
|
||||
|
@ -608,19 +613,18 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
*/
|
||||
for( ; ; )
|
||||
{
|
||||
*aLineNum++;
|
||||
if( fgets( Line, 256 - 1, f ) == NULL )
|
||||
if( !aLine->ReadLine() )
|
||||
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_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 );
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
else if( Line[0] == 'A' && Line[1] == 'R' )
|
||||
else if( line[0] == 'A' && line[1] == 'R' )
|
||||
{
|
||||
/* format:
|
||||
* 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.
|
||||
*/
|
||||
int ii;
|
||||
ptcar = Line + 2;
|
||||
ptcar = line + 2;
|
||||
|
||||
//copy the path.
|
||||
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->GetField( REFERENCE )->m_Text = ref;
|
||||
}
|
||||
else if( Line[0] == 'F' )
|
||||
else if( line[0] == 'F' )
|
||||
{
|
||||
int fieldNdx;
|
||||
|
||||
|
@ -673,7 +677,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
|
||||
FieldUserName[0] = 0;
|
||||
|
||||
ptcar = Line;
|
||||
ptcar = line;
|
||||
|
||||
while( *ptcar && (*ptcar != '"') )
|
||||
ptcar++;
|
||||
|
@ -682,7 +686,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "EESchema file lib field F at line %d, aborted" ),
|
||||
*aLineNum );
|
||||
aLine->LineNumber() );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -693,7 +697,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "Component field F at line %d, aborted" ),
|
||||
*aLineNum );
|
||||
aLine->LineNumber() );
|
||||
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) );
|
||||
|
||||
|
@ -749,7 +753,7 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "Component Field error line %d, aborted" ),
|
||||
*aLineNum );
|
||||
aLine->LineNumber() );
|
||||
DisplayError( frame, aMsgDiag );
|
||||
continue;
|
||||
}
|
||||
|
@ -796,39 +800,38 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag,
|
|||
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 )
|
||||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "Component unit & pos error at line %d, aborted" ),
|
||||
*aLineNum );
|
||||
aLine->LineNumber() );
|
||||
Failed = TRUE;
|
||||
return Failed;
|
||||
}
|
||||
|
||||
*aLineNum++;
|
||||
if( ( fgets( Line, 256 - 1, f ) == NULL )
|
||||
|| ( sscanf( Line, "%d %d %d %d",
|
||||
if( !aLine->ReadLine() ||
|
||||
sscanf( line, "%d %d %d %d",
|
||||
&component->m_Transform.x1,
|
||||
&component->m_Transform.y1,
|
||||
&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;
|
||||
return Failed;
|
||||
}
|
||||
|
||||
if( newfmt )
|
||||
{
|
||||
*aLineNum++;
|
||||
if( fgets( Line, 256 - 1, f ) == NULL )
|
||||
if( !aLine->ReadLine() )
|
||||
return TRUE;
|
||||
if( strnicmp( "$End", Line, 4 ) != 0 )
|
||||
|
||||
if( strnicmp( "$End", line, 4 ) != 0 )
|
||||
{
|
||||
aMsgDiag.Printf(
|
||||
wxT( "Component End expected at line %d, aborted" ),
|
||||
*aLineNum );
|
||||
aLine->LineNumber() );
|
||||
Failed = TRUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public:
|
|||
* of lines of text. The returned string is useful for reporting error
|
||||
* messages.
|
||||
*/
|
||||
const wxString& GetSource()
|
||||
const wxString& GetSource() const
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ public:
|
|||
* returns the line number of the last line read from this LINE_READER. Lines
|
||||
* start from 1.
|
||||
*/
|
||||
int LineNumber()
|
||||
int LineNumber() const
|
||||
{
|
||||
return lineNum;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public:
|
|||
* Function Length
|
||||
* returns the number of bytes in the last line read from this LINE_READER.
|
||||
*/
|
||||
unsigned Length()
|
||||
unsigned Length() const
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue