Commit cdbd1b29 authored by dickelbeck's avatar dickelbeck

tolerate long library lists

parent ae72db7a
...@@ -81,7 +81,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F ...@@ -81,7 +81,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F
MsgDiag = _( "Loading " ) + screen->m_FileName; MsgDiag = _( "Loading " ) + screen->m_FileName;
PrintMsg( MsgDiag ); PrintMsg( MsgDiag );
if( fgets( Line, 1024 - 1, f ) == NULL if( fgets( Line, sizeof(Line), f ) == NULL
|| strncmp( Line + 9, SCHEMATIC_HEAD_STRING, sizeof(SCHEMATIC_HEAD_STRING) - 1 ) || strncmp( Line + 9, SCHEMATIC_HEAD_STRING, sizeof(SCHEMATIC_HEAD_STRING) - 1 )
!= 0 ) != 0 )
{ {
...@@ -113,7 +113,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F ...@@ -113,7 +113,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F
#endif #endif
LineCount++; LineCount++;
if( fgets( Line, 1024 - 1, f ) == NULL || 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 );
...@@ -121,6 +121,15 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F ...@@ -121,6 +121,15 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F
return FALSE; 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' )
{
int c;
while( !feof( f ) && (c = fgetc( f )) != '\n' )
;
}
LoadLayers( f, &LineCount ); LoadLayers( f, &LineCount );
while( !feof( f ) && GetLine( f, Line, &LineCount, sizeof(Line) ) != NULL ) while( !feof( f ) && GetLine( f, Line, &LineCount, sizeof(Line) ) != NULL )
...@@ -407,20 +416,21 @@ static void LoadLayers( FILE* f, int* linecnt ) ...@@ -407,20 +416,21 @@ static void LoadLayers( FILE* f, int* linecnt )
/* Load the Layer Struct from a file /* Load the Layer Struct from a file
*/ */
{ {
int cnt = 0, Number; int Number;
char Line[1024]; char Line[1024];
//int Mode,Color,Layer; //int Mode,Color,Layer;
char Name[256]; char Name[256];
GetLine( f, Line, NULL, sizeof(Line) ); /* read line */ GetLine( f, Line, linecnt, sizeof(Line) ); /* read line */
(*linecnt)++;
sscanf( Line, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer ); sscanf( Line, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer );
if( strcmp( Name, "EELAYER" ) !=0 ) if( strcmp( Name, "EELAYER" ) !=0 )
{ {
/* error : init par defaut */ /* error : init par defaut */
Number = MAX_LAYER; Number = MAX_LAYER;
} }
if( Number <= 0 ) if( Number <= 0 )
Number = MAX_LAYER; Number = MAX_LAYER;
if( Number > MAX_LAYER ) if( Number > MAX_LAYER )
...@@ -428,11 +438,9 @@ static void LoadLayers( FILE* f, int* linecnt ) ...@@ -428,11 +438,9 @@ static void LoadLayers( FILE* f, int* linecnt )
g_LayerDescr.NumberOfLayers = Number; g_LayerDescr.NumberOfLayers = Number;
while( GetLine( f, Line, NULL, sizeof(Line) ) ) while( GetLine( f, Line, linecnt, sizeof(Line) ) )
{ {
(*linecnt)++;
if( strnicmp( Line, "EELAYER END", 11 ) == 0 ) if( strnicmp( Line, "EELAYER END", 11 ) == 0 )
break; break;
cnt++;
} }
} }
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