Commit aba543cb authored by dickelbeck's avatar dickelbeck

clipboard and DSNLEXER testing via target dsntest

parent f1f11cf6
......@@ -25,6 +25,24 @@ Common
* Integer/long/double input boxes should handle comma and dot separated values,
not only comma.
C2) Write a tool to generate DSNLEXER keyword tables (and enums) as *.cpp and
*.h. Language of tool should probably be C++. As input, the tool should take
a list of whitespace separated keywords from a text file that is manually
maintained. The *.cpp file should be named based on input file name and should
include the keyword table with a global array. The *.h file be named based on
the input file name and should hold the enums and an extern array to the keyword table.
The enum table should include the core syntactical enums from dsnlexer.h as
the first negative values. See enum DSN_T { from specctra.h as example.
Tool should verify uniqueness of keywords, enforce all lowercase, and sort.
Spaces are not allowed in keywords, but if whitespace is the delimiter for
the tool, it will be impossible to specify a keyword with whitespaces in it.
Use tool in CMake scripts for future grammars, but remember for cross compiling,
generating and using a tool to run natively on the build machine is a bit tricky with
CMake.
Wayne:
C1) Fix mouse wheel scrolling (ctrl + Mouse wheel) and (Shift + mouse wheel)
to move more than a single scroll increment.
......@@ -55,6 +73,9 @@ GerbView
* Switch to use ZONE instead of SEGZONE for polygons.
PCBNew
------
......
......@@ -1259,9 +1259,43 @@ static const KEYWORD keywords[] = {
};
/* To run this test code, simply copy some DSN text to the clipboard, then run
the program from the command line and it will beautify the input from the
clipboard to stdout. stderr gets errors, if any.
The wxApp is involved because the clipboard is not available to a raw
int main() type program on all platforms.
*/
class DSNTEST : public wxApp
{
DSNLEXER* lexer;
int nestLevel;
void recursion() throw( IOError );
void indent()
{
const int NESTWIDTH = 2;
printf("\n");
for( int i=0; i<nestLevel; ++i )
printf( "%*c", NESTWIDTH, ' ' );
}
public:
DSNTEST() :
lexer(0),
nestLevel(0)
{}
~DSNTEST()
{
delete lexer;
}
virtual bool OnInit();
};
......@@ -1290,7 +1324,7 @@ bool DSNTEST::OnInit()
// this won't compile without a token table.
DSNLEXER lexer( fp, filename, keywords, DIM(keywords) );
#else
#else // clipboard based line reader
if( !wxTheClipboard->Open() )
{
......@@ -1298,36 +1332,86 @@ bool DSNTEST::OnInit()
exit( 1 );
}
/*
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
wxTextDataObject dataObj;
if( !wxTheClipboard->GetData( dataObj ) )
{
fprintf( stderr, "nothing of interest on clipboard\n" );
exit( 2 );
}
*/
wxTextDataObject dataObj;
wxTheClipboard->GetData( dataObj );
int formatCount = dataObj.GetFormatCount();
fprintf( stderr, "formatCount:%d\n", formatCount );
wxDataFormat* formats = new wxDataFormat[formatCount];
DSNLEXER lexer( std::string( CONV_TO_UTF8( dataObj.GetText() ) ),
dataObj.GetAllFormats( formats );
for( int fmt=0; fmt<formatCount; ++fmt )
{
fprintf( stderr, "format:%d\n", formats[fmt].GetType() );
// @todo: what are these formats in terms of enum strings, and how
// do they vary across platforms. I am seeing
// on linux: 2 formats, 13 and 1
}
lexer = new DSNLEXER( std::string( CONV_TO_UTF8( dataObj.GetText() ) ),
keywords, DIM(keywords) );
#endif
// read the stream via the lexer, and use recursion to establish a nesting
// level and some output.
try
{
int tok;
while( (tok = lexer.NextTok()) != DSN_EOF )
int tok;
while( (tok = lexer->NextTok()) != DSN_EOF )
{
printf( "%-3d %s\n", tok, lexer.CurText() );
if( tok == DSN_LEFT )
{
recursion();
}
else
printf( " %s", lexer->CurText() );
}
printf("\n");
}
catch( IOError ioe )
{
printf( "%s\n", (const char*) ioe.errorText.mb_str() );
fprintf( stderr, "%s\n", CONV_TO_UTF8( ioe.errorText ) );
}
return 0;
}
void DSNTEST::recursion() throw(IOError)
{
int tok;
const char* space = "";
indent();
printf("(");
while( (tok = lexer->NextTok()) != DSN_EOF && tok != DSN_RIGHT )
{
if( tok == DSN_LEFT )
{
++nestLevel;
recursion();
--nestLevel;
}
else
printf( "%s%s", space, lexer->CurText() );
space = " "; // only the first tok gets no leading space.
}
printf(")");
}
#endif
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