- Reverted to manual flex push/pup structure for include files.

This commit is contained in:
ccremers 2006-08-01 09:09:44 +00:00
parent 5e10206df1
commit 18d4b94b1e

View File

@ -50,17 +50,37 @@ id @?({letter}|{digit}|[\^\-!'])+
/* the "incl" state is used for picking up the name of an include file /* the "incl" state is used for picking up the name of an include file
*/ */
%x incl inclend %x incl inclend
%{
#define MAX_INCLUDE_DEPTH 10
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
int include_stack_ptr = 0;
%}
%% %%
include BEGIN(incl); include BEGIN(incl);
<incl>[ \t]*\" /* eat the whitespace */ <incl>[ \t]*\" /* eat the whitespace */
<incl>[^\"]+ { /* got the include file name */ <incl>[^\"]+ { /* got the include file name */
if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
{
fprintf( stderr, "Includes nested too deeply" );
exit( 1 );
}
include_stack[include_stack_ptr++] =
YY_CURRENT_BUFFER;
/* try to open, using scytherdirs environment variable as well. */ /* try to open, using scytherdirs environment variable as well. */
yyin = openFileSearch (yytext, NULL); yyin = openFileSearch (yytext, NULL);
if (! yyin) if (! yyin)
{ {
error ("Could not open include file %s.", yytext); error ("could not open include file %s.", yytext);
} }
yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE ));
yy_switch_to_buffer(
yy_create_buffer( yyin, YY_BUF_SIZE ) );
BEGIN(INITIAL); BEGIN(INITIAL);
} }
@ -69,13 +89,16 @@ include BEGIN(incl);
} }
<INITIAL><<EOF>> { <INITIAL><<EOF>> {
yypop_buffer_state(); if ( --include_stack_ptr < 0 )
if (! YY_CURRENT_BUFFER )
{ {
yyterminate(); yyterminate();
} }
else else
{ {
yy_delete_buffer( YY_CURRENT_BUFFER );
yy_switch_to_buffer(
include_stack[include_stack_ptr] );
BEGIN(inclend); BEGIN(inclend);
} }
} }