aboutsummaryrefslogtreecommitdiff
path: root/src/preproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/preproc.c')
-rw-r--r--src/preproc.c81
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)
235} 235}
236 236
237const char *grecs_preprocessor = NULL; 237const char *grecs_preprocessor = NULL;
238static struct grecs_list *include_path; 238static struct grecs_list *grecs_usr_include_path;
239static struct grecs_list *std_include_path; 239static struct grecs_list *grecs_std_include_path;
240 240
241size_t
242grecs_include_path_count(int flag)
243{
244 size_t count = 0;
245 if (flag & GRECS_STD_INCLUDE)
246 count += grecs_std_include_path ? grecs_std_include_path->count : 0;
247 if (flag & GRECS_USR_INCLUDE)
248 count += grecs_usr_include_path ? grecs_usr_include_path->count : 0;
249 return 0;
250}
251
252static int
253foreach_dir(struct grecs_list *list, int flag,
254 int (*fun)(int, const char *, void *), void *data)
255{
256 int rc;
257 struct grecs_list_entry *ep;
258
259 for (ep = list->head; rc == 0 && ep; ep = ep->next)
260 rc = fun(flag, ep->data, data);
261 return rc;
262}
263
264int
265grecs_foreach_include_dir(int flag, int (*fun)(int, const char *, void *),
266 void *data)
267{
268 int rc = 0;
269
270 if (flag & GRECS_STD_INCLUDE)
271 rc = foreach_dir(grecs_std_include_path, GRECS_STD_INCLUDE, fun, data);
272 if (rc == 0 && (flag & GRECS_USR_INCLUDE))
273 rc = foreach_dir(grecs_usr_include_path, GRECS_USR_INCLUDE, fun, data);
274 return rc;
275}
276
277
241struct file_data { 278struct file_data {
242 const char *name; 279 const char *name;
243 size_t namelen; 280 size_t namelen;
@@ -275,26 +312,26 @@ incl_free(void *data)
275void 312void
276grecs_include_path_clear() 313grecs_include_path_clear()
277{ 314{
278 if (include_path) 315 if (grecs_usr_include_path)
279 grecs_list_clear(include_path); 316 grecs_list_clear(grecs_usr_include_path);
280 if (std_include_path) 317 if (grecs_std_include_path)
281 grecs_list_clear(std_include_path); 318 grecs_list_clear(grecs_std_include_path);
282} 319}
283 320
284void 321void
285grecs_include_path_setup_v(char **dirs) 322grecs_include_path_setup_v(char **dirs)
286{ 323{
287 if (!include_path) { 324 if (!grecs_usr_include_path) {
288 include_path = grecs_list_create(); 325 grecs_usr_include_path = grecs_list_create();
289 include_path->free_entry = incl_free; 326 grecs_usr_include_path->free_entry = incl_free;
290 } 327 }
291 std_include_path = grecs_list_create(); 328 grecs_std_include_path = grecs_list_create();
292 std_include_path->free_entry = incl_free; 329 grecs_std_include_path->free_entry = incl_free;
293 if (dirs) { 330 if (dirs) {
294 int i; 331 int i;
295 for (i = 0; dirs[i]; i++) 332 for (i = 0; dirs[i]; i++)
296 /* FIXME: Element never freed */ 333 /* FIXME: Element never freed */
297 grecs_list_append(std_include_path, 334 grecs_list_append(grecs_std_include_path,
298 grecs_strdup(dirs[i])); 335 grecs_strdup(dirs[i]));
299 } 336 }
300} 337}
@@ -331,11 +368,11 @@ grecs_include_path_setup(const char *dir, ...)
331void 368void
332grecs_preproc_add_include_dir(char *dir) 369grecs_preproc_add_include_dir(char *dir)
333{ 370{
334 if (!include_path) { 371 if (!grecs_usr_include_path) {
335 include_path = grecs_list_create(); 372 grecs_usr_include_path = grecs_list_create();
336 include_path->free_entry = incl_free; 373 grecs_usr_include_path->free_entry = incl_free;
337 } 374 }
338 grecs_list_append(include_path, grecs_strdup(dir)); 375 grecs_list_append(grecs_usr_include_path, grecs_strdup(dir));
339} 376}
340 377
341static struct grecs_symtab *incl_sources; 378static struct grecs_symtab *incl_sources;
@@ -497,17 +534,17 @@ grecs_find_include_file(const char *name, int allow_cwd)
497 fd.buflen = 0; 534 fd.buflen = 0;
498 fd.found = 0; 535 fd.found = 0;
499 536
500 if (!include_path) 537 if (!grecs_usr_include_path)
501 grecs_include_path_setup(NULL); 538 grecs_include_path_setup(NULL);
502 if (allow_cwd) { 539 if (allow_cwd) {
503 grecs_list_append(include_path, cwd); 540 grecs_list_append(grecs_usr_include_path, cwd);
504 pp_list_find(include_path, &fd); 541 pp_list_find(grecs_usr_include_path, &fd);
505 grecs_list_remove_tail(include_path); 542 grecs_list_remove_tail(grecs_usr_include_path);
506 } else 543 } else
507 pp_list_find(include_path, &fd); 544 pp_list_find(grecs_usr_include_path, &fd);
508 545
509 if (!fd.found) { 546 if (!fd.found) {
510 pp_list_find(std_include_path, &fd); 547 pp_list_find(grecs_std_include_path, &fd);
511 if (!fd.found) 548 if (!fd.found)
512 return NULL; 549 return NULL;
513 } 550 }

Return to:

Send suggestions and report system problems to the System administrator.