diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Make.am | 7 | ||||
-rw-r--r-- | src/grecs.hin (renamed from src/grecs.h) | 13 | ||||
-rw-r--r-- | src/tree.c | 48 | ||||
-rw-r--r-- | src/wordsplit.c | 4 |
5 files changed, 63 insertions, 10 deletions
diff --git a/src/.gitignore b/src/.gitignore index 6e859b1..322178c 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -14,6 +14,7 @@ bind-gram.c bind-gram.h bind-gram.output bind-lex.c +grecs.h Make-inst.in Make-shared.in Make-static.in diff --git a/src/Make.am b/src/Make.am index 6482d28..7ded902 100644 --- a/src/Make.am +++ b/src/Make.am @@ -71,12 +71,19 @@ noinst_HEADERS = grecs-locus.h EXTRA_DIST=\ grecs-gram.h\ + grecs.hin\ $(GRECS_EXTRA_BIND)\ $(GRECS_EXTRA_DHCPD)\ $(GRECS_EXTRA_META1)\ $(PP_SETUP_FILE)\ Make.am Make-inst.am Make-shared.am Make-static.am +BUILT_SOURCES=grecs.h + +grecs.h: $(abs_srcdir)/grecs.hin + $(AM_V_GEN)sed 's/@''GRECS_TREE_API''@/@GRECS_TREE_API@/g' \ + $(abs_srcdir)/grecs.hin > grecs.h + AM_CPPFLAGS = \ -I$(srcdir)\ -I$(top_srcdir)/@GRECS_SUBDIR@\ diff --git a/src/grecs.h b/src/grecs.hin index ab9e0a8..e83b855 100644 --- a/src/grecs.h +++ b/src/grecs.hin @@ -1,5 +1,5 @@ -/* grecs - Gray's Extensible Configuration System - Copyright (C) 2007-2012 Sergey Poznyakoff +/* grecs - Gray's Extensible Configuration System -*- c -*- + Copyright (C) 2007-2013 Sergey Poznyakoff Grecs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -40,6 +40,8 @@ #define GRECS_VERSION_MAJOR 1 #define GRECS_VERSION_MINOR 0 +#define GRECS_TREE_API @GRECS_TREE_API@ + struct grecs_version_info { const char *package; const char *version; @@ -161,11 +163,18 @@ typedef struct grecs_node { } grecs_node_t; typedef int (*grecs_callback_fn)( +#if GRECS_TREE_API + enum grecs_callback_command cmd, + grecs_node_t * /* node */, + void * /* varptr */, + void * /* cb_data */ +#else enum grecs_callback_command cmd, grecs_locus_t * /* locus */, void * /* varptr */, grecs_value_t * /* value */, void * /* cb_data */ +#endif ); struct grecs_keyword { @@ -253,11 +253,20 @@ grecs_tree_free(struct grecs_node *node) static int -fake_callback(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +fake_callback( +#if GRECS_TREE_API + enum grecs_callback_command cmd, + grecs_node_t *node, + void *varptr, + void *cb_data +#else + enum grecs_callback_command cmd, + grecs_locus_t *locus, + void *varptr, + grecs_value_t *value, + void *cb_data +#endif + ) { return 0; } @@ -692,13 +701,24 @@ grecs_process_ident(struct grecs_keyword *kwp, grecs_value_t *value, target = target_ptr(kwp, (char *) base); - if (kwp->callback) + if (kwp->callback) { +#if GRECS_TREE_API + struct grecs_node node = { 0 }; + node.locus = *locus; + node.v.value = value; + node.ident = (char*) kwp->ident; + kwp->callback(grecs_callback_set_value, + &node, + target, + &kwp->callback_data); +#else kwp->callback(grecs_callback_set_value, locus, target, value, &kwp->callback_data); - else if (kwp->type == grecs_type_void || target == NULL) +#endif + } else if (kwp->type == grecs_type_void || target == NULL) return; else if (!value) { grecs_error(locus, 0, "%s has no value", kwp->ident); @@ -815,11 +835,18 @@ stmt_begin(struct nodeproc_closure *clos, target = target_ptr(kwp, CURRENT_BASE(clos)); clos->cursect = kwp; if (kwp->callback) { +#if GRECS_TREE_API + if (kwp->callback(grecs_callback_section_begin, + node, + target, + &kwp->callback_data)) +#else if (kwp->callback(grecs_callback_section_begin, &node->locus, target, node->v.value, &kwp->callback_data)) +#endif clos->cursect = &fake; } else kwp->callback_data = target; @@ -844,11 +871,18 @@ stmt_end(struct nodeproc_closure *clos, struct grecs_node *node) if (!clos->cursect) abort(); if (callback) +#if GRECS_TREE_API + callback(grecs_callback_section_end, + node, + kwp ? target_ptr(kwp, CURRENT_BASE(clos)) : NULL, + dataptr); +#else callback(grecs_callback_section_end, &node->locus, kwp ? target_ptr(kwp, CURRENT_BASE(clos)) : NULL, NULL, dataptr); +#endif if (kwp) kwp->callback_data = NULL; } diff --git a/src/wordsplit.c b/src/wordsplit.c index 4fe8d6f..9047369 100644 --- a/src/wordsplit.c +++ b/src/wordsplit.c @@ -437,7 +437,8 @@ coalesce_segment (struct wordsplit *wsp, struct wordsplit_node *node) { len += wsnode_len (p); } - len += wsnode_len (p); + if (p) + len += wsnode_len (p); end = p; buf = malloc (len + 1); @@ -1578,6 +1579,7 @@ wordsplit_perror (struct wordsplit *wsp) case WRDSE_NOSUPP: wsp->ws_error (_("command substitution is not yet supported")); + break; case WRDSE_USAGE: wsp->ws_error (_("invalid wordsplit usage")); |