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 doc and minor changes
[protos/libecoli.git]
/
src
/
ecoli_node_many.c
diff --git
a/src/ecoli_node_many.c
b/src/ecoli_node_many.c
index
0850ae7
..
54c100c
100644
(file)
--- a/
src/ecoli_node_many.c
+++ b/
src/ecoli_node_many.c
@@
-24,29
+24,28
@@
EC_LOG_TYPE_REGISTER(node_many);
struct ec_node_many {
EC_LOG_TYPE_REGISTER(node_many);
struct ec_node_many {
- struct ec_node gen;
unsigned int min;
unsigned int max;
struct ec_node *child;
};
unsigned int min;
unsigned int max;
struct ec_node *child;
};
-static int ec_node_many_parse(const struct ec_node *
gen_
node,
- struct ec_p
arse *
state,
+static int ec_node_many_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_many *
node = (struct ec_node_many *)gen_node
;
- struct ec_p
ars
e *child_parse;
+ struct ec_node_many *
priv = ec_node_priv(node)
;
+ struct ec_p
nod
e *child_parse;
struct ec_strvec *childvec = NULL;
size_t off = 0, count;
int ret;
struct ec_strvec *childvec = NULL;
size_t off = 0, count;
int ret;
- for (count = 0;
node->max == 0 || count < node
->max; count++) {
+ for (count = 0;
priv->max == 0 || count < priv
->max; count++) {
childvec = ec_strvec_ndup(strvec, off,
ec_strvec_len(strvec) - off);
if (childvec == NULL)
goto fail;
childvec = ec_strvec_ndup(strvec, off,
ec_strvec_len(strvec) - off);
if (childvec == NULL)
goto fail;
- ret = ec_
node_parse_child(node->child,
state, childvec);
+ ret = ec_
parse_child(priv->child, p
state, childvec);
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
@@
-58,17
+57,17
@@
static int ec_node_many_parse(const struct ec_node *gen_node,
/* it matches an empty strvec, no need to continue */
if (ret == 0) {
/* it matches an empty strvec, no need to continue */
if (ret == 0) {
- child_parse = ec_p
arse_get_last_child(
state);
- ec_p
arse_unlink_child(
state, child_parse);
- ec_p
ars
e_free(child_parse);
+ child_parse = ec_p
node_get_last_child(p
state);
+ ec_p
node_unlink_child(p
state, child_parse);
+ ec_p
nod
e_free(child_parse);
break;
}
off += ret;
}
break;
}
off += ret;
}
- if (count <
node
->min) {
- ec_p
arse_free_children(
state);
+ if (count <
priv
->min) {
+ ec_p
node_free_children(p
state);
return EC_PARSE_NOMATCH;
}
return EC_PARSE_NOMATCH;
}
@@
-80,17
+79,17
@@
fail:
}
static int
}
static int
-__ec_node_many_complete(struct ec_node_many *
node
, unsigned int max,
+__ec_node_many_complete(struct ec_node_many *
priv
, unsigned int max,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_p
arse *parse = ec_comp_get_
state(comp);
+ struct ec_p
node *parse = ec_comp_get_cur_p
state(comp);
struct ec_strvec *childvec = NULL;
unsigned int i;
int ret;
/* first, try to complete with the child node */
struct ec_strvec *childvec = NULL;
unsigned int i;
int ret;
/* first, try to complete with the child node */
- ret = ec_
node_complete_child(node
->child, comp, strvec);
+ ret = ec_
complete_child(priv
->child, comp, strvec);
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
@@
-109,7
+108,7
@@
__ec_node_many_complete(struct ec_node_many *node, unsigned int max,
if (childvec == NULL)
goto fail;
if (childvec == NULL)
goto fail;
- ret = ec_
node_parse_child(node
->child, parse, childvec);
+ ret = ec_
parse_child(priv
->child, parse, childvec);
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
@@
-118,18
+117,18
@@
__ec_node_many_complete(struct ec_node_many *node, unsigned int max,
if ((unsigned int)ret != i) {
if (ret != EC_PARSE_NOMATCH)
if ((unsigned int)ret != i) {
if (ret != EC_PARSE_NOMATCH)
- ec_p
ars
e_del_last_child(parse);
+ ec_p
nod
e_del_last_child(parse);
continue;
}
childvec = ec_strvec_ndup(strvec, i, ec_strvec_len(strvec) - i);
if (childvec == NULL) {
continue;
}
childvec = ec_strvec_ndup(strvec, i, ec_strvec_len(strvec) - i);
if (childvec == NULL) {
- ec_p
ars
e_del_last_child(parse);
+ ec_p
nod
e_del_last_child(parse);
goto fail;
}
goto fail;
}
- ret = __ec_node_many_complete(
node
, max, comp, childvec);
- ec_p
ars
e_del_last_child(parse);
+ ret = __ec_node_many_complete(
priv
, max, comp, childvec);
+ ec_p
nod
e_del_last_child(parse);
ec_strvec_free(childvec);
childvec = NULL;
ec_strvec_free(childvec);
childvec = NULL;
@@
-145,43
+144,43
@@
fail:
}
static int
}
static int
-ec_node_many_complete(const struct ec_node *
gen_
node,
+ec_node_many_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_many *
node = (struct ec_node_many *)gen_node
;
+ struct ec_node_many *
priv = ec_node_priv(node)
;
- return __ec_node_many_complete(
node, node
->max, comp,
+ return __ec_node_many_complete(
priv, priv
->max, comp,
strvec);
}
strvec);
}
-static void ec_node_many_free_priv(struct ec_node *
gen_
node)
+static void ec_node_many_free_priv(struct ec_node *node)
{
{
- struct ec_node_many *
node = (struct ec_node_many *)gen_node
;
+ struct ec_node_many *
priv = ec_node_priv(node)
;
- ec_node_free(
node
->child);
+ ec_node_free(
priv
->child);
}
static size_t
}
static size_t
-ec_node_many_get_children_count(const struct ec_node *
gen_
node)
+ec_node_many_get_children_count(const struct ec_node *node)
{
{
- struct ec_node_many *
node = (struct ec_node_many *)gen_node
;
+ struct ec_node_many *
priv = ec_node_priv(node)
;
- if (
node
->child)
+ if (
priv
->child)
return 1;
return 0;
}
static int
return 1;
return 0;
}
static int
-ec_node_many_get_child(const struct ec_node *
gen_
node, size_t i,
+ec_node_many_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_many *
node = (struct ec_node_many *)gen_node
;
+ struct ec_node_many *
priv = ec_node_priv(node)
;
if (i >= 1)
return -1;
if (i >= 1)
return -1;
- *child =
node
->child;
+ *child =
priv
->child;
*refs = 2;
return 0;
}
*refs = 2;
return 0;
}
@@
-208,10
+207,10
@@
static const struct ec_config_schema ec_node_many_schema[] = {
},
};
},
};
-static int ec_node_many_set_config(struct ec_node *
gen_
node,
+static int ec_node_many_set_config(struct ec_node *node,
const struct ec_config *config)
{
const struct ec_config *config)
{
- struct ec_node_many *
node = (struct ec_node_many *)gen_node
;
+ struct ec_node_many *
priv = ec_node_priv(node)
;
const struct ec_config *child, *min, *max;
child = ec_config_dict_get(config, "child");
const struct ec_config *child, *min, *max;
child = ec_config_dict_get(config, "child");
@@
-234,17
+233,17
@@
static int ec_node_many_set_config(struct ec_node *gen_node,
goto fail;
}
goto fail;
}
- if (
node
->child != NULL)
- ec_node_free(
node
->child);
-
node
->child = ec_node_clone(child->node);
+ if (
priv
->child != NULL)
+ ec_node_free(
priv
->child);
+
priv
->child = ec_node_clone(child->node);
if (min == NULL)
if (min == NULL)
-
node
->min = 0;
+
priv
->min = 0;
else
else
-
node
->min = min->u64;
+
priv
->min = min->u64;
if (max == NULL)
if (max == NULL)
-
node
->max = 0;
+
priv
->max = 0;
else
else
-
node
->max = max->u64;
+
priv
->max = max->u64;
return 0;
return 0;
@@
-267,17
+266,17
@@
static struct ec_node_type ec_node_many_type = {
EC_NODE_TYPE_REGISTER(ec_node_many_type);
int
EC_NODE_TYPE_REGISTER(ec_node_many_type);
int
-ec_node_many_set_params(struct ec_node *
gen_
node, struct ec_node *child,
+ec_node_many_set_params(struct ec_node *node, struct ec_node *child,
unsigned int min, unsigned int max)
{
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL;
int ret;
unsigned int min, unsigned int max)
{
const struct ec_config *cur_config = NULL;
struct ec_config *config = NULL;
int ret;
- if (ec_node_check_type(
gen_
node, &ec_node_many_type) < 0)
+ if (ec_node_check_type(node, &ec_node_many_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
@@
-296,7
+295,7
@@
ec_node_many_set_params(struct ec_node *gen_node, struct ec_node *child,
if (ec_config_dict_set(config, "max", ec_config_u64(max)) < 0)
goto fail;
if (ec_config_dict_set(config, "max", ec_config_u64(max)) < 0)
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;
@@
-312,25
+311,25
@@
fail:
struct ec_node *ec_node_many(const char *id, struct ec_node *child,
unsigned int min, unsigned int max)
{
struct ec_node *ec_node_many(const char *id, struct ec_node *child,
unsigned int min, unsigned int max)
{
- struct ec_node *
gen_
node = NULL;
+ struct ec_node *node = NULL;
if (child == NULL)
return NULL;
if (child == NULL)
return NULL;
-
gen_
node = ec_node_from_type(&ec_node_many_type, id);
- if (
gen_
node == NULL)
+ node = ec_node_from_type(&ec_node_many_type, id);
+ if (node == NULL)
goto fail;
goto fail;
- if (ec_node_many_set_params(
gen_
node, child, min, max) < 0) {
+ if (ec_node_many_set_params(node, child, min, max) < 0) {
child = NULL;
goto fail;
}
child = NULL;
child = NULL;
goto fail;
}
child = NULL;
- return
gen_
node;
+ return node;
fail:
fail:
- ec_node_free(
gen_
node);
+ ec_node_free(node);
ec_node_free(child);
return NULL;
}
ec_node_free(child);
return NULL;
}
@@
-383,26
+382,26
@@
static int ec_node_many_testcase(void)
return -1;
}
testres |= EC_TEST_CHECK_COMPLETE(node,
return -1;
}
testres |= EC_TEST_CHECK_COMPLETE(node,
- "", EC_
NODE_ENDLIST
,
- "foo", EC_
NODE_ENDLIST
);
+ "", EC_
VA_END
,
+ "foo", 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,
- "foo", EC_
NODE_ENDLIST
,
- "foo", EC_
NODE_ENDLIST
);
+ "foo", EC_
VA_END
,
+ "foo", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "foo", "", EC_
NODE_ENDLIST
,
- "foo", EC_
NODE_ENDLIST
);
+ "foo", "", EC_
VA_END
,
+ "foo", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "foo", "foo", "", EC_
NODE_ENDLIST
,
- "foo", EC_
NODE_ENDLIST
);
+ "foo", "foo", "", EC_
VA_END
,
+ "foo", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "foo", "foo", "foo", "", EC_
NODE_ENDLIST
,
- "foo", EC_
NODE_ENDLIST
);
+ "foo", "foo", "foo", "", EC_
VA_END
,
+ "foo", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "foo", "foo", "foo", "foo", "", EC_
NODE_ENDLIST
,
- EC_
NODE_ENDLIST
);
+ "foo", "foo", "foo", "foo", "", EC_
VA_END
,
+ EC_
VA_END
);
ec_node_free(node);
return testres;
ec_node_free(node);
return testres;