summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2009-07-12 20:30:28 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2009-07-12 20:30:28 +0000
commit475001105e136851bef0c0389f449eb102901714 (patch)
tree0a16af1acf6f5fb2ab39f3e8bf213260bd92471b /usr.bin/mandoc
parenta434aaccc80703d795f7b657854c13afc56100c5 (diff)
sync to 1.7.23: unify the various "enum merr" into libman.h and libmdoc.h,
use it as a new argument to mdoc_err(), the same way as for for man_err(), and use string tables instead of switch statements to select error messages
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/libman.h11
-rw-r--r--usr.bin/mandoc/libmdoc.h62
-rw-r--r--usr.bin/mandoc/man.c52
-rw-r--r--usr.bin/mandoc/mdoc.c83
-rw-r--r--usr.bin/mandoc/mdoc_action.c9
-rw-r--r--usr.bin/mandoc/mdoc_argv.c8
-rw-r--r--usr.bin/mandoc/mdoc_macro.c17
-rw-r--r--usr.bin/mandoc/mdoc_validate.c34
8 files changed, 160 insertions, 116 deletions
diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h
index 40a9bf7661b..9d641d8bb52 100644
--- a/usr.bin/mandoc/libman.h
+++ b/usr.bin/mandoc/libman.h
@@ -1,4 +1,4 @@
-/* $Id: libman.h,v 1.4 2009/07/07 00:54:46 schwarze Exp $ */
+/* $Id: libman.h,v 1.5 2009/07/12 20:30:27 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -39,7 +39,7 @@ struct man {
};
enum merr {
- WNPRINT,
+ WNPRINT = 0,
WNMEM,
WMSEC,
WDATE,
@@ -48,15 +48,16 @@ enum merr {
WTQUOTE,
WNODATA,
WNOTITLE,
- WESCAPE
+ WESCAPE,
+ WERRMAX
};
__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/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h
index 41cc81523b7..a2b604b3f6f 100644
--- a/usr.bin/mandoc/libmdoc.h
+++ b/usr.bin/mandoc/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.9 2009/07/12 19:05:52 schwarze Exp $ */
+/* $Id: libmdoc.h,v 1.10 2009/07/12 20:30:27 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -41,6 +41,64 @@ struct mdoc {
enum mdoc_sec lastsec;
};
+enum merr {
+ ETAILWS = 0,
+ ECOLEMPTY,
+ EARGVPARM,
+ EQUOTPARM,
+ EQUOTTERM,
+ EMALLOC,
+ EARGVAL,
+ ENOCALL,
+ EBODYPROL,
+ EPROLBODY,
+ ETEXTPROL,
+ ENOBLANK,
+ ETOOLONG,
+ EESCAPE,
+ EPRINT,
+ ENODAT,
+ ENOPROLOGUE,
+ ELINE,
+ EATT,
+ ENAME,
+ ELISTTYPE,
+ EDISPTYPE,
+ EMULTIDISP,
+ EMULTILIST,
+ ESECNAME,
+ ENAMESECINC,
+ EARGREP,
+ EBOOL,
+ ECOLMIS,
+ ENESTDISP,
+ EMISSWIDTH,
+ EWRONGMSEC,
+ ESECOOO,
+ ESECREP,
+ EBADSTAND,
+ ENOMULTILINE,
+ EMULTILINE,
+ ENOLINE,
+ EPROLOOO,
+ EPROLREP,
+ EBADMSEC,
+ EBADSEC,
+ EFONT,
+ EBADDATE,
+ ENUMFMT,
+ ENOWIDTH,
+ EUTSNAME,
+ EOBS,
+ EMACPARM,
+ EIMPBRK,
+ EIGNE,
+ EOPEN,
+ EQUOTPHR,
+ ENOCTX,
+ ESPACE,
+ MERRMAX
+};
#define MACRO_PROT_ARGS struct mdoc *mdoc, int tok, int line, \
int ppos, int *pos, char *buf
@@ -67,11 +125,11 @@ __BEGIN_DECLS
int mdoc_nerr(struct mdoc *, const struct mdoc_node *,
const char *, ...);
int mdoc_warn(struct mdoc *, enum mdoc_warn, const char *, ...);
-int mdoc_err(struct mdoc *, const char *, ...);
int mdoc_pwarn(struct mdoc *, int, int,
enum mdoc_warn,const char *, ...);
int mdoc_perr(struct mdoc *, int, int, const char *, ...);
+int mdoc_err(struct mdoc *, int, int, int, enum merr);
int mdoc_verr(struct mdoc *, int, int, const char *, ...);
int mdoc_vwarn(struct mdoc *, int, int, const char *, ...);
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index 5e0a1c4133c..a5cefdcb058 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.6 2009/07/07 00:54:46 schwarze Exp $ */
+/* $Id: man.c,v 1.7 2009/07/12 20:30:27 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -23,6 +23,19 @@
#include "libman.h"
+const char *const __man_merrnames[WERRMAX] = {
+ "invalid character", /* WNPRINT */
+ "system: malloc error", /* WNMEM */
+ "invalid manual section", /* WMSEC */
+ "invalid date format", /* WDATE */
+ "scope of prior line violated", /* WLNSCOPE */
+ "trailing whitespace", /* WTSPACE */
+ "unterminated quoted parameter", /* WTQUOTE */
+ "document has no body", /* WNODATA */
+ "document has no title/section", /* WNOTITLE */
+ "invalid escape sequence", /* WESCAPE */
+};
+
const char *const __man_macronames[MAN_MAX] = {
"br", "TH", "SH", "SS",
"TP", "LP", "PP", "P",
@@ -438,44 +451,11 @@ man_vwarn(struct man *man, int ln, int pos, const char *fmt, ...)
int
-man_err(struct man *m, int line, int pos,
- int iserr, enum merr type)
+man_err(struct man *m, int line, int pos, int iserr, enum merr type)
{
const char *p;
- p = NULL;
- switch (type) {
- case (WNPRINT):
- p = "invalid character";
- break;
- case (WNMEM):
- p = "memory exhausted";
- break;
- case (WMSEC):
- p = "invalid manual section";
- break;
- case (WDATE):
- p = "invalid date format";
- break;
- case (WLNSCOPE):
- p = "scope of prior line violated";
- break;
- case (WTSPACE):
- p = "trailing whitespace at end of line";
- break;
- case (WTQUOTE):
- p = "unterminated quotation";
- break;
- case (WNODATA):
- p = "document has no data";
- break;
- case (WNOTITLE):
- p = "document has no title/section";
- break;
- case (WESCAPE):
- p = "invalid escape sequence";
- break;
- }
+ p = __man_merrnames[(int)type];
assert(p);
if (iserr)
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index d88e56d6546..5b90dbb41bf 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.13 2009/07/12 19:05:52 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.14 2009/07/12 20:30:27 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -23,14 +23,62 @@
#include "libmdoc.h"
-enum merr {
- ENOCALL,
- EBODYPROL,
- EPROLBODY,
- ESPACE,
- ETEXTPROL,
- ENOBLANK,
- EMALLOC
+const char *const __mdoc_merrnames[MERRMAX] = {
+ "trailing whitespace", /* ETAILWS */
+ "empty last list column", /* ECOLEMPTY */
+ "argument-like parameter", /* EARGVPARM */
+ "unexpected quoted parameter", /* EQUOTPARM */
+ "unterminated quoted parameter", /* EQUOTTERM */
+ "system: malloc error", /* EMALLOC */
+ "argument parameter suggested", /* EARGVAL */
+ "macro not callable", /* ENOCALL */
+ "macro disallowed in prologue", /* EBODYPROL */
+ "macro disallowed in body", /* EPROLBODY */
+ "text disallowed in prologue", /* ETEXTPROL */
+ "blank line disallowed", /* ENOBLANK */
+ "text parameter too long", /* ETOOLONG */
+ "invalid escape sequence", /* EESCAPE */
+ "invalid character", /* EPRINT */
+ "document has no body", /* ENODAT */
+ "document has no prologue", /* ENOPROLOGUE */
+ "expected line arguments", /* ELINE */
+ "invalid AT&T argument", /* EATT */
+ "default name not yet set", /* ENAME */
+ "missing list type", /* ELISTTYPE */
+ "missing display type", /* EDISPTYPE */
+ "too many display types", /* EMULTIDISP */
+ "too many list types", /* EMULTILIST */
+ "NAME section must be first", /* ESECNAME */
+ "badly-formed NAME section", /* ENAMESECINC */
+ "argument repeated", /* EARGREP */
+ "expected boolean parameter", /* EBOOL */
+ "inconsistent column syntax", /* ECOLMIS */
+ "nested display invalid", /* ENESTDISP */
+ "width argument missing", /* EMISSWIDTH */
+ "invalid section for this manual section", /* EWRONGMSEC */
+ "section out of conventional order", /* ESECOOO */
+ "section repeated", /* ESECREP */
+ "invalid standard argument", /* EBADSTAND */
+ "multi-line arguments discouraged", /* ENOMULTILINE */
+ "multi-line arguments suggested", /* EMULTILINE */
+ "line arguments discouraged", /* ENOLINE */
+ "prologue macro out of conventional order", /* EPROLOOO */
+ "prologue macro repeated", /* EPROLREP */
+ "invalid manual section", /* EBADMSEC */
+ "invalid section", /* EBADSEC */
+ "invalid font mode", /* EFONT */
+ "invalid date syntax", /* EBADDATE */
+ "invalid number format", /* ENUMFMT */
+ "superfluous width argument", /* ENOWIDTH */
+ "system: utsname error", /* EUTSNAME */
+ "obsolete macro", /* EOBS */
+ "macro-like parameter", /* EMACPARM */
+ "end-of-line scope violation", /* EIMPBRK */
+ "empty macro ignored", /* EIGNE */
+ "unclosed explicit scope", /* EOPEN */
+ "unterminated quoted phrase", /* EQUOTPHR */
+ "closure macro without prior context", /* ENOCTX */
+ "invalid whitespace after control character", /* ESPACE */
};
const char *const __mdoc_macronames[MDOC_MAX] = {
@@ -317,19 +365,16 @@ mdoc_warn(struct mdoc *mdoc, enum mdoc_warn type,
int
-mdoc_err(struct mdoc *mdoc, const char *fmt, ...)
+mdoc_err(struct mdoc *m, int line, int pos, int iserr, enum merr type)
{
- char buf[256];
- va_list ap;
+ const char *p;
- if (NULL == mdoc->cb.mdoc_err)
- return(0);
+ p = __mdoc_merrnames[(int)type];
+ assert(p);
- 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));
+ if (iserr)
+ return(mdoc_verr(m, line, pos, p));
+ return(mdoc_vwarn(m, line, pos, p));
}
diff --git a/usr.bin/mandoc/mdoc_action.c b/usr.bin/mandoc/mdoc_action.c
index a8856679aaa..0acaef68a08 100644
--- a/usr.bin/mandoc/mdoc_action.c
+++ b/usr.bin/mandoc/mdoc_action.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_action.c,v 1.10 2009/07/06 21:40:30 schwarze Exp $ */
+/* $Id: mdoc_action.c,v 1.11 2009/07/12 20:30:27 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -30,13 +30,6 @@ enum mwarn {
WBADDATE
};
-enum merr {
- ETOOLONG,
- EMALLOC,
- EUTSNAME,
- ENUMFMT
-};
-
#define PRE_ARGS struct mdoc *m, const struct mdoc_node *n
#define POST_ARGS struct mdoc *m
diff --git a/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c
index beb43406190..5a36765d718 100644
--- a/usr.bin/mandoc/mdoc_argv.c
+++ b/usr.bin/mandoc/mdoc_argv.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_argv.c,v 1.4 2009/06/21 19:09:58 schwarze Exp $ */
+/* $Id: mdoc_argv.c,v 1.5 2009/07/12 20:30:27 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -54,12 +54,6 @@ enum mwarn {
WTAILWS
};
-enum merr {
- EQUOTTERM,
- EMALLOC,
- EARGVAL
-};
-
static int argv_a2arg(int, const char *);
static int args(struct mdoc *, int, int *,
char *, int, char **);
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index 4b657f1dddd..16bc80b0163 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.6 2009/07/12 19:05:52 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.7 2009/07/12 20:30:27 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -29,13 +29,6 @@ enum mwarn {
WOBS
};
-enum merr {
- EOPEN,
- EQUOT,
- ENOCTX,
- ENOPARMS
-};
-
#define REWIND_REWIND (1 << 0)
#define REWIND_NOHALT (1 << 1)
#define REWIND_HALT (1 << 2)
@@ -205,13 +198,13 @@ perr(struct mdoc *mdoc, int line, int pos, enum merr type)
case (EOPEN):
p = "explicit scope still open on exit";
break;
- case (EQUOT):
+ case (EQUOTPHR):
p = "unterminated quotation";
break;
case (ENOCTX):
p = "closure has no prior context";
break;
- case (ENOPARMS):
+ case (ENOLINE):
p = "unexpect line arguments";
break;
}
@@ -728,7 +721,7 @@ blk_exp_close(MACRO_PROT_ARGS)
return(0);
return(rew_expblock(mdoc, tok, line, ppos));
}
- return(perr(mdoc, line, ppos, ENOPARMS));
+ return(perr(mdoc, line, ppos, ENOLINE));
}
if ( ! rew_subblock(MDOC_BODY, mdoc, tok, line, ppos))
@@ -1450,7 +1443,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(perr(mdoc, line, la, EQUOTPHR));
quoted = 1;
} else
for ( ; buf[i]; i++)
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 4849120dd55..1cf5dffcb85 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.17 2009/07/12 19:05:52 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.18 2009/07/12 20:30:27 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -31,26 +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
-};
-
enum mwarn {
WPRINT,
WNOWIDTH,
@@ -417,7 +397,7 @@ perr(struct mdoc *m, int line, int pos, enum merr type)
case (ENOPROLOGUE):
p = "document has no prologue";
break;
- case (ENODATA):
+ case (ENODAT):
p = "document has no data";
break;
case (ECOLMIS):
@@ -1033,12 +1013,12 @@ post_bf(POST_ARGS)
head = mdoc->last->head;
if (mdoc->last->args && head->child)
- return(mdoc_err(mdoc, "one argument expected"));
+ return(mdoc_nerr(mdoc, mdoc->last, "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_nerr(mdoc, mdoc->last, "text argument expected"));
p = head->child->string;
@@ -1291,14 +1271,14 @@ post_root(POST_ARGS)
{
if (NULL == mdoc->first->child)
- return(verr(mdoc, ENODATA));
+ return(verr(mdoc, ENODAT));
if ( ! (MDOC_PBODY & mdoc->flags))
return(verr(mdoc, ENOPROLOGUE));
if (MDOC_BLOCK != mdoc->first->child->type)
- return(verr(mdoc, ENODATA));
+ return(verr(mdoc, ENODAT));
if (MDOC_Sh != mdoc->first->child->tok)
- return(verr(mdoc, ENODATA));
+ return(verr(mdoc, ENODAT));
return(1);
}