From 01a6ef498707895893844c2b9c015ec481b5664e Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Thu, 12 Apr 1990 11:03:24 +0000 Subject: [PATCH] added fix for allowing yy_switch_to_buffer() in yywrap() --- flex.skl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/flex.skl b/flex.skl index 01f70ab..1a6169e 100644 --- a/flex.skl +++ b/flex.skl @@ -211,6 +211,11 @@ static int yy_start = 0; /* start state number */ static yy_state_type yy_last_accepting_state; static YY_CHAR *yy_last_accepting_cpos; +/* flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + static yy_state_type yy_get_previous_state YY_PROTO(( void )); static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); static int yy_get_next_buffer YY_PROTO(( void )); @@ -341,6 +346,8 @@ do_action: /* this label is used only to access EOF actions */ { case EOB_ACT_END_OF_FILE: { + yy_did_buffer_switch_on_eof = 0; + if ( yywrap() ) { /* note: because we've taken care in @@ -358,7 +365,10 @@ do_action: /* this label is used only to access EOF actions */ } else - YY_NEW_FILE; + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } } break; @@ -672,6 +682,13 @@ YY_BUFFER_STATE new_buffer; yy_current_buffer = new_buffer; yy_load_buffer_state(); + + /* we don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; } -- 2.40.0