diff options
Diffstat (limited to 'src/preproc.c')
-rw-r--r-- | src/preproc.c | 81 |
1 files changed, 59 insertions, 22 deletions
diff --git a/src/preproc.c b/src/preproc.c index 2626705..f1d5227 100644 --- a/src/preproc.c +++ b/src/preproc.c @@ -235,9 +235,46 @@ ctx_lookup(struct stat *st) } const char *grecs_preprocessor = NULL; -static struct grecs_list *include_path; -static struct grecs_list *std_include_path; +static struct grecs_list *grecs_usr_include_path; +static struct grecs_list *grecs_std_include_path; +size_t +grecs_include_path_count(int flag) +{ + size_t count = 0; + if (flag & GRECS_STD_INCLUDE) + count += grecs_std_include_path ? grecs_std_include_path->count : 0; + if (flag & GRECS_USR_INCLUDE) + count += grecs_usr_include_path ? grecs_usr_include_path->count : 0; + return 0; +} + +static int +foreach_dir(struct grecs_list *list, int flag, + int (*fun)(int, const char *, void *), void *data) +{ + int rc; + struct grecs_list_entry *ep; + + for (ep = list->head; rc == 0 && ep; ep = ep->next) + rc = fun(flag, ep->data, data); + return rc; +} + +int +grecs_foreach_include_dir(int flag, int (*fun)(int, const char *, void *), + void *data) +{ + int rc = 0; + + if (flag & GRECS_STD_INCLUDE) + rc = foreach_dir(grecs_std_include_path, GRECS_STD_INCLUDE, fun, data); + if (rc == 0 && (flag & GRECS_USR_INCLUDE)) + rc = foreach_dir(grecs_usr_include_path, GRECS_USR_INCLUDE, fun, data); + return rc; +} + + struct file_data { const char *name; size_t namelen; @@ -275,26 +312,26 @@ incl_free(void *data) void grecs_include_path_clear() { - if (include_path) - grecs_list_clear(include_path); - if (std_include_path) - grecs_list_clear(std_include_path); + if (grecs_usr_include_path) + grecs_list_clear(grecs_usr_include_path); + if (grecs_std_include_path) + grecs_list_clear(grecs_std_include_path); } void grecs_include_path_setup_v(char **dirs) { - if (!include_path) { - include_path = grecs_list_create(); - include_path->free_entry = incl_free; + if (!grecs_usr_include_path) { + grecs_usr_include_path = grecs_list_create(); + grecs_usr_include_path->free_entry = incl_free; } - std_include_path = grecs_list_create(); - std_include_path->free_entry = incl_free; + grecs_std_include_path = grecs_list_create(); + grecs_std_include_path->free_entry = incl_free; if (dirs) { int i; for (i = 0; dirs[i]; i++) /* FIXME: Element never freed */ - grecs_list_append(std_include_path, + grecs_list_append(grecs_std_include_path, grecs_strdup(dirs[i])); } } @@ -331,11 +368,11 @@ grecs_include_path_setup(const char *dir, ...) void grecs_preproc_add_include_dir(char *dir) { - if (!include_path) { - include_path = grecs_list_create(); - include_path->free_entry = incl_free; + if (!grecs_usr_include_path) { + grecs_usr_include_path = grecs_list_create(); + grecs_usr_include_path->free_entry = incl_free; } - grecs_list_append(include_path, grecs_strdup(dir)); + grecs_list_append(grecs_usr_include_path, grecs_strdup(dir)); } static struct grecs_symtab *incl_sources; @@ -497,17 +534,17 @@ grecs_find_include_file(const char *name, int allow_cwd) fd.buflen = 0; fd.found = 0; - if (!include_path) + if (!grecs_usr_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); + grecs_list_append(grecs_usr_include_path, cwd); + pp_list_find(grecs_usr_include_path, &fd); + grecs_list_remove_tail(grecs_usr_include_path); } else - pp_list_find(include_path, &fd); + pp_list_find(grecs_usr_include_path, &fd); if (!fd.found) { - pp_list_find(std_include_path, &fd); + pp_list_find(grecs_std_include_path, &fd); if (!fd.found) return NULL; } |