From 5b225186c4d690dd1d95852fa9e7254ca897f9fd Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Wed, 1 May 2013 10:48:00 -0500 Subject: [PATCH] fix 2 corner case bugs in specctra import --- common/dsnlexer.cpp | 7 +++- pcbnew/pcb_parser.cpp | 2 +- pcbnew/specctra.cpp | 82 ++++++++++++++++++-------------------- pcbnew/specctra.h | 6 ++- pcbnew/specctra_import.cpp | 6 +-- 5 files changed, 52 insertions(+), 51 deletions(-) diff --git a/common/dsnlexer.cpp b/common/dsnlexer.cpp index 03b4112221..cd7962c7f6 100644 --- a/common/dsnlexer.cpp +++ b/common/dsnlexer.cpp @@ -2,7 +2,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -30,6 +30,7 @@ #include #include +#include #include //#include "fctsys.h" @@ -60,6 +61,8 @@ void DSNLEXER::init() space_in_quoted_tokens = false; commentsAreTokens = false; + + D(printf( "readerStack::count:%zu\n", readerStack.size() );) } @@ -102,6 +105,8 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount, DSNLEXER::~DSNLEXER() { + D(printf( "~readerStack::count:%zu\n", readerStack.size() );) + if( iOwnReaders ) { // delete the LINE_READERs from the stack, since I own them. diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index 5934d1ed0b..6057bc8182 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -744,7 +744,7 @@ T PCB_PARSER::lookUpLayer( const M& aMap ) throw( PARSE_ERROR, IO_ERROR ) if( it == aMap.end() ) { -#if 1 && defined(DEBUG) +#if 0 && defined(DEBUG) // dump the whole darn table, there's something wrong with it. for( it = aMap.begin(); it != aMap.end(); ++it ) { diff --git a/pcbnew/specctra.cpp b/pcbnew/specctra.cpp index 2c1f2d96d2..5e9d0a51e1 100644 --- a/pcbnew/specctra.cpp +++ b/pcbnew/specctra.cpp @@ -1870,58 +1870,54 @@ void SPECCTRA_DB::doPLACEMENT( PLACEMENT* growth ) throw( IO_ERROR ) { T tok; - NeedLEFT(); - - tok = NextTok(); - if( tok==T_unit || tok==T_resolution ) + while( (tok = NextTok()) != T_RIGHT ) { - growth->unit = new UNIT_RES( growth, tok ); - if( tok==T_resolution ) - doRESOLUTION( growth->unit ); - else - doUNIT( growth->unit ); + if( tok == T_EOF ) + Unexpected( T_EOF ); - if( NextTok() != T_LEFT ) - Expecting( T_LEFT ); - tok = NextTok(); - } - - if( tok == T_place_control ) - { - if( NextTok() != T_LEFT ) + if( tok != T_LEFT ) Expecting( T_LEFT ); tok = NextTok(); - if( tok != T_flip_style ) - Expecting( T_flip_style ); - tok = NextTok(); - if( tok==T_mirror_first || tok==T_rotate_first ) - growth->flip_style = tok; - else - Expecting("mirror_first|rotate_first"); + switch( tok ) + { + case T_unit: + case T_resolution: + growth->unit = new UNIT_RES( growth, tok ); + if( tok==T_resolution ) + doRESOLUTION( growth->unit ); + else + doUNIT( growth->unit ); + break; - NeedRIGHT(); - NeedRIGHT(); - NeedLEFT(); - tok = NextTok(); - } - - while( tok == T_component ) - { - COMPONENT* component = new COMPONENT( growth ); - growth->components.push_back( component ); - doCOMPONENT( component ); - - tok = NextTok(); - if( tok == T_RIGHT ) - return; - - else if( tok == T_LEFT ) + case T_place_control: + NeedRIGHT(); tok = NextTok(); - } + if( tok != T_flip_style ) + Expecting( T_flip_style ); - Unexpected( CurText() ); + tok = NextTok(); + if( tok==T_mirror_first || tok==T_rotate_first ) + growth->flip_style = tok; + else + Expecting( "mirror_first|rotate_first" ); + + NeedRIGHT(); + NeedRIGHT(); + break; + + case T_component: + COMPONENT* component; + component = new COMPONENT( growth ); + growth->components.push_back( component ); + doCOMPONENT( component ); + break; + + default: + Unexpected( tok ); + } + } } diff --git a/pcbnew/specctra.h b/pcbnew/specctra.h index b298cbecf3..5e0a6d9417 100644 --- a/pcbnew/specctra.h +++ b/pcbnew/specctra.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -3796,7 +3796,9 @@ public: SPECCTRA_DB() : SPECCTRA_LEXER( 0 ) // LINE_READER* == NULL, no DSNLEXER::PushReader() { - iOwnReaders = true; // if an exception is thrown, close file. + // The LINE_READER will be pushed from an automatic instantiation, + // we don't own it: + wxASSERT( !iOwnReaders ); pcb = 0; session = 0; diff --git a/pcbnew/specctra_import.cpp b/pcbnew/specctra_import.cpp index d05834c91e..5a45bfbe6a 100644 --- a/pcbnew/specctra_import.cpp +++ b/pcbnew/specctra_import.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2007-2010 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -94,7 +94,6 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) return; SPECCTRA_DB db; - LOCALE_IO toggle; try @@ -118,7 +117,7 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) /* At this point we should call Compile_Ratsnest() * but this could be time consumming. - * So if incorrect number of Connecred and No connected pads is accepted + * So if incorrect number of Connected and No connected pads is accepted * until Compile_Ratsnest() is called (when track tool selected for instance) * leave the next line commented * Otherwise uncomment this line @@ -377,7 +376,6 @@ SEGVIA* SPECCTRA_DB::makeVIA( PADSTACK* aPadstack, const POINT& aPoint, int aNet } - // no UI code in this function, throw exception to report problems to the // UI handler: void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event )