Commit acbe6290 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

switch back to original sexpr usage of PTREE, add new DSNLEXER constructor,...

switch back to original sexpr usage of PTREE, add new DSNLEXER constructor, enforce accessors in kicad.exe
parent 0304598a
Loading
Loading
Loading
Loading
+17 −1
Original line number Original line Diff line number Diff line
@@ -36,6 +36,8 @@


//#define STANDALONE  1       // enable this for stand alone testing.
//#define STANDALONE  1       // enable this for stand alone testing.


#define FMT_CLIPBOARD       _( "clipboard" )



//-----<DSNLEXER>-------------------------------------------------------------
//-----<DSNLEXER>-------------------------------------------------------------


@@ -89,7 +91,7 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
    keywordCount( aKeywordCount )
    keywordCount( aKeywordCount )
{
{
    STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ?
    STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ?
                                        wxString( _( "clipboard" ) ) : aSource );
                                        wxString( FMT_CLIPBOARD ) : aSource );
    PushReader( stringReader );
    PushReader( stringReader );
    init();
    init();
}
}
@@ -107,6 +109,20 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
}
}




static const KEYWORD empty_keywords[1] = {};

DSNLEXER::DSNLEXER( const std::string& aSExpression, const wxString& aSource ) :
    iOwnReaders( true ),
    keywords( empty_keywords ),
    keywordCount( 0 )
{
    STRING_LINE_READER* stringReader = new STRING_LINE_READER( aSExpression, aSource.IsEmpty() ?
                                        wxString( FMT_CLIPBOARD ) : aSource );
    PushReader( stringReader );
    init();
}


DSNLEXER::~DSNLEXER()
DSNLEXER::~DSNLEXER()
{
{
    if( iOwnReaders )
    if( iOwnReaders )
+1 −5
Original line number Original line Diff line number Diff line
@@ -83,11 +83,7 @@ inline void scanAtom( PTREE* aTree, DSNLEXER* aLexer )


    //D(printf( "%s: '%s'\n", __func__, key );)
    //D(printf( "%s: '%s'\n", __func__, key );)


#if 0
    aTree->push_back( PTREE::value_type( key, PTREE() ) );
    aTree->push_back( PTREE::value_type( key, PTREE() ) );
#else
    aTree->put_value( key );
#endif
}
}




@@ -194,7 +190,7 @@ static void formatNode( OUTPUTFORMATTER* out, int aNestLevel, int aCtl,


        out->Print( aNestLevel, "(%s%s", out->Quotes( aKey ).c_str(), ctl & CTL_OMIT_NL ? "" : "\n" );
        out->Print( aNestLevel, "(%s%s", out->Quotes( aKey ).c_str(), ctl & CTL_OMIT_NL ? "" : "\n" );


        if( aTree.data().size() )
        if( aTree.data().size() )       // sexpr format does not use data()
        {
        {
            out->Print( 0, " %s%s",
            out->Print( 0, " %s%s",
                out->Quotes( aTree.data() ).c_str(),
                out->Quotes( aTree.data() ).c_str(),
+39 −33
Original line number Original line Diff line number Diff line
@@ -56,11 +56,11 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef


    sheets.GetComponents( refs, false );
    sheets.GetComponents( refs, false );


    static const KEYWORD empty_keywords[1] = {};
    DSNLEXER    lexer( aChangedSetOfReferences, FROM_UTF8( __func__ ) );

    DSNLEXER    lexer( empty_keywords, 0, aChangedSetOfReferences, FROM_UTF8( __func__ ) );
    PTREE       doc;
    PTREE       doc;


    try
    {
        Scan( &doc, &lexer );
        Scan( &doc, &lexer );


#if defined(DEBUG) && 0
#if defined(DEBUG) && 0
@@ -75,10 +75,10 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef
        {
        {
            wxASSERT( ref->first == "ref" );
            wxASSERT( ref->first == "ref" );


        wxString reference = (UTF8&) ref->second.data();
            wxString reference = (UTF8&) ref->second.front().first;
        wxString footprint = (UTF8)  ref->second.get<std::string>( "fpid" );
            wxString footprint = (UTF8&) ref->second.get_child( "fpid" ).front().first;


        // DBG( printf( "%s: ref:%s  fpid:%s\n", __func__, TO_UTF8( reference ), TO_UTF8( footprint ) ); )
            DBG( printf( "%s: ref:%s  fpid:%s\n", __func__, TO_UTF8( reference ), TO_UTF8( footprint ) ); )


            // Search the component in the flat list
            // Search the component in the flat list
            for( unsigned ii = 0;  ii < refs.GetCount();  ++ii )
            for( unsigned ii = 0;  ii < refs.GetCount();  ++ii )
@@ -105,6 +105,12 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef
                }
                }
            }
            }
        }
        }
    }
    catch( const PTREE_ERROR& ex )
    {
        // remap the exception to something the caller is likely to understand.
        THROW_IO_ERROR( ex.what() );
    }


    if( isChanged )
    if( isChanged )
        OnModify();
        OnModify();
+11 −1
Original line number Original line Diff line number Diff line
@@ -174,7 +174,7 @@ public:
              FILE* aFile, const wxString& aFileName );
              FILE* aFile, const wxString& aFileName );


    /**
    /**
     * Constructor ( std::string&*, const wxString& )
     * Constructor ( const KEYWORD*, unsigned, const std::string&, const wxString& )
     * intializes a DSN lexer and prepares to read from @a aSExpression.
     * intializes a DSN lexer and prepares to read from @a aSExpression.
     *
     *
     * @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount.  This
     * @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount.  This
@@ -186,6 +186,16 @@ public:
    DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
    DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
              const std::string& aSExpression, const wxString& aSource = wxEmptyString );
              const std::string& aSExpression, const wxString& aSource = wxEmptyString );


    /**
     * Constructor ( const std::string&, const wxString& )
     * intializes a DSN lexer and prepares to read from @a aSExpression.  Use this
     * one without a keyword table with the DOM parser in ptree.h.
     *
     * @param aSExpression is text to feed through a STRING_LINE_READER
     * @param aSource is a description of aSExpression, used for error reporting.
     */
    DSNLEXER( const std::string& aSExpression, const wxString& aSource = wxEmptyString );

    /**
    /**
     * Constructor ( LINE_READER* )
     * Constructor ( LINE_READER* )
     * intializes a DSN lexer and prepares to read from @a aLineReader which
     * intializes a DSN lexer and prepares to read from @a aLineReader which
+3 −3
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ makes it easy to extract a subset of a ptree.


typedef boost::property_tree::ptree         PTREE;
typedef boost::property_tree::ptree         PTREE;
typedef const PTREE                         CPTREE;
typedef const PTREE                         CPTREE;

typedef boost::property_tree::ptree_error   PTREE_ERROR;


/**
/**
 * Function Scan
 * Function Scan
Loading