source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Add demandoc utility, a replacement for deroff.
@ 2011-09-01 10:46 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-09-01 10:46 UTC (permalink / raw)
  To: source

Log Message:
-----------
Add demandoc utility, a replacement for deroff.

Modified Files:
--------------
    mdocml:
        Makefile
        index.sgml

Added Files:
-----------
    mdocml:
        demandoc.1
        demandoc.c

Revision Data
-------------
--- /dev/null
+++ demandoc.1
@@ -0,0 +1,74 @@
+.\"	$Id: demandoc.1,v 1.1 2011/09/01 10:46:28 kristaps Exp $
+.\"
+.\" Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+.\"
+.\" 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: September 1 2011 $
+.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 .
Index: index.sgml
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/index.sgml,v
retrieving revision 1.137
retrieving revision 1.138
diff -Lindex.sgml -Lindex.sgml -u -p -r1.137 -r1.138
--- index.sgml
+++ index.sgml
@@ -39,8 +39,9 @@
 			<SPAN CLASS="nm">mdocml</SPAN> consists of the <A HREF="mandoc.3.html">libmandoc</A> validating compiler and <A
 			HREF="mandoc.1.html">mandoc</A>, 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 <A HREF="preconv.1.html">preconv</A>, for recoding multibyte manuals; and <A
-			HREF="mandocdb.8.html">mandocdb</A>, for indexing manuals.
+			It also includes <A HREF="preconv.1.html">preconv</A>, for recoding multibyte manuals; 
+			<A HREF="demandoc.1.html">demandoc</A>, for emitting only text parts of manuals;
+			and <A HREF="mandocdb.8.html">mandocdb</A>, for indexing manuals.
 			It is a <A CLASS="external" HREF="http://bsd.lv/">BSD.lv</A> project.  
 		</P>
 		<P>
@@ -131,13 +132,13 @@
 					</TD>
 				</TR>
 				<TR>
-					<TD VALIGN="top"><A HREF="mandocdb.8.html">mandocdb(8)</A></TD>
+					<TD VALIGN="top"><A HREF="demandoc.1.html">demandoc(1)</A></TD>
 					<TD VALIGN="top">
-						index UNIX manuals
-							(<A HREF="mandocdb.8.txt">text</A> | 
-							<A HREF="mandocdb.8.xhtml">xhtml</A> |
-							<A HREF="mandocdb.8.pdf">pdf</A> |
-							<A HREF="mandocdb.8.ps">ps</A>)
+						emit only text of UNIX manuals
+							(<A HREF="demandoc.1.txt">text</A> | 
+							<A HREF="demandoc.1.xhtml">xhtml</A> |
+							<A HREF="demandoc.1.pdf">pdf</A> |
+							<A HREF="demandoc.1.ps">ps</A>)
 					</TD>
 				</TR>
 				<TR>
@@ -220,6 +221,16 @@
 							<A HREF="tbl.7.ps">ps</A>)
 					</TD>
 				</TR>
+				<TR>
+					<TD VALIGN="top"><A HREF="mandocdb.8.html">mandocdb(8)</A></TD>
+					<TD VALIGN="top">
+						index UNIX manuals
+							(<A HREF="mandocdb.8.txt">text</A> | 
+							<A HREF="mandocdb.8.xhtml">xhtml</A> |
+							<A HREF="mandocdb.8.pdf">pdf</A> |
+							<A HREF="mandocdb.8.ps">ps</A>)
+					</TD>
+				</TR>
 			</TBODY>
 		</TABLE>
 		<H1>
@@ -272,6 +283,13 @@
 			<A NAME="news">News</A>
 		</H1>
 		<P CLASS="news">
+			xx-xx-2011: version 1.11.x
+		</P>
+		<P>
+			Added <A HREF="demandoc.1.html">demandoc</A> utility for stripping away macros and escapes.  This replaces the
+			historical <CODE>deroff</CODE> utility.
+		</P>
+		<P CLASS="news">
 			16-08-2011: version 1.11.6
 		</P>
 		<P>
@@ -294,15 +312,6 @@
 		<P>
 			This is also the first release featuring a distributed Windows binary, available at <A
 			HREF="/binaries/mdocml-win32.zip">/binaries/mdocml-win32.zip</A>.
-		</P>
-		<P CLASS="news">
-			12-07-2011: version 1.11.4
-		</P>
-		<P>
-			Bug-fixes and clean-ups across all systems, especially in <INS><A HREF="mandocdb.8.html">mandocdb</A></INS> <DEL>makewhatis</DEL> (note: still not
-			connected to the general build and must be compiled with <INS><CODE>make mandocdb</CODE></INS> <DEL><CODE>make makewhatis</CODE></DEL>) and the <A
-			HREF="man.7.html">man</A> parser.  This release was significantly assisted by participants in <A CLASS="external"
-			HREF="http://www.openbsd.org">OpenBSD</A>'s c2k11.  Thanks!
 		</P>
 		<P>
 			See <A HREF="http://mdocml.bsd.lv/cgi-bin/cvsweb/index.sgml?cvsroot=mdocml">cvsweb</A> for
Index: Makefile
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v
retrieving revision 1.368
retrieving revision 1.369
diff -LMakefile -LMakefile -u -p -r1.368 -r1.369
--- Makefile
+++ 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)
@@ -391,6 +405,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 >$@
--- /dev/null
+++ demandoc.c
@@ -0,0 +1,180 @@
+/*	$Id: demandoc.c,v 1.1 2011/09/01 10:46:28 kristaps Exp $ */
+/*
+ * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ *
+ * 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 <assert.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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, "<stdin>");
+
+	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);
+	}
+}
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-09-01 10:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-01 10:46 mdocml: Add demandoc utility, a replacement for deroff kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).