aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bind-lex.l31
-rw-r--r--src/grecs-lex.l18
-rw-r--r--src/grecs.h6
-rw-r--r--src/lookup.c4
4 files changed, 46 insertions, 13 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;
diff --git a/src/grecs-lex.l b/src/grecs-lex.l
index 84ee858..205a8f4 100644
--- a/src/grecs-lex.l
+++ b/src/grecs-lex.l
@@ -53,9 +53,6 @@ static char *multiline_strip_tabs(char *text);
static int ident(void);
static int isemptystr(int off);
-static void parse_line(char *text, grecs_locus_t *ploc, size_t *pxlines);
-static void parse_line_cpp(char *text, grecs_locus_t *ploc, size_t *pxlines);
-
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
do \
@@ -84,10 +81,10 @@ P [1-9][0-9]*
<COMMENT>\n ++grecs_current_locus.line;
<COMMENT>"*"+"/" BEGIN(INITIAL);
/* Line directive */
-^[ \t]*#[ \t]*{P}[ \t]+\".*\".*\n { parse_line_cpp(yytext,
+^[ \t]*#[ \t]*{P}[ \t]+\".*\".*\n { grecs_parse_line_directive_cpp(yytext,
&grecs_current_locus,
&xlines); }
-^[ \t]*#[ \t]*line[ \t].*\n { parse_line(yytext, &grecs_current_locus,
+^[ \t]*#[ \t]*line[ \t].*\n { grecs_parse_line_directive(yytext, &grecs_current_locus,
&xlines); }
/* End-of-line comments */
#.*\n { grecs_current_locus.line++; }
@@ -330,8 +327,8 @@ assign_locus(grecs_locus_t *ploc, char *name, char *line, size_t *pxlines)
return *p != 0;
}
-static void
-parse_line(char *text, grecs_locus_t *ploc, size_t *pxlines)
+void
+grecs_parse_line_directive(char *text, grecs_locus_t *ploc, size_t *pxlines)
{
int rc = 1;
struct wordsplit ws;
@@ -348,7 +345,7 @@ parse_line(char *text, grecs_locus_t *ploc, size_t *pxlines)
else if (ws.ws_wordc == 4) {
rc = assign_locus(ploc, ws.ws_wordv[2],
ws.ws_wordv[1], 0);
- if (rc == 0) {
+ if (pxlines && rc == 0) {
char *p;
unsigned long x = strtoul(ws.ws_wordv[3],
&p, 10);
@@ -365,8 +362,9 @@ parse_line(char *text, grecs_locus_t *ploc, size_t *pxlines)
}
}
-static void
-parse_line_cpp(char *text, grecs_locus_t *ploc, size_t *pxlines)
+void
+grecs_parse_line_directive_cpp(char *text, grecs_locus_t *ploc,
+ size_t *pxlines)
{
struct wordsplit ws;
diff --git a/src/grecs.h b/src/grecs.h
index c254439..7be6b21 100644
--- a/src/grecs.h
+++ b/src/grecs.h
@@ -206,6 +206,12 @@ extern int grecs_trace_flags;
#define GRECS_TRACE_LEX 0x02
void grecs_gram_trace(int n);
void grecs_lex_trace(int n);
+
+void grecs_parse_line_directive(char *text, grecs_locus_t *ploc,
+ size_t *pxlines);
+void grecs_parse_line_directive_cpp(char *text, grecs_locus_t *ploc,
+ size_t *pxlines);
+
int grecs_lex_begin(const char*, int);
diff --git a/src/lookup.c b/src/lookup.c
index a67edb9..f16e94b 100644
--- a/src/lookup.c
+++ b/src/lookup.c
@@ -457,8 +457,10 @@ grecs_match_first(struct grecs_node *tree, const char *pattern,
return NULL;
}
errno = 0;
- if (strcmp(pattern, ".") == 0)
+ if (strcmp(pattern, ".") == 0) {
+ *pbuf = NULL;
return tree;
+ }
buf = grecs_zalloc(sizeof(*buf));
if (split_cfg_path(pattern, &buf->argc, &buf->argv, &buf->labelv)) {

Return to:

Send suggestions and report system problems to the System administrator.