Commit fb0bb79a authored by Dick Hollenbeck's avatar Dick Hollenbeck

TokenList2DsnLexer.cmake, netform.cpp enhancements

parent ac2fd246
...@@ -4,6 +4,20 @@ KiCad ChangeLog 2010 ...@@ -4,6 +4,20 @@ KiCad ChangeLog 2010
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2010-Aug-8 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++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 <dick@softplc.com> 2010-Aug-7 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================ ================================================================================
++common ++common
......
...@@ -82,18 +82,17 @@ get_filename_component( result "${inputFile}" NAME_WE ) ...@@ -82,18 +82,17 @@ get_filename_component( result "${inputFile}" NAME_WE )
message( STATUS "Extracted file name ${result} from path ${inputFile}" ) message( STATUS "Extracted file name ${result} from path ${inputFile}" )
# Create include and source file name from the list file name. # 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" ) set( sourceFileName "${outputPath}/${result}_keywords.cpp" )
# Create tag for generating header file. # Create tag for generating header file.
string( TOUPPER "${result}" fileNameTag ) string( TOUPPER "${result}" RESULT )
set( headerTag "_${fileNameTag}_H_" ) set( headerTag "_${RESULT}_H_" )
set( includeFileHeader set( includeFileHeader
" "
/* /* Do not modify this file it was automatically generated by the
* Do not modify this file it was automatically generated by the TokenList2DsnLexer CMake * TokenList2DsnLexer CMake script.
* script.
*/ */
#ifndef ${headerTag} #ifndef ${headerTag}
...@@ -124,18 +123,17 @@ enum ${enum} { ...@@ -124,18 +123,17 @@ enum ${enum} {
set( sourceFileHeader set( sourceFileHeader
" "
/* /* Do not modify this file it was automatically generated by the
* Do not modify this file it was automatically generated by the TokenList2DsnLexer CMake * TokenList2DsnLexer CMake script.
* 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 \"fctsys.h\"
#include \"macros.h\" #include \"macros.h\"
#include \"${result}_keywords.h\" #include \"${result}_lexer.h\"
namespace DSN { namespace DSN {
...@@ -209,18 +207,120 @@ extern const unsigned ${result}_keyword_count; ...@@ -209,18 +207,120 @@ extern const unsigned ${result}_keyword_count;
} // End namespace DSN } // End namespace DSN
using namespace DSN; // enum ${enum} is in this namespace
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 // End ${headerTag} #endif // ${headerTag}
" "
) )
file( APPEND "${sourceFileName}" file( APPEND "${sourceFileName}"
"}; "};
const unsigned ${result}_keyword_count = DIM( ${result}_keywords ); const unsigned ${result}_keyword_count = DIM( ${result}_keywords );
} // End namespace DSN } // End namespace DSN
" "
) )
...@@ -43,6 +43,7 @@ set(COMMON_SRCS ...@@ -43,6 +43,7 @@ set(COMMON_SRCS
gr_basic.cpp gr_basic.cpp
hotkeys_basic.cpp hotkeys_basic.cpp
msgpanel.cpp msgpanel.cpp
netlist_keywords.cpp
newstroke_font.cpp newstroke_font.cpp
../pcbnew/class_drc_item.cpp ../pcbnew/class_drc_item.cpp
projet_config.cpp projet_config.cpp
...@@ -91,6 +92,19 @@ set(PCB_COMMON_SRCS ...@@ -91,6 +92,19 @@ set(PCB_COMMON_SRCS
add_library(pcbcommon ${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. # The dsntest may not build properly using MS Visual Studio.
if(NOT MSVC) if(NOT MSVC)
# This one gets made only when testing. # This one gets made only when testing.
......
...@@ -10,6 +10,8 @@ export ...@@ -10,6 +10,8 @@ export
field field
fields fields
footprint footprint
footprints
fp
lib lib
libpart libpart
libraries libraries
......
...@@ -204,14 +204,14 @@ int OUTPUTFORMATTER::Print( int nestLevel, const char* fmt, ... ) throw( IOError ...@@ -204,14 +204,14 @@ int OUTPUTFORMATTER::Print( int nestLevel, const char* fmt, ... ) throw( IOError
} }
//-----<STRINGFORMATTER>---------------------------------------------------- //-----<STRING_FORMATTER>----------------------------------------------------
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 ); mystring.append( aOutBuf, aCount );
} }
void STRINGFORMATTER::StripUseless() void STRING_FORMATTER::StripUseless()
{ {
std::string copy = mystring; std::string copy = mystring;
......
...@@ -157,34 +157,34 @@ endif(APPLE) ...@@ -157,34 +157,34 @@ endif(APPLE)
# Generate DSN lexer header and source files for the component library file # Generate DSN lexer header and source files for the component library file
# format. # format.
add_custom_command( 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 ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.cpp
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords
-P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords 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" from ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords"
) )
set_source_files_properties( cmp_library_lexer.cpp set_source_files_properties( cmp_library_lexer.cpp
PROPERTIES PROPERTIES
OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_lexer.h
) )
add_custom_command( 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 ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.cpp
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-Denum=TFIELD_T -Denum=TFIELD_T
-DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords
-P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords 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" from ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords"
) )
add_executable(eeschema WIN32 MACOSX_BUNDLE ${EESCHEMA_SRCS} ${EESCHEMA_EXTRA_SRCS} add_executable(eeschema WIN32 MACOSX_BUNDLE ${EESCHEMA_SRCS} ${EESCHEMA_EXTRA_SRCS}
${EESCHEMA_RESOURCES}) ${EESCHEMA_RESOURCES})
......
...@@ -654,10 +654,7 @@ void WinEDA_SchematicFrame::LoadSettings() ...@@ -654,10 +654,7 @@ void WinEDA_SchematicFrame::LoadSettings()
if( !templateFieldNames.IsEmpty() ) if( !templateFieldNames.IsEmpty() )
{ {
std::string dsnTxt = CONV_TO_UTF8( templateFieldNames ); TEMPLATE_FIELDNAMES_LEXER lexer( CONV_TO_UTF8( templateFieldNames ) );
DSNLEXER lexer( dsnTxt, DSN::template_fieldnames_keywords,
DSN::template_fieldnames_keyword_count );
try try
{ {
m_TemplateFieldNames.Parse( &lexer ); m_TemplateFieldNames.Parse( &lexer );
...@@ -735,7 +732,7 @@ void WinEDA_SchematicFrame::SaveSettings() ...@@ -735,7 +732,7 @@ void WinEDA_SchematicFrame::SaveSettings()
} }
// Save template fieldnames // Save template fieldnames
STRINGFORMATTER sf; STRING_FORMATTER sf;
m_TemplateFieldNames.Format( &sf, 0 ); m_TemplateFieldNames.Format( &sf, 0 );
......
...@@ -655,6 +655,8 @@ XNODE* EXPORT_HELP::makeGenericLibParts() ...@@ -655,6 +655,8 @@ XNODE* EXPORT_HELP::makeGenericLibParts()
wxString sFields = wxT( "fields" ); wxString sFields = wxT( "fields" );
wxString sDescr = wxT( "description" ); wxString sDescr = wxT( "description" );
wxString sDocs = wxT( "docs" ); wxString sDocs = wxT( "docs" );
wxString sFprints = wxT( "footprints" );
wxString sFp = wxT( "fp" );
LIB_PIN_LIST pinList; LIB_PIN_LIST pinList;
LIB_FIELD_LIST fieldList; LIB_FIELD_LIST fieldList;
...@@ -680,9 +682,17 @@ XNODE* EXPORT_HELP::makeGenericLibParts() ...@@ -680,9 +682,17 @@ XNODE* EXPORT_HELP::makeGenericLibParts()
if( !lcomp->GetDocFileName().IsEmpty() ) if( !lcomp->GetDocFileName().IsEmpty() )
xlibpart->AddChild( node( sDocs, lcomp->GetDocFileName() ) ); xlibpart->AddChild( node( sDocs, lcomp->GetDocFileName() ) );
// @todo show the footprints here. // Write the footprint list
// (*it)->m_FootprintList if( lcomp->m_FootprintList.GetCount() )
{
XNODE* xfootprints;
xlibpart->AddChild( xfootprints = node( sFprints ) );
for( unsigned i=0; i<lcomp->m_FootprintList.GetCount(); ++i )
{
xfootprints->AddChild( node( sFp, lcomp->m_FootprintList[i] ) );
}
}
//----- show the fields here ---------------------------------- //----- show the fields here ----------------------------------
fieldList.clear(); fieldList.clear();
......
...@@ -46,13 +46,13 @@ void TEMPLATE_FIELDNAME::Format( OUTPUTFORMATTER* out, int nestLevel ) const thr ...@@ -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; TFIELD_T tok;
in->NeedLEFT(); // begin (name ...) in->NeedLEFT(); // begin (name ...)
if( (tok = (TFIELD_T) in->NextTok()) != T_name ) if( (tok = in->NextTok()) != T_name )
in->Expecting( T_name ); in->Expecting( T_name );
in->NeedSYMBOLorNUMBER(); in->NeedSYMBOLorNUMBER();
...@@ -61,11 +61,11 @@ void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError ) ...@@ -61,11 +61,11 @@ void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError )
in->NeedRIGHT(); // end (name ...) 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. // "visible" has no '(' prefix, "value" does, so T_LEFT is optional.
if( tok == T_LEFT ) if( tok == T_LEFT )
tok = (TFIELD_T) in->NextTok(); tok = in->NextTok();
switch( tok ) switch( tok )
{ {
...@@ -89,28 +89,28 @@ void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError ) ...@@ -89,28 +89,28 @@ void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError )
void TEMPLATES::Format( OUTPUTFORMATTER* out, int nestLevel ) const 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 // We'll keep this general, and include the \n, even though the only known
// will not want the newlines or the indentation. // use at this time will not want the newlines or the indentation.
out->Print( nestLevel, "(templatefields" ); out->Print( nestLevel, "(templatefields" );
for( unsigned i=0; i<m_Fields.size(); ++i ) for( unsigned i=0; i<m_Fields.size(); ++i )
m_Fields[i].Format( out, nestLevel+1 ); m_Fields[i].Format( out, nestLevel+1 );
out->Print( 0, ")\n" ); out->Print( 0, ")\n" );
} }
void TEMPLATES::Parse( DSNLEXER* in ) throw( IOError ) void TEMPLATES::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IOError )
{ {
TFIELD_T tok; 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 ) if( tok == T_LEFT )
tok = (TFIELD_T) in->NextTok(); tok = in->NextTok();
switch( tok ) switch( tok )
{ {
case T_templatefields: // a token indicating class TEMPLATES. 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. Caller may not have read the first two tokens out of the
// stream: T_LEFT and T_templatefields, so ignore them if seen here. // stream: T_LEFT and T_templatefields, so ignore them if seen here.
break; break;
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
#include "richio.h" #include "richio.h"
#include "wxstruct.h" #include "wxstruct.h"
#include "macros.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 ...@@ -71,7 +71,7 @@ struct TEMPLATE_FIELDNAME
/** /**
* Function Parse * Function Parse
* fills this object from information in the input stream \a aSpec, which * fills this object from information in the input stream \a aSpec, which
* is a DSNLEXER. The entire textual element spec is <br> * is a TEMPLATE_FIELDNAMES_LEXER. The entire textual element spec is <br>
* (field (name _yourfieldname_)(value _yourvalue_) visible)) <br> * (field (name _yourfieldname_)(value _yourvalue_) visible)) <br>
* The presence of value is optional, the presence of visible is optional. * 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 * When this function is called, the input token stream given by \a aSpec
...@@ -81,7 +81,7 @@ struct TEMPLATE_FIELDNAME ...@@ -81,7 +81,7 @@ struct TEMPLATE_FIELDNAME
* *
* @param aSpec is the input token stream of keywords and symbols. * @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 * Function GetDefaultFieldName
...@@ -110,9 +110,9 @@ public: ...@@ -110,9 +110,9 @@ public:
/** /**
* Function Parse * 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: ...@@ -148,4 +148,3 @@ public:
}; };
#endif // _TEMPLATE_FIELDNAME_H_ #endif // _TEMPLATE_FIELDNAME_H_
...@@ -167,6 +167,62 @@ public: ...@@ -167,6 +167,62 @@ public:
delete reader; delete reader;
} }
// Some functions whose return value is best overloaded to return an enum
// in a derived class.
//-----<overload return values to tokens>------------------------------
/**
* 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;
}
//-----</overload return values to tokens>-----------------------------
/** /**
* Function SetStringDelimiter * Function SetStringDelimiter
...@@ -208,18 +264,6 @@ public: ...@@ -208,18 +264,6 @@ public:
return old; 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 * Function IsSymbol
* tests a token to see if it is a symbol. This means it cannot be a * tests a token to see if it is a symbol. This means it cannot be a
...@@ -286,26 +330,6 @@ public: ...@@ -286,26 +330,6 @@ public:
*/ */
void NeedRIGHT() throw( IOError ); 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 * Function GetTokenText
* returns the C string representation of a DSN_T value. * returns the C string representation of a DSN_T value.
...@@ -329,15 +353,6 @@ public: ...@@ -329,15 +353,6 @@ public:
return curText.c_str(); return curText.c_str();
} }
/**
* Function CurTok
* returns whatever NextTok() returned the last time it was called.
*/
int CurTok()
{
return curTok;
}
/** /**
* Function CurLineNumber * Function CurLineNumber
* returns the current line number within my LINE_READER * returns the current line number within my LINE_READER
...@@ -357,15 +372,6 @@ public: ...@@ -357,15 +372,6 @@ public:
return filename; return filename;
} }
/**
* Function PrevTok
* returns whatever NextTok() returned the 2nd to last time it was called.
*/
int PrevTok()
{
return prevTok;
}
/** /**
* Function CurOffset * Function CurOffset
* returns the char offset within the current line, using a 1 based index. * returns the char offset within the current line, using a 1 based index.
......
...@@ -76,7 +76,6 @@ protected: ...@@ -76,7 +76,6 @@ protected:
unsigned maxLineLength; unsigned maxLineLength;
unsigned capacity; unsigned capacity;
public: public:
LINE_READER( unsigned aMaxLineLength ); LINE_READER( unsigned aMaxLineLength );
...@@ -85,7 +84,6 @@ public: ...@@ -85,7 +84,6 @@ public:
delete[] line; delete[] line;
} }
/** /**
* Function ReadLine * Function ReadLine
* reads a line of text into the buffer and increments the line number * reads a line of text into the buffer and increments the line number
...@@ -125,7 +123,6 @@ protected: ...@@ -125,7 +123,6 @@ protected:
FILE* fp; ///< no ownership, no close on destruction FILE* fp; ///< no ownership, no close on destruction
public: public:
/** /**
* Constructor LINE_READER * Constructor LINE_READER
* takes an open FILE and the size of the desired line buffer. * takes an open FILE and the size of the desired line buffer.
...@@ -134,7 +131,6 @@ public: ...@@ -134,7 +131,6 @@ public:
*/ */
FILE_LINE_READER( FILE* aFile, unsigned aMaxLineLength ); FILE_LINE_READER( FILE* aFile, unsigned aMaxLineLength );
/** /**
* Function ReadLine * Function ReadLine
* reads a line of text into the buffer and increments the line number * reads a line of text into the buffer and increments the line number
...@@ -155,7 +151,6 @@ public: ...@@ -155,7 +151,6 @@ public:
rewind( fp ); rewind( fp );
lineNum = 0; lineNum = 0;
} }
}; };
...@@ -228,6 +223,21 @@ protected: ...@@ -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 * Function write
...@@ -241,10 +251,10 @@ protected: ...@@ -241,10 +251,10 @@ protected:
#if defined(__GNUG__) // The GNU C++ compiler defines this #if defined(__GNUG__) // The GNU C++ compiler defines this
// When used on a C++ function, we must account for the "this" pointer, // When used on a C++ function, we must account for the "this" pointer,
// so increase the STRING-INDEX and FIRST-TO_CHECK by one. // so increase the STRING-INDEX and FIRST-TO_CHECK by one.
// See http://docs.freebsd.org/info/gcc/gcc.info.Function_Attributes.html // 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 // Then to get format checking during the compile, compile with -Wall or -Wformat
#define PRINTF_FUNC __attribute__ ((format (printf, 3, 4))) #define PRINTF_FUNC __attribute__ ((format (printf, 3, 4)))
#else #else
...@@ -253,6 +263,8 @@ protected: ...@@ -253,6 +263,8 @@ protected:
public: public:
//-----<interface functions>------------------------------------------
/** /**
* Function Print * Function Print
* formats and writes text to the output stream. * formats and writes text to the output stream.
...@@ -287,40 +299,43 @@ public: ...@@ -287,40 +299,43 @@ public:
return GetQuoteChar( wrapee, "\"" ); return GetQuoteChar( wrapee, "\"" );
} }
virtual ~OUTPUTFORMATTER() {}
/** /**
* Function GetQuoteChar * Function Quoted
* performs quote character need determination according to the Specctra DSN * checks \a aWrappee input string for a need to be quoted
* specification. * (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
* @param wrapee A string that might need wrapping on each end. * will correctly parse the string from a file later.
* @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 "" * @param aWrapee is a string that might need wraping in double quotes,
* if the wrapee does not need to be wrapped. * 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 );
//-----</interface functions>-----------------------------------------
}; };
/** /**
* Class STRINGFORMATTER * Class STRING_FORMATTER
* implements OUTPUTFORMATTER to a memory buffer. After Print()ing the * implements OUTPUTFORMATTER to a memory buffer. After Print()ing the
* string is available through GetString() * string is available through GetString()
*/ */
class STRINGFORMATTER : public OUTPUTFORMATTER class STRING_FORMATTER : public OUTPUTFORMATTER
{ {
std::string mystring; std::string mystring;
public: public:
/** /**
* Constructor STRINGFORMATTER * Constructor STRING_FORMATTER
* reserves space in the buffer * reserves space in the buffer
*/ */
STRINGFORMATTER( int aReserve = 300 ) : STRING_FORMATTER( int aReserve = 300 ) :
OUTPUTFORMATTER( aReserve ) OUTPUTFORMATTER( aReserve )
{ {
} }
...@@ -363,7 +378,6 @@ class STREAM_OUTPUTFORMATTER : public OUTPUTFORMATTER ...@@ -363,7 +378,6 @@ class STREAM_OUTPUTFORMATTER : public OUTPUTFORMATTER
char quoteChar[2]; char quoteChar[2];
public: public:
/** /**
* Constructor STREAM_OUTPUTFORMATTER * Constructor STREAM_OUTPUTFORMATTER
* can take any number of wxOutputStream derivations, so it can write * can take any number of wxOutputStream derivations, so it can write
...@@ -384,6 +398,4 @@ protected: ...@@ -384,6 +398,4 @@ protected:
//-----</OUTPUTFORMATTER>----------------------------------------------- //-----</OUTPUTFORMATTER>-----------------------------------------------
}; };
#endif // RICHIO_H_ #endif // RICHIO_H_
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
*/ */
#include "richio.h" #include "richio.h"
// #define WXUSINGDLL
#include <wx/xml/xml.h> #include <wx/xml/xml.h>
...@@ -50,7 +49,7 @@ public: ...@@ -50,7 +49,7 @@ public:
/** /**
* Function Format * 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 out The formatter to write to.
* @param nestLevel A multiple of the number of spaces to preceed the output with. * @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. * @throw IOError if a system error writing the output, such as a full disk.
...@@ -59,7 +58,7 @@ public: ...@@ -59,7 +58,7 @@ public:
/** /**
* Function FormatContents * 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. * This is the same as Format() except that the outer wrapper is not included.
* @param out The formatter to write to. * @param out The formatter to write to.
* @param nestLevel A multiple of the number of spaces to preceed the output with. * @param nestLevel A multiple of the number of spaces to preceed the output with.
......
...@@ -51,11 +51,8 @@ ...@@ -51,11 +51,8 @@
#include <cstdio> #include <cstdio>
#include "specctra.h" #include "specctra.h"
//#include <wx/ffile.h>
#include <wx/wfstream.h> // wxFFileOutputStream #include <wx/wfstream.h> // wxFFileOutputStream
#include "build_version.h" #include "build_version.h"
...@@ -3979,7 +3976,7 @@ int ELEM_HOLDER::FindElem( DSN_T aType, int instanceNum ) ...@@ -3979,7 +3976,7 @@ int ELEM_HOLDER::FindElem( DSN_T aType, int instanceNum )
// a reasonably small memory price to pay for improved performance // a reasonably small memory price to pay for improved performance
STRINGFORMATTER ELEM::sf; STRING_FORMATTER ELEM::sf;
//-----<UNIT_RES>--------------------------------------------------------- //-----<UNIT_RES>---------------------------------------------------------
......
...@@ -626,7 +626,7 @@ protected: ...@@ -626,7 +626,7 @@ protected:
} }
// avoid creating this for every compare, make static. // avoid creating this for every compare, make static.
static STRINGFORMATTER sf; static STRING_FORMATTER sf;
public: public:
...@@ -3985,7 +3985,7 @@ class SPECCTRA_DB ...@@ -3985,7 +3985,7 @@ class SPECCTRA_DB
bool modulesAreFlipped; bool modulesAreFlipped;
STRINGFORMATTER sf; STRING_FORMATTER sf;
STRINGS layerIds; ///< indexed by PCB layer number STRINGS layerIds; ///< indexed by PCB layer number
......
...@@ -848,7 +848,7 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IOErr ...@@ -848,7 +848,7 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IOErr
} }
#if 0 && defined(DEBUG) #if 0 && defined(DEBUG)
STRINGFORMATTER sf; STRING_FORMATTER sf;
path->Format( &sf, 0 ); path->Format( &sf, 0 );
printf( "%s\n", sf.GetString().c_str() ); printf( "%s\n", sf.GetString().c_str() );
#endif #endif
......
...@@ -531,7 +531,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) ...@@ -531,7 +531,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
// padstack from its name as a work around. // 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. // wire_via to text and put that text into the exception.
wxString psid( CONV_FROM_UTF8( wire_via->GetPadstackId().c_str() ) ); wxString psid( CONV_FROM_UTF8( wire_via->GetPadstackId().c_str() ) );
......
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