summaryrefslogtreecommitdiffstats
path: root/mdoc_action.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-07-06 13:04:52 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-07-06 13:04:52 +0000
commit7a72fe65c7d5fe05324b8d227b387f2aa3cea747 (patch)
treea9b1a7faf197c0162351bbd69ec28a426e4cc67c /mdoc_action.c
parent836a616d2c9decff2a835b27818ffa4749af5900 (diff)
downloadmandoc-7a72fe65c7d5fe05324b8d227b387f2aa3cea747.tar.gz
Consolidated all err/warnings into mdoc.c via libmdoc.h.
Diffstat (limited to 'mdoc_action.c')
-rw-r--r--mdoc_action.c112
1 files changed, 29 insertions, 83 deletions
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);
}