summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-10-27 08:49:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-10-27 08:49:44 +0000
commit56502d387509c2110dbc7798d17e8a7823573f62 (patch)
tree216c94270baae4a3e7d7faf7df35a694791e3c99
parent5a0f8634e4ed2c22078afd5c992a17992c7b970f (diff)
downloadmandoc-56502d387509c2110dbc7798d17e8a7823573f62.tar.gz
mandoc-56502d387509c2110dbc7798d17e8a7823573f62.tar.zst
mandoc-56502d387509c2110dbc7798d17e8a7823573f62.zip
Removed dynamic allocations of header/footer data.
-rw-r--r--man_term.c25
-rw-r--r--mdoc_term.c33
2 files changed, 16 insertions, 42 deletions
diff --git a/man_term.c b/man_term.c
index 4cdc9370..d2ea4161 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.45 2009/10/26 04:09:45 kristaps Exp $ */
+/* $Id: man_term.c,v 1.46 2009/10/27 08:49:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -939,25 +939,18 @@ print_man_foot(struct termp *p, const struct man_meta *meta)
static void
-print_man_head(struct termp *p, const struct man_meta *meta)
+print_man_head(struct termp *p, const struct man_meta *m)
{
- char *buf, *title;
+ char buf[BUFSIZ], title[BUFSIZ];
p->rmargin = p->maxrmargin;
p->offset = 0;
+ buf[0] = title[0] = '\0';
- if (NULL == (buf = malloc(p->rmargin)))
- err(EXIT_FAILURE, "malloc");
- if (NULL == (title = malloc(p->rmargin)))
- err(EXIT_FAILURE, "malloc");
+ if (m->vol)
+ strlcpy(buf, m->vol, BUFSIZ);
- if (meta->vol)
- (void)strlcpy(buf, meta->vol, p->rmargin);
- else
- *buf = 0;
-
- (void)snprintf(title, p->rmargin, "%s(%d)",
- meta->title, meta->msec);
+ snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec);
p->offset = 0;
p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
@@ -984,8 +977,4 @@ print_man_head(struct termp *p, const struct man_meta *meta)
p->rmargin = p->maxrmargin;
p->offset = 0;
p->flags &= ~TERMP_NOSPACE;
-
- free(title);
- free(buf);
}
-
diff --git a/mdoc_term.c b/mdoc_term.c
index 97370bee..8d337150 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.97 2009/10/27 08:26:12 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.98 2009/10/27 08:49:44 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -348,8 +348,7 @@ print_node(DECL_ARGS)
static void
print_foot(DECL_ARGS)
{
- char buf[DATESIZ];
- char *os;
+ char buf[DATESIZ], os[BUFSIZ];
/*
* Output the footer in new-groff style, that is, three columns
@@ -359,12 +358,8 @@ print_foot(DECL_ARGS)
* SYSTEM DATE SYSTEM
*/
- if (NULL == (os = malloc(p->rmargin)))
- err(EXIT_FAILURE, "malloc");
-
time2a(m->date, buf, DATESIZ);
-
- (void)strlcpy(os, m->os, p->rmargin);
+ strlcpy(os, m->os, BUFSIZ);
term_vspace(p);
@@ -393,8 +388,6 @@ print_foot(DECL_ARGS)
p->offset = 0;
p->rmargin = p->maxrmargin;
p->flags = 0;
-
- free(os);
}
@@ -403,16 +396,11 @@ print_foot(DECL_ARGS)
static void
print_head(DECL_ARGS)
{
- char *buf, *title;
+ char buf[BUFSIZ], title[BUFSIZ];
p->rmargin = p->maxrmargin;
p->offset = 0;
- if (NULL == (buf = malloc(p->rmargin)))
- err(EXIT_FAILURE, "malloc");
- if (NULL == (title = malloc(p->rmargin)))
- err(EXIT_FAILURE, "malloc");
-
/*
* The header is strange. It has three components, which are
* really two with the first duplicated. It goes like this:
@@ -427,15 +415,15 @@ print_head(DECL_ARGS)
*/
assert(m->vol);
- (void)strlcpy(buf, m->vol, p->rmargin);
+ strlcpy(buf, m->vol, BUFSIZ);
if (m->arch) {
- (void)strlcat(buf, " (", p->rmargin);
- (void)strlcat(buf, m->arch, p->rmargin);
- (void)strlcat(buf, ")", p->rmargin);
+ strlcat(buf, " (", BUFSIZ);
+ strlcat(buf, m->arch, BUFSIZ);
+ strlcat(buf, ")", BUFSIZ);
}
- snprintf(title, p->rmargin, "%s(%d)", m->title, m->msec);
+ snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec);
p->offset = 0;
p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
@@ -462,9 +450,6 @@ print_head(DECL_ARGS)
p->offset = 0;
p->rmargin = p->maxrmargin;
p->flags &= ~TERMP_NOSPACE;
-
- free(title);
- free(buf);
}