+// SPDX-License-Identifier: LGPL-2.0
+
/*
- * LGPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of the
- * License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * LGPL HEADER END
- *
* Copyright (c) 2014, 2017, Intel Corporation.
- *
- * Author:
- * Amir Shehata <amir.shehata@intel.com>
*/
/*
+ * This file is part of Lustre, http://www.lustre.org/
+ *
* The cYAML tree is constructed as an n-tree.
* root -> cmd 1
* ||
* ||
* \/
* attr2.1 -> attr2.1.1 -> attr2.1.2
+ *
+ * Author: Amir Shehata <amir.shehata@intel.com>
*/
#include <yaml.h>
struct cYAML *obj = NULL;
if (!list_empty(list)) {
- pop = list_entry(list->next, struct cYAML_ll, list);
+ pop = list_first_entry(list, struct cYAML_ll, list);
obj = pop->obj;
if (print_info != NULL)
int subscale = 0, signsubscale = 1;
const char *num = input;
+ if (!strncmp(input, "0x", 2)) {
+ int64_t hex; /* hex input is always an integer */
+ char *invalid = NULL;
+
+ errno = 0;
+ hex = strtoll(input, &invalid, 16);
+ if (errno)
+ return false;
+ if (*invalid)
+ return false;
+
+ item->cy_valuedouble = (double) hex;
+ item->cy_valueint = hex;
+ item->cy_type = CYAML_TYPE_NUMBER;
+ return true;
+ }
+
if (*num == '-') {
sign = -1;
num++;
return (node != NULL ? node->cy_type == CYAML_TYPE_ARRAY : 0);
}
-void cYAML_tree_recursive_walk(struct cYAML *node, cYAML_walk_cb cb,
+static void cYAML_tree_recursive_walk(struct cYAML *node, cYAML_walk_cb cb,
bool cb_first,
void *usr_data,
void **out)
char *entity, char *err_str,
struct cYAML **root)
{
- struct cYAML *r = NULL, *err, *s, *itm, *cmd_obj;
+ struct cYAML *r = NULL, *err, *s, *itm = NULL, *cmd_obj;
if (root == NULL)
return;
else if (cmd_obj == NULL) {
s = cYAML_create_seq(r, cmd);
itm = cYAML_create_seq_item(s);
- } else if (cmd_obj != NULL && cmd_obj->cy_type != CYAML_TYPE_ARRAY)
+ } else if (cmd_obj != NULL && cmd_obj->cy_type != CYAML_TYPE_ARRAY) {
goto failed;
+ }
err = cYAML_create_object(itm, entity);
if (err == NULL)
bool debug)
{
yaml_parser_t parser;
- struct cYAML *yaml;
+ struct cYAML *yaml = NULL;
char err_str[256];
FILE *input = NULL;
/* Create the Parser object. */
- yaml_parser_initialize(&parser);
+ if (yaml_parser_initialize(&parser) == 0)
+ goto out_init;
/* file always takes precedence */
if (path != NULL) {
if (input != NULL)
fclose(input);
-
+out_init:
return yaml;
}