diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2014-11-13 10:11:46 -0800 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2014-11-13 10:11:46 -0800 |
commit | 3c9bdf645958a1c5b71cc9b96a5b711cca14224f (patch) | |
tree | cd9bb05022d69a017fe8adf63fc8d5f2d5d4480c | |
parent | e5fd42248067b4e8f29a9c2ed9d224ded4526c24 (diff) |
Moved cmark_free_inlines from inlines to ast.
-rw-r--r-- | src/ast.c | 53 | ||||
-rw-r--r-- | src/ast.h | 3 | ||||
-rw-r--r-- | src/inlines.c | 53 | ||||
-rw-r--r-- | src/inlines.h | 2 |
4 files changed, 55 insertions, 56 deletions
@@ -2,7 +2,6 @@ #include <stdio.h> #include "buffer.h" #include "ast.h" -#include "inlines.h" #include "references.h" // Free a node_block list and any children. @@ -28,3 +27,55 @@ void cmark_free_blocks(node_block *e) } } +// Utility function used by free_inlines +static void splice_into_list(node_inl* e, node_inl* children) { + node_inl * tmp; + if (children) { + tmp = children; + // Find last child + while (tmp->next) { + tmp = tmp->next; + } + // Splice children into list + tmp->next = e->next; + e->next = children; + } + return ; +} + +// Free an inline list. Avoid recursion to prevent stack overflows +// on deeply nested structures. +extern void free_inlines(node_inl* e) +{ + node_inl * next; + + while (e != NULL) { + switch (e->tag){ + case INL_STRING: + case INL_RAW_HTML: + case INL_CODE: + chunk_free(&e->content.literal); + break; + case INL_LINEBREAK: + case INL_SOFTBREAK: + break; + case INL_LINK: + case INL_IMAGE: + free(e->content.linkable.url); + free(e->content.linkable.title); + splice_into_list(e, e->content.linkable.label); + break; + case INL_EMPH: + case INL_STRONG: + splice_into_list(e, e->content.inlines); + break; + default: + fprintf(stderr, "[WARN] (%s:%d) Unknown inline tag %d", + __FILE__, __LINE__, e->tag); + break; + } + next = e->next; + free(e); + e = next; + } +} @@ -102,6 +102,7 @@ struct cmark_node_block { typedef struct cmark_node_block cmark_node_block; void cmark_free_blocks(cmark_node_block *e); +void cmark_free_inlines(cmark_node_inl *e); #ifndef CMARK_NO_SHORT_NAMES #define node_inl cmark_node_inl @@ -129,6 +130,8 @@ void cmark_free_blocks(cmark_node_block *e); #define BLOCK_SETEXT_HEADER CMARK_BLOCK_SETEXT_HEADER #define BLOCK_HRULE CMARK_BLOCK_HRULE #define BLOCK_REFERENCE_DEF CMARK_BLOCK_REFERENCE_DEF + #define free_inlines cmark_free_inlines + #define free_blocks cmark_free_blocks #endif #endif diff --git a/src/inlines.c b/src/inlines.c index 6a4e70c..a8756ff 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -111,59 +111,6 @@ inline static node_inl* make_simple(int t) #define make_emph(contents) make_inlines(INL_EMPH, contents) #define make_strong(contents) make_inlines(INL_STRONG, contents) -// Utility function used by free_inlines -static void splice_into_list(node_inl* e, node_inl* children) { - node_inl * tmp; - if (children) { - tmp = children; - // Find last child - while (tmp->next) { - tmp = tmp->next; - } - // Splice children into list - tmp->next = e->next; - e->next = children; - } - return ; -} - -// Free an inline list. Avoid recursion to prevent stack overflows -// on deeply nested structures. -extern void free_inlines(node_inl* e) -{ - node_inl * next; - - while (e != NULL) { - switch (e->tag){ - case INL_STRING: - case INL_RAW_HTML: - case INL_CODE: - chunk_free(&e->content.literal); - break; - case INL_LINEBREAK: - case INL_SOFTBREAK: - break; - case INL_LINK: - case INL_IMAGE: - free(e->content.linkable.url); - free(e->content.linkable.title); - splice_into_list(e, e->content.linkable.label); - break; - case INL_EMPH: - case INL_STRONG: - splice_into_list(e, e->content.inlines); - break; - default: - fprintf(stderr, "[WARN] (%s:%d) Unknown inline tag %d", - __FILE__, __LINE__, e->tag); - break; - } - next = e->next; - free(e); - e = next; - } -} - // Append inline list b to the end of inline list a. // Return pointer to head of new list. inline static node_inl* append_inlines(node_inl* a, node_inl* b) diff --git a/src/inlines.h b/src/inlines.h index 6b3d4d4..fa61c8a 100644 --- a/src/inlines.h +++ b/src/inlines.h @@ -6,7 +6,6 @@ unsigned char *cmark_clean_autolink(cmark_chunk *url, int is_email); unsigned char *cmark_clean_title(cmark_chunk *title); cmark_node_inl* cmark_parse_inlines(cmark_strbuf *input, cmark_reference_map *refmap); -void cmark_free_inlines(cmark_node_inl* e); int cmark_parse_reference_inline(cmark_strbuf *input, cmark_reference_map *refmap); @@ -15,7 +14,6 @@ int cmark_parse_reference_inline(cmark_strbuf *input, cmark_reference_map *refma #define clean_autolink cmark_clean_autolink #define clean_title cmark_clean_title #define parse_inlines cmark_parse_inlines - #define free_inlines cmark_free_inlines #define parse_reference_inline cmark_parse_reference_inline #endif |