From 8ccc3567dcd130a79227be3d388c221b198dd5a2 Mon Sep 17 00:00:00 2001 From: thurston Date: Sun, 23 Sep 2007 17:52:45 +0000 Subject: [PATCH] Remove the 'noend' write option. This example is referenced a lot and as a first example it shouldn't contain a special purpose write option like 'noend'. git-svn-id: http://svn.complang.org/ragel/trunk@284 052ea7fc-9027-0410-9066-f65837a77df0 --- examples/atoi.rl | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/examples/atoi.rl b/examples/atoi.rl index 010de3e..7164b68 100644 --- a/examples/atoi.rl +++ b/examples/atoi.rl @@ -2,21 +2,20 @@ * Convert a string to an integer. */ -#include #include +#include #include -using namespace std; - %%{ machine atoi; - write data noerror; + write data; }%% -int atoi( char *str ) +long long atoi( char *str ) { - char *p = str; - int cs, val = 0; + char *p = str, *pe = str + strlen( str ); + int cs; + long long val = 0; bool neg = false; %%{ @@ -30,18 +29,18 @@ int atoi( char *str ) main := ( '-'@see_neg | '+' )? ( digit @add_digit )+ - '\n' @{ fbreak; }; + '\n'; # Initialize and execute. write init; - write exec noend; + write exec; }%% if ( neg ) val = -1 * val; if ( cs < atoi_first_final ) - cerr << "atoi: there was an error" << endl; + fprintf( stderr, "atoi: there was an error\n" ); return val; }; @@ -53,8 +52,8 @@ int main() { char buf[BUFSIZE]; while ( fgets( buf, sizeof(buf), stdin ) != 0 ) { - int value = atoi( buf ); - cout << value << endl; + long long value = atoi( buf ); + printf( "%lld\n", value ); } return 0; } -- 2.7.4