aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2019-03-03 13:02:11 +0000
committerIngo Schwarze <schwarze@openbsd.org>2019-03-03 13:02:11 +0000
commitf4f4629c2afc1c20003c12753c35528bd807708a (patch)
tree6997e819a3f1fcf467b4f433a29078d073df1fd7
parentfcbf62db4a9cb9f6fe8df047ee6ee41fee8dab76 (diff)
downloadmandoc-f4f4629c2afc1c20003c12753c35528bd807708a.tar.gz
mandoc-f4f4629c2afc1c20003c12753c35528bd807708a.tar.zst
mandoc-f4f4629c2afc1c20003c12753c35528bd807708a.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--html.c25
-rw-r--r--main.c4
-rw-r--r--main.h5
-rw-r--r--mandocd.c6
4 files changed, 28 insertions, 12 deletions
diff --git a/html.c b/html.c
index a9a667ce..1302972a 100644
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.253 2019/03/01 10:57:17 schwarze Exp $ */
+/* $Id: html.c,v 1.254 2019/03/03 13:02:11 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -110,6 +110,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 *);
@@ -145,21 +146,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);
@@ -169,6 +166,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/main.c b/main.c
index 36eb565d..74912cf5 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.318 2019/01/11 17:04:44 schwarze Exp $ */
+/* $Id: main.c,v 1.319 2019/03/03 13:02:11 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -835,6 +835,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/main.h b/main.h
index 772ea648..19a630cd 100644
--- a/main.h
+++ b/main.h
@@ -1,7 +1,7 @@
-/* $Id: main.h,v 1.29 2018/12/30 00:49:55 schwarze Exp $ */
+/* $Id: main.h,v 1.30 2019/03/03 13:02:11 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 *);
diff --git a/mandocd.c b/mandocd.c
index b8b5570d..1a597b38 100644
--- a/mandocd.c
+++ b/mandocd.c
@@ -1,7 +1,7 @@
-/* $Id: mandocd.c,v 1.10 2019/03/03 11:01:15 schwarze Exp $ */
+/* $Id: mandocd.c,v 1.11 2019/03/03 13:02:11 schwarze Exp $ */
/*
* Copyright (c) 2017 Michael Stapelberg <stapelberg@debian.org>
- * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2017, 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
@@ -213,6 +213,8 @@ main(int argc, char *argv[])
process(parser, outtype, formatter);
mparse_reset(parser);
+ if (outtype == OUTT_HTML)
+ html_reset(formatter);
fflush(stdout);
fflush(stderr);