From 8b45797ccfdb3c1d3b9ea9c1466c064eedbe77e7 Mon Sep 17 00:00:00 2001 From: Michael Witten Date: Tue, 4 Mar 2008 23:57:23 -0500 Subject: [PATCH] ivlpp: Fixed handling of absolute paths The updates to the do_include code destroyed the handling of absolute paths; all of the code that handles buffer-switching was erroneously placed in just the relative-path branch. Thanks go to Cary R. for pointing out the problem. Now the common code has been extracted yet again, and the notorious goto statement has been used in favor redundancy. The test vvp_reg.pl produces the same output as before, so hopefully nothing new is broken. Signed-off-by: Michael Witten --- ivlpp/lexor.lex | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 4aa517c80..57fc61c4c 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -1385,10 +1385,8 @@ static void do_include() /* standby is defined by include_filename() */ if (standby->path[0] == '/') { - standby->file = fopen(standby->path, "r"); - - if(depend_file && standby->file) - fprintf(depend_file, "%s\n", istack->path); + if ((standby->file = fopen(standby->path, "r"))) + goto code_that_switches_buffers; } else { @@ -1419,29 +1417,31 @@ static void do_include() if ((standby->file = fopen(path, "r"))) { - if(depend_file) - fprintf(depend_file, "%s\n", path); - - if (line_direct_flag) - fprintf(yyout, "\n`line %u \"%s\" 1\n", istack->lineno+1, path); - standby->path = strdup(path); - standby->next = istack; - - istack->yybs = YY_CURRENT_BUFFER; - istack = standby; - - standby = 0; - - yy_switch_to_buffer(yy_create_buffer(istack->file, YY_BUF_SIZE)); - - return; + goto code_that_switches_buffers; } } } fprintf(stderr, "%s:%u: Include file %s not found\n", istack->path, istack->lineno, standby->path); exit(1); + + code_that_switches_buffers: + + if(depend_file) + fprintf(depend_file, "%s\n", standby->path); + + if (line_direct_flag) + fprintf(yyout, "\n`line %u \"%s\" 1\n", istack->lineno+1, standby->path); + + standby->next = istack; + + istack->yybs = YY_CURRENT_BUFFER; + istack = standby; + + standby = 0; + + yy_switch_to_buffer(yy_create_buffer(istack->file, YY_BUF_SIZE)); } /* walk the include stack until we find an entry with a valid pathname,