diff --git a/src/lexer.l b/src/lexer.l index 6c1e70b..b306d10 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -49,12 +49,6 @@ static unsigned int qstring_len = 0; static void qputc(char ch); #define CFG_QSTRING_BUFSIZ 32 -#define MAX_INCLUDE_DEPTH 10 -struct { - YY_BUFFER_STATE state; - char *filename; - unsigned int line; -} cfg_include_stack[MAX_INCLUDE_DEPTH]; int cfg_include_stack_ptr = 0; static YY_BUFFER_STATE pre_string_scan_state = 0; @@ -221,23 +215,18 @@ static YY_BUFFER_STATE string_scan_state = 0; } <> { - if( string_scan_state != 0 || cfg_include_stack_ptr <= 0 ) - { - return EOF; - } - - else - { - yy_delete_buffer( YY_CURRENT_BUFFER ); - fclose(cfg_yyin); - cfg_yyin = 0; - --cfg_include_stack_ptr; - yy_switch_to_buffer( - cfg_include_stack[cfg_include_stack_ptr].state ); - free(cfg->filename); - cfg->filename = cfg_include_stack[cfg_include_stack_ptr].filename; - cfg->line = cfg_include_stack[cfg_include_stack_ptr].line; - } + if( string_scan_state != 0 || cfg_include_stack_ptr <= 0 ) + return EOF; + else { + if (cfg_include_stack_ptr > 0) { + fclose(cfg_yyin); + --cfg_include_stack_ptr; + } + yypop_buffer_state(); + if (!YY_CURRENT_BUFFER) { + return EOF; + } + } } $\{[^}]*\} { @@ -281,16 +270,6 @@ int cfg_lexer_include(cfg_t *cfg, const char *filename) { char *xfilename; - if(cfg_include_stack_ptr >= MAX_INCLUDE_DEPTH) { - cfg_error(cfg, _("includes nested too deeply")); - return 1; - } - - cfg_include_stack[cfg_include_stack_ptr].state = YY_CURRENT_BUFFER; - cfg_include_stack[cfg_include_stack_ptr].filename = cfg->filename; - cfg_include_stack[cfg_include_stack_ptr].line = cfg->line; - cfg_include_stack_ptr++; - xfilename = cfg_tilde_expand(filename); cfg_yyin = fopen(xfilename, "r"); @@ -301,10 +280,11 @@ int cfg_lexer_include(cfg_t *cfg, const char *filename) return 1; } + cfg_include_stack_ptr++; cfg->filename = xfilename; cfg->line = 1; - yy_switch_to_buffer(yy_create_buffer(cfg_yyin, YY_BUF_SIZE)); + yypush_buffer_state(yy_create_buffer(cfg_yyin, YY_BUF_SIZE)); return 0; } @@ -357,7 +337,6 @@ void cfg_scan_fp_end(void) { /* restore to previous state */ - yy_delete_buffer(fp_scan_state); if(pre_fp_scan_state) yy_switch_to_buffer(pre_fp_scan_state); free(cfg_qstring);