aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bind-lex.l15
-rw-r--r--src/grecs.h2
-rw-r--r--src/preproc.c28
3 files changed, 30 insertions, 15 deletions
diff --git a/src/bind-lex.l b/src/bind-lex.l
index 12dddf7..a5cf644 100644
--- a/src/bind-lex.l
+++ b/src/bind-lex.l
@@ -192,7 +192,20 @@ grecs_bind_new_source(const char *name)
grecs_locus_t *loc = grecs_current_locus.file ?
&grecs_current_locus : NULL;
struct stat st;
- FILE *fp = fopen(name, "r");
+ FILE *fp;
+
+ if (access(name, F_OK)) {
+ int ec = errno;
+ char *tmp = grecs_find_include_file(name, 0);
+ if (!tmp) {
+ grecs_error(loc, ec, _("cannot open `%s'"), name);
+ return 1;
+ }
+ name = grecs_install_text(tmp);
+ free(tmp);
+ }
+
+ fp = fopen(name, "r");
if (!fp) {
grecs_error(loc, errno, _("cannot open `%s'"), name);
return 1;
diff --git a/src/grecs.h b/src/grecs.h
index b839d71..5eef48d 100644
--- a/src/grecs.h
+++ b/src/grecs.h
@@ -263,6 +263,8 @@ int grecs_preproc_init(const char *name);
void grecs_preproc_done(void);
int grecs_preproc_run(const char *config_file, const char *extpp);
+char *grecs_find_include_file(const char *name, int allow_cwd);
+
FILE *grecs_preproc_extrn_start(const char *file, pid_t *ppid);
void grecs_preproc_extrn_shutdown(pid_t pid);
diff --git a/src/preproc.c b/src/preproc.c
index 8debdcf..4ab3066 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -472,8 +472,8 @@ pop_source()
return 0;
}
-static int
-try_file(const char *name, int allow_cwd, int err_not_found, char **newp)
+char *
+grecs_find_include_file(const char *name, int allow_cwd)
{
static char *cwd = ".";
struct file_data fd;
@@ -495,16 +495,10 @@ try_file(const char *name, int allow_cwd, int err_not_found, char **newp)
if (!fd.found) {
pp_list_find(std_include_path, &fd);
-
- if (!fd.found && err_not_found) {
- grecs_error(&LOCUS, 0,
- _("%s: No such file or directory"), name);
- *newp = NULL;
- }
+ if (!fd.found)
+ return NULL;
}
- if (fd.found)
- *newp = fd.buf;
- return fd.found;
+ return fd.buf;
}
static int
@@ -535,8 +529,13 @@ parse_include(const char *text, int once)
else
allow_cwd = 1;
- if (p[0] != '/' && try_file(p, allow_cwd, 1, &tmp))
- p = tmp;
+ if (p[0] != '/') {
+ p = grecs_find_include_file(p, allow_cwd);
+ if (!p)
+ grecs_error(&LOCUS, 0,
+ _("%s: No such file or directory"),
+ p);
+ }
}
if (p)
@@ -574,7 +573,8 @@ grecs_preproc_run(const char *config_file, const char *extpp)
char *setup_file;
char *cmd = NULL;
- if (try_file("pp-setup", 1, 0, &setup_file)) {
+ setup_file = grecs_find_include_file("pp-setup", 1);
+ if (setup_file) {
size_t size = 0;
if (grecs_asprintf(&cmd, &size,
"%s %s -", extpp, setup_file))

Return to:

Send suggestions and report system problems to the System administrator.