author | Olivier Brunel
<jjk@jjacky.com> 2022-12-28 09:03:56 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2022-12-28 09:03:56 UTC |
parent | 8fd1b28a83f813beed35b852045b08e9eace71af |
main.c | +13 | -10 |
diff --git a/main.c b/main.c index f2c7736..8c1405a 100644 --- a/main.c +++ b/main.c @@ -89,6 +89,16 @@ struct ctx { }; }; +#define BUFFERING_ON() \ + ctx->doc.flags |= DOC_BUFFERING; \ + ctx->buf.salen = ctx->buf.sa.len + +#define BUFFERING_OFF(bstr,blen) \ + const char *bstr = ctx->buf.sa.s + ctx->buf.salen; \ + size_t blen = ctx->buf.sa.len - ctx->buf.salen; \ + ctx->buf.sa.len = ctx->buf.salen; \ + ctx->doc.flags &= ~DOC_BUFFERING + enum { ERR_PARSER_ENTER_BLOCK = -100, ERR_PARSER_LEAVE_BLOCK = -101, @@ -409,8 +419,7 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_) } if (ctx->code.flags & CODE_BUFFERED) { - ctx->doc.flags |= DOC_BUFFERING; - ctx->buf.salen = ctx->buf.sa.len; + BUFFERING_ON(); } else { return (raw_str(ctx, "<pre>")) ? 0 : ERR_PARSER_ENTER_BLOCK; } @@ -479,10 +488,7 @@ leave_block(MD_BLOCKTYPE type, void *details, void *ctx_) if (d->level != ctx->title.level) return ERR_INVALID; - const char *s = ctx->buf.sa.s + ctx->buf.salen; - size_t l = ctx->buf.sa.len - ctx->buf.salen; - ctx->buf.sa.len = ctx->buf.salen; - ctx->doc.flags &= ~DOC_BUFFERING; + BUFFERING_OFF(s, l); char buf[UINT32_FMT]; buf[uint32_fmt(buf, (uint32) ctx->title.level)] = '\0'; @@ -522,10 +528,7 @@ leave_block(MD_BLOCKTYPE type, void *details, void *ctx_) if (!(ctx->code.flags & CODE_BUFFERED)) { return (raw_str(ctx, "</pre>")) ? 0 : ERR_PARSER_LEAVE_BLOCK; } else { - const char *buf = ctx->buf.sa.s + ctx->buf.salen; - size_t blen = ctx->buf.sa.len - ctx->buf.salen; - ctx->buf.sa.len = ctx->buf.salen; - ctx->doc.flags &= ~DOC_BUFFERING; + BUFFERING_OFF(buf, blen); if (ctx->code.flags & CODE_LINES) { const char *s = buf;