%% write init;
while ( !done ) {
- char *p = buf + have, *pe;
+ char *p = buf + have, *pe, *eof = 0;
int len, space = BUFSIZE - have;
if ( space == 0 ) {
}
len = fread( p, 1, space, stdin );
+ pe = p + len;
- /* If this is the last buffer, tack on an EOF. */
+ /* Check if this is the end of file. */
if ( len < space ) {
- p[len++] = 0;
+ eof = pe;
done = 1;
}
- pe = p + len;
%% write exec;
if ( cs == clang_error ) {
int Concurrent::finish( )
{
- %% write eof;
if ( cs == Concurrent_error )
return -1;
if ( cs >= Concurrent_first_final )
cin.read( p, space );
int len = cin.gcount();
+ char *pe = p + len;
+ char *eof = 0;
/* If we see eof then append the EOF char. */
- if ( len == 0 ) {
- p[0] = LAST_CHAR, len++;
+ if ( cin.eof() ) {
+ eof = pe;
done = true;
}
- char *pe = p + len;
%% write exec;
/* Check if we failed. */
%% write init;
}
-void format_execute( struct format *fsm, const char *data, int len )
+void format_execute( struct format *fsm, const char *data, int len, int isEof )
{
const char *p = data;
const char *pe = data + len;
+ const char *eof = isEof ? pe : 0;
%% write exec;
}
int format_finish( struct format *fsm )
{
- %% write eof;
-
if ( fsm->cs == format_error )
return -1;
if ( fsm->cs >= format_first_final )
format_init( &fsm );
while ( 1 ) {
int len = fread( buf, 1, INPUT_BUFSIZE, stdin );
- format_execute( &fsm, buf, len );
- if ( len != INPUT_BUFSIZE )
+ int eof = len != INPUT_BUFSIZE;
+ format_execute( &fsm, buf, len, eof );
+ if ( eof )
break;
}
if ( format_finish( &fsm ) <= 0 )
return 0;
}
-int GotoCallRet::finish( )
-{
- %% write eof;
- if ( cs == GotoCallRet_error )
- return -1;
- if ( cs >= GotoCallRet_first_final )
- return 1;
- return 0;
-}
-
#define BUFSIZE 1024
int main()
while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
gcr.execute( buf, strlen(buf) );
}
- if ( gcr.finish() <= 0 )
+ if ( gcr.cs < GotoCallRet_first_final )
cerr << "gotocallret: error: parsing input" << endl;
return 0;
}
int MailboxScanner::finish( )
{
- %% write eof;
if ( cs == MailboxScanner_error )
return -1;
if ( cs >= MailboxScanner_first_final )
int params_finish( struct params *fsm )
{
- %% write eof;
-
if ( fsm->cs == params_error )
return -1;
if ( fsm->cs >= params_first_final )
char *tokend;
char *p;
char *pe;
+ char *eof;
FILE *file;
int done;
memset (s, '\0', sizeof(Scanner));
s->curline = 1;
s->file = file;
+ s->eof = 0;
%% write init;
}
access s->;
variable p s->p;
variable pe s->pe;
+ variable eof s->eof;
main := |*
char *p = inbuf + have;
cin.read( p, space );
int len = cin.gcount();
+ char *pe = p + len;
+ char *eof = 0;
/* Check for EOF. */
if ( len == 0 ) {
- p[0] = 0, len++;
+ eof = pe;
done = true;
}
- char *pe = p + len;
%% write exec;
if ( cs == RagelScan_error ) {
int StateChart::finish( )
{
- %% write eof;
if ( cs == StateChart_error )
return -1;
if ( cs >= StateChart_first_final )