-# $OpenBSD: Makefile,v 1.97 2015/07/19 05:59:07 schwarze Exp $
+# $OpenBSD: Makefile,v 1.98 2015/10/13 15:50:15 schwarze Exp $
.include <bsd.own.mk>
DPADD += ${LIBUTIL}
LDADD += -lsqlite3 -lutil -lz
-SRCS= mandoc.c mandoc_aux.c preconv.c read.c \
+SRCS= mandoc.c mandoc_aux.c mandoc_ohash.c preconv.c read.c \
roff.c tbl.c tbl_opts.c tbl_layout.c tbl_data.c eqn.c
SRCS+= mdoc_macro.c mdoc.c mdoc_hash.c \
mdoc_argv.c mdoc_validate.c att.c msec.c st.c
LIBMAN_OBJS = man.o man_hash.o man_macro.o man_validate.o
LIBROFF_OBJS = roff.o eqn.o tbl.o tbl_data.o tbl_layout.o tbl_opts.o
LIBMANDOC_OBJS = ${LIBMDOC_OBJS} ${LIBMAN_OBJS} ${LIBROFF_OBJS} \
- mandoc.o mandoc_aux.o chars.o msec.o preconv.o read.o
+ mandoc.o mandoc_aux.o mandoc_ohash.o \
+ chars.o msec.o preconv.o read.o
HTML_OBJS = html.o mdoc_html.o man_html.o tbl_html.o eqn_html.o out.o
CGI_OBJS = ${LIBMANDOC_OBJS} ${HTML_OBJS} \
mansearch.o mansearch_const.o cgi.o
-cgi.o: main.h mandoc.h mandoc_aux.h manconf.h mansearch.h cgi.h
+cgi.o: main.h mandoc.h mandoc_aux.h mandoc_ohash.h manconf.h mansearch.h cgi.h
man.cgi: ${CGI_OBJS}
${CC} ${LDFLAGS} ${STATIC} -o ${.TARGET} ${CGI_OBJS} ${LDADD}
--- /dev/null
+/* $OpenBSD: mandoc_ohash.c,v 1.1 2015/10/13 15:50:15 schwarze Exp $ */
+/*
+ * Copyright (c) 2014, 2015 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
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <sys/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "mandoc_aux.h"
+#include "mandoc_ohash.h"
+
+static void *hash_alloc(size_t, void *);
+static void *hash_calloc(size_t, size_t, void *);
+static void hash_free(void *, void *);
+
+
+void
+mandoc_ohash_init(struct ohash *h, unsigned int sz, ptrdiff_t ko)
+{
+ struct ohash_info info;
+
+ info.alloc = hash_alloc;
+ info.calloc = hash_calloc;
+ info.free = hash_free;
+ info.data = NULL;
+ info.key_offset = ko;
+
+ ohash_init(h, sz, &info);
+}
+
+static void *
+hash_alloc(size_t sz, void *arg)
+{
+
+ return mandoc_malloc(sz);
+}
+
+static void *
+hash_calloc(size_t n, size_t sz, void *arg)
+{
+
+ return mandoc_calloc(n, sz);
+}
+
+static void
+hash_free(void *p, void *arg)
+{
+
+ free(p);
+}
--- /dev/null
+/* $OpenBSD: mandoc_ohash.h,v 1.1 2015/10/13 15:50:15 schwarze Exp $ */
+/*
+ * Copyright (c) 2015 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
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <ohash.h>
+
+__BEGIN_DECLS
+
+void mandoc_ohash_init(struct ohash *, unsigned int, ptrdiff_t);
+
+__END_DECLS
-/* $OpenBSD: mandocdb.c,v 1.155 2015/10/12 22:30:27 schwarze Exp $ */
+/* $OpenBSD: mandocdb.c,v 1.156 2015/10/13 15:50:15 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
#include <string.h>
#include <unistd.h>
-#include <ohash.h>
#include <sqlite3.h>
#include "mandoc_aux.h"
+#include "mandoc_ohash.h"
#include "mandoc.h"
#include "roff.h"
#include "mdoc.h"
static int dbopen(int);
static void dbprune(void);
static void filescan(const char *);
-static void *hash_alloc(size_t, void *);
-static void hash_free(void *, void *);
-static void *hash_calloc(size_t, size_t, void *);
static void mlink_add(struct mlink *, const struct stat *);
static void mlink_check(struct mpage *, struct mlink *);
static void mlink_free(struct mlink *);
mandocdb(int argc, char *argv[])
{
struct manconf conf;
- struct ohash_info mpages_info, mlinks_info;
struct mparse *mp;
const char *path_arg;
size_t j, sz;
memset(&conf, 0, sizeof(conf));
memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *));
- mpages_info.alloc = mlinks_info.alloc = hash_alloc;
- mpages_info.calloc = mlinks_info.calloc = hash_calloc;
- mpages_info.free = mlinks_info.free = hash_free;
- mpages_info.data = mlinks_info.data = NULL;
-
- mpages_info.key_offset = offsetof(struct mpage, inodev);
- mlinks_info.key_offset = offsetof(struct mlink, file);
-
/*
* We accept a few different invocations.
* The CHECKOP macro makes sure that invocation styles don't
mchars = mchars_alloc();
mp = mparse_alloc(mparse_options, MANDOCLEVEL_BADARG, NULL,
mchars, NULL);
- ohash_init(&mpages, 6, &mpages_info);
- ohash_init(&mlinks, 6, &mlinks_info);
+ mandoc_ohash_init(&mpages, 6, offsetof(struct mpage, inodev));
+ mandoc_ohash_init(&mlinks, 6, offsetof(struct mlink, file));
if (OP_UPDATE == op || OP_DELETE == op || OP_TEST == op) {
continue;
if (j) {
- ohash_init(&mpages, 6, &mpages_info);
- ohash_init(&mlinks, 6, &mlinks_info);
+ mandoc_ohash_init(&mpages, 6,
+ offsetof(struct mpage, inodev));
+ mandoc_ohash_init(&mlinks, 6,
+ offsetof(struct mlink, file));
}
if ( ! set_basedir(conf.manpath.paths[j], argc > 0))
mpages_merge(struct mparse *mp)
{
char any[] = "any";
- struct ohash_info str_info;
struct mpage *mpage, *mpage_dest;
struct mlink *mlink, *mlink_dest;
struct roff_man *man;
int fd;
unsigned int pslot;
- str_info.alloc = hash_alloc;
- str_info.calloc = hash_calloc;
- str_info.free = hash_free;
- str_info.data = NULL;
- str_info.key_offset = offsetof(struct str, key);
-
if ( ! nodb)
SQL_EXEC("BEGIN TRANSACTION");
}
name_mask = NAME_MASK;
- ohash_init(&names, 4, &str_info);
- ohash_init(&strings, 6, &str_info);
+ mandoc_ohash_init(&names, 4, offsetof(struct str, key));
+ mandoc_ohash_init(&strings, 6, offsetof(struct str, key));
mparse_reset(mp);
man = NULL;
sodest = NULL;
return 1;
}
-static void *
-hash_calloc(size_t n, size_t sz, void *arg)
-{
-
- return mandoc_calloc(n, sz);
-}
-
-static void *
-hash_alloc(size_t sz, void *arg)
-{
-
- return mandoc_malloc(sz);
-}
-
-static void
-hash_free(void *p, void *arg)
-{
-
- free(p);
-}
-
static int
set_basedir(const char *targetdir, int report_baddir)
{
-/* $OpenBSD: mansearch.c,v 1.46 2015/10/11 21:06:59 schwarze Exp $ */
+/* $OpenBSD: mansearch.c,v 1.47 2015/10/13 15:50:15 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
#include <string.h>
#include <unistd.h>
-#include <ohash.h>
#include <sqlite3.h>
#include "mandoc.h"
#include "mandoc_aux.h"
+#include "mandoc_ohash.h"
#include "manconf.h"
#include "mansearch.h"
const char *, int form);
static char *buildoutput(sqlite3 *, sqlite3_stmt *,
uint64_t, uint64_t);
-static void *hash_alloc(size_t, void *);
-static void hash_free(void *, void *);
-static void *hash_calloc(size_t, size_t, void *);
static struct expr *exprcomp(const struct mansearch *,
int, char *[]);
static void exprfree(struct expr *);
sqlite3 *db;
sqlite3_stmt *s, *s2;
struct match *mp;
- struct ohash_info info;
struct ohash htab;
unsigned int idx;
size_t i, j, cur, maxres;
return 0;
}
- info.calloc = hash_calloc;
- info.alloc = hash_alloc;
- info.free = hash_free;
- info.key_offset = offsetof(struct match, pageid);
-
cur = maxres = 0;
*res = NULL;
SQL_BIND_INT64(db, s, j, ep->bits);
}
- memset(&htab, 0, sizeof(struct ohash));
- ohash_init(&htab, 4, &info);
+ mandoc_ohash_init(&htab, 4, offsetof(struct match, pageid));
/*
* Hash each entry on its [unique] document identifier.
p = pp;
}
}
-
-static void *
-hash_calloc(size_t nmemb, size_t sz, void *arg)
-{
-
- return mandoc_calloc(nmemb, sz);
-}
-
-static void *
-hash_alloc(size_t sz, void *arg)
-{
-
- return mandoc_malloc(sz);
-}
-
-static void
-hash_free(void *p, void *arg)
-{
-
- free(p);
-}
-/* $OpenBSD: tag.c,v 1.9 2015/10/11 21:59:48 schwarze Exp $ */
+/* $OpenBSD: tag.c,v 1.10 2015/10/13 15:50:15 schwarze Exp $ */
/*
* Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
*
#include <string.h>
#include <unistd.h>
-#include <ohash.h>
-
#include "mandoc_aux.h"
+#include "mandoc_ohash.h"
#include "tag.h"
struct tag_entry {
};
static void tag_signal(int);
-static void *tag_alloc(size_t, void *);
-static void tag_free(void *, void *);
-static void *tag_calloc(size_t, size_t, void *);
static struct ohash tag_data;
static struct tag_files tag_files;
struct tag_files *
tag_init(void)
{
- struct ohash_info tag_info;
int ofd;
ofd = -1;
* where various marked-up terms are documented.
*/
- tag_info.alloc = tag_alloc;
- tag_info.calloc = tag_calloc;
- tag_info.free = tag_free;
- tag_info.key_offset = offsetof(struct tag_entry, s);
- tag_info.data = NULL;
- ohash_init(&tag_data, 4, &tag_info);
+ mandoc_ohash_init(&tag_data, 4, offsetof(struct tag_entry, s));
return &tag_files;
fail:
/* NOTREACHED */
_exit(1);
}
-
-/*
- * Memory management callback functions for ohash.
- */
-static void *
-tag_alloc(size_t sz, void *arg)
-{
-
- return mandoc_malloc(sz);
-}
-
-static void *
-tag_calloc(size_t nmemb, size_t sz, void *arg)
-{
-
- return mandoc_calloc(nmemb, sz);
-}
-
-static void
-tag_free(void *p, void *arg)
-{
-
- free(p);
-}