From 1b6afb7654d29eced20de720d7b5d37fb861bad3 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 5 Jan 2015 16:45:38 -0800 Subject: Reformatted code consistently with astyle. --- src/blocks.c | 233 +++++++++++++++--------------- src/buffer.c | 14 +- src/buffer.h | 2 +- src/cmark.h | 46 +++--- src/cmark_ctype.c | 35 ++--- src/houdini_href_e.c | 8 +- src/houdini_html_e.c | 14 +- src/html.c | 36 +++-- src/inlines.c | 144 +++++++++---------- src/main.c | 16 +-- src/man.c | 14 +- src/node.c | 185 ++++++++++++++---------- src/references.c | 2 +- src/utf8.c | 396 +++++++++++++++++++++++++-------------------------- src/xml.c | 34 ++--- 15 files changed, 605 insertions(+), 574 deletions(-) diff --git a/src/blocks.c b/src/blocks.c index 6a89312..315ddff 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -20,11 +20,11 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer, size_t len, - bool eof); + bool eof); static void S_process_line(cmark_parser *parser, const unsigned char *buffer, - size_t bytes); + size_t bytes); static cmark_node* make_block(cmark_node_type tag, int start_line, int start_column) { @@ -88,13 +88,13 @@ static bool is_blank(cmark_strbuf *s, int offset) { while (offset < s->size) { switch (s->ptr[offset]) { - case '\n': - return true; - case ' ': - offset++; - break; - default: - return false; + case '\n': + return true; + case ' ': + offset++; + break; + default: + return false; } } @@ -104,16 +104,16 @@ static bool is_blank(cmark_strbuf *s, int offset) static inline bool can_contain(cmark_node_type parent_type, cmark_node_type child_type) { return ( parent_type == NODE_DOCUMENT || - parent_type == NODE_BLOCK_QUOTE || - parent_type == NODE_ITEM || - (parent_type == NODE_LIST && child_type == NODE_ITEM) ); + parent_type == NODE_BLOCK_QUOTE || + parent_type == NODE_ITEM || + (parent_type == NODE_LIST && child_type == NODE_ITEM) ); } static inline bool accepts_lines(cmark_node_type block_type) { return (block_type == NODE_PARAGRAPH || - block_type == NODE_HEADER || - block_type == NODE_CODE_BLOCK); + block_type == NODE_HEADER || + block_type == NODE_CODE_BLOCK); } static void add_line(cmark_node* cmark_node, cmark_chunk *ch, int offset) @@ -199,96 +199,96 @@ finalize(cmark_parser *parser, cmark_node* b) b->end_line = parser->line_number; b->end_column = parser->last_line_length; } else if (b->type == NODE_DOCUMENT || - (b->type == NODE_CODE_BLOCK && b->as.code.fenced) || - (b->type == NODE_HEADER && b->as.header.setext)) { + (b->type == NODE_CODE_BLOCK && b->as.code.fenced) || + (b->type == NODE_HEADER && b->as.header.setext)) { b->end_line = parser->line_number; b->end_column = parser->curline->size - - (parser->curline->ptr[parser->curline->size - 1] == '\n' ? - 1 : 0); + (parser->curline->ptr[parser->curline->size - 1] == '\n' ? + 1 : 0); } else { b->end_line = parser->line_number - 1; b->end_column = parser->last_line_length; } switch (b->type) { - case NODE_PARAGRAPH: - while (cmark_strbuf_at(&b->string_content, 0) == '[' && - (pos = cmark_parse_reference_inline(&b->string_content, parser->refmap))) { + case NODE_PARAGRAPH: + while (cmark_strbuf_at(&b->string_content, 0) == '[' && + (pos = cmark_parse_reference_inline(&b->string_content, parser->refmap))) { - cmark_strbuf_drop(&b->string_content, pos); - } - if (is_blank(&b->string_content, 0)) { - // remove blank node (former reference def) - cmark_node_free(b); - } - break; + cmark_strbuf_drop(&b->string_content, pos); + } + if (is_blank(&b->string_content, 0)) { + // remove blank node (former reference def) + cmark_node_free(b); + } + break; - case NODE_CODE_BLOCK: - if (!b->as.code.fenced) { // indented code - remove_trailing_blank_lines(&b->string_content); - cmark_strbuf_putc(&b->string_content, '\n'); - } else { + case NODE_CODE_BLOCK: + if (!b->as.code.fenced) { // indented code + remove_trailing_blank_lines(&b->string_content); + cmark_strbuf_putc(&b->string_content, '\n'); + } else { - // first line of contents becomes info - firstlinelen = cmark_strbuf_strchr(&b->string_content, '\n', 0); + // first line of contents becomes info + firstlinelen = cmark_strbuf_strchr(&b->string_content, '\n', 0); - cmark_strbuf tmp = GH_BUF_INIT; - houdini_unescape_html_f( - &tmp, - b->string_content.ptr, - firstlinelen - ); - cmark_strbuf_trim(&tmp); - cmark_strbuf_unescape(&tmp); - b->as.code.info = cmark_chunk_buf_detach(&tmp); + cmark_strbuf tmp = GH_BUF_INIT; + houdini_unescape_html_f( + &tmp, + b->string_content.ptr, + firstlinelen + ); + cmark_strbuf_trim(&tmp); + cmark_strbuf_unescape(&tmp); + b->as.code.info = cmark_chunk_buf_detach(&tmp); - cmark_strbuf_drop(&b->string_content, firstlinelen + 1); - } - b->as.code.literal = cmark_chunk_buf_detach(&b->string_content); - break; + cmark_strbuf_drop(&b->string_content, firstlinelen + 1); + } + b->as.code.literal = cmark_chunk_buf_detach(&b->string_content); + break; - case NODE_HTML: - b->as.literal = cmark_chunk_buf_detach(&b->string_content); - break; + case NODE_HTML: + b->as.literal = cmark_chunk_buf_detach(&b->string_content); + break; - case NODE_LIST: // determine tight/loose status - b->as.list.tight = true; // tight by default - item = b->first_child; + case NODE_LIST: // determine tight/loose status + b->as.list.tight = true; // tight by default + item = b->first_child; - while (item) { - // check for non-final non-empty list item ending with blank line: - if (item->last_line_blank && item->next) { + while (item) { + // check for non-final non-empty list item ending with blank line: + if (item->last_line_blank && item->next) { + b->as.list.tight = false; + break; + } + // recurse into children of list item, to see if there are + // spaces between them: + subitem = item->first_child; + while (subitem) { + if (ends_with_blank_line(subitem) && + (item->next || subitem->next)) { b->as.list.tight = false; break; } - // recurse into children of list item, to see if there are - // spaces between them: - subitem = item->first_child; - while (subitem) { - if (ends_with_blank_line(subitem) && - (item->next || subitem->next)) { - b->as.list.tight = false; - break; - } - subitem = subitem->next; - } - if (!(b->as.list.tight)) { - break; - } - item = item->next; + subitem = subitem->next; } + if (!(b->as.list.tight)) { + break; + } + item = item->next; + } - break; + break; - default: - break; + default: + break; } return parent; } // Add a cmark_node as child of another. Return pointer to child. static cmark_node* add_child(cmark_parser *parser, cmark_node* parent, - cmark_node_type block_type, int start_column) + cmark_node_type block_type, int start_column) { assert(parent); @@ -403,9 +403,9 @@ static int parse_list_marker(cmark_chunk *input, int pos, cmark_list **dataptr) static int lists_match(cmark_list *list_data, cmark_list *item_data) { return (list_data->list_type == item_data->list_type && - list_data->delimiter == item_data->delimiter && - // list_data->marker_offset == item_data.marker_offset && - list_data->bullet_char == item_data->bullet_char); + list_data->delimiter == item_data->delimiter && + // list_data->marker_offset == item_data.marker_offset && + list_data->bullet_char == item_data->bullet_char); } static cmark_node *finalize_document(cmark_parser *parser) @@ -460,23 +460,21 @@ cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len) static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer, size_t len, - bool eof) + bool eof) { const unsigned char *end = buffer + len; while (buffer < end) { const unsigned char *eol - = (const unsigned char *)memchr(buffer, '\n', - end - buffer); + = (const unsigned char *)memchr(buffer, '\n', + end - buffer); size_t line_len; if (eol) { line_len = eol + 1 - buffer; - } - else if (eof) { + } else if (eof) { line_len = end - buffer; - } - else { + } else { cmark_strbuf_put(parser->linebuf, buffer, end - buffer); break; } @@ -484,10 +482,9 @@ S_parser_feed(cmark_parser *parser, const unsigned char *buffer, size_t len, if (parser->linebuf->size > 0) { cmark_strbuf_put(parser->linebuf, buffer, line_len); S_process_line(parser, parser->linebuf->ptr, - parser->linebuf->size); + parser->linebuf->size); cmark_strbuf_clear(parser->linebuf); - } - else { + } else { S_process_line(parser, buffer, line_len); } @@ -572,9 +569,9 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) } else if (container->type == NODE_ITEM) { if (indent >= container->as.list.marker_offset + - container->as.list.padding) { + container->as.list.padding) { offset += container->as.list.marker_offset + - container->as.list.padding; + container->as.list.padding; } else if (blank) { offset = first_nonspace; } else { @@ -639,7 +636,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) // unless last matched container is code cmark_node, try new container starts: while (container->type != NODE_CODE_BLOCK && - container->type != NODE_HTML) { + container->type != NODE_HTML) { first_nonspace = offset; while (peek_at(&input, first_nonspace) == ' ') @@ -700,10 +697,10 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) // note, we don't adjust offset because the tag is part of the text } else if (container->type == NODE_PARAGRAPH && - (lev = scan_setext_header_line(&input, first_nonspace)) && - // check that there is only one line in the paragraph: - cmark_strbuf_strrchr(&container->string_content, '\n', - cmark_strbuf_len(&container->string_content) - 2) < 0) { + (lev = scan_setext_header_line(&input, first_nonspace)) && + // check that there is only one line in the paragraph: + cmark_strbuf_strrchr(&container->string_content, '\n', + cmark_strbuf_len(&container->string_content) - 2) < 0) { container->type = NODE_HEADER; container->as.header.level = lev; @@ -711,7 +708,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) offset = input.len - 1; } else if (!(container->type == NODE_PARAGRAPH && !all_matched) && - (matched = scan_hrule(&input, first_nonspace))) { + (matched = scan_hrule(&input, first_nonspace))) { // it's only now that we know the line is not part of a setext header: container = add_child(parser, container, NODE_HRULE, first_nonspace + 1); @@ -743,16 +740,16 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) data->marker_offset = indent; if (container->type != NODE_LIST || - !lists_match(&container->as.list, data)) { + !lists_match(&container->as.list, data)) { container = add_child(parser, container, NODE_LIST, - first_nonspace + 1); + first_nonspace + 1); memcpy(&container->as.list, data, sizeof(*data)); } // add the list item container = add_child(parser, container, NODE_ITEM, - first_nonspace + 1); + first_nonspace + 1); /* TODO: static */ memcpy(&container->as.list, data, sizeof(*data)); free(data); @@ -781,13 +778,13 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) // lists or breaking out of lists. we also don't set last_line_blank // on an empty list item. container->last_line_blank = (blank && - container->type != NODE_BLOCK_QUOTE && - container->type != NODE_HEADER && - !(container->type == NODE_CODE_BLOCK && - container->as.code.fenced) && - !(container->type == NODE_ITEM && - container->first_child == NULL && - container->start_line == parser->line_number)); + container->type != NODE_BLOCK_QUOTE && + container->type != NODE_HEADER && + !(container->type == NODE_CODE_BLOCK && + container->as.code.fenced) && + !(container->type == NODE_ITEM && + container->first_child == NULL && + container->start_line == parser->line_number)); cmark_node *cont = container; while (cont->parent) { @@ -796,10 +793,10 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) } if (cur != last_matched_container && - container == last_matched_container && - !blank && - cur->type == NODE_PARAGRAPH && - cmark_strbuf_len(&cur->string_content) > 0) { + container == last_matched_container && + !blank && + cur->type == NODE_PARAGRAPH && + cmark_strbuf_len(&cur->string_content) > 0) { add_line(cur, &input, offset); @@ -817,11 +814,11 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) add_line(container, &input, offset); } else if (container->type == NODE_CODE_BLOCK && - container->as.code.fenced) { + container->as.code.fenced) { matched = 0; if (indent <= 3 && - peek_at(&input, first_nonspace) == container->as.code.fence_char) { + peek_at(&input, first_nonspace) == container->as.code.fence_char) { int fence_len = scan_close_code_fence(&input, first_nonspace); if (fence_len > container->as.code.fence_length) matched = 1; @@ -853,7 +850,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) add_line(container, &input, first_nonspace); } else if (container->type != NODE_HRULE && - container->type != NODE_HEADER) { + container->type != NODE_HEADER) { // create paragraph container for line container = add_child(parser, container, NODE_PARAGRAPH, first_nonspace + 1); @@ -866,9 +863,9 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) parser->current = container; } parser->last_line_length = parser->curline->size - - (parser->curline->ptr[parser->curline->size - 1] == '\n' ? - 1 : 0); -; + (parser->curline->ptr[parser->curline->size - 1] == '\n' ? + 1 : 0); + ; cmark_strbuf_clear(parser->curline); } @@ -877,7 +874,7 @@ cmark_node *cmark_parser_finish(cmark_parser *parser) { if (parser->linebuf->size) { S_process_line(parser, parser->linebuf->ptr, - parser->linebuf->size); + parser->linebuf->size); cmark_strbuf_clear(parser->linebuf); } diff --git a/src/buffer.c b/src/buffer.c index 87d817b..0df6561 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -130,8 +130,8 @@ int cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, int len) int cmark_strbuf_sets(cmark_strbuf *buf, const char *string) { return cmark_strbuf_set(buf, - (const unsigned char *)string, - string ? strlen(string) : 0); + (const unsigned char *)string, + string ? strlen(string) : 0); } int cmark_strbuf_putc(cmark_strbuf *buf, int c) @@ -171,10 +171,10 @@ int cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap) va_copy(args, ap); len = vsnprintf( - (char *)buf->ptr + buf->size, - buf->asize - buf->size, - format, args - ); + (char *)buf->ptr + buf->size, + buf->asize - buf->size, + format, args + ); va_end(args); @@ -265,7 +265,7 @@ int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b) { int result = memcmp(a->ptr, b->ptr, MIN(a->size, b->size)); return (result != 0) ? result : - (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0; + (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0; } int cmark_strbuf_strchr(const cmark_strbuf *buf, int c, int pos) diff --git a/src/buffer.h b/src/buffer.h index 875cf8c..fb9f910 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -93,7 +93,7 @@ int cmark_strbuf_putc(cmark_strbuf *buf, int c); int cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, int len); int cmark_strbuf_puts(cmark_strbuf *buf, const char *string); int cmark_strbuf_printf(cmark_strbuf *buf, const char *format, ...) - CMARK_ATTRIBUTE((format (printf, 2, 3))); +CMARK_ATTRIBUTE((format (printf, 2, 3))); int cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap); void cmark_strbuf_clear(cmark_strbuf *buf); diff --git a/src/cmark.h b/src/cmark.h index da81de6..2051a04 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -447,29 +447,29 @@ char *cmark_render_man(cmark_node *root, long options); */ #ifndef CMARK_NO_SHORT_NAMES - #define NODE_DOCUMENT CMARK_NODE_DOCUMENT - #define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE - #define NODE_LIST CMARK_NODE_LIST - #define NODE_ITEM CMARK_NODE_ITEM - #define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK - #define NODE_HTML CMARK_NODE_HTML - #define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH - #define NODE_HEADER CMARK_NODE_HEADER - #define NODE_HRULE CMARK_NODE_HRULE - #define NODE_TEXT CMARK_NODE_TEXT - #define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK - #define NODE_LINEBREAK CMARK_NODE_LINEBREAK - #define NODE_CODE CMARK_NODE_CODE - #define NODE_INLINE_HTML CMARK_NODE_INLINE_HTML - #define NODE_EMPH CMARK_NODE_EMPH - #define NODE_STRONG CMARK_NODE_STRONG - #define NODE_LINK CMARK_NODE_LINK - #define NODE_IMAGE CMARK_NODE_IMAGE - #define NODE_LINK_LABEL CMARK_NODE_LINK_LABEL - #define BULLET_LIST CMARK_BULLET_LIST - #define ORDERED_LIST CMARK_ORDERED_LIST - #define PERIOD_DELIM CMARK_PERIOD_DELIM - #define PAREN_DELIM CMARK_PAREN_DELIM +#define NODE_DOCUMENT CMARK_NODE_DOCUMENT +#define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE +#define NODE_LIST CMARK_NODE_LIST +#define NODE_ITEM CMARK_NODE_ITEM +#define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK +#define NODE_HTML CMARK_NODE_HTML +#define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH +#define NODE_HEADER CMARK_NODE_HEADER +#define NODE_HRULE CMARK_NODE_HRULE +#define NODE_TEXT CMARK_NODE_TEXT +#define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK +#define NODE_LINEBREAK CMARK_NODE_LINEBREAK +#define NODE_CODE CMARK_NODE_CODE +#define NODE_INLINE_HTML CMARK_NODE_INLINE_HTML +#define NODE_EMPH CMARK_NODE_EMPH +#define NODE_STRONG CMARK_NODE_STRONG +#define NODE_LINK CMARK_NODE_LINK +#define NODE_IMAGE CMARK_NODE_IMAGE +#define NODE_LINK_LABEL CMARK_NODE_LINK_LABEL +#define BULLET_LIST CMARK_BULLET_LIST +#define ORDERED_LIST CMARK_ORDERED_LIST +#define PERIOD_DELIM CMARK_PERIOD_DELIM +#define PAREN_DELIM CMARK_PAREN_DELIM #endif #ifdef __cplusplus diff --git a/src/cmark_ctype.c b/src/cmark_ctype.c index a3871a8..5de8199 100644 --- a/src/cmark_ctype.c +++ b/src/cmark_ctype.c @@ -5,23 +5,24 @@ /** 1 = space, 2 = punct, 3 = digit, 4 = alpha, 0 = other */ static const int8_t cmark_ctype_class[256] = { -/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ -/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, -/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 2 */ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -/* 3 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, -/* 4 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, -/* 5 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, -/* 6 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, -/* 7 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0, -/* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* c */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* d */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* e */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ + /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, + /* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 2 */ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + /* 3 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, + /* 4 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + /* 5 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, + /* 6 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + /* 7 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0, + /* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* c */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* d */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* e */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; /** * Returns 1 if c is a "whitespace" character as defined by the spec. diff --git a/src/houdini_href_e.c b/src/houdini_href_e.c index c8949d4..7527780 100644 --- a/src/houdini_href_e.c +++ b/src/houdini_href_e.c @@ -83,10 +83,10 @@ houdini_escape_href(cmark_strbuf *ob, const uint8_t *src, size_t size) cmark_strbuf_puts(ob, "'"); break; - /* the space can be escaped to %20 or a plus - * sign. we're going with the generic escape - * for now. the plus thing is more commonly seen - * when building GET strings */ + /* the space can be escaped to %20 or a plus + * sign. we're going with the generic escape + * for now. the plus thing is more commonly seen + * when building GET strings */ #if 0 case ' ': cmark_strbuf_putc(ob, '+'); diff --git a/src/houdini_html_e.c b/src/houdini_html_e.c index 4e523f5..1a4c3e1 100644 --- a/src/houdini_html_e.c +++ b/src/houdini_html_e.c @@ -35,13 +35,13 @@ static const char HTML_ESCAPE_TABLE[] = { }; static const char *HTML_ESCAPES[] = { - "", - """, - "&", - "'", - "/", - "<", - ">" + "", + """, + "&", + "'", + "/", + "<", + ">" }; int diff --git a/src/html.c b/src/html.c index bb04458..abc3e83 100644 --- a/src/html.c +++ b/src/html.c @@ -39,19 +39,20 @@ struct render_state { }; static void -S_render_sourcepos(cmark_node *node, cmark_strbuf *html, long options) { +S_render_sourcepos(cmark_node *node, cmark_strbuf *html, long options) +{ if (CMARK_OPT_SOURCEPOS & options) { cmark_strbuf_printf(html, " data-sourcepos=\"%d:%d-%d:%d\"", - cmark_node_get_start_line(node), - cmark_node_get_start_column(node), - cmark_node_get_end_line(node), - cmark_node_get_end_column(node)); + cmark_node_get_start_line(node), + cmark_node_get_start_column(node), + cmark_node_get_end_line(node), + cmark_node_get_end_column(node)); } } static int S_render_node(cmark_node *node, cmark_event_type ev_type, - struct render_state *state, long options) + struct render_state *state, long options) { cmark_node *parent; cmark_node *grandparent; @@ -72,7 +73,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_CODE: case CMARK_NODE_INLINE_HTML: escape_html(html, node->as.literal.data, - node->as.literal.len); + node->as.literal.len); break; case CMARK_NODE_LINEBREAK: @@ -112,23 +113,21 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, cmark_strbuf_puts(html, "\n"); - } - else if (start == 1) { + } else if (start == 1) { cmark_strbuf_puts(html, "\n"); - } - else { + } else { cmark_strbuf_printf(html, - "
    \n"); } } else { cmark_strbuf_puts(html, - list_type == CMARK_BULLET_LIST ? - "\n" : "
\n"); + list_type == CMARK_BULLET_LIST ? + "\n" : "\n"); } break; } @@ -165,8 +164,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, cmark_strbuf_puts(html, ""); - } - else { + } else { int first_tag = 0; while (first_tag < node->as.code.info.len && node->as.code.info.data[first_tag] != ' ') { @@ -181,7 +179,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, } escape_html(html, node->as.code.literal.data, - node->as.code.literal.len); + node->as.code.literal.len); cmark_strbuf_puts(html, "\n"); break; @@ -220,7 +218,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_TEXT: escape_html(html, node->as.literal.data, - node->as.literal.len); + node->as.literal.len); break; case CMARK_NODE_LINEBREAK: diff --git a/src/inlines.c b/src/inlines.c index 6bed132..2487f63 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -47,7 +47,7 @@ S_insert_emph(subject *subj, delimiter *opener, delimiter *closer); static int parse_inline(subject* subj, cmark_node * parent); static void subject_from_buf(subject *e, cmark_strbuf *buffer, - cmark_reference_map *refmap); + cmark_reference_map *refmap); static int subject_find_special_char(subject *subj); static unsigned char *cmark_clean_autolink(cmark_chunk *url, int is_email) @@ -72,11 +72,11 @@ static inline cmark_node *make_link(cmark_node *label, unsigned char *url, unsig if(e != NULL) { e->type = CMARK_NODE_LINK; e->first_child = label; - e->last_child = label; + e->last_child = label; e->as.link.url = url; e->as.link.title = title; e->next = NULL; - label->parent = e; + label->parent = e; } return e; } @@ -94,14 +94,14 @@ static inline cmark_node* make_literal(cmark_node_type t, cmark_chunk s) e->type = t; e->as.literal = s; e->next = NULL; - e->prev = NULL; - e->parent = NULL; - e->first_child = NULL; - e->last_child = NULL; - // These fields aren't used for inlines: - e->start_line = 0; - e->start_column = 0; - e->end_line = 0; + e->prev = NULL; + e->parent = NULL; + e->first_child = NULL; + e->last_child = NULL; + // These fields aren't used for inlines: + e->start_line = 0; + e->start_column = 0; + e->end_line = 0; } return e; } @@ -113,14 +113,14 @@ static inline cmark_node* make_simple(cmark_node_type t) if(e != NULL) { e->type = t; e->next = NULL; - e->prev = NULL; - e->parent = NULL; - e->first_child = NULL; - e->last_child = NULL; - // These fields aren't used for inlines: - e->start_line = 0; - e->start_column = 0; - e->end_line = 0; + e->prev = NULL; + e->parent = NULL; + e->first_child = NULL; + e->last_child = NULL; + // These fields aren't used for inlines: + e->start_line = 0; + e->start_column = 0; + e->end_line = 0; } return e; } @@ -141,7 +141,7 @@ static unsigned char *bufdup(const unsigned char *buf) } static void subject_from_buf(subject *e, cmark_strbuf *buffer, - cmark_reference_map *refmap) + cmark_reference_map *refmap) { e->input.data = buffer->ptr; e->input.len = buffer->size; @@ -212,7 +212,7 @@ static int scan_to_closing_backticks(subject* subj, int openticklength) advance(subj); numticks++; } - if (numticks != openticklength){ + if (numticks != openticklength) { return(scan_to_closing_backticks(subj, openticklength)); } return (subj->pos); @@ -261,7 +261,7 @@ scan_delims(subject* subj, unsigned char c, bool * can_open, bool * can_close) before_char_pos -= 1; } len = utf8proc_iterate(subj->input.data + before_char_pos, - subj->pos - before_char_pos, &before_char); + subj->pos - before_char_pos, &before_char); if (len == -1) { before_char = 10; } @@ -273,23 +273,23 @@ scan_delims(subject* subj, unsigned char c, bool * can_open, bool * can_close) } len = utf8proc_iterate(subj->input.data + subj->pos, - subj->input.len - subj->pos, &after_char); + subj->input.len - subj->pos, &after_char); if (len == -1) { after_char = 10; } *can_open = numdelims > 0 && !utf8proc_is_space(after_char) && - !(utf8proc_is_punctuation(after_char) && - !utf8proc_is_space(before_char) && - !utf8proc_is_punctuation(before_char)); + !(utf8proc_is_punctuation(after_char) && + !utf8proc_is_space(before_char) && + !utf8proc_is_punctuation(before_char)); *can_close = numdelims > 0 && !utf8proc_is_space(before_char) && - !(utf8proc_is_punctuation(before_char) && - !utf8proc_is_space(after_char) && - !utf8proc_is_punctuation(after_char)); + !(utf8proc_is_punctuation(before_char) && + !utf8proc_is_space(after_char) && + !utf8proc_is_punctuation(after_char)); if (c == '_') { *can_open = *can_open && !(before_char < 128 && - cmark_isalnum((char)before_char)); + cmark_isalnum((char)before_char)); *can_close = *can_close && !(before_char < 128 && - cmark_isalnum((char)after_char)); + cmark_isalnum((char)after_char)); } return numdelims; } @@ -326,10 +326,10 @@ static void remove_delimiter(subject *subj, delimiter *delim) } static void push_delimiter(subject *subj, unsigned char c, bool can_open, - bool can_close, cmark_node *inl_text) + bool can_close, cmark_node *inl_text) { delimiter *delim = - (delimiter*)malloc(sizeof(delimiter)); + (delimiter*)malloc(sizeof(delimiter)); if (delim == NULL) { return; } @@ -418,7 +418,7 @@ S_insert_emph(subject *subj, delimiter *opener, delimiter *closer) // calculate the actual number of characters used from this closer if (closer_num_chars < 3 || opener_num_chars < 3) { use_delims = closer_num_chars <= opener_num_chars ? - closer_num_chars : opener_num_chars; + closer_num_chars : opener_num_chars; } else { // closer and opener both have >= 3 characters use_delims = closer_num_chars % 2 == 0 ? 2 : 1; } @@ -448,8 +448,7 @@ S_insert_emph(subject *subj, delimiter *opener, delimiter *closer) emph->type = use_delims == 1 ? NODE_EMPH : NODE_STRONG; // remove opener from list remove_delimiter(subj, opener); - } - else { + } else { // create new emph or strong, and splice it in to our inlines // between the opener and closer emph = use_delims == 1 ? make_emph() : make_strong(); @@ -510,9 +509,9 @@ static cmark_node* handle_entity(subject* subj) advance(subj); len = houdini_unescape_ent(&ent, - subj->input.data + subj->pos, - subj->input.len - subj->pos - ); + subj->input.data + subj->pos, + subj->input.len - subj->pos + ); if (len == 0) return make_str(cmark_chunk_literal("&")); @@ -557,26 +556,26 @@ unsigned char *cmark_clean_url(cmark_chunk *url) unsigned char *cmark_clean_title(cmark_chunk *title) { - cmark_strbuf buf = GH_BUF_INIT; - unsigned char first, last; - - if (title->len == 0) - return NULL; - - first = title->data[0]; - last = title->data[title->len - 1]; - - // remove surrounding quotes if any: - if ((first == '\'' && last == '\'') || - (first == '(' && last == ')') || - (first == '"' && last == '"')) { - houdini_unescape_html_f(&buf, title->data + 1, title->len - 2); - } else { - houdini_unescape_html_f(&buf, title->data, title->len); - } - - cmark_strbuf_unescape(&buf); - return cmark_strbuf_detach(&buf); + cmark_strbuf buf = GH_BUF_INIT; + unsigned char first, last; + + if (title->len == 0) + return NULL; + + first = title->data[0]; + last = title->data[title->len - 1]; + + // remove surrounding quotes if any: + if ((first == '\'' && last == '\'') || + (first == '(' && last == ')') || + (first == '"' && last == '"')) { + houdini_unescape_html_f(&buf, title->data + 1, title->len - 2); + } else { + houdini_unescape_html_f(&buf, title->data, title->len); + } + + cmark_strbuf_unescape(&buf); + return cmark_strbuf_detach(&buf); } // Parse an autolink or HTML tag. @@ -595,9 +594,9 @@ static cmark_node* handle_pointy_brace(subject* subj) subj->pos += matchlen; return make_autolink( - make_str_with_entities(&contents), - contents, 0 - ); + make_str_with_entities(&contents), + contents, 0 + ); } // next try to match an email autolink @@ -607,9 +606,9 @@ static cmark_node* handle_pointy_brace(subject* subj) subj->pos += matchlen; return make_autolink( - make_str_with_entities(&contents), - contents, 1 - ); + make_str_with_entities(&contents), + contents, 1 + ); } // finally, try to match an html tag @@ -664,7 +663,7 @@ static int link_label(subject* subj, cmark_chunk *raw_label) return 1; } - noMatch: +noMatch: subj->pos = startpos; // rewind return 0; @@ -727,7 +726,7 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent) // ensure there are spaces btw url and title endtitle = (starttitle == endurl) ? starttitle : - starttitle + scan_link_title(&subj->input, starttitle); + starttitle + scan_link_title(&subj->input, starttitle); endall = endtitle + scan_spacechars(&subj->input, endtitle); @@ -755,7 +754,7 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent) if (!found_label || raw_label.len == 0) { cmark_chunk_free(&raw_label); raw_label = cmark_chunk_dup(&subj->input, opener->position, - initial_pos - opener->position - 1); + initial_pos - opener->position - 1); } if (!found_label) { @@ -803,7 +802,7 @@ match: // process_emphasis will remove this delimiter and all later ones. // Now, if we have a link, we also want to deactivate earlier link - // delimiters. (This code can be removed if we decide to allow links + // delimiters. (This code can be removed if we decide to allow links // inside links.) if (!is_image) { opener = subj->last_delim; @@ -861,7 +860,8 @@ static int subject_find_special_char(subject *subj) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; int n = subj->pos + 1; @@ -886,7 +886,7 @@ static int parse_inline(subject* subj, cmark_node * parent) if (c == 0) { return 0; } - switch(c){ + switch(c) { case '\n': new_inl = handle_newline(subj); break; @@ -960,7 +960,7 @@ static void spnl(subject* subj) bool seen_newline = false; while (peek_char(subj) == ' ' || (!seen_newline && - (seen_newline = peek_char(subj) == '\n'))) { + (seen_newline = peek_char(subj) == '\n'))) { advance(subj); } } diff --git a/src/main.c b/src/main.c index e849b82..eaef246 100644 --- a/src/main.c +++ b/src/main.c @@ -8,8 +8,8 @@ #include "bench.h" #if defined(_WIN32) && !defined(__CYGWIN__) - #include - #include +#include +#include #endif typedef enum { @@ -31,7 +31,7 @@ void print_usage() } static void print_document(cmark_node *document, writer_format writer, - long options) + long options) { char *result; switch (writer) { @@ -80,11 +80,11 @@ int main(int argc, char *argv[]) } else if (strcmp(argv[i], "--hardbreaks") == 0) { options |= CMARK_OPT_HARDBREAKS; } else if ((strcmp(argv[i], "--help") == 0) || - (strcmp(argv[i], "-h") == 0)) { + (strcmp(argv[i], "-h") == 0)) { print_usage(); exit(0); } else if ((strcmp(argv[i], "-t") == 0) || - (strcmp(argv[i], "--to") == 0)) { + (strcmp(argv[i], "--to") == 0)) { i += 1; if (i < argc) { if (strcmp(argv[i], "man") == 0) { @@ -95,12 +95,12 @@ int main(int argc, char *argv[]) writer = FORMAT_XML; } else { fprintf(stderr, - "Unknown format %s\n", argv[i]); + "Unknown format %s\n", argv[i]); exit(1); } } else { fprintf(stderr, "No argument provided for %s\n", - argv[i - 1]); + argv[i - 1]); exit(1); } } else if (*argv[i] == '-') { @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) FILE *fp = fopen(argv[files[i]], "r"); if (fp == NULL) { fprintf(stderr, "Error opening file %s: %s\n", - argv[files[i]], strerror(errno)); + argv[files[i]], strerror(errno)); exit(1); } diff --git a/src/man.c b/src/man.c index 176081f..2c8a3a5 100644 --- a/src/man.c +++ b/src/man.c @@ -44,7 +44,7 @@ struct render_state { static int S_render_node(cmark_node *node, cmark_event_type ev_type, - struct render_state *state) + struct render_state *state) { cmark_node *tmp; cmark_strbuf *man = state->man; @@ -60,7 +60,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_TEXT: case CMARK_NODE_CODE: escape_man(man, node->as.literal.data, - node->as.literal.len); + node->as.literal.len); break; case CMARK_NODE_LINEBREAK: @@ -119,8 +119,8 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, if (entering) { cr(man); cmark_strbuf_puts(man, - cmark_node_get_header_level(node) == 1 ? - ".SH" : ".SS"); + cmark_node_get_header_level(node) == 1 ? + ".SH" : ".SS"); cr(man); } else { cr(man); @@ -131,7 +131,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, cr(man); cmark_strbuf_puts(man, ".IP\n.nf\n\\f[C]\n"); escape_man(man, node->as.code.literal.data, - node->as.code.literal.len); + node->as.code.literal.len); cr(man); cmark_strbuf_puts(man, "\\f[]\n.fi"); cr(man); @@ -164,7 +164,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_TEXT: escape_man(man, node->as.literal.data, - node->as.literal.len); + node->as.literal.len); break; case CMARK_NODE_LINEBREAK: @@ -204,7 +204,7 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_LINK: if (!entering) { cmark_strbuf_printf(man, " (%s)", - cmark_node_get_url(node)); + cmark_node_get_url(node)); } break; diff --git a/src/node.c b/src/node.c index 199dd38..3785a27 100644 --- a/src/node.c +++ b/src/node.c @@ -8,7 +8,8 @@ static void S_node_unlink(cmark_node *node); cmark_node* -cmark_node_new(cmark_node_type type) { +cmark_node_new(cmark_node_type type) +{ cmark_node *node = (cmark_node *)calloc(1, sizeof(*node)); node->type = type; @@ -39,7 +40,7 @@ void S_free_nodes(cmark_node *e) cmark_node *next; while (e != NULL) { cmark_strbuf_free(&e->string_content); - switch (e->type){ + switch (e->type) { case NODE_CODE_BLOCK: cmark_chunk_free(&e->as.code.info); cmark_chunk_free(&e->as.code.literal); @@ -70,7 +71,8 @@ void S_free_nodes(cmark_node *e) } void -cmark_node_free(cmark_node *node) { +cmark_node_free(cmark_node *node) +{ S_node_unlink(node); node->next = NULL; S_free_nodes(node); @@ -94,25 +96,44 @@ cmark_node_get_type_string(cmark_node *node) } switch (node->type) { - case CMARK_NODE_NONE: return "none"; - case CMARK_NODE_DOCUMENT: return "document"; - case CMARK_NODE_BLOCK_QUOTE: return "block_quote"; - case CMARK_NODE_LIST: return "list"; - case CMARK_NODE_ITEM: return "item"; - case CMARK_NODE_CODE_BLOCK: return "code_block"; - case CMARK_NODE_HTML: return "html"; - case CMARK_NODE_PARAGRAPH: return "paragraph"; - case CMARK_NODE_HEADER: return "header"; - case CMARK_NODE_HRULE: return "hrule"; - case CMARK_NODE_TEXT: return "text"; - case CMARK_NODE_SOFTBREAK: return "softbreak"; - case CMARK_NODE_LINEBREAK: return "linebreak"; - case CMARK_NODE_CODE: return "code"; - case CMARK_NODE_INLINE_HTML: return "inline_html"; - case CMARK_NODE_EMPH: return "emph"; - case CMARK_NODE_STRONG: return "strong"; - case CMARK_NODE_LINK: return "link"; - case CMARK_NODE_IMAGE: return "image"; + case CMARK_NODE_NONE: + return "none"; + case CMARK_NODE_DOCUMENT: + return "document"; + case CMARK_NODE_BLOCK_QUOTE: + return "block_quote"; + case CMARK_NODE_LIST: + return "list"; + case CMARK_NODE_ITEM: + return "item"; + case CMARK_NODE_CODE_BLOCK: + return "code_block"; + case CMARK_NODE_HTML: + return "html"; + case CMARK_NODE_PARAGRAPH: + return "paragraph"; + case CMARK_NODE_HEADER: + return "header"; + case CMARK_NODE_HRULE: + return "hrule"; + case CMARK_NODE_TEXT: + return "text"; + case CMARK_NODE_SOFTBREAK: + return "softbreak"; + case CMARK_NODE_LINEBREAK: + return "linebreak"; + case CMARK_NODE_CODE: + return "code"; + case CMARK_NODE_INLINE_HTML: + return "inline_html"; + case CMARK_NODE_EMPH: + return "emph"; + case CMARK_NODE_STRONG: + return "strong"; + case CMARK_NODE_LINK: + return "link"; + case CMARK_NODE_IMAGE: + return "image"; } return ""; @@ -169,7 +190,8 @@ cmark_node_last_child(cmark_node *node) } static char* -S_strdup(const char *str) { +S_strdup(const char *str) +{ size_t size = strlen(str) + 1; char *dup = (char *)malloc(size); memcpy(dup, str, size); @@ -177,7 +199,8 @@ S_strdup(const char *str) { } const char* -cmark_node_get_literal(cmark_node *node) { +cmark_node_get_literal(cmark_node *node) +{ if (node == NULL) { return NULL; } @@ -200,7 +223,8 @@ cmark_node_get_literal(cmark_node *node) { } int -cmark_node_set_literal(cmark_node *node, const char *content) { +cmark_node_set_literal(cmark_node *node, const char *content) +{ if (node == NULL) { return 0; } @@ -225,7 +249,8 @@ cmark_node_set_literal(cmark_node *node, const char *content) { } int -cmark_node_get_header_level(cmark_node *node) { +cmark_node_get_header_level(cmark_node *node) +{ if (node == NULL) { return 0; } @@ -242,7 +267,8 @@ cmark_node_get_header_level(cmark_node *node) { } int -cmark_node_set_header_level(cmark_node *node, int level) { +cmark_node_set_header_level(cmark_node *node, int level) +{ if (node == NULL || level < 1 || level > 6) { return 0; } @@ -260,21 +286,22 @@ cmark_node_set_header_level(cmark_node *node, int level) { } cmark_list_type -cmark_node_get_list_type(cmark_node *node) { +cmark_node_get_list_type(cmark_node *node) +{ if (node == NULL) { return CMARK_NO_LIST; } if (node->type == CMARK_NODE_LIST) { return node->as.list.list_type; - } - else { + } else { return CMARK_NO_LIST; } } int -cmark_node_set_list_type(cmark_node *node, cmark_list_type type) { +cmark_node_set_list_type(cmark_node *node, cmark_list_type type) +{ if (!(type == CMARK_BULLET_LIST || type == CMARK_ORDERED_LIST)) { return 0; } @@ -286,28 +313,28 @@ cmark_node_set_list_type(cmark_node *node, cmark_list_type type) { if (node->type == CMARK_NODE_LIST) { node->as.list.list_type = type; return 1; - } - else { + } else { return 0; } } cmark_delim_type -cmark_node_get_list_delim(cmark_node *node) { +cmark_node_get_list_delim(cmark_node *node) +{ if (node == NULL) { return CMARK_NO_DELIM; } if (node->type == CMARK_NODE_LIST) { return node->as.list.delimiter; - } - else { + } else { return CMARK_NO_DELIM; } } int -cmark_node_set_list_delim(cmark_node *node, cmark_delim_type delim) { +cmark_node_set_list_delim(cmark_node *node, cmark_delim_type delim) +{ if (!(delim == CMARK_PERIOD_DELIM || delim == CMARK_PAREN_DELIM)) { return 0; } @@ -319,28 +346,28 @@ cmark_node_set_list_delim(cmark_node *node, cmark_delim_type delim) { if (node->type == CMARK_NODE_LIST) { node->as.list.delimiter = delim; return 1; - } - else { + } else { return 0; } } int -cmark_node_get_list_start(cmark_node *node) { +cmark_node_get_list_start(cmark_node *node) +{ if (node == NULL) { return 0; } if (node->type == CMARK_NODE_LIST) { return node->as.list.start; - } - else { + } else { return 0; } } int -cmark_node_set_list_start(cmark_node *node, int start) { +cmark_node_set_list_start(cmark_node *node, int start) +{ if (node == NULL || start < 0) { return 0; } @@ -348,28 +375,28 @@ cmark_node_set_list_start(cmark_node *node, int start) { if (node->type == CMARK_NODE_LIST) { node->as.list.start = start; return 1; - } - else { + } else { return 0; } } int -cmark_node_get_list_tight(cmark_node *node) { +cmark_node_get_list_tight(cmark_node *node) +{ if (node == NULL) { return 0; } if (node->type == CMARK_NODE_LIST) { return node->as.list.tight; - } - else { + } else { return 0; } } int -cmark_node_set_list_tight(cmark_node *node, int tight) { +cmark_node_set_list_tight(cmark_node *node, int tight) +{ if (node == NULL) { return 0; } @@ -377,28 +404,28 @@ cmark_node_set_list_tight(cmark_node *node, int tight) { if (node->type == CMARK_NODE_LIST) { node->as.list.tight = tight; return 1; - } - else { + } else { return 0; } } const char* -cmark_node_get_fence_info(cmark_node *node) { +cmark_node_get_fence_info(cmark_node *node) +{ if (node == NULL) { return NULL; } if (node->type == NODE_CODE_BLOCK) { return cmark_chunk_to_cstr(&node->as.code.info); - } - else { + } else { return NULL; } } int -cmark_node_set_fence_info(cmark_node *node, const char *info) { +cmark_node_set_fence_info(cmark_node *node, const char *info) +{ if (node == NULL) { return 0; } @@ -406,14 +433,14 @@ cmark_node_set_fence_info(cmark_node *node, const char *info) { if (node->type == NODE_CODE_BLOCK) { cmark_chunk_set_cstr(&node->as.code.info, info); return 1; - } - else { + } else { return 0; } } const char* -cmark_node_get_url(cmark_node *node) { +cmark_node_get_url(cmark_node *node) +{ if (node == NULL) { return NULL; } @@ -430,7 +457,8 @@ cmark_node_get_url(cmark_node *node) { } int -cmark_node_set_url(cmark_node *node, const char *url) { +cmark_node_set_url(cmark_node *node, const char *url) +{ if (node == NULL) { return 0; } @@ -449,7 +477,8 @@ cmark_node_set_url(cmark_node *node, const char *url) { } const char* -cmark_node_get_title(cmark_node *node) { +cmark_node_get_title(cmark_node *node) +{ if (node == NULL) { return NULL; } @@ -466,7 +495,8 @@ cmark_node_get_title(cmark_node *node) { } int -cmark_node_set_title(cmark_node *node, const char *title) { +cmark_node_set_title(cmark_node *node, const char *title) +{ if (node == NULL) { return 0; } @@ -485,7 +515,8 @@ cmark_node_set_title(cmark_node *node, const char *title) { } int -cmark_node_get_start_line(cmark_node *node) { +cmark_node_get_start_line(cmark_node *node) +{ if (node == NULL) { return 0; } @@ -493,7 +524,8 @@ cmark_node_get_start_line(cmark_node *node) { } int -cmark_node_get_start_column(cmark_node *node) { +cmark_node_get_start_column(cmark_node *node) +{ if (node == NULL) { return 0; } @@ -501,7 +533,8 @@ cmark_node_get_start_column(cmark_node *node) { } int -cmark_node_get_end_line(cmark_node *node) { +cmark_node_get_end_line(cmark_node *node) +{ if (node == NULL) { return 0; } @@ -509,7 +542,8 @@ cmark_node_get_end_line(cmark_node *node) { } int -cmark_node_get_end_column(cmark_node *node) { +cmark_node_get_end_column(cmark_node *node) +{ if (node == NULL) { return 0; } @@ -517,7 +551,8 @@ cmark_node_get_end_column(cmark_node *node) { } static inline bool -S_is_block(cmark_node *node) { +S_is_block(cmark_node *node) +{ if (node == NULL) { return false; } @@ -526,7 +561,8 @@ S_is_block(cmark_node *node) { } static inline bool -S_is_inline(cmark_node *node) { +S_is_inline(cmark_node *node) +{ if (node == NULL) { return false; } @@ -609,7 +645,8 @@ S_node_unlink(cmark_node *node) } void -cmark_node_unlink(cmark_node *node) { +cmark_node_unlink(cmark_node *node) +{ S_node_unlink(node); node->next = NULL; @@ -706,8 +743,7 @@ cmark_node_prepend_child(cmark_node *node, cmark_node *child) if (old_first_child) { old_first_child->prev = child; - } - else { + } else { // Also set last_child if node previously had no children. node->last_child = child; } @@ -733,8 +769,7 @@ cmark_node_append_child(cmark_node *node, cmark_node *child) if (old_last_child) { old_last_child->next = child; - } - else { + } else { // Also set first_child if node previously had no children. node->first_child = child; } @@ -749,8 +784,8 @@ S_print_error(FILE *out, cmark_node *node, const char *elem) return; } fprintf(out, "Invalid '%s' in node type %s at %d:%d\n", elem, - cmark_node_get_type_string(node), node->start_line, - node->start_column); + cmark_node_get_type_string(node), node->start_line, + node->start_column); } int @@ -780,7 +815,7 @@ cmark_node_check(cmark_node *node, FILE *out) continue; } - next_sibling: +next_sibling: if (cur == node) { break; } diff --git a/src/references.c b/src/references.c index c9051f0..37bf4cb 100644 --- a/src/references.c +++ b/src/references.c @@ -74,7 +74,7 @@ static void add_reference(cmark_reference_map *map, cmark_reference* ref) } void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label, cmark_chunk *url, - cmark_chunk *title) + cmark_chunk *title) { cmark_reference *ref; unsigned char *reflabel = normalize_reference(label); diff --git a/src/utf8.c b/src/utf8.c index ffb050d..d77c5d1 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -21,7 +21,8 @@ static const int8_t utf8proc_utf8class[256] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0 }; + 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0 +}; static void encode_unknown(cmark_strbuf *buf) { @@ -82,8 +83,7 @@ static int utf8proc_valid(const uint8_t *str, int str_len) // Overlong return -length; } - } - else if (str[0] == 0xED) { + } else if (str[0] == 0xED) { if (str[1] >= 0xA0) { // Surrogate return -length; @@ -97,8 +97,7 @@ static int utf8proc_valid(const uint8_t *str, int str_len) // Overlong return -length; } - } - else if (str[0] >= 0xF4) { + } else if (str[0] >= 0xF4) { if (str[0] > 0xF4 || str[1] >= 0x90) { // Above 0x10FFFF return -length; @@ -121,7 +120,8 @@ void utf8proc_detab(cmark_strbuf *ob, const uint8_t *line, size_t size) while (i < size && line[i] != '\t' && line[i] != '\0' && line[i] < 0x80) { - i++; tab++; + i++; + tab++; } if (i > org) @@ -171,13 +171,13 @@ int utf8proc_iterate(const uint8_t *str, int str_len, int32_t *dst) break; case 3: uc = ((str[0] & 0x0F) << 12) + ((str[1] & 0x3F) << 6) - + (str[2] & 0x3F); + + (str[2] & 0x3F); if (uc < 0x800 || (uc >= 0xD800 && uc < 0xE000) || (uc >= 0xFDD0 && uc < 0xFDF0)) uc = -1; break; case 4: uc = ((str[0] & 0x07) << 18) + ((str[1] & 0x3F) << 12) - + ((str[2] & 0x3F) << 6) + (str[3] & 0x3F); + + ((str[2] & 0x3F) << 6) + (str[3] & 0x3F); if (uc < 0x10000 || uc >= 0x110000) uc = -1; break; } @@ -254,200 +254,200 @@ void utf8proc_case_fold(cmark_strbuf *dest, const uint8_t *str, int len) int utf8proc_is_space(int32_t uc) { return (uc == 9 || - uc == 10 || - uc == 12 || - uc == 13 || - uc == 32 || - uc == 160 || - uc == 5760 || - (uc >= 8192 && uc <= 8202) || - uc == 8239 || - uc == 8287 || - uc == 12288); + uc == 10 || + uc == 12 || + uc == 13 || + uc == 32 || + uc == 160 || + uc == 5760 || + (uc >= 8192 && uc <= 8202) || + uc == 8239 || + uc == 8287 || + uc == 12288); } // matches anything in the P[cdefios] classes. int utf8proc_is_punctuation(int32_t uc) { return ((uc < 128 && cmark_ispunct((char)uc)) || - uc == 161 || - uc == 167 || - uc == 171 || - uc == 182 || - uc == 183 || - uc == 187 || - uc == 191 || - uc == 894 || - uc == 903 || - (uc >= 1370 && uc <= 1375) || - uc == 1417 || - uc == 1418 || - uc == 1470 || - uc == 1472 || - uc == 1475 || - uc == 1478 || - uc == 1523 || - uc == 1524 || - uc == 1545 || - uc == 1546 || - uc == 1548 || - uc == 1549 || - uc == 1563 || - uc == 1566 || - uc == 1567 || - (uc >= 1642 && uc <= 1645) || - uc == 1748 || - (uc >= 1792 && uc <= 1805) || - (uc >= 2039 && uc <= 2041) || - (uc >= 2096 && uc <= 2110) || - uc == 2142 || - uc == 2404 || - uc == 2405 || - uc == 2416 || - uc == 2800 || - uc == 3572 || - uc == 3663 || - uc == 3674 || - uc == 3675 || - (uc >= 3844 && uc <= 3858) || - uc == 3860 || - (uc >= 3898 && uc <= 3901) || - uc == 3973 || - (uc >= 4048 && uc <= 4052) || - uc == 4057 || - uc == 4058 || - (uc >= 4170 && uc <= 4175) || - uc == 4347 || - (uc >= 4960 && uc <= 4968) || - uc == 5120 || - uc == 5741 || - uc == 5742 || - uc == 5787 || - uc == 5788 || - (uc >= 5867 && uc <= 5869) || - uc == 5941 || - uc == 5942 || - (uc >= 6100 && uc <= 6102) || - (uc >= 6104 && uc <= 6106) || - (uc >= 6144 && uc <= 6154) || - uc == 6468 || - uc == 6469 || - uc == 6686 || - uc == 6687 || - (uc >= 6816 && uc <= 6822) || - (uc >= 6824 && uc <= 6829) || - (uc >= 7002 && uc <= 7008) || - (uc >= 7164 && uc <= 7167) || - (uc >= 7227 && uc <= 7231) || - uc == 7294 || - uc == 7295 || - (uc >= 7360 && uc <= 7367) || - uc == 7379 || - (uc >= 8208 && uc <= 8231) || - (uc >= 8240 && uc <= 8259) || - (uc >= 8261 && uc <= 8273) || - (uc >= 8275 && uc <= 8286) || - uc == 8317 || - uc == 8318 || - uc == 8333 || - uc == 8334 || - (uc >= 8968 && uc <= 8971) || - uc == 9001 || - uc == 9002 || - (uc >= 10088 && uc <= 10101) || - uc == 10181 || - uc == 10182 || - (uc >= 10214 && uc <= 10223) || - (uc >= 10627 && uc <= 10648) || - (uc >= 10712 && uc <= 10715) || - uc == 10748 || - uc == 10749 || - (uc >= 11513 && uc <= 11516) || - uc == 11518 || - uc == 11519 || - uc == 11632 || - (uc >= 11776 && uc <= 11822) || - (uc >= 11824 && uc <= 11842) || - (uc >= 12289 && uc <= 12291) || - (uc >= 12296 && uc <= 12305) || - (uc >= 12308 && uc <= 12319) || - uc == 12336 || - uc == 12349 || - uc == 12448 || - uc == 12539 || - uc == 42238 || - uc == 42239 || - (uc >= 42509 && uc <= 42511) || - uc == 42611 || - uc == 42622 || - (uc >= 42738 && uc <= 42743) || - (uc >= 43124 && uc <= 43127) || - uc == 43214 || - uc == 43215 || - (uc >= 43256 && uc <= 43258) || - uc == 43310 || - uc == 43311 || - uc == 43359 || - (uc >= 43457 && uc <= 43469) || - uc == 43486 || - uc == 43487 || - (uc >= 43612 && uc <= 43615) || - uc == 43742 || - uc == 43743 || - uc == 43760 || - uc == 43761 || - uc == 44011 || - uc == 64830 || - uc == 64831 || - (uc >= 65040 && uc <= 65049) || - (uc >= 65072 && uc <= 65106) || - (uc >= 65108 && uc <= 65121) || - uc == 65123 || - uc == 65128 || - uc == 65130 || - uc == 65131 || - (uc >= 65281 && uc <= 65283) || - (uc >= 65285 && uc <= 65290) || - (uc >= 65292 && uc <= 65295) || - uc == 65306 || - uc == 65307 || - uc == 65311 || - uc == 65312 || - (uc >= 65339 && uc <= 65341) || - uc == 65343 || - uc == 65371 || - uc == 65373 || - (uc >= 65375 && uc <= 65381) || - (uc >= 65792 && uc <= 65794) || - uc == 66463 || - uc == 66512 || - uc == 66927 || - uc == 67671 || - uc == 67871 || - uc == 67903 || - (uc >= 68176 && uc <= 68184) || - uc == 68223 || - (uc >= 68336 && uc <= 68342) || - (uc >= 68409 && uc <= 68415) || - (uc >= 68505 && uc <= 68508) || - (uc >= 69703 && uc <= 69709) || - uc == 69819 || - uc == 69820 || - (uc >= 69822 && uc <= 69825) || - (uc >= 69952 && uc <= 69955) || - uc == 70004 || - uc == 70005 || - (uc >= 70085 && uc <= 70088) || - uc == 70093 || - (uc >= 70200 && uc <= 70205) || - uc == 70854 || - (uc >= 71105 && uc <= 71113) || - (uc >= 71233 && uc <= 71235) || - (uc >= 74864 && uc <= 74868) || - uc == 92782 || - uc == 92783 || - uc == 92917 || - (uc >= 92983 && uc <= 92987) || - uc == 92996 || - uc == 113823); + uc == 161 || + uc == 167 || + uc == 171 || + uc == 182 || + uc == 183 || + uc == 187 || + uc == 191 || + uc == 894 || + uc == 903 || + (uc >= 1370 && uc <= 1375) || + uc == 1417 || + uc == 1418 || + uc == 1470 || + uc == 1472 || + uc == 1475 || + uc == 1478 || + uc == 1523 || + uc == 1524 || + uc == 1545 || + uc == 1546 || + uc == 1548 || + uc == 1549 || + uc == 1563 || + uc == 1566 || + uc == 1567 || + (uc >= 1642 && uc <= 1645) || + uc == 1748 || + (uc >= 1792 && uc <= 1805) || + (uc >= 2039 && uc <= 2041) || + (uc >= 2096 && uc <= 2110) || + uc == 2142 || + uc == 2404 || + uc == 2405 || + uc == 2416 || + uc == 2800 || + uc == 3572 || + uc == 3663 || + uc == 3674 || + uc == 3675 || + (uc >= 3844 && uc <= 3858) || + uc == 3860 || + (uc >= 3898 && uc <= 3901) || + uc == 3973 || + (uc >= 4048 && uc <= 4052) || + uc == 4057 || + uc == 4058 || + (uc >= 4170 && uc <= 4175) || + uc == 4347 || + (uc >= 4960 && uc <= 4968) || + uc == 5120 || + uc == 5741 || + uc == 5742 || + uc == 5787 || + uc == 5788 || + (uc >= 5867 && uc <= 5869) || + uc == 5941 || + uc == 5942 || + (uc >= 6100 && uc <= 6102) || + (uc >= 6104 && uc <= 6106) || + (uc >= 6144 && uc <= 6154) || + uc == 6468 || + uc == 6469 || + uc == 6686 || + uc == 6687 || + (uc >= 6816 && uc <= 6822) || + (uc >= 6824 && uc <= 6829) || + (uc >= 7002 && uc <= 7008) || + (uc >= 7164 && uc <= 7167) || + (uc >= 7227 && uc <= 7231) || + uc == 7294 || + uc == 7295 || + (uc >= 7360 && uc <= 7367) || + uc == 7379 || + (uc >= 8208 && uc <= 8231) || + (uc >= 8240 && uc <= 8259) || + (uc >= 8261 && uc <= 8273) || + (uc >= 8275 && uc <= 8286) || + uc == 8317 || + uc == 8318 || + uc == 8333 || + uc == 8334 || + (uc >= 8968 && uc <= 8971) || + uc == 9001 || + uc == 9002 || + (uc >= 10088 && uc <= 10101) || + uc == 10181 || + uc == 10182 || + (uc >= 10214 && uc <= 10223) || + (uc >= 10627 && uc <= 10648) || + (uc >= 10712 && uc <= 10715) || + uc == 10748 || + uc == 10749 || + (uc >= 11513 && uc <= 11516) || + uc == 11518 || + uc == 11519 || + uc == 11632 || + (uc >= 11776 && uc <= 11822) || + (uc >= 11824 && uc <= 11842) || + (uc >= 12289 && uc <= 12291) || + (uc >= 12296 && uc <= 12305) || + (uc >= 12308 && uc <= 12319) || + uc == 12336 || + uc == 12349 || + uc == 12448 || + uc == 12539 || + uc == 42238 || + uc == 42239 || + (uc >= 42509 && uc <= 42511) || + uc == 42611 || + uc == 42622 || + (uc >= 42738 && uc <= 42743) || + (uc >= 43124 && uc <= 43127) || + uc == 43214 || + uc == 43215 || + (uc >= 43256 && uc <= 43258) || + uc == 43310 || + uc == 43311 || + uc == 43359 || + (uc >= 43457 && uc <= 43469) || + uc == 43486 || + uc == 43487 || + (uc >= 43612 && uc <= 43615) || + uc == 43742 || + uc == 43743 || + uc == 43760 || + uc == 43761 || + uc == 44011 || + uc == 64830 || + uc == 64831 || + (uc >= 65040 && uc <= 65049) || + (uc >= 65072 && uc <= 65106) || + (uc >= 65108 && uc <= 65121) || + uc == 65123 || + uc == 65128 || + uc == 65130 || + uc == 65131 || + (uc >= 65281 && uc <= 65283) || + (uc >= 65285 && uc <= 65290) || + (uc >= 65292 && uc <= 65295) || + uc == 65306 || + uc == 65307 || + uc == 65311 || + uc == 65312 || + (uc >= 65339 && uc <= 65341) || + uc == 65343 || + uc == 65371 || + uc == 65373 || + (uc >= 65375 && uc <= 65381) || + (uc >= 65792 && uc <= 65794) || + uc == 66463 || + uc == 66512 || + uc == 66927 || + uc == 67671 || + uc == 67871 || + uc == 67903 || + (uc >= 68176 && uc <= 68184) || + uc == 68223 || + (uc >= 68336 && uc <= 68342) || + (uc >= 68409 && uc <= 68415) || + (uc >= 68505 && uc <= 68508) || + (uc >= 69703 && uc <= 69709) || + uc == 69819 || + uc == 69820 || + (uc >= 69822 && uc <= 69825) || + (uc >= 69952 && uc <= 69955) || + uc == 70004 || + uc == 70005 || + (uc >= 70085 && uc <= 70088) || + uc == 70093 || + (uc >= 70200 && uc <= 70205) || + uc == 70854 || + (uc >= 71105 && uc <= 71113) || + (uc >= 71233 && uc <= 71235) || + (uc >= 74864 && uc <= 74868) || + uc == 92782 || + uc == 92783 || + uc == 92917 || + (uc >= 92983 && uc <= 92987) || + uc == 92996 || + uc == 113823); } diff --git a/src/xml.c b/src/xml.c index 1577f89..2ae900c 100644 --- a/src/xml.c +++ b/src/xml.c @@ -36,7 +36,7 @@ static inline void indent(struct render_state *state) static int S_render_node(cmark_node *node, cmark_event_type ev_type, - struct render_state *state, long options) + struct render_state *state, long options) { cmark_strbuf *xml = state->xml; bool literal = false; @@ -46,14 +46,14 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, if (entering) { indent(state); cmark_strbuf_printf(xml, "<%s", - cmark_node_get_type_string(node)); + cmark_node_get_type_string(node)); if (options & CMARK_OPT_SOURCEPOS && node->start_line != 0) { cmark_strbuf_printf(xml, " sourcepos=\"%d:%d-%d:%d\"", - node->start_line, - node->start_column, - node->end_line, - node->end_column); + node->start_line, + node->start_column, + node->end_line, + node->end_column); } literal = false; @@ -65,25 +65,25 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_INLINE_HTML: cmark_strbuf_puts(xml, ">"); escape_xml(xml, node->as.literal.data, - node->as.literal.len); + node->as.literal.len); cmark_strbuf_puts(xml, "as.code.info.len > 0) { cmark_strbuf_puts(xml, " info=\""); escape_xml(xml, node->as.code.info.data, - node->as.code.info.len); + node->as.code.info.len); cmark_strbuf_putc(xml, '"'); } cmark_strbuf_puts(xml, ">"); escape_xml(xml, node->as.code.literal.data, - node->as.code.literal.len); + node->as.code.literal.len); cmark_strbuf_puts(xml, "first_child) { - state->indent -= 2; - indent(state); - cmark_strbuf_printf(xml, "\n", - cmark_node_get_type_string(node)); + state->indent -= 2; + indent(state); + cmark_strbuf_printf(xml, "\n", + cmark_node_get_type_string(node)); } return 1; @@ -126,9 +126,9 @@ char *cmark_render_xml(cmark_node *root, long options) cmark_iter *iter = cmark_iter_new(root); cmark_strbuf_puts(state.xml, - "\n"); + "\n"); cmark_strbuf_puts(state.xml, - "\n"); + "\n"); while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { cur = cmark_iter_get_node(iter); S_render_node(cur, ev_type, &state, options); -- cgit v1.2.3