~sircmpwn/scdoc

28222288732d233b05d456e6f92561559f41696d — Drew DeVault 3 years ago 5dbc869
Show origin of nested formatting issues
2 files changed, 9 insertions(+), 1 deletions(-)

M include/util.h
M src/main.c
M include/util.h => include/util.h +1 -0
@@ 11,6 11,7 @@ struct parser {
	uint32_t queue[32];
	uint32_t flags;
	const char *str;
	int fmt_line, fmt_col;
};

enum formatting {

M src/main.c => src/main.c +8 -1
@@ 115,13 115,20 @@ static void parse_format(struct parser *p, enum formatting fmt) {
		[FORMAT_BOLD] = 'B',
		[FORMAT_UNDERLINE] = 'I',
	};
	char error[512];
	if (p->flags) {
		if ((p->flags & ~fmt)) {
			parser_fatal(p, "Cannot nest inline formatting.");
			snprintf(error, sizeof(error), "Cannot nest inline formatting "
						"(began with %c at %d:%d)",
					p->flags == FORMAT_BOLD ? '*' : '_',
					p->fmt_line, p->fmt_col);
			parser_fatal(p, error);
		}
		fprintf(p->output, "\\fR");
	} else {
		fprintf(p->output, "\\f%c", formats[fmt]);
		p->fmt_line = p->line;
		p->fmt_col = p->col;
	}
	p->flags ^= fmt;
}