-/* $OpenBSD: libman.h,v 1.46 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: libman.h,v 1.47 2015/04/18 17:01:28 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
void man_body_alloc(struct roff_man *, int, int, int);
void man_elem_alloc(struct roff_man *, int, int, int);
void man_node_delete(struct roff_man *, struct roff_node *);
-void man_hash_init(void);
int man_hash_find(const char *);
void man_macroend(struct roff_man *);
void man_valid_post(struct roff_man *);
-/* $OpenBSD: libmandoc.h,v 1.42 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: libmandoc.h,v 1.43 2015/04/18 17:01:28 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
struct roff_man *mdoc_alloc(struct roff *, struct mparse *,
const char *, int);
void mdoc_reset(struct roff_man *);
+void mdoc_hash_init(void);
int mdoc_parseln(struct roff_man *, int, char *, int);
void mdoc_endparse(struct roff_man *);
void mdoc_addspan(struct roff_man *, const struct tbl_span *);
struct roff_man *man_alloc(struct roff *, struct mparse *,
const char *, int);
void man_reset(struct roff_man *);
+void man_hash_init(void);
int man_parseln(struct roff_man *, int, char *, int);
void man_endparse(struct roff_man *);
void man_addspan(struct roff_man *, const struct tbl_span *);
-/* $OpenBSD: libmdoc.h,v 1.71 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: libmdoc.h,v 1.72 2015/04/18 17:01:28 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
struct roff_node *, enum mdoc_endbody);
void mdoc_node_delete(struct roff_man *, struct roff_node *);
void mdoc_node_relink(struct roff_man *, struct roff_node *);
-void mdoc_hash_init(void);
int mdoc_hash_find(const char *);
const char *mdoc_a2att(const char *);
const char *mdoc_a2st(const char *);
-/* $OpenBSD: man.c,v 1.102 2015/04/18 16:34:03 schwarze Exp $ */
+/* $OpenBSD: man.c,v 1.103 2015/04/18 17:01:28 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
struct roff_man *p;
p = mandoc_calloc(1, sizeof(*p));
-
- man_hash_init();
p->parse = parse;
p->defos = defos;
p->quick = quick;
-/* $OpenBSD: man_hash.c,v 1.21 2015/04/02 22:06:17 schwarze Exp $ */
+/* $OpenBSD: man_hash.c,v 1.22 2015/04/18 17:01:28 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
static unsigned char table[26 * HASH_DEPTH];
-/*
- * XXX - this hash has global scope, so if intended for use as a library
- * with multiple callers, it will need re-invocation protection.
- */
void
man_hash_init(void)
{
int i, j, x;
+ if (*table != '\0')
+ return;
+
memset(table, UCHAR_MAX, sizeof(table));
assert(MAN_MAX < UCHAR_MAX);
-/* $OpenBSD: mdoc.c,v 1.132 2015/04/18 16:34:03 schwarze Exp $ */
+/* $OpenBSD: mdoc.c,v 1.133 2015/04/18 17:01:28 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
p->quick = quick;
p->roff = roff;
- mdoc_hash_init();
mdoc_alloc1(p);
return(p);
}
-/* $OpenBSD: mdoc_hash.c,v 1.18 2015/04/02 22:06:17 schwarze Exp $ */
+/* $OpenBSD: mdoc_hash.c,v 1.19 2015/04/18 17:01:28 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
static unsigned char table[27 * 12];
-/*
- * XXX - this hash has global scope, so if intended for use as a library
- * with multiple callers, it will need re-invocation protection.
- */
void
mdoc_hash_init(void)
{
int i, j, major;
const char *p;
+ if (*table != '\0')
+ return;
+
memset(table, UCHAR_MAX, sizeof(table));
for (i = 0; i < (int)MDOC_MAX; i++) {
-/* $OpenBSD: read.c,v 1.110 2015/04/18 16:34:03 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.111 2015/04/18 17:01:28 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
MPARSE_QUICK & curp->options ? 1 : 0);
else
curp->man->macroset = MACROSET_MDOC;
+ mdoc_hash_init();
return;
}
MPARSE_QUICK & curp->options ? 1 : 0);
else
curp->man->macroset = MACROSET_MAN;
+ man_hash_init();
}
/*
curp->mchars = mchars;
curp->roff = roff_alloc(curp, curp->mchars, options);
- if (curp->options & MPARSE_MDOC)
+ if (curp->options & MPARSE_MDOC) {
curp->man = mdoc_alloc(
curp->roff, curp, curp->defos,
curp->options & MPARSE_QUICK ? 1 : 0);
- if (curp->options & MPARSE_MAN)
+ mdoc_hash_init();
+ }
+ if (curp->options & MPARSE_MAN) {
curp->man = man_alloc(
curp->roff, curp, curp->defos,
curp->options & MPARSE_QUICK ? 1 : 0);
+ man_hash_init();
+ }
return(curp);
}