Skip to content

Commit

Permalink
Reset HTML formatter state, in particular the id_unique hash,
Browse files Browse the repository at this point in the history
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 Debian/debiman#48
which was brought up by Orestis Ioannou <oorestisime at github>.
  • Loading branch information
ischwarze committed Mar 3, 2019
1 parent 6534542 commit 1fd1dc0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
25 changes: 18 additions & 7 deletions usr.bin/mandoc/html.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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 *);
Expand Down Expand Up @@ -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);
Expand All @@ -166,6 +163,20 @@ html_free(void *p)
ohash_delete(&id_unique);
}

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)
{
Expand Down
4 changes: 3 additions & 1 deletion usr.bin/mandoc/main.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions usr.bin/mandoc/main.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 *);
Expand Down

0 comments on commit 1fd1dc0

Please sign in to comment.