~sircmpwn/scdoc

9b01ea2093def60be232a1b57a7d4b3d10b8c8b5 — Drew DeVault 2 years ago 71a5592
Ignore underscores in the middle_of_a_word
4 files changed, 19 insertions(+), 11 deletions(-)

M include/util.h
M scdoc.5.scd
M src/main.c
M src/util.c
M include/util.h => include/util.h +1 -0
@@ 12,6 12,7 @@ struct parser {
	uint32_t flags;
	const char *str;
	int fmt_line, fmt_col;
	uint32_t last[2];
};

enum formatting {

M scdoc.5.scd => scdoc.5.scd +1 -1
@@ 45,7 45,7 @@ like this.
## 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


M src/main.c => src/main.c +5 -0
@@ 163,6 163,11 @@ static void parse_format(struct parser *p, enum formatting fmt) {
		}
		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;

M src/util.c => src/util.c +12 -10
@@ 14,24 14,26 @@ void parser_fatal(struct parser *parser, const char *err) {
}

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;
}