summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-11-04 19:57:28 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-11-04 19:57:28 +0000
commit3b57184b869e4fdb20d572856e5c80ebe5aa9e7d (patch)
treefe8a52d59bc1724cddf5e6c82de0c1fdfa9f2c90
parent3e323453bbacb247a030790fe3d94c167b762097 (diff)
a new utility for bcook@: find mlinks for portable LibreSSL
-rw-r--r--regress/usr.bin/mandoc/db/mlinks/Makefile16
-rw-r--r--regress/usr.bin/mandoc/db/mlinks/mlinks.179
-rw-r--r--regress/usr.bin/mandoc/db/mlinks/mlinks.c97
3 files changed, 192 insertions, 0 deletions
diff --git a/regress/usr.bin/mandoc/db/mlinks/Makefile b/regress/usr.bin/mandoc/db/mlinks/Makefile
new file mode 100644
index 00000000000..c7ea85c73e3
--- /dev/null
+++ b/regress/usr.bin/mandoc/db/mlinks/Makefile
@@ -0,0 +1,16 @@
+# $OpenBSD: Makefile,v 1.1 2016/11/04 19:57:27 schwarze Exp $
+
+PROG = mlinks
+CPPFLAGS += -I${BSDSRCDIR}/usr.bin/mandoc
+MOBJS = dbm.o dbm_map.o
+LDADD += ${MOBJS}
+CLEANFILES = ${MOBJS}
+NOMAN=
+
+mlinks: ${MOBJS}
+
+${MOBJS}:
+ cd ${BSDSRCDIR}/usr.bin/mandoc && make $@
+ ln -sf ${.OBJDIR}/../../../../../usr.bin/mandoc/$@ .
+
+.include <bsd.prog.mk>
diff --git a/regress/usr.bin/mandoc/db/mlinks/mlinks.1 b/regress/usr.bin/mandoc/db/mlinks/mlinks.1
new file mode 100644
index 00000000000..f6239cdb268
--- /dev/null
+++ b/regress/usr.bin/mandoc/db/mlinks/mlinks.1
@@ -0,0 +1,79 @@
+.\" $OpenBSD: mlinks.1,v 1.1 2016/11/04 19:57:27 schwarze Exp $
+.\"
+.\" Copyright (c) 2016 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.
+.\"
+.Dd $Mdocdate: November 4 2016 $
+.Dt MLINKS 1
+.Os
+.Sh NAME
+.Nm mlinks
+.Nd extract desired mlinks from a mandoc.db(5) file
+.Sh SYNOPSIS
+.Nm mlinks
+.Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility reads a
+.Xr mandoc_db 5
+database from the given
+.Ar file .
+For each manual page name that does not agree with the filename,
+it write one line to standard output, containing:
+.Pp
+.Bl -dash -compact
+.It
+the filename
+.It
+a comma
+.It
+the other name
+.It
+a period
+.It
+the section number
+.El
+.Pp
+This format is useful for portable software intended to run on
+operating systems that require multiple file system entries
+for pages having multiple names.
+.Pp
+For example, it is used to generate MLINKS for portable LibreSSL.
+.Sh FILES
+The header files
+.Qq Pa dbm_map.h
+and
+.Qq Pa dbm.h
+and the object files
+.Pa dbm_map.o
+and
+.Pa dbm.o
+from the
+.Xr mandoc 1
+build are required to compile and link
+.Nm .
+.Sh EXIT STATUS
+.Ex -std
+It fails when no argument or more than one argument is given, when
+.Fn dbm_open
+fails, or when database corruption is detected.
+.Sh AUTHORS
+.An Ingo Schwarze Aq Mt schwarze@openbsd.org
+.Sh CAVEATS
+The
+.Nm
+utility only partially validates the database format.
+For complete validation, use
+.Xr dbm_dump 1 .
diff --git a/regress/usr.bin/mandoc/db/mlinks/mlinks.c b/regress/usr.bin/mandoc/db/mlinks/mlinks.c
new file mode 100644
index 00000000000..f3e56fe10e0
--- /dev/null
+++ b/regress/usr.bin/mandoc/db/mlinks/mlinks.c
@@ -0,0 +1,97 @@
+/* $OpenBSD: mlinks.c,v 1.1 2016/11/04 19:57:27 schwarze Exp $ */
+/*
+ * Copyright (c) 2016 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.
+ *
+ * Some operating systems need MLINKS for pages with more than one name.
+ * Extract these in a format suitable for portable LibreSSL.
+ */
+#include <err.h>
+#include <regex.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "dbm_map.h"
+#include "dbm.h"
+
+int
+main(int argc, char *argv[])
+{
+ const int32_t *pp; /* Page record in the pages table. */
+ const char *np; /* Names of the page. */
+ const char *fp; /* Primary filename of the page. */
+ const char *ep; /* Filname extension including the dot. */
+ size_t nlen;
+ int32_t i, npages;
+
+ if (argc != 2)
+ errx(1, "usage: mlinks filename");
+
+ if (dbm_open(argv[1]) == -1)
+ err(1, "%s", argv[1]);
+
+ pp = dbm_getint(4);
+ npages = be32toh(*pp++);
+ if (npages <= 0)
+ errx(1, "database empty or corrupt: %d pages", npages);
+
+ for (i = 0; i < npages; i++, pp += 5) {
+ np = dbm_get(pp[0]);
+ if (np == NULL)
+ errx(1, "database corrupt: bad name pointer");
+
+ /* Skip files with just one name. */
+ if (strchr(np, '\0')[1] == '\0')
+ continue;
+
+ fp = dbm_get(pp[4]);
+ if (fp == NULL)
+ errx(1, "database corrupt: bad file pointer");
+
+ /* Skip the file type byte. */
+ fp++;
+
+ /* Skip directory parts of filenames. */
+ ep = strrchr(fp, '/');
+ if (ep != NULL)
+ fp = ep + 1;
+
+ ep = strrchr(fp, '.');
+ if (ep == NULL)
+ errx(1, "no filename extension: %s", fp);
+
+ while (*np != '\0') {
+
+ /* Skip the name type byte. */
+ np++;
+
+ /* Skip the primary filename. */
+ nlen = strlen(np);
+ if (strncmp(fp, np, nlen) == 0) {
+ np = strchr(np, '\0') + 1;
+ continue;
+ }
+
+ /* Describe the desired mlink. */
+ printf("%s,", fp);
+ while (*np != '\0')
+ putchar(*np++);
+ np++;
+ puts(ep);
+ }
+ }
+ dbm_close();
+ return 0;
+}