From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p81AkTt9006236 for ; Thu, 1 Sep 2011 06:46:29 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id p81AkSDP003333; Thu, 1 Sep 2011 06:46:28 -0400 (EDT) Date: Thu, 1 Sep 2011 06:46:28 -0400 (EDT) Message-Id: <201109011046.p81AkSDP003333@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Add demandoc utility, a replacement for deroff. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 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 +.\" +.\" 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 @@ 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) + +

@@ -272,6 +283,13 @@ News

+ 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

@@ -294,15 +312,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 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 + * + * 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); + } +} -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv