summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2019-03-03 13:01:47 +0000
committerschwarze <schwarze@openbsd.org>2019-03-03 13:01:47 +0000
commit1fd1dc028c9b1ec97b405dff4c48ba4d9999b798 (patch)
tree037f8d145ccf03a352c80662013123761cc6a740
parentAdjust caller of sa2addr() so this compiles again. (diff)
downloadwireguard-openbsd-1fd1dc028c9b1ec97b405dff4c48ba4d9999b798.tar.xz
wireguard-openbsd-1fd1dc028c9b1ec97b405dff4c48ba4d9999b798.zip
Reset HTML formatter state, in particular the id_unique hash,
after processing each manual page, such that the next page starts from a clean state and doesn't continue suffix numbering. Issue found while looking at https://github.com/Debian/debiman/issues/48 which was brought up by Orestis Ioannou <oorestisime at github>.
-rw-r--r--usr.bin/mandoc/html.c25
-rw-r--r--usr.bin/mandoc/main.c4
-rw-r--r--usr.bin/mandoc/main.h5
3 files changed, 24 insertions, 10 deletions
diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
index 87aee9c66fe..1d2e308a55b 100644
--- a/usr.bin/mandoc/html.c
+++ b/usr.bin/mandoc/html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: html.c,v 1.123 2019/03/01 10:48:58 schwarze Exp $ */
+/* $OpenBSD: html.c,v 1.124 2019/03/03 13:01:47 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -108,6 +108,7 @@ static const struct htmldata htmltags[TAG_MAX] = {
/* Avoid duplicate HTML id= attributes. */
static struct ohash id_unique;
+static void html_reset_internal(struct html *);
static void print_byte(struct html *, char);
static void print_endword(struct html *);
static void print_indent(struct html *);
@@ -143,21 +144,17 @@ html_alloc(const struct manoutput *outopts)
return h;
}
-void
-html_free(void *p)
+static void
+html_reset_internal(struct html *h)
{
struct tag *tag;
- struct html *h;
char *cp;
unsigned int slot;
- h = (struct html *)p;
while ((tag = h->tag) != NULL) {
h->tag = tag->next;
free(tag);
}
- free(h);
-
cp = ohash_first(&id_unique, &slot);
while (cp != NULL) {
free(cp);
@@ -167,6 +164,20 @@ html_free(void *p)
}
void
+html_reset(void *p)
+{
+ html_reset_internal(p);
+ mandoc_ohash_init(&id_unique, 4, 0);
+}
+
+void
+html_free(void *p)
+{
+ html_reset_internal(p);
+ free(p);
+}
+
+void
print_gen_head(struct html *h)
{
struct tag *t;
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 11b9ea1702d..2db236a256e 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.221 2019/01/11 17:03:43 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.222 2019/03/03 13:01:47 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -805,6 +805,8 @@ parse(struct curparse *curp, int fd, const char *file)
if (curp->outdata == NULL)
outdata_alloc(curp);
+ else if (curp->outtype == OUTT_HTML)
+ html_reset(curp);
mandoc_xr_reset();
meta = mparse_result(curp->mp);
diff --git a/usr.bin/mandoc/main.h b/usr.bin/mandoc/main.h
index 10ad298012d..ee8e10d2b01 100644
--- a/usr.bin/mandoc/main.h
+++ b/usr.bin/mandoc/main.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: main.h,v 1.24 2018/12/30 00:48:47 schwarze Exp $ */
+/* $OpenBSD: main.h,v 1.25 2019/03/03 13:01:47 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015, 2019 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -29,6 +29,7 @@ struct manoutput;
void *html_alloc(const struct manoutput *);
void html_mdoc(void *, const struct roff_meta *);
void html_man(void *, const struct roff_meta *);
+void html_reset(void *);
void html_free(void *);
void tree_mdoc(void *, const struct roff_meta *);