aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/preproc.c63
1 files changed, 56 insertions, 7 deletions
diff --git a/src/preproc.c b/src/preproc.c
index ce32a29..56dcc22 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -1,5 +1,5 @@
1/* grecs - Gray's Extensible Configuration System 1/* grecs - Gray's Extensible Configuration System
2 Copyright (C) 2007-2012 Sergey Poznyakoff 2 Copyright (C) 2007-2014 Sergey Poznyakoff
3 3
4 Grecs is free software; you can redistribute it and/or modify it 4 Grecs is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the 5 under the terms of the GNU General Public License as published by the
@@ -28,6 +28,7 @@
28#include <string.h> 28#include <string.h>
29#include <errno.h> 29#include <errno.h>
30#include <signal.h> 30#include <signal.h>
31#include <glob.h>
31 32
32#include <wordsplit.h> 33#include <wordsplit.h>
33 34
@@ -62,6 +63,9 @@ static size_t bufsize;
62static char *putback_buffer; 63static char *putback_buffer;
63static size_t putback_size; 64static size_t putback_size;
64static size_t putback_max; 65static size_t putback_max;
66static glob_t include_glob;
67static size_t include_pos;
68static int include_once;
65 69
66static int push_source (const char *name, int once); 70static int push_source (const char *name, int once);
67static int pop_source (void); 71static int pop_source (void);
@@ -287,7 +291,9 @@ static int
287pp_list_find(struct grecs_list *list, struct file_data *dptr) 291pp_list_find(struct grecs_list *list, struct file_data *dptr)
288{ 292{
289 struct grecs_list_entry *ep; 293 struct grecs_list_entry *ep;
290 294
295 if (!list)
296 return 0;
291 for (ep = list->head; !dptr->found && ep; ep = ep->next) { 297 for (ep = list->head; !dptr->found && ep; ep = ep->next) {
292 const char *dir = ep->data; 298 const char *dir = ep->data;
293 size_t size = strlen (dir) + 1 + dptr->namelen + 1; 299 size_t size = strlen (dir) + 1 + dptr->namelen + 1;
@@ -395,6 +401,13 @@ incl_compare(void const *data1, void const *data2)
395} 401}
396 402
397static int 403static int
404incl_copy(void *dst, void *src)
405{
406 memcpy(dst, src, sizeof(struct input_file_ident));
407 return 0;
408}
409
410static int
398source_lookup(struct stat *st) 411source_lookup(struct stat *st)
399{ 412{
400 struct input_file_ident key; 413 struct input_file_ident key;
@@ -405,7 +418,7 @@ source_lookup(struct stat *st)
405 sizeof(struct input_file_ident), 418 sizeof(struct input_file_ident),
406 incl_hasher, 419 incl_hasher,
407 incl_compare, 420 incl_compare,
408 NULL, 421 incl_copy,
409 NULL,/*FIXME: alloc*/ 422 NULL,/*FIXME: alloc*/
410 NULL); 423 NULL);
411 if (!incl_sources) 424 if (!incl_sources)
@@ -505,6 +518,14 @@ pop_source()
505 grecs_free(context_stack); 518 grecs_free(context_stack);
506 context_stack = ctx; 519 context_stack = ctx;
507 520
521 if (include_pos < include_glob.gl_pathc) {
522 push_source(include_glob.gl_pathv[include_pos++], include_once);
523 return 0;
524 } else if (include_glob.gl_pathc) {
525 globfree(&include_glob);
526 include_pos = include_glob.gl_pathc = 0;
527 }
528
508 if (!context_stack) { 529 if (!context_stack) {
509 if (grecs_grecs__flex_debug) 530 if (grecs_grecs__flex_debug)
510 fprintf(stderr, "End of input\n"); 531 fprintf(stderr, "End of input\n");
@@ -552,6 +573,16 @@ grecs_find_include_file(const char *name, int allow_cwd)
552} 573}
553 574
554static int 575static int
576isglob(const char *s)
577{
578 for (; *s; s++) {
579 if (strchr("*?[", *s))
580 return 1;
581 }
582 return 0;
583}
584
585static int
555parse_include(const char *text, int once) 586parse_include(const char *text, int once)
556{ 587{
557 struct wordsplit ws; 588 struct wordsplit ws;
@@ -579,17 +610,35 @@ parse_include(const char *text, int once)
579 else 610 else
580 allow_cwd = 1; 611 allow_cwd = 1;
581 612
582 if (p[0] != '/') { 613 if (isglob(p)) {
583 p = grecs_find_include_file(p, allow_cwd); 614 switch (glob(p, 0, NULL, &include_glob)) {
615 case 0:
616 include_pos = 0;
617 include_once = once;
618 break;
619 case GLOB_NOSPACE:
620 grecs_alloc_die();
621 case GLOB_NOMATCH:
622 break;
623 default:
624 grecs_error(&LOCUS, 0, _("read error"));
625 }
626 p = NULL;
627 } else if (p[0] != '/') {
628 char *q = p;
629 p = grecs_find_include_file(q, allow_cwd);
584 if (!p) 630 if (!p)
585 grecs_error(&LOCUS, 0, 631 grecs_error(&LOCUS, 0,
586 _("%s: No such file or directory"), 632 _("%s: No such file or directory"),
587 p); 633 q);
588 } 634 }
589 } 635 }
590 636
591 if (p) 637 if (p)
592 rc = push_source(p, once); 638 rc = push_source(p, once);
639 else if (include_pos < include_glob.gl_pathc)
640 rc = push_source(include_glob.gl_pathv[include_pos++], once);
641
593 grecs_free(tmp); 642 grecs_free(tmp);
594 wordsplit_free(&ws); 643 wordsplit_free(&ws);
595 return rc; 644 return rc;

Return to:

Send suggestions and report system problems to the System administrator.