+msg_err(void *arg, int tok, int col, enum mdoc_err type)
+{
+ char *fmt, *lit;
+ struct md_parse *p;
+ int i;
+
+ p = (struct md_parse *)arg;
+
+ fmt = lit = NULL;
+
+ switch (type) {
+ case (ERR_SYNTAX_NOTEXT):
+ lit = "syntax: context-free text disallowed";
+ break;
+ case (ERR_SYNTAX_QUOTE):
+ lit = "syntax: disallowed argument quotation";
+ break;
+ case (ERR_SYNTAX_UNQUOTE):
+ lit = "syntax: unterminated quotation";
+ break;
+ case (ERR_SYNTAX_WS):
+ lit = "syntax: whitespace in argument";
+ break;
+ case (ERR_SYNTAX_ARGFORM):
+ fmt = "syntax: macro `%s' arguments malformed";
+ break;
+ case (ERR_SYNTAX_NOPUNCT):
+ fmt = "syntax: macro `%s' doesn't understand punctuation";
+ break;
+ case (ERR_SYNTAX_ARG):
+ fmt = "syntax: unknown argument for macro `%s'";
+ break;
+ case (ERR_SCOPE_BREAK):
+ /* Which scope is broken? */
+ fmt = "scope: macro `%s' breaks prior explicit scope";
+ break;
+ case (ERR_SCOPE_NOCTX):
+ fmt = "scope: closure macro `%s' has no context";
+ break;
+ case (ERR_SCOPE_NONEST):
+ fmt = "scope: macro `%s' may not be nested in the current context";
+ break;
+ case (ERR_MACRO_NOTSUP):
+ lit = "macro not supported";
+ break;
+ case (ERR_MACRO_NOTCALL):
+ fmt = "macro `%s' not callable";
+ break;
+ case (ERR_SEC_PROLOGUE):
+ fmt = "macro `%s' cannot be called in the prologue";
+ break;
+ case (ERR_SEC_NPROLOGUE):
+ fmt = "macro `%s' called outside of prologue";
+ break;
+ case (ERR_ARGS_EQ0):
+ fmt = "macro `%s' expects zero arguments";
+ break;
+ case (ERR_ARGS_EQ1):
+ fmt = "macro `%s' expects one argument";
+ break;
+ case (ERR_ARGS_GE1):
+ fmt = "macro `%s' expects one or more arguments";
+ break;
+ case (ERR_ARGS_LE2):
+ fmt = "macro `%s' expects two or fewer arguments";
+ break;
+ case (ERR_ARGS_MANY):
+ fmt = "macro `%s' has too many arguments";
+ break;
+ case (ERR_SEC_PROLOGUE_OO):
+ fmt = "prologue macro `%s' is out-of-order";
+ break;
+ case (ERR_SEC_PROLOGUE_REP):
+ fmt = "prologue macro `%s' repeated";
+ break;
+ case (ERR_SEC_NAME):
+ lit = "`NAME' section must be first";
+ break;
+ case (ERR_SYNTAX_ARGVAL):
+ lit = "syntax: expected value for macro argument";
+ break;
+ case (ERR_SYNTAX_ARGBAD):
+ lit = "syntax: invalid value for macro argument";
+ break;
+ case (ERR_SYNTAX_ARGMANY):
+ lit = "syntax: too many values for macro argument";
+ break;
+ case (ERR_SYNTAX_CHILDHEAD):
+ lit = "syntax: expected only block-header section";
+ break;
+ case (ERR_SYNTAX_CHILDBODY):
+ lit = "syntax: expected only a block-body section";
+ break;
+ case (ERR_SYNTAX_EMPTYHEAD):
+ lit = "syntax: block-header section may not be empty";
+ break;
+ case (ERR_SYNTAX_EMPTYBODY):
+ lit = "syntax: block-body section may not be empty";
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+
+ if (fmt) {
+ (void)fprintf(stderr, "%s:%d: error: ",
+ p->name, p->lnn);
+ (void)fprintf(stderr, fmt, mdoc_macronames[tok]);
+ } else
+ (void)fprintf(stderr, "%s:%d: error: %s",
+ p->name, p->lnn, lit);
+
+ if (p->dbg < 1) {
+ if (-1 != col)
+ (void)fprintf(stderr, " (column %d)\n", col);
+ return(0);
+ } else if (-1 == col) {
+ (void)fprintf(stderr, "\nFrom: %s", p->line);
+ return(0);
+ }
+
+ (void)fprintf(stderr, "\nFrom: %s\n ", p->line);
+ for (i = 0; i < col; i++)
+ (void)fprintf(stderr, " ");
+ (void)fprintf(stderr, "^\n");
+
+ return(0);
+}
+
+
+static void
+msg_msg(void *arg, int col, const char *msg)