summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2013-02-26 14:14:37 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-02-26 14:35:53 (GMT)
commit487e2cfa988d6c3a5232011ab83897ef23bdb88a (patch) (side-by-side diff)
tree2db411004be434327162149356d9e04e84c786d8 /src
parent5596f7cdcdc1983021185c5e0900d5fcba7f3282 (diff)
downloadgrecs-487e2cfa988d6c3a5232011ab83897ef23bdb88a.tar.gz
grecs-487e2cfa988d6c3a5232011ab83897ef23bdb88a.tar.bz2
Introduce an alternative callback function calling convention.
Depending on the tree-api option to the GRECS_SETUP macro, the signature of callback functions changes. If the option is supplied, a pointer to grecs_node_t is passwd to callback functions as an argument instead of pointers to the value and locus. * am/grecs.m4 (GRECS_SETUP): New option tree-api. * src/.gitignore: Add grecs.h * src/Make.am: Build grecs.h * src/grecs.h: Rename to src/grecs.hin (GRECS_TREE_API): New define (grecs_callback_fn): Provide two alternative signatures depending on the value of GRECS_TREE_API. All uses updated. * src/tree.c (fake_callback): Update signature. (grecs_process_ident) (stmt_begin,stmt_end): Update calls to callback. * tests/gcfset.c: Likewise.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/.gitignore1
-rw-r--r--src/Make.am7
-rw-r--r--src/grecs.hin (renamed from src/grecs.h)13
-rw-r--r--src/tree.c48
-rw-r--r--src/wordsplit.c4
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 {
diff --git a/src/tree.c b/src/tree.c
index abf170e..a0f8736 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -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"));

Return to:

Send suggestions and report system problems to the System administrator.