From 08f730b965977234ebff9e240b1c378cf70d541b Mon Sep 17 00:00:00 2001 From: thurston Date: Thu, 18 Oct 2007 01:11:31 +0000 Subject: [PATCH] These examples need the eof pointer now that >, % and error actions also embed into the EOF event. git-svn-id: http://svn.complang.org/ragel/trunk@302 052ea7fc-9027-0410-9066-f65837a77df0 --- examples/concurrent.rl | 7 ++++--- examples/gotocallret.rl | 12 +++++++----- examples/mailbox.rl | 7 ++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/concurrent.rl b/examples/concurrent.rl index 4b9d421..224f960 100644 --- a/examples/concurrent.rl +++ b/examples/concurrent.rl @@ -20,7 +20,7 @@ struct Concurrent int cs; int init( ); - int execute( const char *data, int len ); + int execute( const char *data, int len, bool isEof ); int finish( ); }; @@ -83,10 +83,11 @@ int Concurrent::init( ) return 1; } -int Concurrent::execute( const char *data, int len ) +int Concurrent::execute( const char *data, int len, bool isEof ) { const char *p = data; const char *pe = data + len; + const char *eof = isEof ? pe : 0; %% write exec; @@ -114,7 +115,7 @@ int main() concurrent.init(); while ( 1 ) { int len = fread( buf, 1, BUFSIZE, stdin ); - concurrent.execute( buf, len ); + concurrent.execute( buf, len, len != BUFSIZE ); if ( len != BUFSIZE ) break; } diff --git a/examples/gotocallret.rl b/examples/gotocallret.rl index d7fa49b..05ac398 100644 --- a/examples/gotocallret.rl +++ b/examples/gotocallret.rl @@ -19,7 +19,7 @@ struct GotoCallRet int cs, top, stack[32]; int init( ); - int execute( const char *data, int len ); + int execute( const char *data, int len, bool isEof ); int finish( ); }; @@ -63,10 +63,11 @@ int GotoCallRet::init( ) return 1; } -int GotoCallRet::execute( const char *data, int len ) +int GotoCallRet::execute( const char *data, int len, bool isEof ) { const char *p = data; const char *pe = data + len; + const char *eof = isEof ? pe : 0; %% write exec; if ( cs == GotoCallRet_error ) @@ -84,9 +85,10 @@ int main() GotoCallRet gcr; gcr.init(); - while ( fgets( buf, sizeof(buf), stdin ) != 0 ) { - gcr.execute( buf, strlen(buf) ); - } + while ( fgets( buf, sizeof(buf), stdin ) != 0 ) + gcr.execute( buf, strlen(buf), false ); + + gcr.execute( 0, 0, true ); if ( gcr.cs < GotoCallRet_first_final ) cerr << "gotocallret: error: parsing input" << endl; return 0; diff --git a/examples/mailbox.rl b/examples/mailbox.rl index 3abc1c7..9f64d46 100644 --- a/examples/mailbox.rl +++ b/examples/mailbox.rl @@ -40,7 +40,7 @@ struct MailboxScanner int cs, top, stack[1]; int init( ); - int execute( const char *data, int len ); + int execute( const char *data, int len, bool isEof ); int finish( ); }; @@ -143,10 +143,11 @@ int MailboxScanner::init( ) return 1; } -int MailboxScanner::execute( const char *data, int len ) +int MailboxScanner::execute( const char *data, int len, bool isEof ) { const char *p = data; const char *pe = data + len; + const char *eof = isEof ? pe : 0; %% write exec; @@ -195,7 +196,7 @@ int main() mailbox.init(); while ( 1 ) { int len = fread( buf, 1, BUFSIZE, stdin ); - mailbox.execute( buf, len ); + mailbox.execute( buf, len, len != BUFSIZE ); if ( len != BUFSIZE ) break; } -- 2.7.4