scdoc2mdoc

A fork of scdoc to output mdoc(7)
git clone git://git.sgregoratto.me/scdoc2mdoc
Log | Files | Refs | README | LICENSE

commit 10e1cf68bc6d451ef957c3008d9879655f4e1c63
parent 49e39ef72a0c669adf03f15f0e54b0aceae3d563
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 10 Dec 2017 00:08:17 -0500

Implement bold and underline

Diffstat:
Minclude/util.h | 7+++++++
Mscdoc.5.scd | 2+-
Msrc/main.c | 22++++++++++++++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/include/util.h b/include/util.h @@ -9,6 +9,13 @@ struct parser { int line, col; int qhead; uint32_t queue[32]; + uint32_t flags; +}; + +enum formatting { + FORMAT_BOLD = 1, + FORMAT_UNDERLINE = 2, + FORMAT_LAST = 4, }; void parser_fatal(struct parser *parser, const char *err); diff --git a/scdoc.5.scd b/scdoc.5.scd @@ -41,7 +41,7 @@ or \_underlined\_. # INDENTATION -You may indent lines with tab characters ("\t") to indent them by 4 spaces in +You may indent lines with tab characters (*\\t*) to indent them by 4 spaces in the output. Indented lines may not contain headers. # LISTS diff --git a/src/main.c b/src/main.c @@ -60,6 +60,22 @@ static void parse_preamble(struct parser *p) { str_free(name); } +static void parse_format(struct parser *p, enum formatting fmt) { + char formats[FORMAT_LAST] = { + [FORMAT_BOLD] = 'B', + [FORMAT_UNDERLINE] = 'I', + }; + if (p->flags) { + if ((p->flags & ~fmt)) { + parser_fatal(p, "Cannot nest inline formatting."); + } + fprintf(p->output, "\\fR"); + } else { + fprintf(p->output, "\\f%c", formats[fmt]); + } + p->flags ^= fmt; +} + static void parse_text(struct parser *p) { uint32_t ch; int i = 0; @@ -75,6 +91,12 @@ static void parse_text(struct parser *p) { utf8_fputch(p->output, ch); } break; + case '*': + parse_format(p, FORMAT_BOLD); + break; + case '_': + parse_format(p, FORMAT_UNDERLINE); + break; case '.': if (!i) { // Escape . if it's the first character