From 28222288732d233b05d456e6f92561559f41696d Mon Sep 17 00:00:00 2001
From: Drew DeVault <sir@cmpwn.com>
Date: Sun, 07 Oct 2018 11:11:54 -0400
Subject: [PATCH] Show origin of nested formatting issues

---
 include/util.h | 1 +
 src/main.c     | 9 ++++++++-

diff --git a/include/util.h b/include/util.h
index 7df48a71247bc8b1d172d2ff8dfa8c81735424db..fe50986736a4108788fa34ceee6fb21698bb2292 100644
--- a/include/util.h
+++ b/include/util.h
@@ -11,6 +11,7 @@ 	int qhead;
 	uint32_t queue[32];
 	uint32_t flags;
 	const char *str;
+	int fmt_line, fmt_col;
 };
 
 enum formatting {
diff --git a/src/main.c b/src/main.c
index bcf7274396ad70c4b452d950ee46f77e763b3e51..b0835d16000486456e20c053ec703f917a955376 100644
--- a/src/main.c
+++ b/src/main.c
@@ -115,13 +115,20 @@ 	char formats[FORMAT_LAST] = {
 		[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;
 }

-- 
2.48.1