diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-06-23 22:05:43 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-06-23 22:05:43 +0000 |
commit | 32b7487bfa1e73f1524212e7b99e5ee5775c9d4b (patch) | |
tree | a58ff5d80d1b9cd7b19cd59ee52f38dd3e8bc6cc /usr.bin/mandoc | |
parent | 9e7b012b85b2635f648d0f1506a01d6a48b72e13 (diff) |
sync to 1.7.20: error reporting functions for -man
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/libman.h | 24 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 45 | ||||
-rw-r--r-- | usr.bin/mandoc/man_action.c | 17 | ||||
-rw-r--r-- | usr.bin/mandoc/man_macro.c | 14 |
4 files changed, 80 insertions, 20 deletions
diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index 103831aaf08..299b2134a68 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.2 2009/06/14 23:00:57 schwarze Exp $ */ +/* $Id: libman.h,v 1.3 2009/06/23 22:05:42 schwarze Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -38,8 +38,30 @@ struct man { struct man_meta meta; }; +enum merr { + WNPRINT, + WNMEM, + WMSEC, + WDATE, + WLNSCOPE, + WTSPACE, + WTQUOTE, + WNODATA, + WNOTITLE +}; + __BEGIN_DECLS +#define man_perr(m, l, p, t) \ + man_err((m), l, p, 1, (t)) +#define man_pwarn(m, l, p, 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) \ + man_err((m), (n)->line, (n)->pos, 0, (t)) + +int man_err(struct man *, int, int, int, enum merr); int man_word_alloc(struct man *, int, int, const char *); int man_elem_alloc(struct man *, int, int, int); void man_node_free(struct man_node *); diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index a1e4578e7ac..6c00c53c852 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.3 2009/06/18 23:34:53 schwarze Exp $ */ +/* $Id: man.c,v 1.4 2009/06/23 22:05:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -432,3 +432,46 @@ 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) +{ + 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; + } + assert(p); + + if (iserr) + return(man_verr(m, line, pos, p)); + + return(man_vwarn(m, line, pos, p)); +} diff --git a/usr.bin/mandoc/man_action.c b/usr.bin/mandoc/man_action.c index 24bfb51a6d3..eb1ecd1e895 100644 --- a/usr.bin/mandoc/man_action.c +++ b/usr.bin/mandoc/man_action.c @@ -1,4 +1,4 @@ -/* $Id: man_action.c,v 1.3 2009/06/18 23:34:53 schwarze Exp $ */ +/* $Id: man_action.c,v 1.4 2009/06/23 22:05:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -104,8 +104,7 @@ post_TH(struct man *m) assert(n); if (NULL == (m->meta.title = strdup(n->string))) - return(man_verr(m, n->line, n->pos, - "memory exhausted")); + return(man_nerr(m, n, WNMEM)); /* TITLE ->MSEC<- DATE SOURCE VOL */ @@ -116,7 +115,7 @@ post_TH(struct man *m) lval = strtol(n->string, &ep, 10); if (n->string[0] != '\0' && *ep == '\0') m->meta.msec = (int)lval; - else if ( ! man_vwarn(m, n->line, n->pos, "invalid section")) + else if ( ! man_nwarn(m, n, WMSEC)) return(0); /* TITLE MSEC ->DATE<- SOURCE VOL */ @@ -124,7 +123,7 @@ post_TH(struct man *m) if (NULL == (n = n->next)) m->meta.date = time(NULL); else if (0 == (m->meta.date = man_atotime(n->string))) { - if ( ! man_vwarn(m, n->line, n->pos, "invalid date")) + if ( ! man_nwarn(m, n, WDATE)) return(0); m->meta.date = time(NULL); } @@ -133,15 +132,13 @@ post_TH(struct man *m) if (n && (n = n->next)) if (NULL == (m->meta.source = strdup(n->string))) - return(man_verr(m, n->line, n->pos, - "memory exhausted")); + return(man_nerr(m, n, WNMEM)); /* TITLE MSEC DATE SOURCE ->VOL<- */ if (n && (n = n->next)) if (NULL == (m->meta.vol = strdup(n->string))) - return(man_verr(m, n->line, n->pos, - "memory exhausted")); + return(man_nerr(m, n, WNMEM)); /* * The end document shouldn't have the prologue macros as part @@ -174,7 +171,7 @@ man_atotime(const char *p) struct tm tm; char *pp; - (void)memset(&tm, 0, sizeof(struct tm)); + bzero(&tm, sizeof(struct tm)); if ((pp = strptime(p, "%b %d %Y", &tm)) && 0 == *pp) return(mktime(&tm)); diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c index 2f342331aee..2b15e16bf7b 100644 --- a/usr.bin/mandoc/man_macro.c +++ b/usr.bin/mandoc/man_macro.c @@ -1,4 +1,4 @@ -/* $Id: man_macro.c,v 1.3 2009/06/18 23:34:53 schwarze Exp $ */ +/* $Id: man_macro.c,v 1.4 2009/06/23 22:05:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -82,16 +82,14 @@ man_macro(struct man *man, int tok, int line, if (n == man->last && (FL_NLINE & man_flags[tok])) { if (MAN_NLINE & man->flags) - return(man_verr(man, line, ppos, - "next-line scope already open")); + return(man_perr(man, line, ppos, WLNSCOPE)); man->flags |= MAN_NLINE; return(1); } if (FL_TLINE & man_flags[tok]) { if (MAN_NLINE & man->flags) - return(man_verr(man, line, ppos, - "next-line scope already open")); + return(man_perr(man, line, ppos, WLNSCOPE)); man->flags |= MAN_NLINE; return(1); } @@ -186,7 +184,7 @@ man_args(struct man *m, int line, if (buf[*pos]) return(1); - if ( ! man_vwarn(m, line, *pos, "trailing spaces")) + if ( ! man_pwarn(m, line, *pos, WTSPACE)) return(-1); return(1); @@ -204,7 +202,7 @@ man_args(struct man *m, int line, (*pos)++; if (0 == buf[*pos]) { - if ( ! man_vwarn(m, line, *pos, "unterminated quote")) + if ( ! man_pwarn(m, line, *pos, WTQUOTE)) return(-1); return(1); } @@ -219,7 +217,7 @@ man_args(struct man *m, int line, if (buf[*pos]) return(1); - if ( ! man_vwarn(m, line, *pos, "trailing spaces")) + if ( ! man_pwarn(m, line, *pos, WTSPACE)) return(-1); return(1); } |