diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-18 00:12:27 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-11-17 21:43:47 -0800 |
commit | 59fd5633da5395cbd3627af4a2ab855dc43ce1e0 (patch) | |
tree | 89da7422572556dc2ac911a78889431f14db107b /src/node.c | |
parent | c38944d4565b6266b3ab1fd6fd576710fdec420b (diff) |
Set prev, parent and last_child for inlines
Diffstat (limited to 'src/node.c')
-rw-r--r-- | src/node.c | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -249,6 +249,64 @@ static void splice_into_list(cmark_node* e, cmark_node* children) { return ; } +int +cmark_node_check(cmark_node *node) { + cmark_node *cur = node; + int errors = 0; + + while (cur) { + if (cur->first_child) { + if (cur->first_child->parent != cur) { + fprintf(stderr, + "Invalid 'parent' in node type %d\n", + cur->first_child->type); + cur->first_child->parent = cur; + ++errors; + } + cur = cur->first_child; + } + else if (cur->next) { + if (cur->next->prev != cur) { + fprintf(stderr, + "Invalid 'prev' in node type %d\n", + cur->next->type); + cur->next->prev = cur; + ++errors; + } + if (cur->next->parent != cur->parent) { + fprintf(stderr, + "Invalid 'parent' in node type %d\n", + cur->next->type); + cur->next->parent = cur->parent; + ++errors; + } + cur = cur->next; + } + else { + if (cur->parent->last_child != cur) { + fprintf(stderr, + "Invalid 'last_child' in node type %d\n", + cur->parent->type); + cur->parent->last_child = cur; + ++errors; + } + + cmark_node *ancestor = cur->parent; + cur = NULL; + + while (ancestor != node->parent) { + if (ancestor->next) { + cur = ancestor->next; + break; + } + ancestor = ancestor->parent; + } + } + } + + return errors; +} + // Free a cmark_node list and any children. void cmark_free_nodes(cmark_node *e) { |