summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/man.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2009-12-22 23:58:01 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2009-12-22 23:58:01 +0000
commit89c124b1e04e596f4ba06193091daad0e01dc939 (patch)
tree9ed92a7f590db13da46deb9d8434a83b1802ba08 /usr.bin/mandoc/man.c
parent3577315b7c4436e4b96b8b9f1d54181b4451d77e (diff)
sync to 1.9.12, mostly portability and refactoring:
correctness/functionality: - bugfix: do not die when overstep hits the right margin - new option: -fign-escape - and various HTML features portability: - replace bzero(3) by memset(3), which is ANSI C - replace err(3)/warn(3) by perror(3)/exit(3), which is ANSI C - iuse argv[0] instead of __progname - add time.h to various files for FreeBSD compilation simplicity: - do not allocate header/footer data dynamically in *_term.c - provide and use malloc frontends that error out on failure for full changelogs, see http://bsd.lv/cgi-bin/cvsweb.cgi/
Diffstat (limited to 'usr.bin/mandoc/man.c')
-rw-r--r--usr.bin/mandoc/man.c55
1 files changed, 15 insertions, 40 deletions
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index 5321673fda1..eff62501e24 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.15 2009/10/27 21:40:07 schwarze Exp $ */
+/* $Id: man.c,v 1.16 2009/12/22 23:58:00 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -24,10 +24,10 @@
#include <string.h>
#include "libman.h"
+#include "libmandoc.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 */
@@ -67,7 +67,7 @@ static int man_node_append(struct man *,
static int man_ptext(struct man *, int, char *);
static int man_pmacro(struct man *, int, char *);
static void man_free1(struct man *);
-static int man_alloc1(struct man *);
+static void man_alloc1(struct man *);
static int pstring(struct man *, int, int,
const char *, size_t);
static int macrowarn(struct man *, int, const char *);
@@ -89,12 +89,12 @@ man_meta(const struct man *m)
}
-int
+void
man_reset(struct man *man)
{
man_free1(man);
- return(man_alloc1(man));
+ man_alloc1(man);
}
@@ -112,19 +112,16 @@ man_alloc(void *data, int pflags, const struct man_cb *cb)
{
struct man *p;
- if (NULL == (p = calloc(1, sizeof(struct man))))
- return(NULL);
+ p = mandoc_calloc(1, sizeof(struct man));
- if ( ! man_alloc1(p)) {
- free(p);
- return(NULL);
- }
+ if (cb)
+ memcpy(&p->cb, cb, sizeof(struct man_cb));
man_hash_init();
-
p->data = data;
p->pflags = pflags;
- (void)memcpy(&p->cb, cb, sizeof(struct man_cb));
+
+ man_alloc1(p);
return(p);
}
@@ -167,19 +164,16 @@ man_free1(struct man *man)
}
-static int
+static void
man_alloc1(struct man *m)
{
- bzero(&m->meta, sizeof(struct man_meta));
+ memset(&m->meta, 0, sizeof(struct man_meta));
m->flags = 0;
- m->last = calloc(1, sizeof(struct man_node));
- if (NULL == m->last)
- return(0);
+ m->last = mandoc_calloc(1, sizeof(struct man_node));
m->first = m->last;
m->last->type = MAN_ROOT;
m->next = MAN_NEXT_CHILD;
- return(1);
}
@@ -246,10 +240,7 @@ man_node_alloc(int line, int pos, enum man_type type, int tok)
{
struct man_node *p;
- p = calloc(1, sizeof(struct man_node));
- if (NULL == p)
- return(NULL);
-
+ p = mandoc_calloc(1, sizeof(struct man_node));
p->line = line;
p->pos = pos;
p->type = type;
@@ -264,8 +255,6 @@ man_elem_alloc(struct man *m, int line, int pos, int tok)
struct man_node *p;
p = man_node_alloc(line, pos, MAN_ELEM, tok);
- if (NULL == p)
- return(0);
if ( ! man_node_append(m, p))
return(0);
m->next = MAN_NEXT_CHILD;
@@ -279,8 +268,6 @@ man_head_alloc(struct man *m, int line, int pos, int tok)
struct man_node *p;
p = man_node_alloc(line, pos, MAN_HEAD, tok);
- if (NULL == p)
- return(0);
if ( ! man_node_append(m, p))
return(0);
m->next = MAN_NEXT_CHILD;
@@ -294,8 +281,6 @@ man_body_alloc(struct man *m, int line, int pos, int tok)
struct man_node *p;
p = man_node_alloc(line, pos, MAN_BODY, tok);
- if (NULL == p)
- return(0);
if ( ! man_node_append(m, p))
return(0);
m->next = MAN_NEXT_CHILD;
@@ -309,8 +294,6 @@ man_block_alloc(struct man *m, int line, int pos, int tok)
struct man_node *p;
p = man_node_alloc(line, pos, MAN_BLOCK, tok);
- if (NULL == p)
- return(0);
if ( ! man_node_append(m, p))
return(0);
m->next = MAN_NEXT_CHILD;
@@ -326,15 +309,7 @@ pstring(struct man *m, int line, int pos,
size_t sv;
n = man_node_alloc(line, pos, MAN_TEXT, -1);
- if (NULL == n)
- return(0);
-
- n->string = malloc(len + 1);
- if (NULL == n->string) {
- free(n);
- return(0);
- }
-
+ n->string = mandoc_malloc(len + 1);
sv = strlcpy(n->string, p, len + 1);
/* Prohibit truncation. */