git.droids-corp.org
/
protos
/
libecoli.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
api documentation for ec_parse
[protos/libecoli.git]
/
src
/
ecoli_node_or.c
diff --git
a/src/ecoli_node_or.c
b/src/ecoli_node_or.c
index
2bf8fc7
..
e9d6c1e
100644
(file)
--- a/
src/ecoli_node_or.c
+++ b/
src/ecoli_node_or.c
@@
-25,22
+25,21
@@
EC_LOG_TYPE_REGISTER(node_or);
struct ec_node_or {
EC_LOG_TYPE_REGISTER(node_or);
struct ec_node_or {
- struct ec_node gen;
struct ec_node **table;
size_t len;
};
static int
struct ec_node **table;
size_t len;
};
static int
-ec_node_or_parse(const struct ec_node *
gen_
node,
- struct ec_p
arse *
state,
+ec_node_or_parse(const struct ec_node *node,
+ struct ec_p
node *p
state,
const struct ec_strvec *strvec)
{
const struct ec_strvec *strvec)
{
- struct ec_node_or *
node = (struct ec_node_or *)gen_node
;
+ struct ec_node_or *
priv = ec_node_priv(node)
;
unsigned int i;
int ret;
unsigned int i;
int ret;
- for (i = 0; i <
node
->len; i++) {
- ret = ec_
node_parse_child(node->table[i],
state, strvec);
+ for (i = 0; i <
priv
->len; i++) {
+ ret = ec_
parse_child(priv->table[i], p
state, strvec);
if (ret == EC_PARSE_NOMATCH)
continue;
return ret;
if (ret == EC_PARSE_NOMATCH)
continue;
return ret;
@@
-50,16
+49,16
@@
ec_node_or_parse(const struct ec_node *gen_node,
}
static int
}
static int
-ec_node_or_complete(const struct ec_node *
gen_
node,
+ec_node_or_complete(const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_node_or *
node = (struct ec_node_or *)gen_node
;
+ struct ec_node_or *
priv = ec_node_priv(node)
;
int ret;
size_t n;
int ret;
size_t n;
- for (n = 0; n <
node
->len; n++) {
- ret = ec_
node_complete_child(node
->table[n],
+ for (n = 0; n <
priv
->len; n++) {
+ ret = ec_
complete_child(priv
->table[n],
comp, strvec);
if (ret < 0)
return ret;
comp, strvec);
if (ret < 0)
return ret;
@@
-68,16
+67,16
@@
ec_node_or_complete(const struct ec_node *gen_node,
return 0;
}
return 0;
}
-static void ec_node_or_free_priv(struct ec_node *
gen_
node)
+static void ec_node_or_free_priv(struct ec_node *node)
{
{
- struct ec_node_or *
node = (struct ec_node_or *)gen_node
;
+ struct ec_node_or *
priv = ec_node_priv(node)
;
size_t i;
size_t i;
- for (i = 0; i <
node
->len; i++)
- ec_node_free(
node
->table[i]);
- ec_free(
node
->table);
-
node
->table = NULL;
-
node
->len = 0;
+ for (i = 0; i <
priv
->len; i++)
+ ec_node_free(
priv
->table[i]);
+ ec_free(
priv
->table);
+
priv
->table = NULL;
+
priv
->len = 0;
}
static const struct ec_config_schema ec_node_or_subschema[] = {
}
static const struct ec_config_schema ec_node_or_subschema[] = {
@@
-103,10
+102,10
@@
static const struct ec_config_schema ec_node_or_schema[] = {
},
};
},
};
-static int ec_node_or_set_config(struct ec_node *
gen_
node,
+static int ec_node_or_set_config(struct ec_node *node,
const struct ec_config *config)
{
const struct ec_config *config)
{
- struct ec_node_or *
node = (struct ec_node_or *)gen_node
;
+ struct ec_node_or *
priv = ec_node_priv(node)
;
struct ec_node **table = NULL;
size_t i, len = 0;
struct ec_node **table = NULL;
size_t i, len = 0;
@@
-115,11
+114,11
@@
static int ec_node_or_set_config(struct ec_node *gen_node,
if (table == NULL)
goto fail;
if (table == NULL)
goto fail;
- for (i = 0; i <
node
->len; i++)
- ec_node_free(
node
->table[i]);
- ec_free(
node
->table);
-
node
->table = table;
-
node
->len = len;
+ for (i = 0; i <
priv
->len; i++)
+ ec_node_free(
priv
->table[i]);
+ ec_free(
priv
->table);
+
priv
->table = table;
+
priv
->len = len;
return 0;
return 0;
@@
-131,24
+130,24
@@
fail:
}
static size_t
}
static size_t
-ec_node_or_get_children_count(const struct ec_node *
gen_
node)
+ec_node_or_get_children_count(const struct ec_node *node)
{
{
- struct ec_node_or *
node = (struct ec_node_or *)gen_node
;
- return
node
->len;
+ struct ec_node_or *
priv = ec_node_priv(node)
;
+ return
priv
->len;
}
static int
}
static int
-ec_node_or_get_child(const struct ec_node *
gen_
node, size_t i,
+ec_node_or_get_child(const struct ec_node *node, size_t i,
struct ec_node **child, unsigned int *refs)
{
struct ec_node **child, unsigned int *refs)
{
- struct ec_node_or *
node = (struct ec_node_or *)gen_node
;
+ struct ec_node_or *
priv = ec_node_priv(node)
;
- if (i >=
node
->len)
+ if (i >=
priv
->len)
return -1;
return -1;
- *child =
node
->table[i];
+ *child =
priv
->table[i];
/* each child node is referenced twice: once in the config and
/* each child node is referenced twice: once in the config and
- * once in the
node
->table[] */
+ * once in the
priv
->table[] */
*refs = 2;
return 0;
}
*refs = 2;
return 0;
}
@@
-167,9
+166,8
@@
static struct ec_node_type ec_node_or_type = {
EC_NODE_TYPE_REGISTER(ec_node_or_type);
EC_NODE_TYPE_REGISTER(ec_node_or_type);
-int ec_node_or_add(struct ec_node *
gen_
node, struct ec_node *child)
+int ec_node_or_add(struct ec_node *node, struct ec_node *child)
{
{
- struct ec_node_or *node = (struct ec_node_or *)gen_node;
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL, *children;
int ret;
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL, *children;
int ret;
@@
-178,10
+176,10
@@
int ec_node_or_add(struct ec_node *gen_node, struct ec_node *child)
/* XXX factorize this code in a helper */
/* XXX factorize this code in a helper */
- if (ec_node_check_type(
gen_
node, &ec_node_or_type) < 0)
+ if (ec_node_check_type(node, &ec_node_or_type) < 0)
goto fail;
goto fail;
- cur_config = ec_node_get_config(
gen_
node);
+ cur_config = ec_node_get_config(node);
if (cur_config == NULL)
config = ec_config_dict();
else
if (cur_config == NULL)
config = ec_config_dict();
else
@@
-204,7
+202,7
@@
int ec_node_or_add(struct ec_node *gen_node, struct ec_node *child)
goto fail;
}
goto fail;
}
- ret = ec_node_set_config(
gen_
node, config);
+ ret = ec_node_set_config(node, config);
config = NULL; /* freed */
if (ret < 0)
goto fail;
config = NULL; /* freed */
if (ret < 0)
goto fail;
@@
-220,7
+218,7
@@
fail:
struct ec_node *__ec_node_or(const char *id, ...)
{
struct ec_config *config = NULL, *children = NULL;
struct ec_node *__ec_node_or(const char *id, ...)
{
struct ec_config *config = NULL, *children = NULL;
- struct ec_node *
gen_
node = NULL;
+ struct ec_node *node = NULL;
struct ec_node *child;
va_list ap;
int ret;
struct ec_node *child;
va_list ap;
int ret;
@@
-228,8
+226,8
@@
struct ec_node *__ec_node_or(const char *id, ...)
va_start(ap, id);
child = va_arg(ap, struct ec_node *);
va_start(ap, id);
child = va_arg(ap, struct ec_node *);
-
gen_
node = ec_node_from_type(&ec_node_or_type, id);
- if (
gen_
node == NULL)
+ node = ec_node_from_type(&ec_node_or_type, id);
+ if (node == NULL)
goto fail_free_children;
config = ec_config_dict();
goto fail_free_children;
config = ec_config_dict();
@@
-240,7
+238,7
@@
struct ec_node *__ec_node_or(const char *id, ...)
if (children == NULL)
goto fail_free_children;
if (children == NULL)
goto fail_free_children;
- for (; child != EC_
NODE_ENDLIST
; child = va_arg(ap, struct ec_node *)) {
+ for (; child != EC_
VA_END
; child = va_arg(ap, struct ec_node *)) {
if (child == NULL)
goto fail_free_children;
if (child == NULL)
goto fail_free_children;
@@
-256,20
+254,20
@@
struct ec_node *__ec_node_or(const char *id, ...)
}
children = NULL;
}
children = NULL;
- ret = ec_node_set_config(
gen_
node, config);
+ ret = ec_node_set_config(node, config);
config = NULL; /* freed */
if (ret < 0)
goto fail;
va_end(ap);
config = NULL; /* freed */
if (ret < 0)
goto fail;
va_end(ap);
- return
gen_
node;
+ return node;
fail_free_children:
fail_free_children:
- for (; child != EC_
NODE_ENDLIST
; child = va_arg(ap, struct ec_node *))
+ for (; child != EC_
VA_END
; child = va_arg(ap, struct ec_node *))
ec_node_free(child);
fail:
ec_node_free(child);
fail:
- ec_node_free(
gen_
node); /* will also free added children */
+ ec_node_free(node); /* will also free added children */
ec_config_free(children);
ec_config_free(config);
va_end(ap);
ec_config_free(children);
ec_config_free(config);
va_end(ap);
@@
-313,26
+311,26
@@
static int ec_node_or_testcase(void)
return -1;
}
testres |= EC_TEST_CHECK_COMPLETE(node,
return -1;
}
testres |= EC_TEST_CHECK_COMPLETE(node,
- "", EC_
NODE_ENDLIST
,
- "foo", "bar", "bar2", "toto", "titi", EC_
NODE_ENDLIST
);
+ "", EC_
VA_END
,
+ "foo", "bar", "bar2", "toto", "titi", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "f", EC_
NODE_ENDLIST
,
- "foo", EC_
NODE_ENDLIST
);
+ "f", EC_
VA_END
,
+ "foo", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "b", EC_
NODE_ENDLIST
,
- "bar", "bar2", EC_
NODE_ENDLIST
);
+ "b", EC_
VA_END
,
+ "bar", "bar2", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "bar", EC_
NODE_ENDLIST
,
- "bar", "bar2", EC_
NODE_ENDLIST
);
+ "bar", EC_
VA_END
,
+ "bar", "bar2", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "t", EC_
NODE_ENDLIST
,
- "toto", "titi", EC_
NODE_ENDLIST
);
+ "t", EC_
VA_END
,
+ "toto", "titi", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "to", EC_
NODE_ENDLIST
,
- "toto", EC_
NODE_ENDLIST
);
+ "to", EC_
VA_END
,
+ "toto", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "x", EC_
NODE_ENDLIST
,
- EC_
NODE_ENDLIST
);
+ "x", EC_
VA_END
,
+ EC_
VA_END
);
ec_node_free(node);
return testres;
ec_node_free(node);
return testres;