From fb0bb79a8d15370422b0201d2aa3ae913adffc36 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sun, 8 Aug 2010 21:03:16 -0500 Subject: [PATCH] TokenList2DsnLexer.cmake, netform.cpp enhancements --- CHANGELOG.txt | 14 +++ CMakeModules/TokenList2DsnLexer.cmake | 130 +++++++++++++++++++++++--- common/CMakeLists.txt | 14 +++ {eeschema => common}/netlist.keywords | 2 + common/richio.cpp | 6 +- eeschema/CMakeLists.txt | 12 +-- eeschema/eeschema_config.cpp | 7 +- eeschema/netform.cpp | 14 ++- eeschema/template_fieldnames.cpp | 20 ++-- eeschema/template_fieldnames.h | 13 ++- include/dsnlexer.h | 106 +++++++++++---------- include/richio.h | 68 ++++++++------ include/xnode.h | 5 +- pcbnew/specctra.cpp | 5 +- pcbnew/specctra.h | 4 +- pcbnew/specctra_export.cpp | 2 +- pcbnew/specctra_import.cpp | 2 +- 17 files changed, 287 insertions(+), 137 deletions(-) rename {eeschema => common}/netlist.keywords (94%) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 73e0166fd0..ef82e4fffd 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,20 @@ KiCad ChangeLog 2010 Please add newer entries at the top, list the date and your name with email address. +2010-Aug-8 UPDATE Dick Hollenbeck +================================================================================ +++CMakeModules: + Revise TokenList2DsnLexer.cmake to make an entire derived lexer class that + returns the proper enum type for superior debugging. +++eeschema + * netform.cpp now outputs the allowed footprint filters for a given library + component. + * There is an auto-generated class called NETLIST_LEXER which is defined in + from netlist.keywords by TokenList2DsnLexer.cmake into netlist_lexer.h, that + may be the basis of loading a S-expression form of the generic netlist format + which is written from netform.cpp. + + 2010-Aug-7 UPDATE Dick Hollenbeck ================================================================================ ++common diff --git a/CMakeModules/TokenList2DsnLexer.cmake b/CMakeModules/TokenList2DsnLexer.cmake index 4223089373..9f5acc069f 100644 --- a/CMakeModules/TokenList2DsnLexer.cmake +++ b/CMakeModules/TokenList2DsnLexer.cmake @@ -82,18 +82,17 @@ get_filename_component( result "${inputFile}" NAME_WE ) message( STATUS "Extracted file name ${result} from path ${inputFile}" ) # Create include and source file name from the list file name. -set( includeFileName "${outputPath}/${result}_keywords.h" ) +set( includeFileName "${outputPath}/${result}_lexer.h" ) set( sourceFileName "${outputPath}/${result}_keywords.cpp" ) # Create tag for generating header file. -string( TOUPPER "${result}" fileNameTag ) -set( headerTag "_${fileNameTag}_H_" ) +string( TOUPPER "${result}" RESULT ) +set( headerTag "_${RESULT}_H_" ) set( includeFileHeader " -/* - * Do not modify this file it was automatically generated by the TokenList2DsnLexer CMake - * script. +/* Do not modify this file it was automatically generated by the + * TokenList2DsnLexer CMake script. */ #ifndef ${headerTag} @@ -124,18 +123,17 @@ enum ${enum} { set( sourceFileHeader " -/* - * Do not modify this file it was automatically generated by the TokenList2DsnLexer CMake - * script. +/* Do not modify this file it was automatically generated by the + * TokenList2DsnLexer CMake script. * - * Include this file in your lexer class to provide the keywords for you DSN lexer. + * Include this file in your lexer class to provide the keywords for + * your DSN lexer. */ #include \"fctsys.h\" #include \"macros.h\" -#include \"${result}_keywords.h\" - +#include \"${result}_lexer.h\" namespace DSN { @@ -209,18 +207,120 @@ extern const unsigned ${result}_keyword_count; } // End namespace DSN +using namespace DSN; // enum ${enum} is in this namespace -#endif // End ${headerTag} +class ${RESULT}_LEXER : public DSNLEXER +{ +public: + /** + * Constructor ${RESULT}_LEXER + * @param aClipboartTxt is std::string (8 bit) text possibly from the + * clipboard that you want to parse. + */ + ${RESULT}_LEXER( const std::string& aClipboardTxt ) : + DSNLEXER( aClipboardTxt, + DSN::${result}_keywords, + DSN::${result}_keyword_count ) + { + } + + /** + * Constructor ${RESULT}_LEXER + * takes @a aFile already opened for reading and @a aFilename as parameters. + * The opened file is not closed by this class, and is assumed to be positioned + * at the beginning of the file for purposes of accurate line number reporting + * in error messages. + * @param aFile is a FILE already opened for reading. + * @param aFilename is the name of the opened file, needed for error reporting. + */ + ${RESULT}_LEXER( FILE* aFile, const wxString& aFilename ) : + DSNLEXER( aFile, aFilename, + DSN::${result}_keywords, + DSN::${result}_keyword_count ) + { + } + + /** + * Function NextTok + * returns the next token found in the input file or T_EOF when reaching + * the end of file. Users should wrap this function to return an enum + * to aid in grammar debugging while running under a debugger, but leave + * this lower level function returning an int (so the enum does not collide + * with another usage). + * @return ${enum} - the type of token found next. + * @throw IOError - only if the LINE_READER throws it. + */ + ${enum} NextTok() throw (IOError) + { + return (${enum}) DSNLEXER::NextTok(); + } + + /** + * Function NeedSYMBOL + * calls NextTok() and then verifies that the token read in + * satisfies bool IsSymbol(). + * If not, an IOError is thrown. + * @return int - the actual token read in. + * @throw IOError, if the next token does not satisfy IsSymbol() + */ + ${enum} NeedSYMBOL() throw( IOError ) + { + return (${enum}) DSNLEXER::NeedSYMBOL(); + } + + /** + * Function NeedSYMBOLorNUMBER + * calls NextTok() and then verifies that the token read in + * satisfies bool IsSymbol() or tok==T_NUMBER. + * If not, an IOError is thrown. + * @return int - the actual token read in. + * @throw IOError, if the next token does not satisfy the above test + */ + ${enum} NeedSYMBOLorNUMBER() throw( IOError ) + { + return (${enum}) DSNLEXER::NeedSYMBOLorNUMBER(); + } + + /** + * Function CurTok + * returns whatever NextTok() returned the last time it was called. + */ + ${enum} CurTok() + { + return (${enum}) DSNLEXER::CurTok(); + } + + /** + * Function PrevTok + * returns whatever NextTok() returned the 2nd to last time it was called. + */ + ${enum} PrevTok() + { + return (${enum}) DSNLEXER::PrevTok(); + } +}; + +// example usage + +/** + * Class ${RESULT}_PARSER + * holds data and functions pertinent to parsing a S-expression file . + * +class ${RESULT}_PARSER : public ${RESULT}_LEXER +{ + +}; + */ + +#endif // ${headerTag} " ) file( APPEND "${sourceFileName}" "}; - const unsigned ${result}_keyword_count = DIM( ${result}_keywords ); - } // End namespace DSN " ) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 3402525ac8..e2d285ebc9 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -43,6 +43,7 @@ set(COMMON_SRCS gr_basic.cpp hotkeys_basic.cpp msgpanel.cpp + netlist_keywords.cpp newstroke_font.cpp ../pcbnew/class_drc_item.cpp projet_config.cpp @@ -91,6 +92,19 @@ set(PCB_COMMON_SRCS add_library(pcbcommon ${PCB_COMMON_SRCS}) +# auto-generate netlist_lexer.h and netlist_keywords.cpp +add_custom_command( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/netlist_lexer.h + ${CMAKE_CURRENT_SOURCE_DIR}/netlist_keywords.cpp + COMMAND ${CMAKE_COMMAND} + -Denum=NL_T + -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/netlist.keywords + -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/netlist.keywords + COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/netlist_{lexer.h,keywords.cpp} + from ${CMAKE_CURRENT_SOURCE_DIR}/netlist.keywords" + ) + # The dsntest may not build properly using MS Visual Studio. if(NOT MSVC) # This one gets made only when testing. diff --git a/eeschema/netlist.keywords b/common/netlist.keywords similarity index 94% rename from eeschema/netlist.keywords rename to common/netlist.keywords index 3067b27ea6..255dfa3e43 100644 --- a/eeschema/netlist.keywords +++ b/common/netlist.keywords @@ -10,6 +10,8 @@ export field fields footprint +footprints +fp lib libpart libraries diff --git a/common/richio.cpp b/common/richio.cpp index 344da30cc3..b037687b56 100644 --- a/common/richio.cpp +++ b/common/richio.cpp @@ -204,14 +204,14 @@ int OUTPUTFORMATTER::Print( int nestLevel, const char* fmt, ... ) throw( IOError } -//--------------------------------------------------------- +//--------------------------------------------------------- -void STRINGFORMATTER::write( const char* aOutBuf, int aCount ) throw( IOError ) +void STRING_FORMATTER::write( const char* aOutBuf, int aCount ) throw( IOError ) { mystring.append( aOutBuf, aCount ); } -void STRINGFORMATTER::StripUseless() +void STRING_FORMATTER::StripUseless() { std::string copy = mystring; diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index f260c712a3..936ccc2170 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -157,34 +157,34 @@ endif(APPLE) # Generate DSN lexer header and source files for the component library file # format. add_custom_command( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_lexer.h ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.cpp COMMAND ${CMAKE_COMMAND} -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords - COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h(.cpp) + COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_{lexer.h,keywords.cpp} from ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords" ) + set_source_files_properties( cmp_library_lexer.cpp PROPERTIES - OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h + OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_lexer.h ) add_custom_command( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.h + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_lexer.h ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.cpp COMMAND ${CMAKE_COMMAND} -Denum=TFIELD_T -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords - COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.h(.cpp) + COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_{lexer.h,keywords.cpp} from ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords" ) - add_executable(eeschema WIN32 MACOSX_BUNDLE ${EESCHEMA_SRCS} ${EESCHEMA_EXTRA_SRCS} ${EESCHEMA_RESOURCES}) diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index e0cb490c0e..0de33a9571 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -654,10 +654,7 @@ void WinEDA_SchematicFrame::LoadSettings() if( !templateFieldNames.IsEmpty() ) { - std::string dsnTxt = CONV_TO_UTF8( templateFieldNames ); - - DSNLEXER lexer( dsnTxt, DSN::template_fieldnames_keywords, - DSN::template_fieldnames_keyword_count ); + TEMPLATE_FIELDNAMES_LEXER lexer( CONV_TO_UTF8( templateFieldNames ) ); try { m_TemplateFieldNames.Parse( &lexer ); @@ -735,7 +732,7 @@ void WinEDA_SchematicFrame::SaveSettings() } // Save template fieldnames - STRINGFORMATTER sf; + STRING_FORMATTER sf; m_TemplateFieldNames.Format( &sf, 0 ); diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index 21bd78de13..264e388a06 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -655,6 +655,8 @@ XNODE* EXPORT_HELP::makeGenericLibParts() wxString sFields = wxT( "fields" ); wxString sDescr = wxT( "description" ); wxString sDocs = wxT( "docs" ); + wxString sFprints = wxT( "footprints" ); + wxString sFp = wxT( "fp" ); LIB_PIN_LIST pinList; LIB_FIELD_LIST fieldList; @@ -680,9 +682,17 @@ XNODE* EXPORT_HELP::makeGenericLibParts() if( !lcomp->GetDocFileName().IsEmpty() ) xlibpart->AddChild( node( sDocs, lcomp->GetDocFileName() ) ); - // @todo show the footprints here. - // (*it)->m_FootprintList + // Write the footprint list + if( lcomp->m_FootprintList.GetCount() ) + { + XNODE* xfootprints; + xlibpart->AddChild( xfootprints = node( sFprints ) ); + for( unsigned i=0; im_FootprintList.GetCount(); ++i ) + { + xfootprints->AddChild( node( sFp, lcomp->m_FootprintList[i] ) ); + } + } //----- show the fields here ---------------------------------- fieldList.clear(); diff --git a/eeschema/template_fieldnames.cpp b/eeschema/template_fieldnames.cpp index daa21419db..674ba94013 100644 --- a/eeschema/template_fieldnames.cpp +++ b/eeschema/template_fieldnames.cpp @@ -46,13 +46,13 @@ void TEMPLATE_FIELDNAME::Format( OUTPUTFORMATTER* out, int nestLevel ) const thr } -void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError ) +void TEMPLATE_FIELDNAME::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IOError ) { TFIELD_T tok; in->NeedLEFT(); // begin (name ...) - if( (tok = (TFIELD_T) in->NextTok()) != T_name ) + if( (tok = in->NextTok()) != T_name ) in->Expecting( T_name ); in->NeedSYMBOLorNUMBER(); @@ -61,11 +61,11 @@ void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError ) in->NeedRIGHT(); // end (name ...) - while( (tok = (TFIELD_T) in->NextTok() ) != T_RIGHT && tok != T_EOF ) + while( (tok = in->NextTok() ) != T_RIGHT && tok != T_EOF ) { // "visible" has no '(' prefix, "value" does, so T_LEFT is optional. if( tok == T_LEFT ) - tok = (TFIELD_T) in->NextTok(); + tok = in->NextTok(); switch( tok ) { @@ -89,28 +89,28 @@ void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError ) void TEMPLATES::Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IOError ) { - // We'll keep this general even though the only know use at this time - // will not want the newlines or the indentation. + // We'll keep this general, and include the \n, even though the only known + // use at this time will not want the newlines or the indentation. out->Print( nestLevel, "(templatefields" ); for( unsigned i=0; iPrint( 0, ")\n" ); } -void TEMPLATES::Parse( DSNLEXER* in ) throw( IOError ) +void TEMPLATES::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IOError ) { TFIELD_T tok; - while( (tok = (TFIELD_T) in->NextTok() ) != T_RIGHT && tok != T_EOF ) + while( (tok = in->NextTok() ) != T_RIGHT && tok != T_EOF ) { if( tok == T_LEFT ) - tok = (TFIELD_T) in->NextTok(); + tok = in->NextTok(); switch( tok ) { case T_templatefields: // a token indicating class TEMPLATES. - // Be flexible regarding the starting point of the DSNLEXER + // Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER // stream. Caller may not have read the first two tokens out of the // stream: T_LEFT and T_templatefields, so ignore them if seen here. break; diff --git a/eeschema/template_fieldnames.h b/eeschema/template_fieldnames.h index dadf36a359..82f3b5d733 100644 --- a/eeschema/template_fieldnames.h +++ b/eeschema/template_fieldnames.h @@ -5,9 +5,9 @@ #include "richio.h" #include "wxstruct.h" #include "macros.h" -#include "template_fieldnames_keywords.h" +#include "template_fieldnames_lexer.h" -class DSNLEXER; +class TEMPLATE_FIELDNAMES_LEXER; /** @@ -71,7 +71,7 @@ struct TEMPLATE_FIELDNAME /** * Function Parse * fills this object from information in the input stream \a aSpec, which - * is a DSNLEXER. The entire textual element spec is
+ * is a TEMPLATE_FIELDNAMES_LEXER. The entire textual element spec is
* (field (name _yourfieldname_)(value _yourvalue_) visible))
* The presence of value is optional, the presence of visible is optional. * When this function is called, the input token stream given by \a aSpec @@ -81,7 +81,7 @@ struct TEMPLATE_FIELDNAME * * @param aSpec is the input token stream of keywords and symbols. */ - void Parse( DSNLEXER* aSpec ) throw( IOError ); + void Parse( TEMPLATE_FIELDNAMES_LEXER* aSpec ) throw( IOError ); /** * Function GetDefaultFieldName @@ -110,9 +110,9 @@ public: /** * Function Parse - * fills this object from information in the input stream handled by DSNLEXER + * fills this object from information in the input stream handled by TEMPLATE_FIELDNAMES_LEXER */ - void Parse( DSNLEXER* in ) throw( IOError ); + void Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IOError ); /** @@ -148,4 +148,3 @@ public: }; #endif // _TEMPLATE_FIELDNAME_H_ - diff --git a/include/dsnlexer.h b/include/dsnlexer.h index acda44614a..996b3db779 100644 --- a/include/dsnlexer.h +++ b/include/dsnlexer.h @@ -167,6 +167,62 @@ public: delete reader; } + // Some functions whose return value is best overloaded to return an enum + // in a derived class. + //----------------------------------- + + /** + * Function NextTok + * returns the next token found in the input file or DSN_EOF when reaching + * the end of file. Users should wrap this function to return an enum + * to aid in grammar debugging while running under a debugger, but leave + * this lower level function returning an int (so the enum does not collide + * with another usage). + * @return int - the type of token found next. + * @throw IOError - only if the LINE_READER throws it. + */ + int NextTok() throw (IOError); + + /** + * Function NeedSYMBOL + * calls NextTok() and then verifies that the token read in + * satisfies bool IsSymbol(). + * If not, an IOError is thrown. + * @return int - the actual token read in. + * @throw IOError, if the next token does not satisfy IsSymbol() + */ + int NeedSYMBOL() throw( IOError ); + + /** + * Function NeedSYMBOLorNUMBER + * calls NextTok() and then verifies that the token read in + * satisfies bool IsSymbol() or tok==DSN_NUMBER. + * If not, an IOError is thrown. + * @return int - the actual token read in. + * @throw IOError, if the next token does not satisfy the above test + */ + int NeedSYMBOLorNUMBER() throw( IOError ); + + /** + * Function CurTok + * returns whatever NextTok() returned the last time it was called. + */ + int CurTok() + { + return curTok; + } + + /** + * Function PrevTok + * returns whatever NextTok() returned the 2nd to last time it was called. + */ + int PrevTok() + { + return prevTok; + } + + //---------------------------------- + /** * Function SetStringDelimiter @@ -208,18 +264,6 @@ public: return old; } - /** - * Function NextTok - * returns the next token found in the input file or DSN_EOF when reaching - * the end of file. Users should wrap this function to return an enum - * to aid in grammar debugging while running under a debugger, but leave - * this lower level function returning an int (so the enum does not collide - * with another usage). - * @return int - the type of token found next. - * @throw IOError - only if the LINE_READER throws it. - */ - int NextTok() throw (IOError); - /** * Function IsSymbol * tests a token to see if it is a symbol. This means it cannot be a @@ -286,26 +330,6 @@ public: */ void NeedRIGHT() throw( IOError ); - /** - * Function NeedSYMBOL - * calls NextTok() and then verifies that the token read in - * satisfies bool IsSymbol(). - * If not, an IOError is thrown. - * @return int - the actual token read in. - * @throw IOError, if the next token does not satisfy IsSymbol() - */ - int NeedSYMBOL() throw( IOError ); - - /** - * Function NeedSYMBOLorNUMBER - * calls NextTok() and then verifies that the token read in - * satisfies bool IsSymbol() or tok==DSN_NUMBER. - * If not, an IOError is thrown. - * @return int - the actual token read in. - * @throw IOError, if the next token does not satisfy the above test - */ - int NeedSYMBOLorNUMBER() throw( IOError ); - /** * Function GetTokenText * returns the C string representation of a DSN_T value. @@ -329,15 +353,6 @@ public: return curText.c_str(); } - /** - * Function CurTok - * returns whatever NextTok() returned the last time it was called. - */ - int CurTok() - { - return curTok; - } - /** * Function CurLineNumber * returns the current line number within my LINE_READER @@ -357,15 +372,6 @@ public: return filename; } - /** - * Function PrevTok - * returns whatever NextTok() returned the 2nd to last time it was called. - */ - int PrevTok() - { - return prevTok; - } - /** * Function CurOffset * returns the char offset within the current line, using a 1 based index. diff --git a/include/richio.h b/include/richio.h index 345f740f96..45b4d2ff48 100644 --- a/include/richio.h +++ b/include/richio.h @@ -76,7 +76,6 @@ protected: unsigned maxLineLength; unsigned capacity; - public: LINE_READER( unsigned aMaxLineLength ); @@ -85,7 +84,6 @@ public: delete[] line; } - /** * Function ReadLine * reads a line of text into the buffer and increments the line number @@ -125,7 +123,6 @@ protected: FILE* fp; ///< no ownership, no close on destruction public: - /** * Constructor LINE_READER * takes an open FILE and the size of the desired line buffer. @@ -134,7 +131,6 @@ public: */ FILE_LINE_READER( FILE* aFile, unsigned aMaxLineLength ); - /** * Function ReadLine * reads a line of text into the buffer and increments the line number @@ -155,7 +151,6 @@ public: rewind( fp ); lineNum = 0; } - }; @@ -228,6 +223,21 @@ protected: { } + virtual ~OUTPUTFORMATTER() {} + + /** + * Function GetQuoteChar + * performs quote character need determination according to the Specctra DSN + * specification. + + * @param wrapee A string that might need wrapping on each end. + * @param quote_char A single character C string which provides the current + * quote character, should it be needed by the wrapee. + * + * @return const char* - the quote_char as a single character string, or "" + * if the wrapee does not need to be wrapped. + */ + static const char* GetQuoteChar( const char* wrapee, const char* quote_char ); /** * Function write @@ -241,10 +251,10 @@ protected: #if defined(__GNUG__) // The GNU C++ compiler defines this -// When used on a C++ function, we must account for the "this" pointer, -// so increase the STRING-INDEX and FIRST-TO_CHECK by one. -// See http://docs.freebsd.org/info/gcc/gcc.info.Function_Attributes.html -// Then to get format checking during the compile, compile with -Wall or -Wformat + // When used on a C++ function, we must account for the "this" pointer, + // so increase the STRING-INDEX and FIRST-TO_CHECK by one. + // See http://docs.freebsd.org/info/gcc/gcc.info.Function_Attributes.html + // Then to get format checking during the compile, compile with -Wall or -Wformat #define PRINTF_FUNC __attribute__ ((format (printf, 3, 4))) #else @@ -253,6 +263,8 @@ protected: public: + //----------------------------------------------- + /** * Function Print * formats and writes text to the output stream. @@ -287,40 +299,43 @@ public: return GetQuoteChar( wrapee, "\"" ); } - virtual ~OUTPUTFORMATTER() {} - /** - * Function GetQuoteChar - * performs quote character need determination according to the Specctra DSN - * specification. - - * @param wrapee A string that might need wrapping on each end. - * @param quote_char A single character C string which provides the current - * quote character, should it be needed by the wrapee. + * Function Quoted + * checks \a aWrappee input string for a need to be quoted + * (e.g. contains a ')' character or a space), and for \" double quotes + * within the string that need to be doubled up such that the DSNLEXER + * will correctly parse the string from a file later. * - * @return const char* - the quote_char as a single character string, or "" - * if the wrapee does not need to be wrapped. + * @param aWrapee is a string that might need wraping in double quotes, + * and it might need to have its internal quotes doubled up, or not. + * Caller's copy may be modified, or not. + * + * @return const char* - useful for passing to printf() style functions that + * must output utf8 streams. + virtual const char* Quoted( std::string* aWrapee ); + thinking about using wxCharBuffer* instead. */ - static const char* GetQuoteChar( const char* wrapee, const char* quote_char ); + + //---------------------------------------------- }; /** - * Class STRINGFORMATTER + * Class STRING_FORMATTER * implements OUTPUTFORMATTER to a memory buffer. After Print()ing the * string is available through GetString() */ -class STRINGFORMATTER : public OUTPUTFORMATTER +class STRING_FORMATTER : public OUTPUTFORMATTER { std::string mystring; public: /** - * Constructor STRINGFORMATTER + * Constructor STRING_FORMATTER * reserves space in the buffer */ - STRINGFORMATTER( int aReserve = 300 ) : + STRING_FORMATTER( int aReserve = 300 ) : OUTPUTFORMATTER( aReserve ) { } @@ -363,7 +378,6 @@ class STREAM_OUTPUTFORMATTER : public OUTPUTFORMATTER char quoteChar[2]; public: - /** * Constructor STREAM_OUTPUTFORMATTER * can take any number of wxOutputStream derivations, so it can write @@ -384,6 +398,4 @@ protected: //---------------------------------------------------- }; - #endif // RICHIO_H_ - diff --git a/include/xnode.h b/include/xnode.h index b93d00b58e..af482574fe 100644 --- a/include/xnode.h +++ b/include/xnode.h @@ -26,7 +26,6 @@ */ #include "richio.h" -// #define WXUSINGDLL #include @@ -50,7 +49,7 @@ public: /** * Function Format - * writes this object as UTF8 out to an OUTPUTFORMATTER as an S-expression + * writes this object as UTF8 out to an OUTPUTFORMATTER as an S-expression. * @param out The formatter to write to. * @param nestLevel A multiple of the number of spaces to preceed the output with. * @throw IOError if a system error writing the output, such as a full disk. @@ -59,7 +58,7 @@ public: /** * Function FormatContents - * writes the contents of object as UTF8 out to an OUTPUTFORMATTER as an S-expression + * writes the contents of object as UTF8 out to an OUTPUTFORMATTER as an S-expression. * This is the same as Format() except that the outer wrapper is not included. * @param out The formatter to write to. * @param nestLevel A multiple of the number of spaces to preceed the output with. diff --git a/pcbnew/specctra.cpp b/pcbnew/specctra.cpp index 73644d8257..48e555b670 100644 --- a/pcbnew/specctra.cpp +++ b/pcbnew/specctra.cpp @@ -51,11 +51,8 @@ #include #include "specctra.h" - -//#include #include // wxFFileOutputStream - #include "build_version.h" @@ -3979,7 +3976,7 @@ int ELEM_HOLDER::FindElem( DSN_T aType, int instanceNum ) // a reasonably small memory price to pay for improved performance -STRINGFORMATTER ELEM::sf; +STRING_FORMATTER ELEM::sf; //-------------------------------------------------------------- diff --git a/pcbnew/specctra.h b/pcbnew/specctra.h index 8d7ddcf6bd..08474bd069 100644 --- a/pcbnew/specctra.h +++ b/pcbnew/specctra.h @@ -626,7 +626,7 @@ protected: } // avoid creating this for every compare, make static. - static STRINGFORMATTER sf; + static STRING_FORMATTER sf; public: @@ -3985,7 +3985,7 @@ class SPECCTRA_DB bool modulesAreFlipped; - STRINGFORMATTER sf; + STRING_FORMATTER sf; STRINGS layerIds; ///< indexed by PCB layer number diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index adb6d5317a..6eb8c371c6 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -848,7 +848,7 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IOErr } #if 0 && defined(DEBUG) - STRINGFORMATTER sf; + STRING_FORMATTER sf; path->Format( &sf, 0 ); printf( "%s\n", sf.GetString().c_str() ); #endif diff --git a/pcbnew/specctra_import.cpp b/pcbnew/specctra_import.cpp index b47e534976..a5e84a9c61 100644 --- a/pcbnew/specctra_import.cpp +++ b/pcbnew/specctra_import.cpp @@ -531,7 +531,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) // padstack from its name as a work around. - // Could use a STRINGFORMATTER here and convert the entire + // Could use a STRING_FORMATTER here and convert the entire // wire_via to text and put that text into the exception. wxString psid( CONV_FROM_UTF8( wire_via->GetPadstackId().c_str() ) );