summaryrefslogtreecommitdiffstats
path: root/mdoc_action.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-05-17 22:11:42 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-05-17 22:11:42 +0000
commitb11413460f4cfc6adeaaec03d30246715922f54d (patch)
tree4836abc5d313954c48af7a9145a26a861f309230 /mdoc_action.c
parent4123a170dcf7bb0ee57516df099aa6efc10ef5e1 (diff)
downloadmandoc-b11413460f4cfc6adeaaec03d30246715922f54d.tar.gz
Enable the unified error/warning enumeration in mandoc.h that's
stringified in main.c. Allow `An' to handle an argument and child (with a warning). Allow `Rv' and `Ex' to work without a prior `Nm' as groff does (with a warning). Allow inconsistent column syntax to only raise a warning.
Diffstat (limited to 'mdoc_action.c')
-rw-r--r--mdoc_action.c66
1 files changed, 45 insertions, 21 deletions
diff --git a/mdoc_action.c b/mdoc_action.c
index cb949df6..12b62d1b 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <time.h>
+#include "mandoc.h"
#include "libmdoc.h"
#include "libmandoc.h"
@@ -269,12 +270,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);
@@ -288,14 +298,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;
@@ -453,7 +465,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;
}
@@ -517,7 +529,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
@@ -574,19 +586,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*/
}
@@ -621,7 +646,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;
}
@@ -684,12 +709,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. */
@@ -848,7 +872,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);
}