summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libman.h4
-rw-r--r--libmdoc.h81
-rw-r--r--mdoc.c313
-rw-r--r--mdoc_action.c112
-rw-r--r--mdoc_argv.c114
-rw-r--r--mdoc_macro.c90
-rw-r--r--mdoc_validate.c294
7 files changed, 402 insertions, 606 deletions
diff --git a/libman.h b/libman.h
index 39718ff0..5bbf39b1 100644
--- a/libman.h
+++ b/libman.h
@@ -54,9 +54,9 @@ enum merr {
__BEGIN_DECLS
#define man_perr(m, l, p, t) \
- man_err((m), l, p, 1, (t))
+ man_err((m), (l), (p), 1, (t))
#define man_pwarn(m, l, p, t) \
- man_err((m), l, p, 0, (t))
+ man_err((m), (l), (p), 0, (t))
#define man_nerr(m, n, t) \
man_err((m), (n)->line, (n)->pos, 1, (t))
#define man_nwarn(m, n, t) \
diff --git a/libmdoc.h b/libmdoc.h
index c8e97efe..f9e31cd6 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -41,6 +41,64 @@ struct mdoc {
enum mdoc_sec lastsec;
};
+enum merr {
+ ETAILWS,
+ ECOLEMPTY,
+ EARGVPARM,
+ EQUOTPARM,
+ EQUOTTERM,
+ EMALLOC,
+ EARGVAL,
+ ENOCALL,
+ EBODYPROL,
+ EPROLBODY,
+ ESPACE,
+ ETEXTPROL,
+ ENOBLANK,
+ ETOOLONG,
+ EESCAPE,
+ EPRINT,
+ ENODAT,
+ ENOPROLOGUE,
+ ELINE,
+ EATT,
+ ENAME,
+ ELISTTYPE,
+ EDISPTYPE,
+ EMULTIDISP,
+ ESECNAME,
+ EMULTILIST,
+ EARGREP,
+ EBOOL,
+ ECOLMIS,
+ ENESTDISP,
+ EMISSWIDTH,
+ EWRONGMSEC,
+ ESECOOO,
+ ESECREP,
+ EBADSTAND,
+ ENAMESECINC,
+ ENOMULTILINE,
+ EMULTILINE,
+ ENOLINE,
+ EPROLOOO,
+ EPROLREP,
+ EBADMSEC,
+ EFONT,
+ EBADDATE,
+ ENOWIDTH,
+ EBADSEC,
+ EUTSNAME,
+ ENUMFMT,
+ EOBS,
+ EMACPARM,
+ EIMPBRK,
+ EIGNE,
+ EOPEN,
+ EQUOT,
+ ENOCTX,
+ ENOPARMS
+};
#define MACRO_PROT_ARGS struct mdoc *mdoc, int tok, int line, \
int ppos, int *pos, char *buf
@@ -60,18 +118,19 @@ extern const struct mdoc_macro *const mdoc_macros;
__BEGIN_DECLS
-/*
- * When GCC2 is deprecated, most of these can be reverted to #define
- * as mdoc_vXXX using __VA_ARGS__. Until then, use real functions.
- */
-int mdoc_vwarn(struct mdoc *, int, int, const char *, ...);
+#define mdoc_perr(m, l, p, t) \
+ mdoc_err((m), (l), (p), 1, (t))
+#define mdoc_pwarn(m, l, p, t) \
+ mdoc_err((m), (l), (p), 0, (t))
+#define mdoc_nerr(m, n, t) \
+ mdoc_err((m), (n)->line, (n)->pos, 0, (t))
+#define mdoc_nwarn(m, n, t) \
+ mdoc_err((m), (n)->line, (n)->pos, 1, (t))
+
+int mdoc_err(struct mdoc *, int, int, int, enum merr);
int mdoc_verr(struct mdoc *, int, int, const char *, ...);
-int mdoc_nerr(struct mdoc *, const struct mdoc_node *,
- const char *, ...);
-int mdoc_warn(struct mdoc *, const char *, ...);
-int mdoc_err(struct mdoc *, const char *, ...);
-int mdoc_pwarn(struct mdoc *, int, int, const char *, ...);
-int mdoc_perr(struct mdoc *, int, int, const char *, ...);
+int mdoc_vwarn(struct mdoc *, int, int, const char *, ...);
+
int mdoc_macro(MACRO_PROT_ARGS);
int mdoc_word_alloc(struct mdoc *,
int, int, const char *);
diff --git a/mdoc.c b/mdoc.c
index 02fe0d10..5e2f3ae9 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -23,16 +23,6 @@
#include "libmdoc.h"
-enum merr {
- ENOCALL,
- EBODYPROL,
- EPROLBODY,
- ESPACE,
- ETEXTPROL,
- ENOBLANK,
- EMALLOC
-};
-
const char *const __mdoc_macronames[MDOC_MAX] = {
"Ap", "Dd", "Dt", "Os",
"Sh", "Ss", "Pp", "D1",
@@ -95,7 +85,7 @@ static int node_append(struct mdoc *,
static int parsetext(struct mdoc *, int, char *);
static int parsemacro(struct mdoc *, int, char *);
static int macrowarn(struct mdoc *, int, const char *);
-static int perr(struct mdoc *, int, int, enum merr);
+
const struct mdoc_node *
mdoc_node(const struct mdoc *m)
@@ -259,6 +249,7 @@ mdoc_verr(struct mdoc *mdoc, int ln, int pos,
va_start(ap, fmt);
(void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
va_end(ap);
+
return((*mdoc->cb.mdoc_err)(mdoc->data, ln, pos, buf));
}
@@ -275,118 +266,18 @@ mdoc_vwarn(struct mdoc *mdoc, int ln, int pos, const char *fmt, ...)
va_start(ap, fmt);
(void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
va_end(ap);
- return((*mdoc->cb.mdoc_warn)(mdoc->data, ln, pos, buf));
-}
-
-
-int
-mdoc_nerr(struct mdoc *mdoc, const struct mdoc_node *node,
- const char *fmt, ...)
-{
- char buf[256];
- va_list ap;
-
- if (NULL == mdoc->cb.mdoc_err)
- return(0);
-
- va_start(ap, fmt);
- (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
- va_end(ap);
- return((*mdoc->cb.mdoc_err)(mdoc->data,
- node->line, node->pos, buf));
-}
-
-int
-mdoc_warn(struct mdoc *mdoc, const char *fmt, ...)
-{
- char buf[256];
- va_list ap;
-
- if (NULL == mdoc->cb.mdoc_warn)
- return(0);
-
- va_start(ap, fmt);
- (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
- va_end(ap);
- return((*mdoc->cb.mdoc_warn)(mdoc->data, mdoc->last->line,
- mdoc->last->pos, buf));
-}
-
-
-int
-mdoc_err(struct mdoc *mdoc, const char *fmt, ...)
-{
- char buf[256];
- va_list ap;
-
- if (NULL == mdoc->cb.mdoc_err)
- return(0);
-
- va_start(ap, fmt);
- (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
- va_end(ap);
- return((*mdoc->cb.mdoc_err)(mdoc->data, mdoc->last->line,
- mdoc->last->pos, buf));
-}
-
-
-int
-mdoc_pwarn(struct mdoc *mdoc, int line, int pos, const char *fmt, ...)
-{
- char buf[256];
- va_list ap;
-
- if (NULL == mdoc->cb.mdoc_warn)
- return(0);
-
- va_start(ap, fmt);
- (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
- va_end(ap);
- return((*mdoc->cb.mdoc_warn)(mdoc->data, line, pos, buf));
-}
-
-int
-mdoc_perr(struct mdoc *mdoc, int line, int pos, const char *fmt, ...)
-{
- char buf[256];
- va_list ap;
-
- if (NULL == mdoc->cb.mdoc_err)
- return(0);
-
- va_start(ap, fmt);
- (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
- va_end(ap);
- return((*mdoc->cb.mdoc_err)(mdoc->data, line, pos, buf));
+ return((*mdoc->cb.mdoc_warn)(mdoc->data, ln, pos, buf));
}
int
-mdoc_macro(struct mdoc *m, int tok,
- int ln, int pp, int *pos, char *buf)
-{
-
- if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
- MDOC_PBODY & m->flags)
- return(perr(m, ln, pp, EPROLBODY));
- if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
- ! (MDOC_PBODY & m->flags))
- return(perr(m, ln, pp, EBODYPROL));
-
- if (1 != pp && ! (MDOC_CALLABLE & mdoc_macros[tok].flags))
- return(perr(m, ln, pp, ENOCALL));
-
- return((*mdoc_macros[tok].fp)(m, tok, ln, pp, pos, buf));
-}
-
-
-static int
-perr(struct mdoc *m, int line, int pos, enum merr type)
+mdoc_err(struct mdoc *m, int line, int pos, int iserr, enum merr type)
{
- char *p;
-
+ char *p;
+
p = NULL;
+
switch (type) {
case (ENOCALL):
p = "not callable";
@@ -409,9 +300,180 @@ perr(struct mdoc *m, int line, int pos, enum merr type)
case (ESPACE):
p = "whitespace disallowed after delimiter";
break;
+ case (ETOOLONG):
+ p = "text argument too long";
+ break;
+ case (EESCAPE):
+ p = "invalid escape sequence";
+ break;
+ case (EPRINT):
+ p = "invalid character";
+ break;
+ case (ENESTDISP):
+ p = "displays may not be nested";
+ break;
+ case (EBOOL):
+ p = "expected boolean value";
+ break;
+ case (EARGREP):
+ p = "argument repeated";
+ break;
+ case (EMULTIDISP):
+ p = "multiple display types specified";
+ break;
+ case (EMULTILIST):
+ p = "multiple list types specified";
+ break;
+ case (ELISTTYPE):
+ p = "missing list type";
+ break;
+ case (EDISPTYPE):
+ p = "missing display type";
+ break;
+ case (ESECNAME):
+ p = "the NAME section must come first";
+ break;
+ case (ELINE):
+ p = "expected line arguments";
+ break;
+ case (ENOPROLOGUE):
+ p = "document has no prologue";
+ break;
+ case (ENODAT):
+ p = "document has no data";
+ break;
+ case (ECOLMIS):
+ p = "column syntax style mismatch";
+ break;
+ case (EATT):
+ p = "expected valid AT&T symbol";
+ break;
+ case (ENAME):
+ p = "default name not yet set";
+ break;
+ case (ENOWIDTH):
+ p = "superfluous width argument";
+ break;
+ case (EMISSWIDTH):
+ p = "missing width argument";
+ break;
+ case (EWRONGMSEC):
+ p = "document section in wrong manual section";
+ break;
+ case (ESECOOO):
+ p = "document section out of conventional order";
+ break;
+ case (ESECREP):
+ p = "document section repeated";
+ break;
+ case (EBADSTAND):
+ p = "unknown standard";
+ break;
+ case (ENAMESECINC):
+ p = "NAME section contents incomplete/badly-ordered";
+ break;
+ case (ENOMULTILINE):
+ p = "suggested no multi-line arguments";
+ break;
+ case (EMULTILINE):
+ p = "suggested multi-line arguments";
+ break;
+ case (ENOLINE):
+ p = "suggested no line arguments";
+ break;
+ case (EPROLOOO):
+ p = "prologue macros out-of-order";
+ break;
+ case (EPROLREP):
+ p = "prologue macros repeated";
+ break;
+ case (EARGVAL):
+ p = "argument value suggested";
+ break;
+ case (EFONT):
+ p = "invalid font mode";
+ break;
+ case (EBADMSEC):
+ p = "inappropriate manual section";
+ break;
+ case (EBADSEC):
+ p = "inappropriate document section";
+ break;
+ case (EQUOTTERM):
+ p = "unterminated quoted parameter";
+ break;
+ case (EQUOTPARM):
+ p = "unexpected quoted parameter";
+ break;
+ case (EARGVPARM):
+ p = "argument-like parameter";
+ break;
+ case (ECOLEMPTY):
+ p = "last list column is empty";
+ break;
+ case (ETAILWS):
+ p = "trailing whitespace";
+ break;
+ case (ENUMFMT):
+ p = "bad number format";
+ break;
+ case (EUTSNAME):
+ p = "utsname";
+ break;
+ case (EBADDATE):
+ p = "malformed date syntax";
+ break;
+ case (EOPEN):
+ p = "explicit scope still open on exit";
+ break;
+ case (EQUOT):
+ p = "unterminated quotation";
+ break;
+ case (ENOCTX):
+ p = "closure has no prior context";
+ break;
+ case (ENOPARMS):
+ p = "unexpect line arguments";
+ break;
+ case (EIGNE):
+ p = "ignoring empty element";
+ break;
+ case (EIMPBRK):
+ p = "crufty end-of-line scope violation";
+ break;
+ case (EMACPARM):
+ p = "macro-like parameter";
+ break;
+ case (EOBS):
+ p = "macro marked obsolete";
+ break;
}
+
assert(p);
- return(mdoc_perr(m, line, pos, p));
+
+ if (iserr)
+ return(mdoc_verr(m, line, pos, p));
+
+ return(mdoc_vwarn(m, line, pos, p));
+}
+
+
+int
+mdoc_macro(struct mdoc *m, int tok,
+ int ln, int pp, int *pos, char *buf)
+{
+
+ if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
+ MDOC_PBODY & m->flags)
+ return(mdoc_perr(m, ln, pp, EPROLBODY));
+ if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
+ ! (MDOC_PBODY & m->flags))
+ return(mdoc_perr(m, ln, pp, EBODYPROL));
+
+ if (1 != pp && ! (MDOC_CALLABLE & mdoc_macros[tok].flags))
+ return(mdoc_perr(m, ln, pp, ENOCALL));
+
+ return((*mdoc_macros[tok].fp)(m, tok, ln, pp, pos, buf));
}
@@ -486,8 +548,7 @@ node_alloc(struct mdoc *mdoc, int line,
struct mdoc_node *p;
if (NULL == (p = calloc(1, sizeof(struct mdoc_node)))) {
- (void)perr(mdoc, (mdoc)->last->line,
- (mdoc)->last->pos, EMALLOC);
+ (void)mdoc_nerr(mdoc, mdoc->last, EMALLOC);
return(NULL);
}
@@ -583,10 +644,10 @@ mdoc_word_alloc(struct mdoc *mdoc,
if (NULL == p)
return(0);
if (NULL == (p->string = strdup(word))) {
- (void)perr(mdoc, (mdoc)->last->line,
- (mdoc)->last->pos, EMALLOC);
+ (void)mdoc_nerr(mdoc, mdoc->last, EMALLOC);
return(0);
}
+
return(node_append(mdoc, p));
}
@@ -628,10 +689,10 @@ parsetext(struct mdoc *m, int line, char *buf)
{
if (SEC_NONE == m->lastnamed)
- return(perr(m, line, 0, ETEXTPROL));
+ return(mdoc_perr(m, line, 0, ETEXTPROL));
if (0 == buf[0] && ! (MDOC_LITERAL & m->flags))
- return(perr(m, line, 0, ENOBLANK));
+ return(mdoc_perr(m, line, 0, ENOBLANK));
if ( ! mdoc_word_alloc(m, line, 0, buf))
return(0);
@@ -645,10 +706,10 @@ static int
macrowarn(struct mdoc *m, int ln, const char *buf)
{
if ( ! (MDOC_IGN_MACRO & m->pflags))
- return(mdoc_perr(m, ln, 1,
+ return(mdoc_verr(m, ln, 1,
"unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
- return(mdoc_pwarn(m, ln, 1, "unknown macro: %s%s",
+ return(mdoc_vwarn(m, ln, 1, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
}
@@ -674,7 +735,7 @@ parsemacro(struct mdoc *m, int ln, char *buf)
i++;
if (0 == buf[i])
return(1);
- return(perr(m, ln, 1, ESPACE));
+ return(mdoc_perr(m, ln, 1, ESPACE));
}
/* Copy the first word into a nil-terminated buffer. */
diff --git a/mdoc_action.c b/mdoc_action.c
index 915b58e3..8d36635e 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -24,16 +24,6 @@
#include "libmdoc.h"
-enum merr {
- EBADDATE,
- ENOWIDTH,
- EBADSEC,
- ETOOLONG,
- EMALLOC,
- EUTSNAME,
- ENUMFMT
-};
-
#define PRE_ARGS struct mdoc *m, const struct mdoc_node *n
#define POST_ARGS struct mdoc *m
@@ -42,7 +32,6 @@ struct actions {
int (*post)(POST_ARGS);
};
-static int perr(struct mdoc *, int, int, enum merr, int);
static int concat(struct mdoc *, const struct mdoc_node *,
char *, size_t);
@@ -64,10 +53,6 @@ static int post_std(POST_ARGS);
static int pre_bd(PRE_ARGS);
static int pre_dl(PRE_ARGS);
-#define vwarn(m, t) perr((m), (m)->last->line, (m)->last->pos, (t), 0)
-#define verr(m, t) perr((m), (m)->last->line, (m)->last->pos, (t), 1)
-#define nerr(m, n, t) perr((m), (n)->line, (n)->pos, (t), 1)
-
const struct actions mdoc_actions[MDOC_MAX] = {
{ NULL, NULL }, /* Ap */
{ NULL, post_dd }, /* Dd */
@@ -245,11 +230,11 @@ concat(struct mdoc *m, const struct mdoc_node *n,
for ( ; n; n = n->next) {
assert(MDOC_TEXT == n->type);
if (strlcat(buf, n->string, sz) >= sz)
- return(nerr(m, n, ETOOLONG));
+ return(mdoc_nerr(m, n, ETOOLONG));
if (NULL == n->next)
continue;
if (strlcat(buf, " ", sz) >= sz)
- return(nerr(m, n, ETOOLONG));
+ return(mdoc_nerr(m, n, ETOOLONG));
}
return(1);
@@ -257,45 +242,6 @@ concat(struct mdoc *m, const struct mdoc_node *n,
static int
-perr(struct mdoc *m, int line, int pos, enum merr type, int iserr)
-{
- char *p;
-
- p = NULL;
-
- switch (type) {
- case (ENUMFMT):
- p = "bad number format";
- break;
- case (ETOOLONG):
- p = "argument text too long";
- break;
- case (EUTSNAME):
- p = "utsname";
- break;
- case (EMALLOC):
- p = "memory exhausted";
- break;
- case (EBADSEC):
- p = "inappropriate document section in manual section";
- break;
- case (ENOWIDTH):
- p = "cannot determine default width";
- break;
- case (EBADDATE):
- p = "malformed date syntax";
- break;
- }
-
- assert(p);
- if (iserr)
- return(mdoc_perr(m, line, pos, p));
-
- return(mdoc_pwarn(m, line, pos, p));
-}
-
-
-static int
post_std(POST_ARGS)
{
@@ -313,12 +259,12 @@ post_std(POST_ARGS)
m->last->args->argv[0].value = calloc(1, sizeof(char *));
if (NULL == m->last->args->argv[0].value)
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
m->last->args->argv[0].sz = 1;
m->last->args->argv[0].value[0] = strdup(m->meta.name);
if (NULL == m->last->args->argv[0].value[0])
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
return(1);
}
@@ -337,7 +283,7 @@ post_nm(POST_ARGS)
return(0);
if (NULL == (m->meta.name = strdup(buf)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
return(1);
}
@@ -376,7 +322,7 @@ post_sh(POST_ARGS)
case (9):
break;
default:
- return(vwarn(m, EBADSEC));
+ return(mdoc_nwarn(m, m->last, EBADSEC));
}
break;
default:
@@ -410,9 +356,9 @@ post_dt(POST_ARGS)
if (NULL == (n = m->last->child)) {
if (NULL == (m->meta.title = strdup("unknown")))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
if (NULL == (m->meta.vol = strdup("local")))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
return(post_prol(m));
}
@@ -421,11 +367,11 @@ post_dt(POST_ARGS)
*/
if (NULL == (m->meta.title = strdup(n->string)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
if (NULL == (n = n->next)) {
if (NULL == (m->meta.vol = strdup("local")))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
return(post_prol(m));
}
@@ -439,13 +385,13 @@ post_dt(POST_ARGS)
cp = mdoc_a2msec(n->string);
if (cp) {
if (NULL == (m->meta.vol = strdup(cp)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
errno = 0;
lval = strtol(n->string, &ep, 10);
if (n->string[0] != '\0' && *ep == '\0')
m->meta.msec = (int)lval;
} else if (NULL == (m->meta.vol = strdup(n->string)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
if (NULL == (n = n->next))
return(post_prol(m));
@@ -461,16 +407,16 @@ post_dt(POST_ARGS)
if (cp) {
free(m->meta.vol);
if (NULL == (m->meta.vol = strdup(cp)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
n = n->next;
} else {
cp = mdoc_a2arch(n->string);
if (NULL == cp) {
free(m->meta.vol);
if (NULL == (m->meta.vol = strdup(n->string)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
} else if (NULL == (m->meta.arch = strdup(cp)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
}
/* Ignore any subsequent parameters... */
@@ -494,17 +440,17 @@ post_os(POST_ARGS)
if (0 == buf[0]) {
if (-1 == uname(&utsname))
- return(verr(m, EUTSNAME));
+ return(mdoc_nerr(m, m->last, EUTSNAME));
if (strlcat(buf, utsname.sysname, 64) >= 64)
- return(verr(m, ETOOLONG));
+ return(mdoc_nerr(m, m->last, ETOOLONG));
if (strlcat(buf, " ", 64) >= 64)
- return(verr(m, ETOOLONG));
+ return(mdoc_nerr(m, m->last, ETOOLONG));
if (strlcat(buf, utsname.release, 64) >= 64)
- return(verr(m, ETOOLONG));
+ return(mdoc_nerr(m, m->last, ETOOLONG));
}
if (NULL == (m->meta.os = strdup(buf)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
m->flags |= MDOC_PBODY;
return(post_prol(m));
@@ -539,14 +485,14 @@ post_bl_tagwidth(struct mdoc *m)
if (n) {
if (MDOC_TEXT != n->type) {
if (0 == (sz = (int)mdoc_macro2len(n->tok)))
- if ( ! vwarn(m, ENOWIDTH))
+ if ( ! mdoc_nwarn(m, m->last, ENOWIDTH))
return(0);
} else
sz = (int)strlen(n->string) + 1;
}
if (-1 == snprintf(buf, sizeof(buf), "%dn", sz))
- return(verr(m, ENUMFMT));
+ return(mdoc_nerr(m, m->last, ENUMFMT));
/*
* We have to dynamically add this to the macro's argument list.
@@ -561,7 +507,7 @@ post_bl_tagwidth(struct mdoc *m)
n->args->argc * sizeof(struct mdoc_argv));
if (NULL == n->args->argv)
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
n->args->argv[sz].arg = MDOC_Width;
n->args->argv[sz].line = m->last->line;
@@ -570,9 +516,9 @@ post_bl_tagwidth(struct mdoc *m)
n->args->argv[sz].value = calloc(1, sizeof(char *));
if (NULL == n->args->argv[sz].value)
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
if (NULL == (n->args->argv[sz].value[0] = strdup(buf)))
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
return(1);
}
@@ -607,17 +553,17 @@ post_bl_width(struct mdoc *m)
else if (MDOC_MAX == (tok = mdoc_hash_find(m->htab, p)))
return(1);
else if (0 == (width = mdoc_macro2len(tok)))
- return(vwarn(m, ENOWIDTH));
+ return(mdoc_nwarn(m, m->last, ENOWIDTH));
/* The value already exists: free and reallocate it. */
if (-1 == snprintf(buf, sizeof(buf), "%zun", width))
- return(verr(m, ENUMFMT));
+ return(mdoc_nerr(m, m->last, ENUMFMT));
free(m->last->args->argv[i].value[0]);
m->last->args->argv[i].value[0] = strdup(buf);
if (NULL == m->last->args->argv[i].value[0])
- return(verr(m, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
return(1);
}
@@ -764,7 +710,7 @@ post_dd(POST_ARGS)
return(0);
if (0 == (m->meta.date = mdoc_atotime(buf))) {
- if ( ! vwarn(m, EBADDATE))
+ if ( ! mdoc_nwarn(m, m->last, EBADDATE))
return(0);
m->meta.date = time(NULL);
}
diff --git a/mdoc_argv.c b/mdoc_argv.c
index 407edcb6..cd397f5d 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -47,16 +47,6 @@
#define MULTI_STEP 5
-enum merr {
- ETAILWS,
- ECOLEMPTY,
- EARGVPARM,
- EQUOTPARM,
- EQUOTTERM,
- EMALLOC,
- EARGVAL
-};
-
static int argv_a2arg(int, const char *);
static int args(struct mdoc *, int, int *,
char *, int, char **);
@@ -68,10 +58,6 @@ static int argv_opt_single(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
static int argv_multi(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
-static int perr(struct mdoc *, int, int, enum merr, int);
-
-#define pwarn(m, l, p, t) perr((m), (l), (p), (t), 0)
-#define verr(m, t) perr((m), (m)->last->line, (m)->last->pos, (t), 1)
/* Per-argument flags. */
@@ -232,7 +218,7 @@ static int mdoc_argflags[MDOC_MAX] = {
* one mandatory value, an optional single value, or no value.
*/
int
-mdoc_argv(struct mdoc *mdoc, int line, int tok,
+mdoc_argv(struct mdoc *m, int line, int tok,
struct mdoc_arg **v, int *pos, char *buf)
{
int i;
@@ -281,7 +267,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
/* XXX - restore saved zeroed byte. */
if (sv)
buf[*pos - 1] = sv;
- if ( ! pwarn(mdoc, line, i, EARGVPARM))
+ if ( ! mdoc_pwarn(m, line, i, EARGVPARM))
return(ARGV_ERROR);
return(ARGV_WORD);
}
@@ -289,13 +275,13 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
while (buf[*pos] && ' ' == buf[*pos])
(*pos)++;
- if ( ! argv(mdoc, line, &tmp, pos, buf))
+ if ( ! argv(m, line, &tmp, pos, buf))
return(ARGV_ERROR);
if (NULL == (arg = *v)) {
*v = calloc(1, sizeof(struct mdoc_arg));
if (NULL == *v) {
- (void)verr(mdoc, EMALLOC);
+ (void)mdoc_nerr(m, m->last, EMALLOC);
return(ARGV_ERROR);
}
arg = *v;
@@ -306,7 +292,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
sizeof(struct mdoc_argv));
if (NULL == arg->argv) {
- (void)verr(mdoc, EMALLOC);
+ (void)mdoc_nerr(m, m->last, EMALLOC);
return(ARGV_ERROR);
}
@@ -348,48 +334,8 @@ mdoc_argv_free(struct mdoc_arg *p)
}
-
-static int
-perr(struct mdoc *mdoc, int line, int pos, enum merr code, int iserr)
-{
- char *p;
-
- p = NULL;
-
- switch (code) {
- case (EMALLOC):
- p = "memory exhausted";
- break;
- case (EQUOTTERM):
- p = "unterminated quoted parameter";
- break;
- case (EARGVAL):
- p = "argument requires a value";
- break;
- case (EQUOTPARM):
- p = "unexpected quoted parameter";
- break;
- case (EARGVPARM):
- p = "argument-like parameter";
- break;
- case (ECOLEMPTY):
- p = "last list column is empty";
- break;
- case (ETAILWS):
- p = "trailing whitespace";
- break;
- }
-
- assert(p);
- if (iserr)
- return(mdoc_perr(mdoc, line, pos, p));
-
- return(mdoc_pwarn(mdoc, line, pos, p));
-}
-
-
int
-mdoc_args(struct mdoc *mdoc, int line,
+mdoc_args(struct mdoc *m, int line,
int *pos, char *buf, int tok, char **v)
{
int fl, c, i;
@@ -405,7 +351,7 @@ mdoc_args(struct mdoc *mdoc, int line,
switch (tok) {
case (MDOC_It):
- for (n = mdoc->last; n; n = n->parent)
+ for (n = m->last; n; n = n->parent)
if (MDOC_BLOCK == n->type && MDOC_Bl == n->tok)
break;
@@ -440,12 +386,12 @@ mdoc_args(struct mdoc *mdoc, int line,
break;
}
- return(args(mdoc, line, pos, buf, fl, v));
+ return(args(m, line, pos, buf, fl, v));
}
static int
-args(struct mdoc *mdoc, int line,
+args(struct mdoc *m, int line,
int *pos, char *buf, int fl, char **v)
{
int i;
@@ -457,11 +403,11 @@ args(struct mdoc *mdoc, int line,
return(ARGS_EOLN);
if ('\"' == buf[*pos] && ! (fl & ARGS_QUOTED))
- if ( ! pwarn(mdoc, line, *pos, EQUOTPARM))
+ if ( ! mdoc_pwarn(m, line, *pos, EQUOTPARM))
return(ARGS_ERROR);
if ( ! (fl & ARGS_ARGVLIKE) && '-' == buf[*pos])
- if ( ! pwarn(mdoc, line, *pos, EARGVPARM))
+ if ( ! mdoc_pwarn(m, line, *pos, EARGVPARM))
return(ARGS_ERROR);
/*
@@ -553,10 +499,10 @@ args(struct mdoc *mdoc, int line,
}
if (p && 0 == *p)
- if ( ! pwarn(mdoc, line, *pos, ECOLEMPTY))
+ if ( ! mdoc_pwarn(m, line, *pos, ECOLEMPTY))
return(0);
if (p && 0 == *p && p > *v && ' ' == *(p - 1))
- if ( ! pwarn(mdoc, line, *pos, ETAILWS))
+ if ( ! mdoc_pwarn(m, line, *pos, ETAILWS))
return(0);
if (p)
@@ -568,7 +514,7 @@ args(struct mdoc *mdoc, int line,
assert(p);
if (p > *v && ' ' == *(p - 1))
- if ( ! pwarn(mdoc, line, *pos, ETAILWS))
+ if ( ! mdoc_pwarn(m, line, *pos, ETAILWS))
return(0);
*pos += (int)(p - *v);
@@ -600,7 +546,7 @@ args(struct mdoc *mdoc, int line,
if (buf[*pos])
return(ARGS_WORD);
- if ( ! pwarn(mdoc, line, *pos, ETAILWS))
+ if ( ! mdoc_pwarn(m, line, *pos, ETAILWS))
return(ARGS_ERROR);
return(ARGS_WORD);
@@ -618,7 +564,7 @@ args(struct mdoc *mdoc, int line,
(*pos)++;
if (0 == buf[*pos]) {
- (void)perr(mdoc, line, *pos, EQUOTTERM, 1);
+ (void)mdoc_perr(m, line, *pos, EQUOTTERM);
return(ARGS_ERROR);
}
@@ -632,7 +578,7 @@ args(struct mdoc *mdoc, int line,
if (buf[*pos])
return(ARGS_QWORD);
- if ( ! pwarn(mdoc, line, *pos, ETAILWS))
+ if ( ! mdoc_pwarn(m, line, *pos, ETAILWS))
return(ARGS_ERROR);
return(ARGS_QWORD);
@@ -738,7 +684,7 @@ argv_a2arg(int tok, const char *argv)
static int
-argv_multi(struct mdoc *mdoc, int line,
+argv_multi(struct mdoc *m, int line,
struct mdoc_argv *v, int *pos, char *buf)
{
int c;
@@ -747,7 +693,7 @@ argv_multi(struct mdoc *mdoc, int line,
for (v->sz = 0; ; v->sz++) {
if ('-' == buf[*pos])
break;
- c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
+ c = args(m, line, pos, buf, ARGS_QUOTED, &p);
if (ARGS_ERROR == c)
return(0);
else if (ARGS_EOLN == c)
@@ -757,12 +703,12 @@ argv_multi(struct mdoc *mdoc, int line,
v->value = realloc(v->value,
(v->sz + MULTI_STEP) * sizeof(char *));
if (NULL == v->value) {
- (void)verr(mdoc, EMALLOC);
+ (void)mdoc_nerr(m, m->last, EMALLOC);
return(ARGV_ERROR);
}
}
if (NULL == (v->value[(int)v->sz] = strdup(p)))
- return(verr(mdoc, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
}
return(1);
@@ -770,7 +716,7 @@ argv_multi(struct mdoc *mdoc, int line,
static int
-argv_opt_single(struct mdoc *mdoc, int line,
+argv_opt_single(struct mdoc *m, int line,
struct mdoc_argv *v, int *pos, char *buf)
{
int c;
@@ -779,7 +725,7 @@ argv_opt_single(struct mdoc *mdoc, int line,
if ('-' == buf[*pos])
return(1);
- c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
+ c = args(m, line, pos, buf, ARGS_QUOTED, &p);
if (ARGS_ERROR == c)
return(0);
if (ARGS_EOLN == c)
@@ -787,9 +733,9 @@ argv_opt_single(struct mdoc *mdoc, int line,
v->sz = 1;
if (NULL == (v->value = calloc(1, sizeof(char *))))
- return(verr(mdoc, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
if (NULL == (v->value[0] = strdup(p)))
- return(verr(mdoc, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
return(1);
}
@@ -799,7 +745,7 @@ argv_opt_single(struct mdoc *mdoc, int line,
* Parse a single, mandatory value from the stream.
*/
static int
-argv_single(struct mdoc *mdoc, int line,
+argv_single(struct mdoc *m, int line,
struct mdoc_argv *v, int *pos, char *buf)
{
int c, ppos;
@@ -807,17 +753,17 @@ argv_single(struct mdoc *mdoc, int line,
ppos = *pos;
- c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
+ c = args(m, line, pos, buf, ARGS_QUOTED, &p);
if (ARGS_ERROR == c)
return(0);
if (ARGS_EOLN == c)
- return(perr(mdoc, line, ppos, EARGVAL, 1));
+ return(mdoc_perr(m, line, ppos, EARGVAL));
v->sz = 1;
if (NULL == (v->value = calloc(1, sizeof(char *))))
- return(verr(mdoc, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
if (NULL == (v->value[0] = strdup(p)))
- return(verr(mdoc, EMALLOC));
+ return(mdoc_nerr(m, m->last, EMALLOC));
return(1);
}
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 857c4bce..87a0ddfb 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -22,20 +22,6 @@
#include "libmdoc.h"
-enum mwarn {
- WIGNE,
- WIMPBRK,
- WMACPARM,
- WOBS
-};
-
-enum merr {
- EOPEN,
- EQUOT,
- ENOCTX,
- ENOPARMS
-};
-
#define REWIND_REWIND (1 << 0)
#define REWIND_NOHALT (1 << 1)
#define REWIND_HALT (1 << 2)
@@ -62,13 +48,9 @@ static int rew_subblock(enum mdoc_type,
static int rew_last(struct mdoc *, struct mdoc_node *);
static int append_delims(struct mdoc *, int, int *, char *);
static int lookup(struct mdoc *, int, int, int, const char *);
-static int pwarn(struct mdoc *, int, int, enum mwarn);
-static int perr(struct mdoc *, int, int, enum merr);
static int swarn(struct mdoc *, enum mdoc_type, int, int,
const struct mdoc_node *);
-#define nerr(m, n, t) perr((m), (n)->line, (n)->pos, (t))
-
/* Central table of library: who gets parsed how. */
const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
@@ -196,56 +178,6 @@ const struct mdoc_macro * const mdoc_macros = __mdoc_macros;
static int
-perr(struct mdoc *mdoc, int line, int pos, enum merr type)
-{
- char *p;
-
- p = NULL;
- switch (type) {
- case (EOPEN):
- p = "explicit scope still open on exit";
- break;
- case (EQUOT):
- p = "unterminated quotation";
- break;
- case (ENOCTX):
- p = "closure has no prior context";
- break;
- case (ENOPARMS):
- p = "unexpect line arguments";
- break;
- }
- assert(p);
- return(mdoc_perr(mdoc, line, pos, p));
-}
-
-
-static int
-pwarn(struct mdoc *mdoc, int line, int pos, enum mwarn type)
-{
- char *p;
-
- p = NULL;
- switch (type) {
- case (WIGNE):
- p = "ignoring empty element";
- break;
- case (WIMPBRK):
- p = "crufty end-of-line scope violation";
- break;
- case (WMACPARM):
- p = "macro-like parameter";
- break;
- case (WOBS):
- p = "macro marked obsolete";
- break;
- }
- assert(p);
- return(mdoc_pwarn(mdoc, line, pos, p));
-}
-
-
-static int
swarn(struct mdoc *mdoc, enum mdoc_type type,
int line, int pos, const struct mdoc_node *p)
{
@@ -283,10 +215,10 @@ swarn(struct mdoc *mdoc, enum mdoc_type type,
}
if ( ! (MDOC_IGN_SCOPE & mdoc->pflags))
- return(mdoc_perr(mdoc, line, pos,
+ return(mdoc_verr(mdoc, line, pos,
"%s scope breaks %s scope of %s",
tt, t, n));
- return(mdoc_pwarn(mdoc, line, pos,
+ return(mdoc_vwarn(mdoc, line, pos,
"%s scope breaks %s scope of %s",
tt, t, n));
}
@@ -312,7 +244,7 @@ mdoc_macroend(struct mdoc *mdoc)
continue;
if ( ! (MDOC_EXPLICIT & mdoc_macros[n->tok].flags))
continue;
- return(nerr(mdoc, n, EOPEN));
+ return(mdoc_nerr(mdoc, n, EOPEN));
}
return(rew_last(mdoc, mdoc->first));
@@ -328,7 +260,7 @@ lookup(struct mdoc *mdoc, int line, int pos, int from, const char *p)
return(res);
if (MDOC_MAX == res)
return(res);
- if ( ! pwarn(mdoc, line, pos, WMACPARM))
+ if ( ! mdoc_pwarn(mdoc, line, pos, EMACPARM))
return(-1);
return(MDOC_MAX);
}
@@ -637,7 +569,7 @@ rew_expblock(struct mdoc *mdoc, int tok, int line, int ppos)
for (n = mdoc->last; n; n = n->parent) {
c = rew_dohalt(tok, MDOC_BLOCK, n);
if (REWIND_HALT == c)
- return(perr(mdoc, line, ppos, ENOCTX));
+ return(mdoc_perr(mdoc, line, ppos, ENOCTX));
if (REWIND_REWIND == c)
break;
else if (rew_dobreak(tok, n))
@@ -728,7 +660,7 @@ blk_exp_close(MACRO_PROT_ARGS)
return(0);
return(rew_expblock(mdoc, tok, line, ppos));
}
- return(perr(mdoc, line, ppos, ENOPARMS));
+ return(mdoc_perr(mdoc, line, ppos, ENOPARMS));
}
if ( ! rew_subblock(MDOC_BODY, mdoc, tok, line, ppos))
@@ -871,7 +803,7 @@ in_line(MACRO_PROT_ARGS)
return(0);
} else if ( ! nc && 0 == cnt) {
mdoc_argv_free(arg);
- if ( ! pwarn(mdoc, line, ppos, WIGNE))
+ if ( ! mdoc_pwarn(mdoc, line, ppos, EIGNE))
return(0);
}
c = mdoc_macro(mdoc, c, line, la, pos, buf);
@@ -927,7 +859,7 @@ in_line(MACRO_PROT_ARGS)
return(0);
} else if ( ! nc && 0 == cnt) {
mdoc_argv_free(arg);
- if ( ! pwarn(mdoc, line, ppos, WIGNE))
+ if ( ! mdoc_pwarn(mdoc, line, ppos, EIGNE))
return(0);
}
@@ -1111,7 +1043,7 @@ blk_part_imp(MACRO_PROT_ARGS)
if (body == n)
break;
- if (NULL == n && ! pwarn(mdoc, body->line, body->pos, WIMPBRK))
+ if (NULL == n && ! mdoc_nwarn(mdoc, body, EIMPBRK))
return(0);
if (n && ! rew_last(mdoc, body))
@@ -1414,7 +1346,7 @@ static int
obsolete(MACRO_PROT_ARGS)
{
- return(pwarn(mdoc, line, ppos, WOBS));
+ return(mdoc_pwarn(mdoc, line, ppos, EOBS));
}
@@ -1450,7 +1382,7 @@ phrase(struct mdoc *mdoc, int line, int ppos, char *buf)
else if ('\\' != buf[i - 1])
break;
if (0 == buf[i])
- return(perr(mdoc, line, la, EQUOT));
+ return(mdoc_perr(mdoc, line, la, EQUOT));
quoted = 1;
} else
for ( ; buf[i]; i++)
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 12898f45..8541c8e2 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -31,40 +31,6 @@
#define PRE_ARGS struct mdoc *mdoc, const struct mdoc_node *n
#define POST_ARGS struct mdoc *mdoc
-enum merr {
- ETOOLONG,
- EESCAPE,
- EPRINT,
- ENODATA,
- ENOPROLOGUE,
- ELINE,
- EATT,
- ENAME,
- ELISTTYPE,
- EDISPTYPE,
- EMULTIDISP,
- ESECNAME,
- EMULTILIST,
- EARGREP,
- EBOOL,
- ECOLMIS,
- ENESTDISP,
- ENOWIDTH,
- EMISSWIDTH,
- EWRONGMSEC,
- ESECOOO,
- ESECREP,
- EBADSTAND,
- ENAMESECINC,
- ENOMULTILINE,
- EMULTILINE,
- ENOLINE,
- EPROLOOO,
- EPROLREP,
- EARGVAL,
- EBADSEC,
- EBADMSEC
-};
typedef int (*v_pre)(PRE_ARGS);
typedef int (*v_post)(POST_ARGS);
@@ -74,7 +40,6 @@ struct valids {
v_post *post;
};
-static int perr(struct mdoc *, int, int, enum merr, int);
static int check_parent(PRE_ARGS, int, enum mdoc_type);
static int check_msec(PRE_ARGS, ...);
static int check_sec(PRE_ARGS, ...);
@@ -139,11 +104,6 @@ static int post_sh_body(POST_ARGS);
static int post_sh_head(POST_ARGS);
static int post_st(POST_ARGS);
-#define vwarn(m, t) nwarn((m), (m)->last, (t))
-#define verr(m, t) nerr((m), (m)->last, (t))
-#define nwarn(m, n, t) perr((m), (n)->line, (n)->pos, (t), 0)
-#define nerr(m, n, t) perr((m), (n)->line, (n)->pos, (t), 1)
-
static v_pre pres_an[] = { pre_an, NULL };
static v_pre pres_bd[] = { pre_display, pre_bd, NULL };
static v_pre pres_bl[] = { pre_bl, NULL };
@@ -370,125 +330,12 @@ mdoc_valid_post(struct mdoc *mdoc)
static int
-perr(struct mdoc *m, int line, int pos, enum merr type, int iserr)
-{
- char *p;
-
- p = NULL;
-
- switch (type) {
- case (ETOOLONG):
- p = "text argument too long";
- break;
- case (EESCAPE):
- p = "invalid escape sequence";
- break;
- case (EPRINT):
- p = "invalid character";
- break;
- case (ENESTDISP):
- p = "displays may not be nested";
- break;
- case (EBOOL):
- p = "expected boolean value";
- break;
- case (EARGREP):
- p = "argument repeated";
- break;
- case (EMULTIDISP):
- p = "multiple display types specified";
- break;
- case (EMULTILIST):
- p = "multiple list types specified";
- break;
- case (ELISTTYPE):
- p = "missing list type";
- break;
- case (EDISPTYPE):
- p = "missing display type";
- break;
- case (ESECNAME):
- p = "the NAME section must come first";
- break;
- case (ELINE):
- p = "expected line arguments";
- break;
- case (ENOPROLOGUE):
- p = "document has no prologue";
- break;
- case (ENODATA):
- p = "document has no data";
- break;
- case (ECOLMIS):
- p = "column syntax style mismatch";
- break;
- case (EATT):
- p = "expected valid AT&T symbol";
- break;
- case (ENAME):
- p = "default name not yet set";
- break;
- case (ENOWIDTH):
- p = "superfluous width argument";
- break;
- case (EMISSWIDTH):
- p = "missing width argument";
- break;
- case (EWRONGMSEC):
- p = "document section in wrong manual section";
- break;
- case (ESECOOO):
- p = "document section out of conventional order";
- break;
- case (ESECREP):
- p = "document section repeated";
- break;
- case (EBADSTAND):
- p = "unknown standard";
- break;
- case (ENAMESECINC):
- p = "NAME section contents incomplete/badly-ordered";
- break;
- case (ENOMULTILINE):
- p = "suggested no multi-line arguments";
- break;
- case (EMULTILINE):
- p = "suggested multi-line arguments";
- break;
- case (ENOLINE):
- p = "suggested no line arguments";
- break;
- case (EPROLOOO):
- p = "prologue macros out-of-order";
- break;
- case (EPROLREP):
- p = "prologue macros repeated";
- break;
- case (EARGVAL):
- p = "argument value suggested";
- break;
- case (EBADMSEC):
- p = "inappropriate manual section";
- break;
- case (EBADSEC):
- p = "inappropriate document section";
- break;
- }
-
- assert(p);
-
- if (iserr)
- return(mdoc_perr(m, line, pos, p));
-
- return(mdoc_pwarn(m, line, pos, p));
-}
-
-
-static int
warn_print(struct mdoc *m, int ln, int pos)
{
- return(perr(m, ln, pos, EPRINT, ! (MDOC_IGN_CHARS & m->pflags)));
+ if (MDOC_IGN_CHARS & m->pflags)
+ return(mdoc_pwarn(m, ln, pos, EPRINT));
+ return(mdoc_perr(m, ln, pos, EPRINT));
}
@@ -497,8 +344,8 @@ warn_count(struct mdoc *m, const char *k,
int want, const char *v, int has)
{
- return(mdoc_warn(m, "suggests %s %s %d (has %d)",
- v, k, want, has));
+ return(mdoc_vwarn(m, m->last->line, m->last->pos,
+ "suggests %s %s %d (has %d)", v, k, want, has));
}
@@ -507,7 +354,7 @@ err_count(struct mdoc *m, const char *k,
int want, const char *v, int has)
{
- return(mdoc_err(m,
+ return(mdoc_verr(m, m->last->line, m->last->pos,
"requires %s %s %d (has %d)", v, k, want, has));
}
@@ -581,7 +428,7 @@ check_stdarg(PRE_ARGS)
if (n->args && 1 == n->args->argc)
if (MDOC_Std == n->args->argv[0].arg)
return(1);
- return(nwarn(mdoc, n, EARGVAL));
+ return(mdoc_nwarn(mdoc, n, EARGVAL));
}
@@ -605,7 +452,7 @@ check_sec(PRE_ARGS, ...)
}
va_end(ap);
- return(nwarn(mdoc, n, EBADSEC));
+ return(mdoc_nwarn(mdoc, n, EBADSEC));
}
@@ -627,7 +474,7 @@ check_msec(PRE_ARGS, ...)
}
va_end(ap);
- return(nwarn(mdoc, n, EBADMSEC));
+ return(mdoc_nwarn(mdoc, n, EBADMSEC));
}
@@ -662,7 +509,7 @@ check_argv(struct mdoc *m, const struct mdoc_node *n,
/* `Nm' name must be set. */
if (v->sz || m->meta.name)
return(1);
- return(nerr(m, n, ENAME));
+ return(mdoc_nerr(m, n, ENAME));
}
return(1);
@@ -693,8 +540,8 @@ check_text(struct mdoc *mdoc, int line, int pos, const char *p)
continue;
}
if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags))
- return(perr(mdoc, line, pos, EESCAPE, 1));
- if ( ! perr(mdoc, line, pos, EESCAPE, 0))
+ return(mdoc_perr(mdoc, line, pos, EESCAPE));
+ if ( ! mdoc_perr(mdoc, line, pos, EESCAPE))
return(0);
}
@@ -713,7 +560,7 @@ check_parent(PRE_ARGS, int tok, enum mdoc_type t)
(t == n->parent->type))
return(1);
- return(mdoc_nerr(mdoc, n, "require parent %s",
+ return(mdoc_verr(mdoc, n->line, n->pos, "require parent %s",
MDOC_ROOT == t ? "<root>" : mdoc_macronames[tok]));
}
@@ -737,7 +584,7 @@ pre_display(PRE_ARGS)
if (NULL == node)
return(1);
- return(nerr(mdoc, n, ENESTDISP));
+ return(mdoc_nerr(mdoc, n, ENESTDISP));
}
@@ -749,7 +596,7 @@ pre_bl(PRE_ARGS)
if (MDOC_BLOCK != n->type)
return(1);
if (NULL == n->args)
- return(nerr(mdoc, n, ELISTTYPE));
+ return(mdoc_nerr(mdoc, n, ELISTTYPE));
/* Make sure that only one type of list is specified. */
@@ -780,17 +627,17 @@ pre_bl(PRE_ARGS)
/* FALLTHROUGH */
case (MDOC_Column):
if (-1 != type)
- return(nerr(mdoc, n, EMULTILIST));
+ return(mdoc_nerr(mdoc, n, EMULTILIST));
type = n->args->argv[pos].arg;
break;
case (MDOC_Width):
if (-1 != width)
- return(nerr(mdoc, n, EARGREP));
+ return(mdoc_nerr(mdoc, n, EARGREP));
width = n->args->argv[pos].arg;
break;
case (MDOC_Offset):
if (-1 != offset)
- return(nerr(mdoc, n, EARGREP));
+ return(mdoc_nerr(mdoc, n, EARGREP));
offset = n->args->argv[pos].arg;
break;
default:
@@ -798,7 +645,7 @@ pre_bl(PRE_ARGS)
}
if (-1 == type)
- return(nerr(mdoc, n, ELISTTYPE));
+ return(mdoc_nerr(mdoc, n, ELISTTYPE));
/*
* Validate the width field. Some list types don't need width
@@ -808,7 +655,7 @@ pre_bl(PRE_ARGS)
switch (type) {
case (MDOC_Tag):
- if (-1 == width && ! nwarn(mdoc, n, EMISSWIDTH))
+ if (-1 == width && ! mdoc_nwarn(mdoc, n, EMISSWIDTH))
return(0);
break;
case (MDOC_Column):
@@ -818,7 +665,7 @@ pre_bl(PRE_ARGS)
case (MDOC_Inset):
/* FALLTHROUGH */
case (MDOC_Item):
- if (-1 != width && ! nwarn(mdoc, n, ENOWIDTH))
+ if (-1 != width && ! mdoc_nwarn(mdoc, n, ENOWIDTH))
return(0);
break;
default:
@@ -837,7 +684,7 @@ pre_bd(PRE_ARGS)
if (MDOC_BLOCK != n->type)
return(1);
if (NULL == n->args)
- return(nerr(mdoc, n, EDISPTYPE));
+ return(mdoc_nerr(mdoc, n, EDISPTYPE));
/* Make sure that only one type of display is specified. */
@@ -856,14 +703,14 @@ pre_bd(PRE_ARGS)
case (MDOC_File):
if (0 == type++)
break;
- return(nerr(mdoc, n, EMULTIDISP));
+ return(mdoc_nerr(mdoc, n, EMULTIDISP));
default:
break;
}
if (type)
return(1);
- return(nerr(mdoc, n, EDISPTYPE));
+ return(mdoc_nerr(mdoc, n, EDISPTYPE));
}
@@ -903,7 +750,8 @@ pre_an(PRE_ARGS)
if (NULL == n->args || 1 == n->args->argc)
return(1);
- return(mdoc_nerr(mdoc, n, "only one argument allowed"));
+ return(mdoc_verr(mdoc, n->line, n->pos,
+ "only one argument allowed"));
}
@@ -956,10 +804,10 @@ pre_dt(PRE_ARGS)
{
if (0 == mdoc->meta.date || mdoc->meta.os)
- if ( ! nwarn(mdoc, n, EPROLOOO))
+ if ( ! mdoc_nwarn(mdoc, n, EPROLOOO))
return(0);
if (mdoc->meta.title)
- if ( ! nwarn(mdoc, n, EPROLREP))
+ if ( ! mdoc_nwarn(mdoc, n, EPROLREP))
return(0);
return(1);
}
@@ -970,10 +818,10 @@ pre_os(PRE_ARGS)
{
if (NULL == mdoc->meta.title || 0 == mdoc->meta.date)
- if ( ! nwarn(mdoc, n, EPROLOOO))
+ if ( ! mdoc_nwarn(mdoc, n, EPROLOOO))
return(0);
if (mdoc->meta.os)
- if ( ! nwarn(mdoc, n, EPROLREP))
+ if ( ! mdoc_nwarn(mdoc, n, EPROLREP))
return(0);
return(1);
}
@@ -984,10 +832,10 @@ pre_dd(PRE_ARGS)
{
if (mdoc->meta.title || mdoc->meta.os)
- if ( ! nwarn(mdoc, n, EPROLOOO))
+ if ( ! mdoc_nwarn(mdoc, n, EPROLOOO))
return(0);
if (mdoc->meta.date)
- if ( ! nwarn(mdoc, n, EPROLREP))
+ if ( ! mdoc_nwarn(mdoc, n, EPROLREP))
return(0);
return(1);
}
@@ -1005,12 +853,14 @@ post_bf(POST_ARGS)
head = mdoc->last->head;
if (mdoc->last->args && head->child)
- return(mdoc_err(mdoc, "one argument expected"));
+ return(mdoc_verr(mdoc, mdoc->last->line,
+ mdoc->last->pos, "one argument expected"));
else if (mdoc->last->args)
return(1);
if (NULL == head->child || MDOC_TEXT != head->child->type)
- return(mdoc_err(mdoc, "text argument expected"));
+ return(mdoc_verr(mdoc, mdoc->last->line,
+ mdoc->last->pos, "text argument expected"));
p = head->child->string;
@@ -1021,7 +871,7 @@ post_bf(POST_ARGS)
else if (0 == strcmp(p, "Sm"))
return(1);
- return(mdoc_nerr(mdoc, head->child, "invalid font mode"));
+ return(mdoc_nerr(mdoc, head, EFONT));
}
@@ -1033,7 +883,7 @@ post_nm(POST_ARGS)
return(1);
if (mdoc->meta.name)
return(1);
- return(verr(mdoc, ENAME));
+ return(mdoc_nerr(mdoc, mdoc->last, ENAME));
}
@@ -1044,10 +894,10 @@ post_at(POST_ARGS)
if (NULL == mdoc->last->child)
return(1);
if (MDOC_TEXT != mdoc->last->child->type)
- return(verr(mdoc, EATT));
+ return(mdoc_nerr(mdoc, mdoc->last, EATT));
if (mdoc_a2att(mdoc->last->child->string))
return(1);
- return(verr(mdoc, EATT));
+ return(mdoc_nerr(mdoc, mdoc->last, EATT));
}
@@ -1058,12 +908,12 @@ post_an(POST_ARGS)
if (mdoc->last->args) {
if (NULL == mdoc->last->child)
return(1);
- return(verr(mdoc, ELINE));
+ return(mdoc_nerr(mdoc, mdoc->last, ELINE));
}
if (mdoc->last->child)
return(1);
- return(verr(mdoc, ELINE));
+ return(mdoc_nerr(mdoc, mdoc->last, ELINE));
}
@@ -1073,7 +923,7 @@ post_args(POST_ARGS)
if (mdoc->last->args)
return(1);
- return(verr(mdoc, ELINE));
+ return(mdoc_nerr(mdoc, mdoc->last, ELINE));
}
@@ -1088,7 +938,7 @@ post_it(POST_ARGS)
n = mdoc->last->parent->parent;
if (NULL == n->args)
- return(verr(mdoc, ELISTTYPE));
+ return(mdoc_nerr(mdoc, mdoc->last, ELISTTYPE));
/* Some types require block-head, some not. */
@@ -1126,12 +976,12 @@ post_it(POST_ARGS)
}
if (-1 == type)
- return(verr(mdoc, ELISTTYPE));
+ return(mdoc_nerr(mdoc, mdoc->last, ELISTTYPE));
switch (type) {
case (MDOC_Tag):
if (NULL == mdoc->last->head->child)
- if ( ! vwarn(mdoc, ELINE))
+ if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE))
return(0);
break;
case (MDOC_Hang):
@@ -1142,10 +992,10 @@ post_it(POST_ARGS)
/* FALLTHROUGH */
case (MDOC_Diag):
if (NULL == mdoc->last->head->child)
- if ( ! vwarn(mdoc, ELINE))
+ if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE))
return(0);
if (NULL == mdoc->last->body->child)
- if ( ! vwarn(mdoc, EMULTILINE))
+ if ( ! mdoc_nwarn(mdoc, mdoc->last, EMULTILINE))
return(0);
break;
case (MDOC_Bullet):
@@ -1158,26 +1008,27 @@ post_it(POST_ARGS)
/* FALLTHROUGH */
case (MDOC_Item):
if (mdoc->last->head->child)
- if ( ! vwarn(mdoc, ENOLINE))
+ if ( ! mdoc_nwarn(mdoc, mdoc->last, ENOLINE))
return(0);
if (NULL == mdoc->last->body->child)
- if ( ! vwarn(mdoc, EMULTILINE))
+ if ( ! mdoc_nwarn(mdoc, mdoc->last, EMULTILINE))
return(0);
break;
case (MDOC_Column):
if (NULL == mdoc->last->head->child)
- if ( ! vwarn(mdoc, ELINE))
+ if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE))
return(0);
if (mdoc->last->body->child)
- if ( ! vwarn(mdoc, ENOMULTILINE))
+ if ( ! mdoc_nwarn(mdoc, mdoc->last, ENOMULTILINE))
return(0);
c = mdoc->last->child;
for (i = 0; c && MDOC_HEAD == c->type; c = c->next)
i++;
if (i == cols)
break;
- return(mdoc_err(mdoc, "column mismatch (have "
- "%d, want %d)", i, cols));
+ return(mdoc_verr(mdoc, mdoc->last->line, mdoc->last->pos,
+ "column mismatch (have %d, want %d)",
+ i, cols));
default:
break;
}
@@ -1203,7 +1054,7 @@ post_bl_head(POST_ARGS)
return(1);
if (n->args->argv[i].sz && mdoc->last->child)
- return(nerr(mdoc, n, ECOLMIS));
+ return(mdoc_nerr(mdoc, n, ECOLMIS));
return(1);
}
@@ -1226,7 +1077,8 @@ post_bl(POST_ARGS)
if (MDOC_BLOCK == n->type)
if (MDOC_It == n->tok)
continue;
- return(mdoc_nerr(mdoc, n, "bad child of parent %s",
+ return(mdoc_verr(mdoc, n->line, n->pos,
+ "bad child of parent %s",
mdoc_macronames[mdoc->last->tok]));
}
@@ -1252,7 +1104,7 @@ ebool(struct mdoc *mdoc)
if (NULL == n)
return(1);
- return(nerr(mdoc, n, EBOOL));
+ return(mdoc_nerr(mdoc, n, EBOOL));
}
@@ -1261,14 +1113,14 @@ post_root(POST_ARGS)
{
if (NULL == mdoc->first->child)
- return(verr(mdoc, ENODATA));
+ return(mdoc_nerr(mdoc, mdoc->first, ENODAT));
if ( ! (MDOC_PBODY & mdoc->flags))
- return(verr(mdoc, ENOPROLOGUE));
+ return(mdoc_nerr(mdoc, mdoc->first, ENOPROLOGUE));
if (MDOC_BLOCK != mdoc->first->child->type)
- return(verr(mdoc, ENODATA));
+ return(mdoc_nerr(mdoc, mdoc->first, ENODAT));
if (MDOC_Sh != mdoc->first->child->tok)
- return(verr(mdoc, ENODATA));
+ return(mdoc_nerr(mdoc, mdoc->first, ENODAT));
return(1);
}
@@ -1280,7 +1132,7 @@ post_st(POST_ARGS)
if (mdoc_a2st(mdoc->last->child->string))
return(1);
- return(vwarn(mdoc, EBADSTAND));
+ return(mdoc_nwarn(mdoc, mdoc->last, EBADSTAND));
}
@@ -1312,20 +1164,20 @@ post_sh_body(POST_ARGS)
*/
if (NULL == (n = mdoc->last->child))
- return(vwarn(mdoc, ENAMESECINC));
+ return(mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC));
for ( ; n && n->next; n = n->next) {
if (MDOC_ELEM == n->type && MDOC_Nm == n->tok)
continue;
if (MDOC_TEXT == n->type)
continue;
- if ( ! vwarn(mdoc, ENAMESECINC))
+ if ( ! mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC))
return(0);
}
if (MDOC_ELEM == n->type && MDOC_Nd == n->tok)
return(1);
- return(vwarn(mdoc, ENAMESECINC));
+ return(mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC));
}
@@ -1350,11 +1202,11 @@ post_sh_head(POST_ARGS)
assert(MDOC_TEXT == n->type);
if (strlcat(buf, n->string, 64) >= 64)
- return(nerr(mdoc, n, ETOOLONG));
+ return(mdoc_nerr(mdoc, n, ETOOLONG));
if (NULL == n->next)
continue;
if (strlcat(buf, " ", 64) >= 64)
- return(nerr(mdoc, n, ETOOLONG));
+ return(mdoc_nerr(mdoc, n, ETOOLONG));
}
sec = mdoc_atosec(buf);
@@ -1365,13 +1217,13 @@ post_sh_head(POST_ARGS)
*/
if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed)
- return(verr(mdoc, ESECNAME));
+ return(mdoc_nerr(mdoc, mdoc->last, ESECNAME));
if (SEC_CUSTOM == sec)
return(1);
if (sec == mdoc->lastnamed)
- return(vwarn(mdoc, ESECREP));
+ return(mdoc_nwarn(mdoc, mdoc->last, ESECREP));
if (sec < mdoc->lastnamed)
- return(vwarn(mdoc, ESECOOO));
+ return(mdoc_nwarn(mdoc, mdoc->last, ESECOOO));
/*
* Check particular section/manual conventions. LIBRARY can
@@ -1386,7 +1238,7 @@ post_sh_head(POST_ARGS)
case (3):
break;
default:
- return(vwarn(mdoc, EWRONGMSEC));
+ return(mdoc_nwarn(mdoc, mdoc->last, EWRONGMSEC));
}
break;
default: