diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-22 20:17:43 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-22 20:32:34 +0300 |
commit | 4a994c621995aafa110caa26114acb75f6ad76ed (patch) | |
tree | 0304a8ec0e434bac53a3caae132756cec526a69b /src/bind-lex.l | |
parent | 024cfd63846c0c7ef630a5dab819ad97942264a1 (diff) | |
download | grecs-4a994c621995aafa110caa26114acb75f6ad76ed.tar.gz grecs-4a994c621995aafa110caa26114acb75f6ad76ed.tar.bz2 |
Optionally use preprocessor for bind configs.
* src/bind-lex.l: Parse #line directives.
(_pop_context): Use fclose or pclose, depending on how
the stream was opened.
(grecs_bind_new_source): Use preprocessor if grecs_preprocessor
was set.
* src/grecs-lex.l (parse_line): Rename to grecs_parse_line_directive.
(parse_line_cpp): Rename to grecs_parse_line_directive_cpp.
* src/grecs.h (grecs_parse_line_directive)
(grecs_parse_line_directive_cpp): New protos.
* src/lookup.c (grecs_match_first): Bugfix.
Diffstat (limited to 'src/bind-lex.l')
-rw-r--r-- | src/bind-lex.l | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/bind-lex.l b/src/bind-lex.l index 440b17a..7a9ff90 100644 --- a/src/bind-lex.l +++ b/src/bind-lex.l @@ -47,6 +47,13 @@ P [1-9][0-9]* <COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ <COMMENT>\n ++grecs_current_locus.line; <COMMENT>"*"+"/" BEGIN(INITIAL); + /* Line directive */ +^[ \t]*#[ \t]*{P}[ \t]+\".*\".*\n { grecs_parse_line_directive_cpp(yytext, + &grecs_current_locus, + NULL); } +^[ \t]*#[ \t]*line[ \t].*\n { grecs_parse_line_directive(yytext, + &grecs_current_locus, + NULL); } /* End-of-line comments */ #.*\n { grecs_current_locus.line++; } #.* /* end-of-file comment */; @@ -165,7 +172,10 @@ _pop_context() if (!yyin) return 1; - fclose(yyin); + if (grecs_preprocessor) + pclose(yyin); + else + fclose(yyin); pctx = grecs_list_pop(input_stack); if (!pctx) { yyin = NULL; @@ -216,8 +226,25 @@ grecs_bind_new_source(const char *name) fclose(fp); return 1; } - if (_push_context(name, st.st_ino, st.st_dev)) { + if (grecs_preprocessor) { + char *cmd = NULL; + size_t size = 0; + fclose(fp); + if (grecs_asprintf(&cmd, &size, "%s \"%s\"", + grecs_preprocessor, name)) + grecs_alloc_die(); + + fp = popen(cmd, "r"); + if (!fp) { + grecs_error(loc, errno, _("cannot open `%s'"), cmd); + grecs_free(cmd); + return 1; + } + grecs_free(cmd); + } + + if (_push_context(name, st.st_ino, st.st_dev)) { return 1; } i_node = st.st_ino; |