aboutsummaryrefslogtreecommitdiff
path: root/src/preproc.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-16 19:31:53 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-16 19:31:53 +0300
commitc8865a0d524f3d545836bd4581329089a357661e (patch)
tree4fc437a07086c4304e7ec2446be2a504a3dbd507 /src/preproc.c
parent50e703a9a92e755f928699b705612cd4153ffb9f (diff)
downloadgrecs-c8865a0d524f3d545836bd4581329089a357661e.tar.gz
grecs-c8865a0d524f3d545836bd4581329089a357661e.tar.bz2
Add bind testsuite.
* README.submodule: Update URL. * src/bind-lex.l (grecs_bind_new_source): Scan include path. * src/grecs.h (grecs_find_include_file): new proto. * src/preproc.c (try_file): Rename to grecs_find_include_file. Change signature and return type. All uses updated. * tests/Makefile.am (EXTRA_DIST): Add new configs. (TESTSUITE_AT): Add parser-bind.at. * tests/gcffmt.c: Add -I (-include) option. * tests/testsuite.at: Include parser-bind.at. * tests/bind.conf: New file. * tests/bind.dlz: New file. * tests/bind.ext.conf: New file. * tests/bind.int.conf: New file. * tests/bind.keys: New file. * tests/parser-bind.at: New file.
Diffstat (limited to 'src/preproc.c')
-rw-r--r--src/preproc.c34
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
@@ -463,57 +463,51 @@ pop_source()
LOCUS.line++;
if (grecs_grecs__flex_debug)
fprintf(stderr, "Resuming file `%s' at line %lu\n",
LOCUS.file, (unsigned long) LOCUS.line);
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);
fd.buf = NULL;
fd.buflen = 0;
fd.found = 0;
if (!include_path)
grecs_include_path_setup(NULL);
if (allow_cwd) {
grecs_list_append(include_path, cwd);
pp_list_find(include_path, &fd);
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;
char *tmp = NULL;
char *p = NULL;
int rc = 1;
if (wordsplit(text, &ws, WRDSF_DEFFLAGS))
grecs_error(&LOCUS, 0, _("Cannot parse include line"));
@@ -526,26 +520,31 @@ parse_include(const char *text, int once)
p = ws.ws_wordv[1];
len = strlen (p);
if (p[0] == '<' && p[len - 1] == '>') {
allow_cwd = 0;
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);
return rc;
}
int
grecs_preproc_init(const char *name)
{
@@ -564,36 +563,37 @@ grecs_preproc_done()
int
grecs_preproc_run(const char *config_file, const char *extpp)
{
size_t i;
char buffer[512];
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;
}
while ((i = grecs_preproc_fill_buffer(buffer, sizeof buffer)))
fwrite(buffer, 1, i, outfile);
pclose(outfile);
grecs_free(cmd);
} else {

Return to:

Send suggestions and report system problems to the System administrator.