diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2010-05-23 22:45:02 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2010-05-23 22:45:02 +0000 |
commit | 5f11e83ec40e027d9941a83310ca46e5e32821c7 (patch) | |
tree | 443369858d56a918cd55fb337d34f528d8d4d96b /usr.bin/mandoc/mdoc_action.c | |
parent | 22bfa887a3d98fe67ad553bf37793e74ab6f8142 (diff) |
Unified error and warning message system for all of mandoc,
featuring three message levels, as agreed during the mandoc hackathon:
* FATAL parser failure, cannot produce any output from this input file:
eventually, we hope to convert most of these to ERRORs.
* ERROR, meaning mandoc cannot cope fully with the input syntax and will
probably lose information or produce structurally garbled output;
it will try to produce output anyway but exit non-zero at the end,
which is eventually intended to make the ports infrastructure happy.
* WARNING, meaning you should clean up the input file, but output
is probably mostly OK, so this will not cause error-exit at the end.
This commit is mostly just converting the old system to the new one; before
the classification will become really reliable, we must check all messages.
In particular,
* set up a new central message string table in main.c
* drop the old message string tables from man.c and mdoc.c
* get rid of the piece-meal merr enums in libman and libmdoc
* reduce number of error/warning functions from 16 to 6 (still a lot...)
While here, handle a few problems more gracefully:
* allow .Rv and .Ex to work without a prior .Nm
* allow .An to ignore extra arguments
* allow undeclared columns in .Bl -column
Written by kristaps@.
Diffstat (limited to 'usr.bin/mandoc/mdoc_action.c')
-rw-r--r-- | usr.bin/mandoc/mdoc_action.c | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/usr.bin/mandoc/mdoc_action.c b/usr.bin/mandoc/mdoc_action.c index c3d97413966..05e8022c30b 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.35 2010/05/15 18:25:51 schwarze Exp $ */ +/* $Id: mdoc_action.c,v 1.36 2010/05/23 22:45:00 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -24,6 +24,7 @@ #include <string.h> #include <time.h> +#include "mandoc.h" #include "libmdoc.h" #include "libmandoc.h" @@ -265,12 +266,21 @@ concat(struct mdoc *m, char *p, const struct mdoc_node *n, size_t sz) p[0] = '\0'; for ( ; n; n = n->next) { assert(MDOC_TEXT == n->type); - if (strlcat(p, n->string, sz) >= sz) - return(mdoc_nerr(m, n, ETOOLONG)); + /* + * XXX: yes, these can technically be resized, but it's + * highly unlikely that we're going to get here, so let + * it slip for now. + */ + if (strlcat(p, n->string, sz) >= sz) { + mdoc_nmsg(m, n, MANDOCERR_MEM); + return(0); + } if (NULL == n->next) continue; - if (strlcat(p, " ", sz) >= sz) - return(mdoc_nerr(m, n, ETOOLONG)); + if (strlcat(p, " ", sz) >= sz) { + mdoc_nmsg(m, n, MANDOCERR_MEM); + return(0); + } } return(1); @@ -284,14 +294,16 @@ concat(struct mdoc *m, char *p, const struct mdoc_node *n, size_t sz) static int post_std(POST_ARGS) { - struct mdoc_node *nn; + struct mdoc_node *nn; if (n->child) return(1); + if (NULL == m->meta.name) + return(1); nn = n; m->next = MDOC_NEXT_CHILD; - assert(m->meta.name); + if ( ! mdoc_word_alloc(m, n->line, n->pos, m->meta.name)) return(0); m->last = nn; @@ -449,7 +461,7 @@ post_sh(POST_ARGS) break; if (*m->meta.msec == '9') break; - return(mdoc_nwarn(m, n, EWRONGMSEC)); + return(mdoc_nmsg(m, n, MANDOCERR_SECMSEC)); default: break; } @@ -513,7 +525,7 @@ post_dt(POST_ARGS) if (cp) { m->meta.vol = mandoc_strdup(cp); m->meta.msec = mandoc_strdup(nn->string); - } else if (mdoc_nwarn(m, n, EBADMSEC)) { + } else if (mdoc_nmsg(m, n, MANDOCERR_BADMSEC)) { m->meta.vol = mandoc_strdup(nn->string); m->meta.msec = mandoc_strdup(nn->string); } else @@ -570,19 +582,32 @@ post_os(POST_ARGS) if ( ! concat(m, buf, n->child, BUFSIZ)) return(0); + /* XXX: yes, these can all be dynamically-adjusted buffers, but + * it's really not worth the extra hackery. + */ + if ('\0' == buf[0]) { #ifdef OSNAME - if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) - return(mdoc_nerr(m, n, EUTSNAME)); + if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) { + mdoc_nmsg(m, n, MANDOCERR_MEM); + return(0); + } #else /*!OSNAME */ if (-1 == uname(&utsname)) - return(mdoc_nerr(m, n, EUTSNAME)); - if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) - return(mdoc_nerr(m, n, ETOOLONG)); - if (strlcat(buf, " ", 64) >= BUFSIZ) - return(mdoc_nerr(m, n, ETOOLONG)); - if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) - return(mdoc_nerr(m, n, ETOOLONG)); + return(mdoc_nmsg(m, n, MANDOCERR_UTSNAME)); + + if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) { + mdoc_nmsg(m, n, MANDOCERR_MEM); + return(0); + } + if (strlcat(buf, " ", 64) >= BUFSIZ) { + mdoc_nmsg(m, n, MANDOCERR_MEM); + return(0); + } + if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) { + mdoc_nmsg(m, n, MANDOCERR_MEM); + return(0); + } #endif /*!OSNAME*/ } @@ -617,7 +642,7 @@ post_bl_tagwidth(POST_ARGS) if (MDOC_TEXT != nn->type) { sz = mdoc_macro2len(nn->tok); if (sz == 0) { - if ( ! mdoc_nwarn(m, n, ENOWIDTH)) + if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG)) return(0); sz = 10; } @@ -680,12 +705,11 @@ post_bl_width(POST_ARGS) */ if (0 == strcmp(p, "Ds")) - /* XXX: make into a macro. */ width = 6; else if (MDOC_MAX == (tok = mdoc_hash_find(p))) return(1); else if (0 == (width = mdoc_macro2len(tok))) - return(mdoc_nwarn(m, n, ENOWIDTH)); + return(mdoc_nmsg(m, n, MANDOCERR_BADWIDTH)); /* The value already exists: free and reallocate it. */ @@ -844,7 +868,7 @@ post_dd(POST_ARGS) (MTIME_MDOCDATE | MTIME_CANONICAL, buf); if (0 == m->meta.date) { - if ( ! mdoc_nwarn(m, n, EBADDATE)) + if ( ! mdoc_nmsg(m, n, MANDOCERR_BADDATE)) return(0); m->meta.date = time(NULL); } |