From ec731385f1ed38a35e4e0df83e5ae4e8b8151df6 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Fri, 22 Feb 2019 18:30:57 +0100 Subject: [PATCH] yaml: set node attributes --- .../parse-yaml/parse-yaml.sh | 0 src/ecoli_yaml.c | 21 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) rename parse-yaml.sh => examples/parse-yaml/parse-yaml.sh (100%) diff --git a/parse-yaml.sh b/examples/parse-yaml/parse-yaml.sh similarity index 100% rename from parse-yaml.sh rename to examples/parse-yaml/parse-yaml.sh diff --git a/src/ecoli_yaml.c b/src/ecoli_yaml.c index 84007d5..8ac47eb 100644 --- a/src/ecoli_yaml.c +++ b/src/ecoli_yaml.c @@ -360,6 +360,7 @@ parse_ec_node(struct enode_table *table, const yaml_node_pair_t *pair; const char *key_str, *value_str; struct ec_node *enode = NULL; + char *value_dup = NULL; if (ynode->type != YAML_MAPPING_NODE) { fprintf(stderr, "Ecoli node should be a yaml mapping node\n"); @@ -468,7 +469,24 @@ parse_ec_node(struct enode_table *table, } /* add attributes (all as string) */ - //XXX + if (attrs != NULL) { + for (pair = attrs->data.mapping.pairs.start; + pair < attrs->data.mapping.pairs.top; pair++) { + key = document->nodes.start + pair->key - 1; + value = document->nodes.start + pair->value - 1; + key_str = (const char *)key->data.scalar.value; + value_str = (const char *)value->data.scalar.value; + value_dup = ec_strdup(value_str); + if (value_dup == NULL) + goto fail; + if (ec_keyval_set(ec_node_attrs(enode), key_str, + value_dup, ec_free_func) < 0) { + value_dup = NULL; + goto fail; + } + value_dup = NULL; + } + } return enode; @@ -476,6 +494,7 @@ fail: ec_node_free(enode); ec_config_free(config); ec_free(help); + ec_free(value_dup); return NULL; } -- 2.20.1