From ff990a7507fa64271846971250247ca30bd62dc5 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sun, 7 Dec 2008 21:30:49 +0000 Subject: *** empty log message *** --- Makefile | 11 ++++++- html.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++--- index.7 | 48 ++++++++++++++++++++++++----- mdocml.css | 4 ++- ml.h | 8 ++++- mlg.c | 102 ++++++++++++++++++++++++++++++++++--------------------------- xml.c | 32 ++++++++++++++++++- 7 files changed, 231 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index b9bdef4c..e8021900 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.SUFFIXES: .html .7 + CFLAGS += -W -Wall -Wno-unused-parameter -g -DDEBUG LINTFLAGS += -c -e -f -u @@ -16,7 +18,9 @@ HEADS = libmdocml.h private.h ml.h roff.h MANS = mdocml.1 -CLEAN = mdocml mdocml.tgz $(LLNS) $(LNS) $(OBJS) $(LIBS) +HTML = index.html + +CLEAN = mdocml mdocml.tgz $(LLNS) $(LNS) $(OBJS) $(LIBS) $(HTML) INSTALL = Makefile $(HEADS) $(SRCS) $(MANS) @@ -37,6 +41,8 @@ lint: llib-lmdocml.ln dist: mdocml.tgz +www: $(HTML) + regress: mdocml @for f in $(FAIL); do \ echo "./mdocml $$f" ; \ @@ -53,6 +59,9 @@ mdocml: mdocml.o libmdocml.a clean: rm -f $(CLEAN) +index.html: index.7 mdocml.css + ./mdocml -W -fhtml -e -o $@ $< + mdocml.tgz: $(INSTALL) mkdir -p .dist/mdocml/ install -m 0644 $(INSTALL) .dist/mdocml/ diff --git a/html.c b/html.c index f93ca764..a62c7fb4 100644 --- a/html.c +++ b/html.c @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.13 2008/12/06 21:10:31 kristaps Exp $ */ +/* $Id: html.c,v 1.14 2008/12/07 21:30:49 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -55,6 +55,18 @@ static void html_free(void *); static ssize_t html_endtag(struct md_mbuf *, void *, const struct md_args *, enum md_ns, int); +static ssize_t html_beginstring(struct md_mbuf *, + const struct md_args *, + const char *, size_t); +static ssize_t html_beginhttp(struct md_mbuf *, + const struct md_args *, + const char *, size_t); +static ssize_t html_endstring(struct md_mbuf *, + const struct md_args *, + const char *, size_t); +static ssize_t html_endhttp(struct md_mbuf *, + const struct md_args *, + const char *, size_t); static ssize_t html_begintag(struct md_mbuf *, void *, const struct md_args *, enum md_ns, int, @@ -127,6 +139,9 @@ html_It_headtagname(struct md_mbuf *mbuf, struct htmlq *q, for (i = 0; ROFF_ARGMAX != n->argc[i] && i < ROFF_MAXLINEARG; i++) { switch (n->argc[i]) { + case (ROFF_Ohang): + return(ml_nputs(mbuf, "div", 3, res)); + case (ROFF_Tag): /* FALLTHROUGH */ case (ROFF_Column): @@ -136,11 +151,8 @@ html_It_headtagname(struct md_mbuf *mbuf, struct htmlq *q, } } - assert(i != ROFF_MAXLINEARG); abort(); /* NOTREACHED */ - - return(1); } @@ -739,6 +751,70 @@ html_free(void *p) } +static ssize_t +html_beginhttp(struct md_mbuf *mbuf, + const struct md_args *args, + const char *buf, size_t sz) +{ + size_t res; + + res = 0; + + if ( ! ml_puts(mbuf, "", &res)) + return(-1); + + return((ssize_t)res); +} + + +static ssize_t +html_endhttp(struct md_mbuf *mbuf, + const struct md_args *args, + const char *buf, size_t sz) +{ + size_t res; + + res = 0; + + if ( ! ml_puts(mbuf, "", &res)) + return(-1); + + return((ssize_t)res); +} + + +/* ARGSUSED */ +static ssize_t +html_beginstring(struct md_mbuf *mbuf, + const struct md_args *args, + const char *buf, size_t sz) +{ + + if (0 == strncmp(buf, "http://", 7)) + return(html_beginhttp(mbuf, args, buf, sz)); + + return(0); +} + + +/* ARGSUSED */ +static ssize_t +html_endstring(struct md_mbuf *mbuf, + const struct md_args *args, + const char *buf, size_t sz) +{ + + if (0 == strncmp(buf, "http://", 7)) + return(html_endhttp(mbuf, args, buf, sz)); + + return(0); +} + + int md_line_html(void *data, char *buf) { @@ -767,7 +843,8 @@ md_init_html(const struct md_args *args, cbs.ml_endtag = html_endtag; cbs.ml_begin = html_begin; cbs.ml_end = html_end; + cbs.ml_beginstring = html_beginstring; + cbs.ml_endstring = html_endstring; return(mlg_alloc(args, rbuf, mbuf, &cbs)); } - diff --git a/index.7 b/index.7 index 74f2c3e1..d696df60 100644 --- a/index.7 +++ b/index.7 @@ -1,11 +1,11 @@ .\" -.Dd $Mdocdate: December 6 2008 $ +.Dd $Mdocdate: December 7 2008 $ .Dt index 7 .Os LOCAL .\" .Sh NAME .Nm mdocml -.Nd compile manpage source into mark-up language +.Nd compile mdoc macros into mark-up language .\" .Sh DESCRIPTION The @@ -52,23 +52,57 @@ or .It and so on. .El -.Pp +.Ss Filtering +When a block of source has been verified, it's passed to the front-end +fitlers, which format and display data. The +.Nm +utility is invoked with a filter by the +.Fl f +flag. The HTML filter has the following features: +.Bl -enum -compact +.It +HTML-4.01 strict compliance. +.It +Proper render of values in UTF-8, such as +.Dq quotes +and \*(>= predefined values. +.It +URI-appearing http://bsd.lv strings are correctly enclosed in link tags. +.It +CSS-dictated style with meaningful non-CSS defaults. +.El .\" .Sh ENVIRONMENT The .Nm -utility has been tested under Linux and OpenBSD. +utility has been tested under Linux and +.Ox , +specifically on +.Ox +manual source. .\" .Sh EXAMPLES This page was produced as follows: .Pp -.D1 % mdocml -fhtml -o index.html index.7 +.D1 % mdocml -fhtml -W -e -o index.html index.7 .\" .Sh SEE ALSO -TODO. +.Bl -ohang +.It Xr rman Ns : http://polyglotman.sourceforge.net/rman.html +Accepts either formatted roff output or source and produces HTML output. +.It Xr man2html Ns : http://www.nongnu.org/man2html/ +Accepts formatted +.Xr nroff 1 +text and produces HTML output. +.It Xr man.cgi Ns : http://www.freebsd.org/cgi/man.cgi/source +.Fx +and +.Ox +project CGI for producing HTML from nroff source. +.El .\" .Sh AUTHORS The .Nm utility was written by -.An Em Kristaps Dzonsons Aq kristaps@kth.se . +.An Kristaps Dzonsons Aq kristaps@kth.se . diff --git a/mdocml.css b/mdocml.css index fb5e79e6..f9a1df3c 100644 --- a/mdocml.css +++ b/mdocml.css @@ -1,9 +1,10 @@ body { margin: 10px; font-family: Tahoma, sans-serif; font-size: small; } + h1 { font-size: medium; } + h2 { font-size: small; } div.mdoc { width: 600px; } div.block-Sh { margin-bottom: 20px; } - div.head-Sh { font-weight: bold; } div.head-Ss { font-weight: bold; margin-top: 10px; text-align: justify; } @@ -16,6 +17,7 @@ span.inline-Cm { font-weight: bolder; } span.inline-Cd { font-weight: bolder; } span.inline-Nm { font-weight: bolder; } + span.inline-An { text-decoration: underline; } span.inline-Ar { text-decoration: underline; } span.inline-Pa { text-decoration: underline; } div.block-Bl { margin-top: 10px; diff --git a/ml.h b/ml.h index c375a671..3c28399e 100644 --- a/ml.h +++ b/ml.h @@ -1,4 +1,4 @@ -/* $Id: ml.h,v 1.7 2008/12/05 19:45:15 kristaps Exp $ */ +/* $Id: ml.h,v 1.8 2008/12/07 21:30:49 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -37,6 +37,12 @@ struct ml_cbs { const char *, const char *); int (*ml_end)(struct md_mbuf *, const struct md_args *); + ssize_t (*ml_beginstring)(struct md_mbuf *, + const struct md_args *, + const char *, size_t); + ssize_t (*ml_endstring)(struct md_mbuf *, + const struct md_args *, + const char *, size_t); ssize_t (*ml_endtag)(struct md_mbuf *, void *, const struct md_args *, enum md_ns, int); diff --git a/mlg.c b/mlg.c index bb0b5514..548ddbae 100644 --- a/mlg.c +++ b/mlg.c @@ -1,4 +1,4 @@ -/* $Id: mlg.c,v 1.18 2008/12/07 16:41:04 kristaps Exp $ */ +/* $Id: mlg.c,v 1.19 2008/12/07 21:30:49 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -92,12 +92,14 @@ static int mlg_endtag(struct md_mlg *, enum md_ns, int); static int mlg_indent(struct md_mlg *); static int mlg_newline(struct md_mlg *); static void mlg_mode(struct md_mlg *, enum md_tok); +static int mlg_nstring(struct md_mlg *, + const char *, const char *, size_t); +static int mlg_string(struct md_mlg *, + const char *, const char *); static int mlg_data(struct md_mlg *, int, const char *, char *); static void mlg_err(struct md_mlg *, const char *, const char *, const char *, ...); -static void mlg_warn(struct md_mlg *, const char *, - const char *, const char *, ...); static void mlg_msg(struct md_mlg *, enum roffmsg, const char *, const char *, char *); static void mlg_vmsg(struct md_mlg *, enum roffmsg, @@ -419,11 +421,47 @@ mlg_mode(struct md_mlg *p, enum md_tok ns) } +static int +mlg_string(struct md_mlg *p, const char *start, const char *buf) +{ + + return(mlg_nstring(p, start, buf, strlen(buf))); +} + + +static int +mlg_nstring(struct md_mlg *p, const char *start, + const char *buf, size_t sz) +{ + int c; + ssize_t res; + + assert(p->mbuf); + assert(0 != p->indent); + + res = (*p->cbs.ml_beginstring)(p->mbuf, p->args, buf, sz); + if (-1 == res) + return(0); + + if (0 == (c = ml_nputstring(p->mbuf, buf, sz, &p->pos))) { + mlg_err(p, start, buf, "bad string " + "encoding: `%s'", buf); + return(0); + } else if (-1 == c) + return(0); + + res = (*p->cbs.ml_endstring)(p->mbuf, p->args, buf, sz); + if (-1 == res) + return(0); + + return(1); +} + + static int mlg_data(struct md_mlg *p, int space, const char *start, char *buf) { size_t sz; - int c; assert(p->mbuf); assert(0 != p->indent); @@ -437,16 +475,7 @@ mlg_data(struct md_mlg *p, int space, const char *start, char *buf) if (0 == p->pos) { if ( ! mlg_indent(p)) return(0); - - c = ml_nputstring(p->mbuf, buf, sz, &p->pos); - - if (0 == c) { - mlg_err(p, start, buf, "bad char sequence"); - return(0); - } else if (c > 1) { - mlg_warn(p, start, buf, "bogus char sequence"); - return(0); - } else if (-1 == c) + if ( ! mlg_nstring(p, start, buf, sz)) return(0); if (p->indent * INDENT + sz >= COLUMNS) @@ -466,18 +495,7 @@ mlg_data(struct md_mlg *p, int space, const char *start, char *buf) return(0); } - c = ml_nputstring(p->mbuf, buf, sz, &p->pos); - - if (0 == c) { - mlg_err(p, start, buf, "bad char sequence"); - return(0); - } else if (c > 1) { - mlg_warn(p, start, buf, "bogus char sequence"); - return(0); - } else if (-1 == c) - return(0); - - return(1); + return(mlg_nstring(p, start, buf, sz)); } @@ -625,7 +643,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, assert(*more); if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, more)) return(0); - if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + if ( ! mlg_string(p, start, *more++)) return(0); if ( ! mlg_endtag(p, MD_NS_INLINE, tok)) return(0); @@ -636,7 +654,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, if ( ! mlg_begintag(p, MD_NS_INLINE, ROFF_Fa, NULL, more)) return(0); - if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + if ( ! mlg_string(p, start, *more++)) return(0); if ( ! mlg_endtag(p, MD_NS_INLINE, ROFF_Fa)) return(0); @@ -645,7 +663,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, return(0); if ( ! mlg_begintag(p, MD_NS_INLINE, ROFF_Fa, NULL, more)) return(0); - if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + if ( ! mlg_string(p, start, *more++)) return(0); if ( ! mlg_endtag(p, MD_NS_INLINE, ROFF_Fa)) return(0); @@ -675,7 +693,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, while (*more) { if ( ! ml_nputs(p->mbuf, " ", 1, &p->pos)) return(0); - if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + if ( ! mlg_string(p, start, *more++)) return(0); } break; @@ -690,7 +708,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, if (*more) { if ( ! ml_nputs(p->mbuf, "(", 1, &p->pos)) return(0); - if ( ! ml_puts(p->mbuf, *more++, &p->pos)) + if ( ! mlg_string(p, start, *more++)) return(0); if ( ! ml_nputs(p->mbuf, ")", 1, &p->pos)) return(0); @@ -700,11 +718,12 @@ mlg_roffspecial(void *arg, int tok, const char *start, return(0); } break; + case (ROFF_Sx): /* FALLTHROUGH */ case (ROFF_Nm): assert(*more); - if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + if ( ! mlg_string(p, start, *more++)) return(0); assert(NULL == *more); break; @@ -722,10 +741,13 @@ mlg_roffspecial(void *arg, int tok, const char *start, return(0); assert(NULL == *more); break; + case (ROFF_At): + /* FIXME: *more must be ml-filtered. */ if ( ! ml_puts(p->mbuf, mlg_At_literal(*more), &p->pos)) return(0); break; + case (ROFF_Bx): /* FALLTHROUGH */ case (ROFF_Bsx): @@ -740,10 +762,11 @@ mlg_roffspecial(void *arg, int tok, const char *start, while (*more) { if ( ! ml_nputs(p->mbuf, " ", 1, &p->pos)) return(0); - if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + if ( ! mlg_string(p, start, *more++)) return(0); } break; + case (ROFF_Bt): /* FALLTHROUGH */ case (ROFF_Ud): @@ -753,6 +776,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, if ( ! ml_puts(p->mbuf, mlg_literal(tok), &p->pos)) return(0); break; + default: mlg_err(p, start, start, "`%s' not yet supported", toknames[tok]); @@ -868,18 +892,6 @@ mlg_vmsg(struct md_mlg *p, enum roffmsg lvl, const char *start, } -static void -mlg_warn(struct md_mlg *p, const char *start, - const char *pos, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - mlg_vmsg(p, ROFF_WARN, start, pos, fmt, ap); - va_end(ap); -} - - static void mlg_err(struct md_mlg *p, const char *start, const char *pos, const char *fmt, ...) diff --git a/xml.c b/xml.c index 81979a15..16582027 100644 --- a/xml.c +++ b/xml.c @@ -1,4 +1,4 @@ -/* $Id: xml.c,v 1.17 2008/12/06 21:10:31 kristaps Exp $ */ +/* $Id: xml.c,v 1.18 2008/12/07 21:30:49 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -34,6 +34,12 @@ static ssize_t xml_begintag(struct md_mbuf *, void *, const struct md_args *, enum md_ns, int, const int *, const char **); +static ssize_t xml_beginstring(struct md_mbuf *, + const struct md_args *, + const char *, size_t); +static ssize_t xml_endstring(struct md_mbuf *, + const struct md_args *, + const char *, size_t); static int xml_begin(struct md_mbuf *, const struct md_args *, const struct tm *, @@ -139,6 +145,28 @@ xml_end(struct md_mbuf *mbuf, const struct md_args *args) } +/* ARGSUSED */ +static ssize_t +xml_beginstring(struct md_mbuf *mbuf, + const struct md_args *args, + const char *buf, size_t sz) +{ + + return(0); +} + + +/* ARGSUSED */ +static ssize_t +xml_endstring(struct md_mbuf *mbuf, + const struct md_args *args, + const char *buf, size_t sz) +{ + + return(0); +} + + /* ARGSUSED */ static ssize_t xml_begintag(struct md_mbuf *mbuf, void *data, @@ -211,6 +239,8 @@ md_init_xml(const struct md_args *args, cbs.ml_endtag = xml_endtag; cbs.ml_begin = xml_begin; cbs.ml_end = xml_end; + cbs.ml_beginstring = xml_beginstring; + cbs.ml_endstring = xml_endstring; return(mlg_alloc(args, rbuf, mbuf, &cbs)); } -- cgit v1.2.3-56-ge451