~sircmpwn/scdoc

10e1cf68bc6d451ef957c3008d9879655f4e1c63 — Drew DeVault 3 years ago 49e39ef
Implement bold and underline
3 files changed, 30 insertions(+), 1 deletions(-)

M include/util.h
M scdoc.5.scd
M src/main.c
M include/util.h => include/util.h +7 -0
@@ 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);

M scdoc.5.scd => scdoc.5.scd +1 -1
@@ 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

M src/main.c => src/main.c +22 -0
@@ 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