diff options
Diffstat (limited to 'src/preproc.c')
-rw-r--r-- | src/preproc.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/preproc.c b/src/preproc.c index 8debdcf..4ab3066 100644 --- a/src/preproc.c +++ b/src/preproc.c @@ -469,14 +469,14 @@ pop_source() pp_line_stmt(); 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; fd.name = name; fd.namelen = strlen(name); @@ -492,22 +492,16 @@ try_file(const char *name, int allow_cwd, int err_not_found, char **newp) grecs_list_remove_tail(include_path); } else pp_list_find(include_path, &fd); 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 parse_include(const char *text, int once) { struct wordsplit ws; @@ -532,14 +526,19 @@ parse_include(const char *text, int once) p[len - 1] = 0; p++; } 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) rc = push_source(p, once); grecs_free(tmp); wordsplit_free(&ws); @@ -570,24 +569,25 @@ grecs_preproc_run(const char *config_file, const char *extpp) if (grecs_preproc_init(config_file)) return 1; if (extpp) { FILE *outfile; 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)) grecs_alloc_die(); grecs_free(setup_file); } else - cmd = grecs_strdup (extpp); + cmd = grecs_strdup(extpp); /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", cmd);*/ outfile = popen(cmd, "w"); - if (!outfile){ + if (!outfile) { grecs_error(NULL, errno, _("Unable to start external preprocessor `%s'"), cmd); grecs_free(cmd); return 1; } |