diff options
-rw-r--r-- | Makefile | 44 | ||||
-rw-r--r-- | index.7 | 2 | ||||
-rw-r--r-- | libmdocml.c | 29 | ||||
-rw-r--r-- | libmdocml.h | 8 | ||||
-rw-r--r-- | mdocml.1 | 37 | ||||
-rw-r--r-- | mdocml.c | 4 | ||||
-rw-r--r-- | noop.c | 292 | ||||
-rw-r--r-- | private.h | 4 |
8 files changed, 375 insertions, 45 deletions
@@ -1,20 +1,20 @@ -VERSION = 1.0.2 +VERSION = 1.0.3 # FIXME CFLAGS += -W -Wall -Wno-unused-parameter -g -DDEBUG LNS = mdocml.ln html.ln xml.ln libmdocml.ln roff.ln ml.ln mlg.ln \ - compat.ln tokens.ln literals.ln tags.ln + compat.ln tokens.ln literals.ln tags.ln noop.ln LLNS = llib-lmdocml.ln LIBS = libmdocml.a OBJS = mdocml.o html.o xml.o libmdocml.o roff.o ml.o mlg.o \ - compat.o tokens.o literals.o tags.o + compat.o tokens.o literals.o tags.o noop.o SRCS = mdocml.c html.c xml.c libmdocml.c roff.c ml.c mlg.c \ - compat.c tokens.c literals.c tags.c + compat.c tokens.c literals.c tags.c noop.c HEADS = libmdocml.h private.h ml.h roff.h html.h @@ -106,48 +106,52 @@ mdocml-port.tgz: $(INSTALL) ( cd .dist/ && tar zcf ../$@ mdocml/ ) rm -rf .dist/ -llib-lmdocml.ln: mdocml.ln libmdocml.ln html.ln xml.ln roff.ln ml.ln mlg.ln compat.ln tokens.ln literals.ln tags.ln - $(LINT) $(LINTFLAGS) -Cmdocml mdocml.ln libmdocml.ln html.ln xml.ln roff.ln ml.ln mlg.ln compat.ln tokens.ln literals.ln tags.ln +llib-lmdocml.ln: mdocml.ln libmdocml.ln html.ln xml.ln roff.ln ml.ln mlg.ln compat.ln tokens.ln literals.ln tags.ln noop.ln + $(LINT) $(LINTFLAGS) -Cmdocml mdocml.ln libmdocml.ln html.ln xml.ln roff.ln ml.ln mlg.ln compat.ln tokens.ln literals.ln tags.ln noop.ln mdocml.ln: mdocml.c libmdocml.h mdocml.o: mdocml.c libmdocml.h -libmdocml.a: libmdocml.o html.o xml.o roff.o ml.o mlg.o compat.o tokens.o literals.o tags.o - $(AR) rs $@ libmdocml.o html.o xml.o roff.o ml.o mlg.o compat.o tokens.o literals.o tags.o +libmdocml.a: libmdocml.o html.o xml.o roff.o ml.o mlg.o compat.o tokens.o literals.o tags.o noop.o + $(AR) rs $@ libmdocml.o html.o xml.o roff.o ml.o mlg.o compat.o tokens.o literals.o tags.o noop.o -xml.ln: xml.c private.h libmdocml.h ml.h +xml.ln: xml.c ml.h -xml.o: xml.c private.h libmdocml.h ml.h +xml.o: xml.c ml.h -html.ln: html.c private.h libmdocml.h +html.ln: html.c private.h -html.o: html.c private.h libmdocml.h +html.o: html.c private.h tags.ln: tags.c html.h tags.o: tags.c html.h -roff.ln: roff.c private.h roff.h libmdocml.h +roff.ln: roff.c private.h -roff.o: roff.c private.h roff.h libmdocml.h +roff.o: roff.c private.h -libmdocml.ln: libmdocml.c private.h libmdocml.h +libmdocml.ln: libmdocml.c private.h -libmdocml.o: libmdocml.c private.h libmdocml.h +libmdocml.o: libmdocml.c private.h -ml.ln: ml.c private.h libmdocml.h ml.h +ml.ln: ml.c ml.h -ml.o: ml.c private.h libmdocml.h ml.h +ml.o: ml.c ml.h -mlg.ln: mlg.c private.h libmdocml.h ml.h +mlg.ln: mlg.c ml.h -mlg.o: mlg.c private.h libmdocml.h ml.h +mlg.o: mlg.c ml.h compat.ln: compat.c compat.o: compat.c +noop.ln: noop.c private.h + +noop.o: noop.c private.h + html.h: ml.h ml.h: private.h @@ -107,7 +107,7 @@ Download at http://mdocml.bsd.lv/mdocml.tgz .Ns . .\" - UPDATE ME WITH EVERY RELEASE. ---------------------------------- -The current version is 1.0.2, dated 10/12/2008. +The current version is 1.0.3, dated 10/12/2008. .\" ------------------------------------------------------------------ .Pp Previous versions are archived as mdocml-x.y.z.tgz, with the appropriate diff --git a/libmdocml.c b/libmdocml.c index 5c28e408..33f5ffa7 100644 --- a/libmdocml.c +++ b/libmdocml.c @@ -130,6 +130,8 @@ static int md_run_leave(const struct md_args *args, struct md_mbuf *mbuf, struct md_rbuf *rbuf, int c, void *data) { + md_exit fp; + assert(args); assert(mbuf); assert(rbuf); @@ -137,15 +139,19 @@ md_run_leave(const struct md_args *args, struct md_mbuf *mbuf, /* Run exiters. */ switch (args->type) { case (MD_HTML): - if ( ! md_exit_html(data, -1 == c ? 0 : 1)) - c = -1; + fp = md_exit_html; + break; + case (MD_XML): + fp = md_exit_xml; break; default: - if ( ! md_exit_xml(data, -1 == c ? 0 : 1)) - c = -1; + fp = md_exit_noop; break; } + if ( ! (*fp)(data, -1 == c ? 0 : 1)) + c = -1; + /* Make final flush of buffer. */ if (-1 != c && ! md_buf_flush(mbuf)) return(-1); @@ -172,9 +178,12 @@ md_run_enter(const struct md_args *args, struct md_mbuf *mbuf, case (MD_HTML): fp = md_line_html; break; - default: + case (MD_XML): fp = md_line_xml; break; + default: + fp = md_line_noop; + break; } pos = 0; @@ -217,6 +226,7 @@ int md_run(const struct md_args *args, const struct md_buf *out, const struct md_buf *in) { + md_init fp; struct md_mbuf mbuf; struct md_rbuf rbuf; void *data; @@ -234,13 +244,18 @@ md_run(const struct md_args *args, /* Run initialisers. */ switch (args->type) { case (MD_HTML): - data = md_init_html(args, &mbuf, &rbuf); + fp = md_init_html; + break; + case (MD_XML): + fp = md_init_xml; break; default: - data = md_init_xml(args, &mbuf, &rbuf); + fp = md_init_noop; break; } + data = (*fp)(args, &mbuf, &rbuf); + /* Go into mainline. */ return(md_run_enter(args, &mbuf, &rbuf, data)); } diff --git a/libmdocml.h b/libmdocml.h index b7426a7d..93126e85 100644 --- a/libmdocml.h +++ b/libmdocml.h @@ -21,10 +21,6 @@ #include <sys/types.h> -struct md_params_xml { - int dummy; -}; - struct md_params_html { char *css; int flags; @@ -32,13 +28,13 @@ struct md_params_html { }; union md_params { - struct md_params_xml xml; struct md_params_html html; }; enum md_type { MD_XML, /* XML. */ - MD_HTML /* HTML4.01-strict. */ + MD_HTML, /* HTML4.01-strict. */ + MD_NOOP /* Validates only. */ }; struct md_args { @@ -20,21 +20,24 @@ The .Nm utility parses mdoc formatted manual source and passes results into an output filter. The current output filters are -.Ar html +.Fl f Ar html and -.Ar xml , -the default. Arguments common to all filters follow: +.Fl f Ar xml . +By default, +.Nm +only validates its input. This may be explicitly directed with +.Fl f Ar noop . +Arguments common to all filters follow: .Bl -tag -width "\-o outfile" .It Fl f Ar filter -The output filter name. This -.Em must -be declared before any other options. +The output filter name. .It Fl o Ar outfile Write output to .Ar outfile , which may be .Dq \- -for stdout. +for stdout. This is meaningless for +.Fl f Ar noop . .It Fl W Ns Ar err... Print warning messages. If set to .Fl W Ns Ar all , @@ -56,14 +59,21 @@ for stdin. .Pp By default, .Nm -reads from stdin and writes to stdout using the xml filter. +reads from stdin and writes to stdout. .Pp .Ex -std mdocml .\" +.Ss Noop Filter +The default noop +.Dq validating +filter simply validates its input; it produces no output beyond error +and warning messages. +.\" .Ss XML Filter The XML filter, specified by .Fl f Ar xml , -is the default filter. This filter has no additional arguments. +produces correctly-formatted XML output. This filter has no additional +arguments. .Pp The XML filter creates an XML document where element names are their respective roff macro names. Each element name has an associated @@ -88,6 +98,7 @@ namespace is for block bodies; and the .Dq inline namespace is for in-line elements (such as .Sq .Em ) . +.\" .Ss HTML Filter The HTML filter, specified by .Fl f Ar html , @@ -99,6 +110,10 @@ The CSS file location, which defaults to .It Fl e Whether to embed the CSS file into the HTML prologue. .El +.Pp +By default, the HTML filter produces HTML-4.01 strict mark-up. The +default CSS document styles the page as it would appear in a terminal +window. .\" .Sh EXAMPLES To produce an HTML4-strict document @@ -118,7 +133,9 @@ with the default namespace identifiers and .Li inline : .Pp -.D1 % mdocml mdocml.1 +.D1 % mdocml -Wall,error -fxml mdocml.1 +.Pp +The previous example will also halt on input document warnings. .\" .Sh SEE ALSO .Xr groff 1 , @@ -71,7 +71,7 @@ main(int argc, char *argv[]) (void)memset(&args, 0, sizeof(struct md_args)); - args.type = MD_XML; + args.type = MD_NOOP; while (-1 != (c = getopt(argc, argv, "c:ef:o:vW:"))) switch (c) { @@ -90,6 +90,8 @@ main(int argc, char *argv[]) args.type = MD_HTML; else if (0 == strcmp(optarg, "xml")) args.type = MD_XML; + else if (0 == strcmp(optarg, "noop")) + args.type = MD_NOOP; else errx(1, "invalid filter type"); break; @@ -0,0 +1,292 @@ +/* $Id$ */ +/* + * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> + * + * 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 <assert.h> +#include <err.h> +#include <stdlib.h> + +#include "private.h" + + +struct md_noop { + const struct md_args *args; + const struct md_rbuf *rbuf; + struct rofftree *tree; +}; + + +static int noop_roffmsg(void *arg, + enum roffmsg, const char *, + const char *, const char *); +static int noop_roffhead(void *, const struct tm *, + const char *, const char *, + enum roffmsec, enum roffvol); +static int noop_rofftail(void *, const struct tm *, + const char *, const char *, + enum roffmsec, enum roffvol); +static int noop_roffin(void *, int, + int *, const char **); +static int noop_roffdata(void *, int, + const char *, const char *); +static int noop_roffout(void *, int); +static int noop_roffblkin(void *, int, int *, + const char **); +static int noop_roffblkout(void *, int); +static int noop_roffspecial(void *, int, + const char *, const int *, + const char **, const char **); +static int noop_roffblkheadin(void *, int, + int *, const char **); +static int noop_roffblkheadout(void *, int); +static int noop_roffblkbodyin(void *, int, + int *, const char **); +static int noop_roffblkbodyout(void *, int); + +#ifdef __linux__ +extern size_t strlcat(char *, const char *, size_t); +extern size_t strlcpy(char *, const char *, size_t); +#endif + + +int +md_exit_noop(void *data, int flush) +{ + struct md_noop *noop; + int c; + + noop = (struct md_noop *)data; + c = roff_free(noop->tree, flush); + free(noop); + return(c); +} + + +int +md_line_noop(void *data, char *buf) +{ + struct md_noop *noop; + + noop = (struct md_noop *)data; + return(roff_engine(noop->tree, buf)); +} + + +void * +md_init_noop(const struct md_args *args, + struct md_mbuf *mbuf, const struct md_rbuf *rbuf) +{ + struct roffcb cb; + struct md_noop *noop; + + if (NULL == (noop = calloc(1, sizeof(struct md_noop)))) + err(1, "calloc"); + + noop->args = args; + noop->rbuf = rbuf; + + cb.roffhead = noop_roffhead; + cb.rofftail = noop_rofftail; + cb.roffin = noop_roffin; + cb.roffout = noop_roffout; + cb.roffblkin = noop_roffblkin; + cb.roffblkheadin = noop_roffblkheadin; + cb.roffblkheadout = noop_roffblkheadout; + cb.roffblkbodyin = noop_roffblkbodyin; + cb.roffblkbodyout = noop_roffblkbodyout; + cb.roffblkout = noop_roffblkout; + cb.roffspecial = noop_roffspecial; + cb.roffmsg = noop_roffmsg; + cb.roffdata = noop_roffdata; + + if (NULL == (noop->tree = roff_alloc(&cb, noop))) { + free(noop); + return(NULL); + } + return(noop); +} + + +/* ARGSUSED */ +static int +noop_roffhead(void *arg, const struct tm *tm, const char *os, + const char *title, enum roffmsec sec, enum roffvol vol) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_rofftail(void *arg, const struct tm *tm, const char *os, + const char *title, enum roffmsec sec, enum roffvol vol) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffspecial(void *arg, int tok, const char *start, + const int *argc, const char **argv, const char **more) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffblkin(void *arg, int tok, + int *argc, const char **argv) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffblkout(void *arg, int tok) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffblkbodyin(void *arg, int tok, + int *argc, const char **argv) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffblkbodyout(void *arg, int tok) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffblkheadin(void *arg, int tok, + int *argc, const char **argv) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffblkheadout(void *arg, int tok) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffin(void *arg, int tok, int *argc, const char **argv) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffout(void *arg, int tok) +{ + + return(1); +} + + +/* ARGSUSED */ +static int +noop_roffdata(void *arg, int tok, + const char *start, const char *buf) +{ + + return(1); +} + + +static int +noop_roffmsg(void *arg, enum roffmsg lvl, + const char *buf, const char *pos, const char *msg) +{ + struct md_noop *p; + char *level; + char b[256]; + int i; + + p = (struct md_noop *)arg; + assert(p); + + switch (lvl) { + case (ROFF_WARN): + level = "warning"; + if ( ! (MD_WARN_ALL & p->args->warnings)) + return(1); + break; + case (ROFF_ERROR): + level = "error"; + break; + default: + abort(); + /* NOTREACHED */ + } + + if (pos) { + assert(pos >= buf); + if (0 < p->args->verbosity) { + (void)snprintf(b, sizeof(b), + "%s:%zu: %s: %s\n", + p->rbuf->name, p->rbuf->line, + level, msg); + (void)strlcat(b, "Error at: ", sizeof(b)); + (void)strlcat(b, p->rbuf->linebuf, sizeof(b)); + + (void)strlcat(b, "\n ", sizeof(b)); + for (i = 0; i < pos - buf; i++) + (void)strlcat(b, " ", sizeof(b)); + (void)strlcat(b, "^", sizeof(b)); + + } else + (void)snprintf(b, sizeof(b), + "%s:%zu: %s: %s (col %zu)", + p->rbuf->name, p->rbuf->line, + level, msg, pos - buf); + } else + (void)snprintf(b, sizeof(b), "%s: %s: %s", + p->rbuf->name, level, msg); + + (void)fprintf(stderr, "%s\n", b); + return(lvl == ROFF_WARN ? 1 : 0); +} + @@ -376,6 +376,10 @@ void *md_init_html(const struct md_args *, struct md_mbuf *, const struct md_rbuf *); int md_line_html(void *, char *); int md_exit_html(void *, int); +void *md_init_noop(const struct md_args *, + struct md_mbuf *, const struct md_rbuf *); +int md_line_noop(void *, char *); +int md_exit_noop(void *, int); void *md_init_xml(const struct md_args *, struct md_mbuf *, const struct md_rbuf *); int md_line_xml(void *, char *); |