commit 80984c98c8eae61b5905a2c7ddaf8e3cae53068a
parent 1ff00d684d37e2841bf9f236db33b155d53b5328
Author: Martin Mitas <mity@morous.org>
Date: Tue, 4 Oct 2016 02:18:47 +0200
Little code clean-up.
Diffstat:
| M | md2html/md2html.c | | | 66 | +++++++++++++++++++++++++++++++++--------------------------------- |
| M | md4c/md4c.c | | | 33 | +++++++++++++++++++++++---------- |
2 files changed, 56 insertions(+), 43 deletions(-)
diff --git a/md2html/md2html.c b/md2html/md2html.c
@@ -33,9 +33,9 @@
#include "cmdline.h"
-/********************************
- *** Simple growable buffer ***
- ********************************/
+/*********************************
+ *** Simple grow-able buffer ***
+ *********************************/
/* We render to a memory buffer instead of directly outputting the rendered
* documents, as this allows using this utility for evaluating performance
@@ -108,10 +108,10 @@ membuf_append_escaped(struct membuffer* buf, const char* data, MD_SIZE size)
if(off < size) {
switch(data[off]) {
- case '&': MEMBUF_APPEND_LITERAL(buf, "&"); break;
- case '<': MEMBUF_APPEND_LITERAL(buf, "<"); break;
- case '>': MEMBUF_APPEND_LITERAL(buf, ">"); break;
- case '"': MEMBUF_APPEND_LITERAL(buf, """); break;
+ case '&': MEMBUF_APPEND_LITERAL(buf, "&"); break;
+ case '<': MEMBUF_APPEND_LITERAL(buf, "<"); break;
+ case '>': MEMBUF_APPEND_LITERAL(buf, ">"); break;
+ case '"': MEMBUF_APPEND_LITERAL(buf, """); break;
}
off++;
} else {
@@ -132,10 +132,10 @@ enter_block_callback(MD_BLOCKTYPE type, void* detail, void* userdata)
struct membuffer* out = (struct membuffer*) userdata;
switch(type) {
- case MD_BLOCK_DOC: /* noop */ break;
- case MD_BLOCK_HR: MEMBUF_APPEND_LITERAL(out, "<hr>\n"); break;
- case MD_BLOCK_H: MEMBUF_APPEND_LITERAL(out, head[((MD_BLOCK_H_DETAIL*)detail)->level - 1]); break;
- case MD_BLOCK_P: MEMBUF_APPEND_LITERAL(out, "<p>"); break;
+ case MD_BLOCK_DOC: /* noop */ break;
+ case MD_BLOCK_HR: MEMBUF_APPEND_LITERAL(out, "<hr>\n"); break;
+ case MD_BLOCK_H: MEMBUF_APPEND_LITERAL(out, head[((MD_BLOCK_H_DETAIL*)detail)->level - 1]); break;
+ case MD_BLOCK_P: MEMBUF_APPEND_LITERAL(out, "<p>"); break;
}
return 0;
@@ -148,10 +148,10 @@ leave_block_callback(MD_BLOCKTYPE type, void* detail, void* userdata)
struct membuffer* out = (struct membuffer*) userdata;
switch(type) {
- case MD_BLOCK_DOC: /*noop*/ break;
- case MD_BLOCK_HR: /*noop*/ break;
- case MD_BLOCK_H: MEMBUF_APPEND_LITERAL(out, head[((MD_BLOCK_H_DETAIL*)detail)->level - 1]); break;
- case MD_BLOCK_P: MEMBUF_APPEND_LITERAL(out, "</p>\n"); break;
+ case MD_BLOCK_DOC: /*noop*/ break;
+ case MD_BLOCK_HR: /*noop*/ break;
+ case MD_BLOCK_H: MEMBUF_APPEND_LITERAL(out, head[((MD_BLOCK_H_DETAIL*)detail)->level - 1]); break;
+ case MD_BLOCK_P: MEMBUF_APPEND_LITERAL(out, "</p>\n"); break;
}
return 0;
@@ -317,27 +317,27 @@ static int
cmdline_callback(int opt, char const* value, void* data)
{
switch(opt) {
- case 0:
- if(input_path) {
- fprintf(stderr, "Too many arguments. Only one input file can be specified.\n");
- fprintf(stderr, "Use --help for more info.\n");
- exit(1);
- }
- input_path = value;
- break;
+ case 0:
+ if(input_path) {
+ fprintf(stderr, "Too many arguments. Only one input file can be specified.\n");
+ fprintf(stderr, "Use --help for more info.\n");
+ exit(1);
+ }
+ input_path = value;
+ break;
- case 'o': output_path = value; break;
- case 'f': want_fullhtml = 1; break;
- case 's': want_stat = 1; break;
- case 'h': usage(); exit(0); break;
+ case 'o': output_path = value; break;
+ case 'f': want_fullhtml = 1; break;
+ case 's': want_stat = 1; break;
+ case 'h': usage(); exit(0); break;
- case 'A': renderer_flags |= MD_FLAG_PERMISSIVEATXHEADERS; break;
+ case 'A': renderer_flags |= MD_FLAG_PERMISSIVEATXHEADERS; break;
- default:
- fprintf(stderr, "Illegal option: %s\n", value);
- fprintf(stderr, "Use --help for more info.\n");
- exit(1);
- break;
+ default:
+ fprintf(stderr, "Illegal option: %s\n", value);
+ fprintf(stderr, "Use --help for more info.\n");
+ exit(1);
+ break;
}
return 0;
diff --git a/md4c/md4c.c b/md4c/md4c.c
@@ -395,25 +395,38 @@ md_process_block(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
/* Derive block type from type of the first line. */
switch(lines[0].type) {
- case MD_LINE_BLANK: return 0;
- case MD_LINE_HR: block_type = MD_BLOCK_HR; break;
+ case MD_LINE_BLANK:
+ return 0;
- case MD_LINE_ATXHEADER:
- block_type = MD_BLOCK_H;
- det.header.level = ctx->header_level;
- break;
+ case MD_LINE_HR:
+ block_type = MD_BLOCK_HR;
+ break;
- case MD_LINE_TEXT: block_type = MD_BLOCK_P; break;
+ case MD_LINE_ATXHEADER:
+ block_type = MD_BLOCK_H;
+ det.header.level = ctx->header_level;
+ break;
+
+ case MD_LINE_TEXT:
+ block_type = MD_BLOCK_P;
+ break;
}
- /* Process the block accordingly to is type. */
MD_ENTER_BLOCK(block_type, (void*) &det);
+
+ /* Process the block contents accordingly to is type. */
switch(block_type) {
- case MD_BLOCK_HR: /* Noop. */ break;
- default: ret = md_process_normal_block(ctx, lines, n_lines); break;
+ case MD_BLOCK_HR:
+ /* Noop. */
+ break;
+
+ default:
+ ret = md_process_normal_block(ctx, lines, n_lines);
+ break;
}
if(ret != 0)
goto abort;
+
MD_LEAVE_BLOCK(block_type, (void*) &det);
abort: