Little code clean-up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
diff --git a/md2html/md2html.c b/md2html/md2html.c
index 481f3e8..1779306 100644
--- 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
index 4949510..e439735 100644
--- 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: