MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / yaml_sequence_analyze

Function yaml_sequence_analyze

src/cli/config_yaml_edit.c:2965–3012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2963}
2964
2965static int yaml_sequence_analyze(const yaml_doc_t *doc, const char *const *sequence_path,
2966 const size_t *path_lengths, size_t sequence_path_len,
2967 const char *identity_key, const char *identity_value,
2968 yaml_mapping_sequence_target_t *target) {
2969 memset(target, 0, sizeof(*target));
2970 if (yaml_sequence_validate_document(doc, sequence_path[0], path_lengths[0]) != 0) {
2971 return YAML_ERROR;
2972 }
2973 size_t parent_begin = 0U;
2974 size_t parent_end = doc->line_count;
2975 for (size_t depth = 0U; depth < sequence_path_len; depth++) {
2976 if (depth > SIZE_MAX / YAML_ENTRY_INDENT) {
2977 return YAML_ERROR;
2978 }
2979 size_t indent = depth * YAML_ENTRY_INDENT;
2980 if (yaml_sequence_validate_mapping_range(doc, parent_begin, parent_end, indent) != 0) {
2981 return YAML_ERROR;
2982 }
2983 bool found = false;
2984 size_t key_line = 0U;
2985 size_t colon = 0U;
2986 if (yaml_sequence_find_key(doc, parent_begin, parent_end, indent, sequence_path[depth],
2987 path_lengths[depth], &found, &key_line, &colon) != 0) {
2988 return YAML_ERROR;
2989 }
2990 if (!found) {
2991 target->missing_index = depth;
2992 target->insert_offset = yaml_sequence_line_offset(doc, parent_end);
2993 return 0;
2994 }
2995 const yaml_line_t *header = &doc->lines[key_line];
2996 if (!yaml_tail_is_empty(doc->data, colon, header->text_end)) {
2997 return YAML_ERROR;
2998 }
2999 size_t child_end = yaml_sequence_nested_end(doc, key_line, parent_end);
3000 if (depth + YAML_UNIT == sequence_path_len) {
3001 target->sequence_found = true;
3002 target->missing_index = sequence_path_len;
3003 target->insert_offset = yaml_sequence_line_offset(doc, child_end);
3004 return yaml_sequence_parse_block(doc, key_line + YAML_UNIT, child_end,
3005 indent + YAML_ENTRY_INDENT, identity_key,
3006 identity_value, target);
3007 }
3008 parent_begin = key_line + YAML_UNIT;
3009 parent_end = child_end;
3010 }
3011 return YAML_ERROR;
3012}
3013
3014static int yaml_sequence_append_spaces(yaml_buf_t *out, size_t count) {
3015 static const char spaces[] = " ";

Tested by

no test coverage detected