From 39f38f46ef135991e2c1ff53d33926edd13f4fb9 Mon Sep 17 00:00:00 2001
From: Kristaps Dzonsons
Date: Thu, 1 Sep 2011 10:46:28 +0000
Subject: Add demandoc utility, a replacement for deroff.
---
Makefile | 30 +++++++++--
demandoc.1 | 74 +++++++++++++++++++++++++
demandoc.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
index.sgml | 43 +++++++++------
4 files changed, 305 insertions(+), 22 deletions(-)
create mode 100644 demandoc.1
create mode 100644 demandoc.c
diff --git a/Makefile b/Makefile
index 55bf5753..2fcbdde4 100644
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@ INSTALL_MAN = $(INSTALL_DATA)
# Linux needs -ldb to compile mandocdb.
#DBLIB = -ldb
-all: mandoc preconv
+all: mandoc preconv demandoc
SRCS = Makefile \
arch.c \
@@ -51,6 +51,8 @@ SRCS = Makefile \
compat_strlcpy.c \
config.h.post \
config.h.pre \
+ demandoc.c \
+ demandoc.1 \
eqn.7 \
eqn.c \
eqn_html.c \
@@ -258,7 +260,17 @@ PRECONV_LNS = preconv.ln
$(PRECONV_OBJS) $(PRECONV_LNS): config.h
-INDEX_MANS = mandoc.1.html \
+DEMANDOC_OBJS = demandoc.o
+DEMANDOC_LNS = demandoc.ln
+
+$(DEMANDOC_OBJS) $(DEMANDOC_LNS): config.h
+
+INDEX_MANS = demandoc.1.html \
+ demandoc.1.xhtml \
+ demandoc.1.ps \
+ demandoc.1.pdf \
+ demandoc.1.txt \
+ mandoc.1.html \
mandoc.1.xhtml \
mandoc.1.ps \
mandoc.1.pdf \
@@ -320,7 +332,7 @@ INDEX_OBJS = $(INDEX_MANS) \
www: index.html
-lint: llib-llibmandoc.ln llib-lmandoc.ln llib-lpreconv.ln
+lint: llib-llibmandoc.ln llib-lmandoc.ln llib-lpreconv.ln llib-ldemandoc.ln
clean:
rm -f libmandoc.a $(LIBMANDOC_OBJS)
@@ -329,6 +341,8 @@ clean:
rm -f llib-lmandocdb.ln $(MANDOCDB_LNS)
rm -f preconv $(PRECONV_OBJS)
rm -f llib-lpreconv.ln $(PRECONV_LNS)
+ rm -f demandoc $(DEMANDOC_OBJS)
+ rm -f llib-ldemandoc.ln $(DEMANDOC_LNS)
rm -f mandoc $(MANDOC_OBJS)
rm -f llib-lmandoc.ln $(MANDOC_LNS)
rm -f config.h config.log $(COMPAT_OBJS) $(COMPAT_LNS)
@@ -349,10 +363,10 @@ install: all
mkdir -p $(DESTDIR)$(MANDIR)/man3
mkdir -p $(DESTDIR)$(MANDIR)/man7
mkdir -p $(DESTDIR)$(MANDIR)/man8
- $(INSTALL_PROGRAM) mandoc preconv $(DESTDIR)$(BINDIR)
+ $(INSTALL_PROGRAM) mandoc preconv demandoc $(DESTDIR)$(BINDIR)
$(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR)
$(INSTALL_LIB) man.h mdoc.h mandoc.h $(DESTDIR)$(INCLUDEDIR)
- $(INSTALL_MAN) mandoc.1 preconv.1 $(DESTDIR)$(MANDIR)/man1
+ $(INSTALL_MAN) mandoc.1 preconv.1 demandoc.1 $(DESTDIR)$(MANDIR)/man1
$(INSTALL_MAN) mandoc.3 $(DESTDIR)$(MANDIR)/man3
$(INSTALL_MAN) man.7 mdoc.7 roff.7 eqn.7 tbl.7 mandoc_char.7 $(DESTDIR)$(MANDIR)/man7
$(INSTALL_DATA) example.style.css $(DESTDIR)$(EXAMPLEDIR)
@@ -392,6 +406,12 @@ preconv: $(PRECONV_OBJS)
llib-lpreconv.ln: $(PRECONV_LNS)
$(LINT) $(LINTFLAGS) -Cpreconv $(PRECONV_LNS)
+demandoc: $(DEMANDOC_OBJS) libmandoc.a
+ $(CC) $(LDFLAGS) -o $@ $(DEMANDOC_OBJS) libmandoc.a
+
+llib-ldemandoc.ln: $(DEMANDOC_LNS)
+ $(LINT) $(LINTFLAGS) -Cdemandoc $(DEMANDOC_LNS)
+
mdocml.md5: mdocml.tar.gz
md5 mdocml.tar.gz >$@
diff --git a/demandoc.1 b/demandoc.1
new file mode 100644
index 00000000..23463af1
--- /dev/null
+++ b/demandoc.1
@@ -0,0 +1,74 @@
+.\" $Id$
+.\"
+.\" Copyright (c) 2011 Kristaps Dzonsons
+.\"
+.\" 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$
+.Dt DEMANDOC 1
+.Os
+.Sh NAME
+.Nm demandoc
+.Nd emit only text of UNIX manuals
+.Sh SYNOPSIS
+.Nm demandoc
+.Op Ar
+.Sh DESCRIPTION
+The
+.Nm
+utility emits only the text portions of
+.Xr mdoc 7
+and
+.Xr man 7
+.Ux
+manual files.
+Its arguments are as follows:
+.Bl -tag -width Ds
+.It Ar
+The input files.
+.El
+.Pp
+If
+.Ar file
+is not provided,
+.Nm
+accepts standard input.
+.Pp
+.Nm
+output preserves the line numbering and column position of its input.
+.Sh EXIT STATUS
+The
+.Nm
+utility exits with one of the following values:
+.Pp
+.Bl -tag -width Ds -compact
+.It 0
+No errors occurred.
+.It 6
+An operating system error occurred, for example memory exhaustion or an
+error accessing input files.
+Such errors cause
+.Nm
+to exit at once, possibly in the middle of parsing or formatting a file.
+The output databases are corrupt and should be removed .
+.El
+.Sh SEE ALSO
+.Xr mandoc 1 ,
+.Xr man 7
+.Xr mdoc 7
+.Sh AUTHORS
+The
+.Nm
+utility was written by
+.An Kristaps Dzonsons ,
+.Mt kristaps@bsd.lv .
diff --git a/demandoc.c b/demandoc.c
new file mode 100644
index 00000000..37003ca0
--- /dev/null
+++ b/demandoc.c
@@ -0,0 +1,180 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2011 Kristaps Dzonsons
+ *
+ * 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.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include
+#include
+#include
+#include
+#include
+
+#include "man.h"
+#include "mdoc.h"
+#include "mandoc.h"
+
+static void pline(int, int *, int *);
+static void pman(const struct man_node *, int *, int *);
+static void pmandoc(struct mparse *, int, const char *);
+static void pmdoc(const struct mdoc_node *, int *, int *);
+static void pstring(const char *, int, int *);
+static void usage(void);
+
+static const char *progname;
+
+int
+main(int argc, char *argv[])
+{
+ struct mparse *mp;
+ int ch, i;
+ extern int optind;
+ extern char *optarg;
+
+ progname = strrchr(argv[0], '/');
+ if (progname == NULL)
+ progname = argv[0];
+ else
+ ++progname;
+
+ mp = NULL;
+
+ while (-1 != (ch = getopt(argc, argv, "")))
+ switch (ch) {
+ default:
+ usage();
+ return((int)MANDOCLEVEL_BADARG);
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL);
+ assert(mp);
+
+ if (0 == argc)
+ pmandoc(mp, STDIN_FILENO, "");
+
+ for (i = 0; i < argc; i++) {
+ mparse_reset(mp);
+ pmandoc(mp, -1, argv[i]);
+ }
+
+ mparse_free(mp);
+ return(MANDOCLEVEL_OK);
+}
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "usage: %s [files...]\n", progname);
+}
+
+static void
+pmandoc(struct mparse *mp, int fd, const char *fn)
+{
+ struct mdoc *mdoc;
+ struct man *man;
+ int line, col;
+
+ if (mparse_readfd(mp, fd, fn) >= MANDOCLEVEL_FATAL) {
+ fprintf(stderr, "%s: Parse failure\n", fn);
+ return;
+ }
+
+ mparse_result(mp, &mdoc, &man);
+ line = 1;
+ col = 0;
+
+ if (mdoc)
+ pmdoc(mdoc_node(mdoc), &line, &col);
+ else if (man)
+ pman(man_node(man), &line, &col);
+ else
+ return;
+
+ putchar('\n');
+}
+
+/*
+ * Strip the escapes out of a string, emitting the results.
+ */
+static void
+pstring(const char *p, int col, int *colp)
+{
+ enum mandoc_esc esc;
+
+ while (*colp < col) {
+ putchar(' ');
+ (*colp)++;
+ }
+
+ while ('\0' != *p) {
+ if ('\\' == *p) {
+ p++;
+ esc = mandoc_escape(&p, NULL, NULL);
+ if (ESCAPE_ERROR == esc)
+ return;
+ } else {
+ putchar(*p++);
+ (*colp)++;
+ }
+ }
+}
+
+/*
+ * Emit lines until we're in sync with our input.
+ */
+static void
+pline(int line, int *linep, int *col)
+{
+
+ while (*linep < line) {
+ putchar('\n');
+ (*linep)++;
+ }
+ *col = 0;
+}
+
+static void
+pmdoc(const struct mdoc_node *p, int *line, int *col)
+{
+
+ for ( ; p; p = p->next) {
+ if (MDOC_LINE & p->flags)
+ pline(p->line, line, col);
+ if (MDOC_TEXT == p->type)
+ pstring(p->string, p->pos, col);
+ if (p->child)
+ pmdoc(p->child, line, col);
+ }
+}
+
+static void
+pman(const struct man_node *p, int *line, int *col)
+{
+
+ for ( ; p; p = p->next) {
+ if (MAN_LINE & p->flags)
+ pline(p->line, line, col);
+ if (MAN_TEXT == p->type)
+ pstring(p->string, p->pos, col);
+ if (p->child)
+ pman(p->child, line, col);
+ }
+}
diff --git a/index.sgml b/index.sgml
index 5b6b48dd..44b13cb8 100644
--- a/index.sgml
+++ b/index.sgml
@@ -39,8 +39,9 @@
mdocml consists of the libmandoc validating compiler and mandoc, which interfaces with the compiler library to format output for UNIX terminals (with
support for wide-character locales), XHTML, HTML, PostScript, and PDF.
- It also includes preconv, for recoding multibyte manuals; and mandocdb, for indexing manuals.
+ It also includes preconv, for recoding multibyte manuals;
+ demandoc, for emitting only text parts of manuals;
+ and mandocdb, for indexing manuals.
It is a BSD.lv project.
@@ -131,13 +132,13 @@
- mandocdb(8) |
+ demandoc(1) |
- index UNIX manuals
- (text |
- xhtml |
- pdf |
- ps)
+ emit only text of UNIX manuals
+ (text |
+ xhtml |
+ pdf |
+ ps)
|
@@ -220,6 +221,16 @@
ps)
+
+ mandocdb(8) |
+
+ index UNIX manuals
+ (text |
+ xhtml |
+ pdf |
+ ps)
+ |
+
@@ -271,6 +282,13 @@
+
+ xx-xx-2011: version 1.11.x
+
+
+ Added demandoc utility for stripping away macros and escapes. This replaces the
+ historical deroff
utility.
+
16-08-2011: version 1.11.6
@@ -295,15 +313,6 @@
This is also the first release featuring a distributed Windows binary, available at /binaries/mdocml-win32.zip.
-
- 12-07-2011: version 1.11.4
-
-
- Bug-fixes and clean-ups across all systems, especially in mandocdb makewhatis (note: still not
- connected to the general build and must be compiled with make mandocdb
make makewhatis
) and the man parser. This release was significantly assisted by participants in OpenBSD's c2k11. Thanks!
-
See cvsweb for
historical notes.
--
cgit