/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2016, Olivier MATZ <zer0@droids-corp.org>
+ * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
*/
#include <stdio.h>
#include <ecoli_test.h>
#include <ecoli_strvec.h>
#include <ecoli_node.h>
-#include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_parse.h>
+#include <ecoli_complete.h>
#include <ecoli_node_str.h>
EC_LOG_TYPE_REGISTER(node_str);
static int
ec_node_str_parse(const struct ec_node *gen_node,
- struct ec_parsed *state,
+ struct ec_parse *state,
const struct ec_strvec *strvec)
{
struct ec_node_str *node = (struct ec_node_str *)gen_node;
(void)state;
if (ec_strvec_len(strvec) == 0)
- return EC_PARSED_NOMATCH;
+ return EC_PARSE_NOMATCH;
str = ec_strvec_val(strvec, 0);
if (strcmp(str, node->string) != 0)
- return EC_PARSED_NOMATCH;
+ return EC_PARSE_NOMATCH;
return 1;
}
static int
ec_node_str_complete(const struct ec_node *gen_node,
- struct ec_completed *completed,
+ struct ec_comp *comp,
const struct ec_strvec *strvec)
{
struct ec_node_str *node = (struct ec_node_str *)gen_node;
/* no completion */
if (str[n] != '\0')
- return EC_PARSED_NOMATCH;
+ return EC_PARSE_NOMATCH;
- if (ec_completed_add_item(completed, gen_node, NULL, EC_COMP_FULL,
+ if (ec_comp_add_item(comp, gen_node, NULL, EC_COMP_FULL,
str, node->string) < 0)
return -1;
int ec_node_str_set_str(struct ec_node *gen_node, const char *str)
{
struct ec_node_str *node = (struct ec_node_str *)gen_node;
+ char *s = NULL;
int ret;
ret = ec_node_check_type(gen_node, &ec_node_str_type);
if (ret < 0)
return ret;
- if (str == NULL)
- return -EINVAL;
- ec_free(node->string);
- node->string = ec_strdup(str);
- if (node->string == NULL)
- return -ENOMEM;
+ if (str == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+ s = ec_strdup(str);
+ if (s == NULL)
+ return -1;
+
+ ec_free(node->string);
+ node->string = s;
node->len = strlen(node->string);
return 0;