MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / yaml_document_initialize

Function yaml_document_initialize

xs/tools/yaml/api.c:1055–1136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1053 */
1054
1055YAML_DECLARE(int)
1056yaml_document_initialize(yaml_document_t *document,
1057 yaml_version_directive_t *version_directive,
1058 yaml_tag_directive_t *tag_directives_start,
1059 yaml_tag_directive_t *tag_directives_end,
1060 int start_implicit, int end_implicit)
1061{
1062 struct {
1063 yaml_error_type_t error;
1064 } context;
1065 struct {
1066 yaml_node_t *start;
1067 yaml_node_t *end;
1068 yaml_node_t *top;
1069 } nodes = { NULL, NULL, NULL };
1070 yaml_version_directive_t *version_directive_copy = NULL;
1071 struct {
1072 yaml_tag_directive_t *start;
1073 yaml_tag_directive_t *end;
1074 yaml_tag_directive_t *top;
1075 } tag_directives_copy = { NULL, NULL, NULL };
1076 yaml_tag_directive_t value = { NULL, NULL };
1077 yaml_mark_t mark = { 0, 0, 0 };
1078
1079 assert(document); /* Non-NULL document object is expected. */
1080 assert((tag_directives_start && tag_directives_end) ||
1081 (tag_directives_start == tag_directives_end));
1082 /* Valid tag directives are expected. */
1083
1084 if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error;
1085
1086 if (version_directive) {
1087 version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t));
1088 if (!version_directive_copy) goto error;
1089 version_directive_copy->major = version_directive->major;
1090 version_directive_copy->minor = version_directive->minor;
1091 }
1092
1093 if (tag_directives_start != tag_directives_end) {
1094 yaml_tag_directive_t *tag_directive;
1095 if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE))
1096 goto error;
1097 for (tag_directive = tag_directives_start;
1098 tag_directive != tag_directives_end; tag_directive ++) {
1099 assert(tag_directive->handle);
1100 assert(tag_directive->prefix);
1101 if (!yaml_check_utf8(tag_directive->handle,
1102 strlen((char *)tag_directive->handle)))
1103 goto error;
1104 if (!yaml_check_utf8(tag_directive->prefix,
1105 strlen((char *)tag_directive->prefix)))
1106 goto error;
1107 value.handle = yaml_strdup(tag_directive->handle);
1108 value.prefix = yaml_strdup(tag_directive->prefix);
1109 if (!value.handle || !value.prefix) goto error;
1110 if (!PUSH(&context, tag_directives_copy, value))
1111 goto error;
1112 value.handle = NULL;

Callers

nothing calls this directly

Calls 5

yaml_mallocFunction · 0.85
yaml_check_utf8Function · 0.85
yaml_strdupFunction · 0.85
yaml_freeFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected