*
* LGPL HEADER END
*
- * Copyright (c) 2013, Intel Corporation.
+ * Copyright (c) 2014, 2015, Intel Corporation.
*
* Author:
* Amir Shehata <amir.shehata@intel.com>
#include <float.h>
#include <limits.h>
#include <ctype.h>
-#include "libcfs/list.h"
+#include "libcfs/util/list.h"
#include "cyaml.h"
#define INDENT 4
[YAML_SCALAR_TOKEN] = yaml_scalar,
};
+/* dispatch table */
+static char *token_type_string[] = {
+ [YAML_NO_TOKEN] = "YAML_NO_TOKEN",
+ [YAML_STREAM_START_TOKEN] = "YAML_STREAM_START_TOKEN",
+ [YAML_STREAM_END_TOKEN] = "YAML_STREAM_END_TOKEN",
+ [YAML_VERSION_DIRECTIVE_TOKEN] = "YAML_VERSION_DIRECTIVE_TOKEN",
+ [YAML_TAG_DIRECTIVE_TOKEN] = "YAML_TAG_DIRECTIVE_TOKEN",
+ [YAML_DOCUMENT_START_TOKEN] = "YAML_DOCUMENT_START_TOKEN",
+ [YAML_DOCUMENT_END_TOKEN] = "YAML_DOCUMENT_END_TOKEN",
+ [YAML_BLOCK_SEQUENCE_START_TOKEN] = "YAML_BLOCK_SEQUENCE_START_TOKEN",
+ [YAML_BLOCK_MAPPING_START_TOKEN] = "YAML_BLOCK_MAPPING_START_TOKEN",
+ [YAML_BLOCK_END_TOKEN] = "YAML_BLOCK_END_TOKEN",
+ [YAML_FLOW_SEQUENCE_START_TOKEN] = "YAML_FLOW_SEQUENCE_START_TOKEN",
+ [YAML_FLOW_SEQUENCE_END_TOKEN] = "YAML_FLOW_SEQUENCE_END_TOKEN",
+ [YAML_FLOW_MAPPING_START_TOKEN] = "YAML_FLOW_MAPPING_START_TOKEN",
+ [YAML_FLOW_MAPPING_END_TOKEN] = "YAML_FLOW_MAPPING_END_TOKEN",
+ [YAML_BLOCK_ENTRY_TOKEN] = "YAML_BLOCK_ENTRY_TOKEN",
+ [YAML_FLOW_ENTRY_TOKEN] = "YAML_FLOW_ENTRY_TOKEN",
+ [YAML_KEY_TOKEN] = "YAML_KEY_TOKEN",
+ [YAML_VALUE_TOKEN] = "YAML_VALUE_TOKEN",
+ [YAML_ALIAS_TOKEN] = "YAML_ALIAS_TOKEN",
+ [YAML_ANCHOR_TOKEN] = "YAML_ANCHOR_TOKEN",
+ [YAML_TAG_TOKEN] = "YAML_TAG_TOKEN",
+ [YAML_SCALAR_TOKEN] = "YAML_SCALAR_TOKEN",
+};
+
static void cYAML_ll_free(struct list_head *ll)
{
struct cYAML_ll *node, *tmp;
static enum cYAML_handler_error yaml_stream_end(yaml_token_t *token,
struct cYAML_tree_node *tree)
{
- if (tree->state != TREE_STATE_TREE_STARTED)
+ if (tree->state != TREE_STATE_TREE_STARTED &&
+ tree->state != TREE_STATE_COMPLETE)
return CYAML_ERROR_UNEXPECTED_STATE;
tree->state = TREE_STATE_INITED;
struct cYAML_print_info *cpi = NULL;
struct cYAML *node = cYAML_ll_pop(stack, &cpi);
+ if (node == NULL)
+ return;
+
switch (node->cy_type) {
case CYAML_TYPE_FALSE:
case CYAML_TYPE_TRUE:
goto failed;
if (seq_no >= 0 &&
- cYAML_create_number(err, "seqno", seq_no) == NULL)
+ cYAML_create_number(err, "seq_no", seq_no) == NULL)
goto failed;
if (cYAML_create_number(err, "errno", rc) == NULL)
return;
failed:
+ /* Only reason we get here is if we run out of memory */
cYAML_free_tree(r);
r = NULL;
+ fprintf(stderr, "error:\n\tfatal: out of memory\n");
}
struct cYAML *cYAML_build_tree(char *yaml_file,
const char *yaml_blk,
size_t yaml_blk_size,
- struct cYAML **err_rc)
+ struct cYAML **err_rc,
+ bool debug)
{
yaml_parser_t parser;
yaml_token_t token;
/* Create the Parser object. */
yaml_parser_initialize(&parser);
- /* file alwyas takes precedence */
+ /* file always takes precedence */
if (yaml_file != NULL) {
/* Set a file input. */
input = fopen(yaml_file, "rb");
*/
yaml_parser_scan(&parser, &token);
+ if (debug)
+ fprintf(stderr, "token.type = %s: %s\n",
+ token_type_string[token.type],
+ (token.type == YAML_SCALAR_TOKEN) ?
+ (char*)token.data.scalar.value : "");
rc = dispatch_tbl[token.type](&token, &tree);
if (rc != CYAML_ERROR_NONE) {
snprintf(err_str, sizeof(err_str),