From 9b01ea2093def60be232a1b57a7d4b3d10b8c8b5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 27 Jan 2019 10:48:28 -0500 Subject: [PATCH] Ignore underscores in the middle_of_a_word --- include/util.h | 1 + scdoc.5.scd | 2 +- src/main.c | 5 +++++ src/util.c | 22 ++++++++++++---------- diff --git a/include/util.h b/include/util.h index fe50986736a4108788fa34ceee6fb21698bb2292..d9a1a5cdde6af9b1af04b38f4c10297e08318ac2 100644 --- a/include/util.h +++ b/include/util.h @@ -12,6 +12,7 @@ uint32_t queue[32]; uint32_t flags; const char *str; int fmt_line, fmt_col; + uint32_t last[2]; }; enum formatting { diff --git a/scdoc.5.scd b/scdoc.5.scd index ab641a77169b8fd36f2a6e2e35f32e05adb25455..1720ffc0f5d25b9e487fb06f8a3a832aeadd981d 100644 --- a/scdoc.5.scd +++ b/scdoc.5.scd @@ -45,7 +45,7 @@ ## FORMATTING Text can be made *bold* or _underlined_ with asterisks and underscores: \*bold\* -or \_underlined\_. +or \_underlined\_. Underscores in the_middle_of_words will be disregarded. ## INDENTATION diff --git a/src/main.c b/src/main.c index eab674ee0681cf85441d02c452d0a62d8425c5d1..d240ea47d6cf921e7b08fead8a7ff487b8501207 100644 --- a/src/main.c +++ b/src/main.c @@ -163,6 +163,11 @@ parser_fatal(p, error); } fprintf(p->output, "\\fR"); } else { + if (fmt == FORMAT_UNDERLINE && !isspace(p->last[0])) { + // Ignore underscores in the middle of words + utf8_fputch(p->output, '_'); + return; + } fprintf(p->output, "\\f%c", formats[fmt]); p->fmt_line = p->line; p->fmt_col = p->col; diff --git a/src/util.c b/src/util.c index ec55abbe07ca9c08cc0ce7c80034e04729bca31e..38c3fcaccc589dc7872231f8da917ef236928ef8 100644 --- a/src/util.c +++ b/src/util.c @@ -14,24 +14,26 @@ exit(1); } uint32_t parser_getch(struct parser *parser) { + uint32_t ch; if (parser->qhead) { - return parser->queue[--parser->qhead]; - } - if (parser->str) { + ch = parser->queue[--parser->qhead]; + } else if (parser->str) { uint32_t ch = utf8_decode(&parser->str); if (!ch || ch == UTF8_INVALID) { parser->str = NULL; return UTF8_INVALID; } - return ch; - } - uint32_t ch = utf8_fgetch(parser->input); - if (ch == '\n') { - parser->col = 0; - ++parser->line; } else { - ++parser->col; + ch = utf8_fgetch(parser->input); + if (ch == '\n') { + parser->col = 0; + ++parser->line; + } else { + ++parser->col; + } } + parser->last[0] = parser->last[1]; + parser->last[1] = ch; return ch; } -- 2.48.1