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
[protos/libecoli.git]
/
src
/
ecoli_node_subset.c
diff --git
a/src/ecoli_node_subset.c
b/src/ecoli_node_subset.c
index
e3184ef
..
eddef84
100644
(file)
--- a/
src/ecoli_node_subset.c
+++ b/
src/ecoli_node_subset.c
@@
-24,7
+24,6
@@
EC_LOG_TYPE_REGISTER(node_subset);
struct ec_node_subset {
EC_LOG_TYPE_REGISTER(node_subset);
struct ec_node_subset {
- struct ec_node gen;
struct ec_node **table;
unsigned int len;
};
struct ec_node **table;
unsigned int len;
};
@@
-38,14
+37,14
@@
struct parse_result {
* updated accordingly. */
static int
__ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
* updated accordingly. */
static int
__ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
- size_t table_len, struct ec_p
ars
e *state,
+ size_t table_len, struct ec_p
nod
e *state,
const struct ec_strvec *strvec)
{
struct ec_node **child_table;
struct ec_strvec *childvec = NULL;
size_t i, j, len = 0;
struct parse_result best_result, result;
const struct ec_strvec *strvec)
{
struct ec_node **child_table;
struct ec_strvec *childvec = NULL;
size_t i, j, len = 0;
struct parse_result best_result, result;
- struct ec_p
ars
e *best_parse = NULL;
+ struct ec_p
nod
e *best_parse = NULL;
int ret;
if (table_len == 0)
int ret;
if (table_len == 0)
@@
-59,7
+58,7
@@
__ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
for (i = 0; i < table_len; i++) {
/* try to parse elt i */
for (i = 0; i < table_len; i++) {
/* try to parse elt i */
- ret = ec_
node_
parse_child(table[i], state, strvec);
+ ret = ec_parse_child(table[i], state, strvec);
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
@@
-92,14
+91,14
@@
__ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
/* if result is not the best, ignore */
if (result.parse_len < best_result.parse_len) {
memset(&result, 0, sizeof(result));
/* if result is not the best, ignore */
if (result.parse_len < best_result.parse_len) {
memset(&result, 0, sizeof(result));
- ec_p
ars
e_del_last_child(state);
+ ec_p
nod
e_del_last_child(state);
continue;
}
/* replace the previous best result */
continue;
}
/* replace the previous best result */
- ec_p
ars
e_free(best_parse);
- best_parse = ec_p
ars
e_get_last_child(state);
- ec_p
ars
e_unlink_child(state, best_parse);
+ ec_p
nod
e_free(best_parse);
+ best_parse = ec_p
nod
e_get_last_child(state);
+ ec_p
nod
e_unlink_child(state, best_parse);
best_result.parse_len = result.parse_len + 1;
best_result.len = len + result.len;
best_result.parse_len = result.parse_len + 1;
best_result.len = len + result.len;
@@
-110,31
+109,31
@@
__ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
*out = best_result;
ec_free(child_table);
if (best_parse != NULL)
*out = best_result;
ec_free(child_table);
if (best_parse != NULL)
- ec_p
ars
e_link_child(state, best_parse);
+ ec_p
nod
e_link_child(state, best_parse);
return 0;
fail:
return 0;
fail:
- ec_p
ars
e_free(best_parse);
+ ec_p
nod
e_free(best_parse);
ec_strvec_free(childvec);
ec_free(child_table);
return -1;
}
static int
ec_strvec_free(childvec);
ec_free(child_table);
return -1;
}
static int
-ec_node_subset_parse(const struct ec_node *
gen_
node,
- struct ec_p
ars
e *state,
+ec_node_subset_parse(const struct ec_node *node,
+ struct ec_p
nod
e *state,
const struct ec_strvec *strvec)
{
const struct ec_strvec *strvec)
{
- struct ec_node_subset *
node = (struct ec_node_subset *)gen_node
;
- struct ec_p
ars
e *parse = NULL;
+ struct ec_node_subset *
priv = ec_node_priv(node)
;
+ struct ec_p
nod
e *parse = NULL;
struct parse_result result;
int ret;
memset(&result, 0, sizeof(result));
struct parse_result result;
int ret;
memset(&result, 0, sizeof(result));
- ret = __ec_node_subset_parse(&result,
node
->table,
-
node
->len, state, strvec);
+ ret = __ec_node_subset_parse(&result,
priv
->table,
+
priv
->len, state, strvec);
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
@@
-145,7
+144,7
@@
ec_node_subset_parse(const struct ec_node *gen_node,
return result.len;
fail:
return result.len;
fail:
- ec_p
ars
e_free(parse);
+ ec_p
nod
e_free(parse);
return ret;
}
return ret;
}
@@
-154,7
+153,7
@@
__ec_node_subset_complete(struct ec_node **table, size_t table_len,
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_p
ars
e *parse = ec_comp_get_state(comp);
+ struct ec_p
nod
e *parse = ec_comp_get_state(comp);
struct ec_strvec *childvec = NULL;
struct ec_node *save;
size_t i, len;
struct ec_strvec *childvec = NULL;
struct ec_node *save;
size_t i, len;
@@
-174,7
+173,7
@@
__ec_node_subset_complete(struct ec_node **table, size_t table_len,
if (table[i] == NULL)
continue;
if (table[i] == NULL)
continue;
- ret = ec_
node_
complete_child(table[i],
+ ret = ec_complete_child(table[i],
comp, strvec);
if (ret < 0)
goto fail;
comp, strvec);
if (ret < 0)
goto fail;
@@
-186,7
+185,7
@@
__ec_node_subset_complete(struct ec_node **table, size_t table_len,
if (table[i] == NULL)
continue;
if (table[i] == NULL)
continue;
- ret = ec_
node_
parse_child(table[i], parse, strvec);
+ ret = ec_parse_child(table[i], parse, strvec);
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
@@
-197,7
+196,7
@@
__ec_node_subset_complete(struct ec_node **table, size_t table_len,
childvec = ec_strvec_ndup(strvec, len,
ec_strvec_len(strvec) - len);
if (childvec == NULL) {
childvec = ec_strvec_ndup(strvec, len,
ec_strvec_len(strvec) - len);
if (childvec == NULL) {
- ec_p
ars
e_del_last_child(parse);
+ ec_p
nod
e_del_last_child(parse);
goto fail;
}
goto fail;
}
@@
-208,7
+207,7
@@
__ec_node_subset_complete(struct ec_node **table, size_t table_len,
table[i] = save;
ec_strvec_free(childvec);
childvec = NULL;
table[i] = save;
ec_strvec_free(childvec);
childvec = NULL;
- ec_p
ars
e_del_last_child(parse);
+ ec_p
nod
e_del_last_child(parse);
if (ret < 0)
goto fail;
if (ret < 0)
goto fail;
@@
-221,43
+220,43
@@
fail:
}
static int
}
static int
-ec_node_subset_complete(const struct ec_node *
gen_
node,
+ec_node_subset_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_subset *
node = (struct ec_node_subset *)gen_node
;
+ struct ec_node_subset *
priv = ec_node_priv(node)
;
- return __ec_node_subset_complete(
node->table, node
->len, comp,
+ return __ec_node_subset_complete(
priv->table, priv
->len, comp,
strvec);
}
strvec);
}
-static void ec_node_subset_free_priv(struct ec_node *
gen_
node)
+static void ec_node_subset_free_priv(struct ec_node *node)
{
{
- struct ec_node_subset *
node = (struct ec_node_subset *)gen_node
;
+ struct ec_node_subset *
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);
+ for (i = 0; i <
priv
->len; i++)
+ ec_node_free(
priv
->table[i]);
+ ec_free(
priv
->table);
}
static size_t
}
static size_t
-ec_node_subset_get_children_count(const struct ec_node *
gen_
node)
+ec_node_subset_get_children_count(const struct ec_node *node)
{
{
- struct ec_node_subset *
node = (struct ec_node_subset *)gen_node
;
- return
node
->len;
+ struct ec_node_subset *
priv = ec_node_priv(node)
;
+ return
priv
->len;
}
static int
}
static int
-ec_node_subset_get_child(const struct ec_node *
gen_
node, size_t i,
+ec_node_subset_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_subset *
node = (struct ec_node_subset *)gen_node
;
+ struct ec_node_subset *
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];
*refs = 1;
return 0;
}
*refs = 1;
return 0;
}
@@
-274,9
+273,9
@@
static struct ec_node_type ec_node_subset_type = {
EC_NODE_TYPE_REGISTER(ec_node_subset_type);
EC_NODE_TYPE_REGISTER(ec_node_subset_type);
-int ec_node_subset_add(struct ec_node *
gen_
node, struct ec_node *child)
+int ec_node_subset_add(struct ec_node *node, struct ec_node *child)
{
{
- struct ec_node_subset *
node = (struct ec_node_subset *)gen_node
;
+ struct ec_node_subset *
priv = ec_node_priv(node)
;
struct ec_node **table;
assert(node != NULL); // XXX specific assert for it, like in libyang
struct ec_node **table;
assert(node != NULL); // XXX specific assert for it, like in libyang
@@
-286,18
+285,18
@@
int ec_node_subset_add(struct ec_node *gen_node, struct ec_node *child)
goto fail;
}
goto fail;
}
- if (ec_node_check_type(
gen_
node, &ec_node_subset_type) < 0)
+ if (ec_node_check_type(node, &ec_node_subset_type) < 0)
goto fail;
goto fail;
- table = ec_realloc(
node->table, (node->len + 1) * sizeof(*node
->table));
+ table = ec_realloc(
priv->table, (priv->len + 1) * sizeof(*priv
->table));
if (table == NULL) {
ec_node_free(child);
return -1;
}
if (table == NULL) {
ec_node_free(child);
return -1;
}
-
node
->table = table;
- table[
node
->len] = child;
-
node
->len++;
+
priv
->table = table;
+ table[
priv
->len] = child;
+
priv
->len++;
return 0;
return 0;
@@
-308,26
+307,24
@@
fail:
struct ec_node *__ec_node_subset(const char *id, ...)
{
struct ec_node *__ec_node_subset(const char *id, ...)
{
- struct ec_node *gen_node = NULL;
- struct ec_node_subset *node = NULL;
+ struct ec_node *node = NULL;
struct ec_node *child;
va_list ap;
int fail = 0;
va_start(ap, id);
struct ec_node *child;
va_list ap;
int fail = 0;
va_start(ap, id);
- gen_node = ec_node_from_type(&ec_node_subset_type, id);
- node = (struct ec_node_subset *)gen_node;
+ node = ec_node_from_type(&ec_node_subset_type, id);
if (node == NULL)
fail = 1;;
for (child = va_arg(ap, struct ec_node *);
if (node == NULL)
fail = 1;;
for (child = va_arg(ap, struct ec_node *);
- child != EC_
NODE_ENDLIST
;
+ child != EC_
VA_END
;
child = va_arg(ap, struct ec_node *)) {
/* on error, don't quit the loop to avoid leaks */
if (fail == 1 || child == NULL ||
child = va_arg(ap, struct ec_node *)) {
/* on error, don't quit the loop to avoid leaks */
if (fail == 1 || child == NULL ||
- ec_node_subset_add(
gen_
node, child) < 0) {
+ ec_node_subset_add(node, child) < 0) {
fail = 1;
ec_node_free(child);
}
fail = 1;
ec_node_free(child);
}
@@
-337,10
+334,10
@@
struct ec_node *__ec_node_subset(const char *id, ...)
goto fail;
va_end(ap);
goto fail;
va_end(ap);
- return
gen_
node;
+ return node;
fail:
fail:
- ec_node_free(
gen_
node); /* will also free children */
+ ec_node_free(node); /* will also free children */
va_end(ap);
return NULL;
}
va_end(ap);
return NULL;
}
@@
-387,35
+384,35
@@
static int ec_node_subset_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,
- "", EC_
NODE_ENDLIST
,
- "bar2", "bar", "foo", "toto", "titi", EC_
NODE_ENDLIST
);
+ "", EC_
VA_END
,
+ "bar2", "bar", "foo", "toto", "titi", EC_
VA_END
);
testres |= EC_TEST_CHECK_COMPLETE(node,
testres |= EC_TEST_CHECK_COMPLETE(node,
- "bar", "bar2", "", EC_
NODE_ENDLIST
,
- "foo", "toto", "titi", EC_
NODE_ENDLIST
);
+ "bar", "bar2", "", EC_
VA_END
,
+ "foo", "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,
- "bar", "b", EC_
NODE_ENDLIST
,
- "bar2", EC_
NODE_ENDLIST
);
+ "bar", "b", EC_
VA_END
,
+ "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;