diff options
-rw-r--r-- | html.c | 182 | ||||
-rw-r--r-- | ml.h | 31 | ||||
-rw-r--r-- | mlg.c | 112 | ||||
-rw-r--r-- | noop.c | 2 | ||||
-rw-r--r-- | roff.h | 2 | ||||
-rw-r--r-- | xml.c | 87 |
6 files changed, 191 insertions, 225 deletions
@@ -49,38 +49,32 @@ static int html_loadcss(struct md_mbuf *, const char *); static int html_alloc(void **); static void html_free(void *); -static ssize_t html_endtag(struct md_mbuf *, void *, - const struct md_args *, +static ssize_t html_endtag(struct ml_args *, enum md_ns, int); -static ssize_t html_beginstring(struct md_mbuf *, - const struct md_args *, +static ssize_t html_beginstring(struct ml_args *, const char *, size_t); -static ssize_t html_beginhttp(struct md_mbuf *, - const struct md_args *, +static ssize_t html_endstring(struct ml_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, +static ssize_t html_begintag(struct ml_args *, + enum md_ns, int, const int *, const char **); -static int html_begin(struct md_mbuf *, - const struct md_args *, +static int html_begin(struct ml_args *, const struct tm *, const char *, const char *, enum roffmsec, enum roffvol); -static int html_printargs(struct md_mbuf *, int, - const char *, const int *, - const char **, size_t *); -static int html_end(struct md_mbuf *, - const struct md_args *, +static int html_end(struct ml_args *, const struct tm *, const char *, const char *, enum roffmsec, enum roffvol); +static int html_printargs(struct md_mbuf *, int, + const char *, const int *, + const char **, size_t *); +static ssize_t html_beginhttp(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 int html_blocktagname(struct md_mbuf *, const struct md_args *, int, struct htmlq *, const int *, @@ -383,8 +377,7 @@ html_aputln(struct md_mbuf *mbuf, enum ml_scope scope, int i, /* ARGSUSED */ static int -html_begin(struct md_mbuf *mbuf, const struct md_args *args, - const struct tm *tm, const char *os, +html_begin(struct ml_args *p, const struct tm *tm, const char *os, const char *name, enum roffmsec msec, enum roffvol vol) { enum roffvol bvol; @@ -441,11 +434,11 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args, i = 0; - if ( ! html_typeput(mbuf, HTML_TYPE_4_01_STRICT, NULL)) + if ( ! html_typeput(p->mbuf, HTML_TYPE_4_01_STRICT, NULL)) return(0); - if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_HTML)) + if ( ! html_tputln(p->mbuf, ML_OPEN, i, HTML_TAG_HTML)) return(0); - if ( ! html_tputln(mbuf, ML_OPEN, i++, HTML_TAG_HEAD)) + if ( ! html_tputln(p->mbuf, ML_OPEN, i++, HTML_TAG_HEAD)) return(0); attr[0].attr = HTML_ATTR_HTTP_EQUIV; @@ -453,7 +446,7 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CONTENT; attr[1].val = "text/html;charset=utf-8"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_META, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_META, 2, attr)) return(0); attr[0].attr = HTML_ATTR_NAME; @@ -461,32 +454,32 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CONTENT; attr[1].val = "document"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_META, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_META, 2, attr)) return(0); - if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_TITLE)) + if ( ! html_tputln(p->mbuf, ML_OPEN, i, HTML_TAG_TITLE)) return(0); - if ( ! ml_putstring(mbuf, ts, NULL)) + if ( ! ml_putstring(p->mbuf, ts, NULL)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TITLE)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, i, HTML_TAG_TITLE)) return(0); - if (HTML_CSS_EMBED & args->params.html.flags) { + if (HTML_CSS_EMBED & p->args->params.html.flags) { attr[0].attr = HTML_ATTR_TYPE; attr[0].val = "text/css"; - if ( ! html_aputln(mbuf, ML_OPEN, i, + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_STYLE, 1, attr)) return(0); - if ( ! html_commentput(mbuf, ML_OPEN, NULL)) + if ( ! html_commentput(p->mbuf, ML_OPEN, NULL)) return(0); - if ( ! html_loadcss(mbuf, args->params.html.css)) + if ( ! html_loadcss(p->mbuf, p->args->params.html.css)) return(0); - if ( ! html_commentput(mbuf, ML_CLOSE, NULL)) + if ( ! html_commentput(p->mbuf, ML_CLOSE, NULL)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_STYLE)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, i, HTML_TAG_STYLE)) return(0); } else { attr[0].attr = HTML_ATTR_REL; @@ -494,22 +487,22 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_TYPE; attr[1].val = "text/css"; attr[2].attr = HTML_ATTR_HREF; - attr[2].val = args->params.html.css; + attr[2].val = p->args->params.html.css; - if ( ! html_aputln(mbuf, ML_OPEN, i, + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_LINK, 3, attr)) return(0); } - if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_HEAD)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, --i, HTML_TAG_HEAD)) return(0); - if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_BODY)) + if ( ! html_tputln(p->mbuf, ML_OPEN, i, HTML_TAG_BODY)) return(0); attr[0].attr = HTML_ATTR_CLASS; attr[0].val = "mdoc"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_DIV, 1, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_DIV, 1, attr)) return(0); attr[0].attr = HTML_ATTR_WIDTH; @@ -517,9 +510,9 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CLASS; attr[1].val = "header-table"; - if ( ! html_aputln(mbuf, ML_OPEN, i++, HTML_TAG_TABLE, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i++, HTML_TAG_TABLE, 2, attr)) return(0); - if ( ! html_tputln(mbuf, ML_OPEN, i++, HTML_TAG_TR)) + if ( ! html_tputln(p->mbuf, ML_OPEN, i++, HTML_TAG_TR)) return(0); attr[0].attr = HTML_ATTR_ALIGN; @@ -527,11 +520,11 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CLASS; attr[1].val = "header-section"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) return(0); - if ( ! ml_putstring(mbuf, ts, NULL)) + if ( ! ml_putstring(p->mbuf, ts, NULL)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, i, HTML_TAG_TD)) return(0); attr[0].attr = HTML_ATTR_ALIGN; @@ -539,11 +532,11 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CLASS; attr[1].val = "header-volume"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) return(0); - if ( ! ml_putstring(mbuf, title, NULL)) + if ( ! ml_putstring(p->mbuf, title, NULL)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, i, HTML_TAG_TD)) return(0); attr[0].attr = HTML_ATTR_ALIGN; @@ -551,23 +544,22 @@ html_begin(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CLASS; attr[1].val = "header-section"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) return(0); - if ( ! ml_putstring(mbuf, ts, NULL)) + if ( ! ml_putstring(p->mbuf, ts, NULL)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, i, HTML_TAG_TD)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TR)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, --i, HTML_TAG_TR)) return(0); - return(html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TABLE)); + return(html_tputln(p->mbuf, ML_CLOSE, --i, HTML_TAG_TABLE)); } /* ARGSUSED */ static int -html_end(struct md_mbuf *mbuf, const struct md_args *args, - const struct tm *tm, const char *os, +html_end(struct ml_args *p, const struct tm *tm, const char *os, const char *name, enum roffmsec msec, enum roffvol vol) { struct html_pair attr[4]; @@ -586,9 +578,9 @@ html_end(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CLASS; attr[1].val = "header-footer"; - if ( ! html_aputln(mbuf, ML_OPEN, i++, HTML_TAG_TABLE, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i++, HTML_TAG_TABLE, 2, attr)) return(0); - if ( ! html_tputln(mbuf, ML_OPEN, i++, HTML_TAG_TR)) + if ( ! html_tputln(p->mbuf, ML_OPEN, i++, HTML_TAG_TR)) return(0); attr[0].attr = HTML_ATTR_ALIGN; @@ -596,11 +588,11 @@ html_end(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CLASS; attr[1].val = "footer-os"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) return(0); - if ( ! ml_putstring(mbuf, os, NULL)) + if ( ! ml_putstring(p->mbuf, os, NULL)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, i, HTML_TAG_TD)) return(0); attr[0].attr = HTML_ATTR_ALIGN; @@ -608,23 +600,23 @@ html_end(struct md_mbuf *mbuf, const struct md_args *args, attr[1].attr = HTML_ATTR_CLASS; attr[1].val = "footer-date"; - if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) + if ( ! html_aputln(p->mbuf, ML_OPEN, i, HTML_TAG_TD, 2, attr)) return(0); - if ( ! ml_putstring(mbuf, ts, NULL)) + if ( ! ml_putstring(p->mbuf, ts, NULL)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, i, HTML_TAG_TD)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TR)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, --i, HTML_TAG_TR)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TABLE)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, --i, HTML_TAG_TABLE)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_DIV)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, 0, HTML_TAG_DIV)) return(0); - if ( ! html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_BODY)) + if ( ! html_tputln(p->mbuf, ML_CLOSE, 0, HTML_TAG_BODY)) return(0); - return(html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_HTML)); + return(html_tputln(p->mbuf, ML_CLOSE, 0, HTML_TAG_HTML)); } @@ -832,8 +824,7 @@ html_inlinetagname(struct md_mbuf *mbuf, static ssize_t -html_begintag(struct md_mbuf *mbuf, void *data, - const struct md_args *args, enum md_ns ns, +html_begintag(struct ml_args *p, enum md_ns ns, int tok, const int *argc, const char **argv) { size_t res; @@ -844,8 +835,7 @@ html_begintag(struct md_mbuf *mbuf, void *data, assert(ns != MD_NS_DEFAULT); res = 0; - assert(data); - q = (struct htmlq *)data; + q = (struct htmlq *)p->data; if (NULL == (node = calloc(1, sizeof(struct htmlnode)))) { warn("calloc"); @@ -872,33 +862,33 @@ html_begintag(struct md_mbuf *mbuf, void *data, switch (ns) { case (MD_NS_BLOCK): - if ( ! html_blocktagname(mbuf, args, tok, + if ( ! html_blocktagname(p->mbuf, p->args, tok, q, argc, argv, &res)) return(-1); - if ( ! html_blocktagargs(mbuf, args, tok, + if ( ! html_blocktagargs(p->mbuf, p->args, tok, argc, argv, &res)) return(-1); break; case (MD_NS_BODY): - if ( ! html_bodytagname(mbuf, args, tok, + if ( ! html_bodytagname(p->mbuf, p->args, tok, q, argc, argv, &res)) return(-1); - if ( ! html_bodytagargs(mbuf, args, tok, + if ( ! html_bodytagargs(p->mbuf, p->args, tok, argc, argv, &res)) return(-1); break; case (MD_NS_HEAD): - if ( ! html_headtagname(mbuf, args, tok, q, + if ( ! html_headtagname(p->mbuf, p->args, tok, q, argc, argv, &res)) return(-1); - if ( ! html_headtagargs(mbuf, args, tok, + if ( ! html_headtagargs(p->mbuf, p->args, tok, argc, argv, &res)) return(-1); break; default: - if ( ! html_inlinetagname(mbuf, args, tok, &res)) + if ( ! html_inlinetagname(p->mbuf, p->args, tok, &res)) return(-1); - if ( ! html_inlinetagargs(mbuf, args, tok, + if ( ! html_inlinetagargs(p->mbuf, p->args, tok, argc, argv, &res)) return(-1); break; @@ -909,8 +899,7 @@ html_begintag(struct md_mbuf *mbuf, void *data, static ssize_t -html_endtag(struct md_mbuf *mbuf, void *data, - const struct md_args *args, enum md_ns ns, int tok) +html_endtag(struct ml_args *p, enum md_ns ns, int tok) { size_t res; struct htmlq *q; @@ -919,31 +908,30 @@ html_endtag(struct md_mbuf *mbuf, void *data, assert(ns != MD_NS_DEFAULT); res = 0; - assert(data); - q = (struct htmlq *)data; + q = (struct htmlq *)p->data; node = q->last; switch (ns) { case (MD_NS_BLOCK): - if ( ! html_blocktagname(mbuf, args, tok, + if ( ! html_blocktagname(p->mbuf, p->args, tok, q, node->argc, (const char **)node->argv, &res)) return(-1); break; case (MD_NS_BODY): - if ( ! html_bodytagname(mbuf, args, tok, + if ( ! html_bodytagname(p->mbuf, p->args, tok, q, node->argc, (const char **)node->argv, &res)) return(-1); break; case (MD_NS_HEAD): - if ( ! html_headtagname(mbuf, args, tok, + if ( ! html_headtagname(p->mbuf, p->args, tok, q, node->argc, (const char **)node->argv, &res)) return(-1); break; default: - if ( ! html_inlinetagname(mbuf, args, tok, &res)) + if ( ! html_inlinetagname(p->mbuf, p->args, tok, &res)) return(-1); break; } @@ -1023,13 +1011,11 @@ html_endhttp(struct md_mbuf *mbuf, /* ARGSUSED */ static ssize_t -html_beginstring(struct md_mbuf *mbuf, - const struct md_args *args, - const char *buf, size_t sz) +html_beginstring(struct ml_args *p, const char *buf, size_t sz) { if (0 == strncmp(buf, "http://", 7)) - return(html_beginhttp(mbuf, args, buf, sz)); + return(html_beginhttp(p->mbuf, p->args, buf, sz)); return(0); } @@ -1037,13 +1023,11 @@ html_beginstring(struct md_mbuf *mbuf, /* ARGSUSED */ static ssize_t -html_endstring(struct md_mbuf *mbuf, - const struct md_args *args, - const char *buf, size_t sz) +html_endstring(struct ml_args *p, const char *buf, size_t sz) { if (0 == strncmp(buf, "http://", 7)) - return(html_endhttp(mbuf, args, buf, sz)); + return(html_endhttp(p->mbuf, p->args, buf, sz)); return(0); } @@ -41,29 +41,27 @@ enum ml_scope { ML_CLOSE }; +struct ml_args { + const struct md_args *args; + const struct md_rbuf *rbuf; + struct md_mbuf *mbuf; + int section; + void *data; +}; + struct ml_cbs { - int (*ml_begin)(struct md_mbuf *, - const struct md_args *, - const struct tm *, + int (*ml_begin)(struct ml_args *, const struct tm *, const char *, const char *, enum roffmsec, enum roffvol); - int (*ml_end)(struct md_mbuf *, - const struct md_args *, - const struct tm *, + int (*ml_end)(struct ml_args *, const struct tm *, const char *, const char *, enum roffmsec, enum roffvol); - ssize_t (*ml_beginstring)(struct md_mbuf *, - const struct md_args *, + ssize_t (*ml_beginstring)(struct ml_args *, const char *, size_t); - ssize_t (*ml_endstring)(struct md_mbuf *, - const struct md_args *, + ssize_t (*ml_endstring)(struct ml_args *, const char *, size_t); - ssize_t (*ml_endtag)(struct md_mbuf *, - void *, const struct md_args *, - enum md_ns, int); - ssize_t (*ml_begintag)(struct md_mbuf *, - void *, const struct md_args *, - enum md_ns, int, + ssize_t (*ml_endtag)(struct ml_args *, enum md_ns, int); + ssize_t (*ml_begintag)(struct ml_args *, enum md_ns, int, const int *, const char **); int (*ml_alloc)(void **); void (*ml_free)(void *); @@ -81,7 +79,6 @@ int ml_puts(struct md_mbuf *, const char *, size_t *); int ml_putchars(struct md_mbuf *, char, size_t, size_t *); -/* FIXME: move into mlg.h or private.h. */ struct md_mlg *mlg_alloc(const struct md_args *, const struct md_rbuf *, struct md_mbuf *, const struct ml_cbs *); @@ -37,10 +37,7 @@ enum md_tok { }; struct md_mlg { - const struct md_args *args; - const struct md_rbuf *rbuf; - - struct md_mbuf *mbuf; + struct ml_args args; struct rofftree *tree; size_t indent; size_t pos; @@ -50,7 +47,6 @@ struct md_mlg { int flags; #define ML_OVERRIDE_ONE (1 << 0) #define ML_OVERRIDE_ALL (1 << 1) - void *data; }; static int mlg_roffmsg(void *arg, @@ -143,7 +139,7 @@ mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok, MD_INLINE_OUT == p->last) && ! (ML_OVERRIDE_ONE & p->flags) && ! (ML_OVERRIDE_ALL & p->flags)) - if ( ! ml_nputs(p->mbuf, " ", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, " ", 1, &p->pos)) return(0); if (0 == p->pos && ! mlg_indent(p)) return(0); @@ -162,18 +158,17 @@ mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok, break; } - if ( ! ml_nputs(p->mbuf, "<", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, "<", 1, &p->pos)) return(0); - res = (*p->cbs.ml_begintag)(p->mbuf, p->data, - p->args, ns, tok, argc, argv); + res = (*p->cbs.ml_begintag)(&p->args, ns, tok, argc, argv); if (-1 == res) return(0); assert(res >= 0); p->pos += (size_t)res; - if ( ! ml_nputs(p->mbuf, ">", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, ">", 1, &p->pos)) return(0); switch (ns) { @@ -211,17 +206,17 @@ mlg_endtag(struct md_mlg *p, enum md_ns ns, int tok) break; } - if ( ! ml_nputs(p->mbuf, "</", 2, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, "</", 2, &p->pos)) return(0); - res = (*p->cbs.ml_endtag)(p->mbuf, p->data, p->args, ns, tok); + res = (*p->cbs.ml_endtag)(&p->args, ns, tok); if (-1 == res) return(0); assert(res >= 0); p->pos += (size_t)res; - if ( ! ml_nputs(p->mbuf, ">", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, ">", 1, &p->pos)) return(0); switch (ns) { @@ -242,7 +237,7 @@ mlg_indent(struct md_mlg *p) { assert(0 == p->pos); - return(ml_putchars(p->mbuf, ' ', INDENT_SZ * + return(ml_putchars(p->args.mbuf, ' ', INDENT_SZ * INDENT(p->indent), &p->pos)); } @@ -252,7 +247,7 @@ mlg_newline(struct md_mlg *p) { p->pos = 0; - return(ml_nputs(p->mbuf, "\n", 1, NULL)); + return(ml_nputs(p->args.mbuf, "\n", 1, NULL)); } @@ -280,20 +275,20 @@ mlg_nstring(struct md_mlg *p, const char *start, int c; ssize_t res; - assert(p->mbuf); + assert(p->args.mbuf); assert(0 != p->indent); - res = (*p->cbs.ml_beginstring)(p->mbuf, p->args, buf, sz); + res = (*p->cbs.ml_beginstring)(&p->args, buf, sz); if (-1 == res) return(0); - if (0 == (c = ml_nputstring(p->mbuf, buf, sz, &p->pos))) + if (0 == (c = ml_nputstring(p->args.mbuf, buf, sz, &p->pos))) return(mlg_err(p, start, buf, "bad string " "encoding: `%s'", buf)); else if (-1 == c) return(0); - res = (*p->cbs.ml_endstring)(p->mbuf, p->args, buf, sz); + res = (*p->cbs.ml_endstring)(&p->args, buf, sz); if (-1 == res) return(0); @@ -307,7 +302,7 @@ mlg_data(struct md_mlg *p, int space, { size_t sz; - assert(p->mbuf); + assert(p->args.mbuf); assert(0 != p->indent); if (ML_OVERRIDE_ONE & p->flags || @@ -335,7 +330,7 @@ mlg_data(struct md_mlg *p, int space, if ( ! mlg_indent(p)) return(0); } else if (space) { - if ( ! ml_nputs(p->mbuf, " ", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, " ", 1, &p->pos)) return(0); } @@ -357,7 +352,7 @@ mlg_exit(struct md_mlg *p, int flush) int c; c = roff_free(p->tree, flush); - (*p->cbs.ml_free)(p->data); + (*p->cbs.ml_free)(p->args.data); free(p); @@ -391,15 +386,15 @@ mlg_alloc(const struct md_args *args, if (NULL == (p = calloc(1, sizeof(struct md_mlg)))) err(1, "calloc"); - p->args = args; - p->mbuf = mbuf; - p->rbuf = rbuf; + p->args.args = args; + p->args.mbuf = mbuf; + p->args.rbuf = rbuf; (void)memcpy(&p->cbs, cbs, sizeof(struct ml_cbs)); if (NULL == (p->tree = roff_alloc(&cb, p))) free(p); - else if ( ! (*p->cbs.ml_alloc)(&p->data)) + else if ( ! (*p->cbs.ml_alloc)(&p->args.data)) free(p); else return(p); @@ -419,8 +414,7 @@ mlg_roffhead(void *arg, const struct tm *tm, const char *os, mlg_mode(p, MD_BLK_IN); - if ( ! (*p->cbs.ml_begin)(p->mbuf, p->args, - tm, os, title, sec, vol)) + if ( ! (*p->cbs.ml_begin)(&p->args, tm, os, title, sec, vol)) return(0); p->indent++; @@ -441,8 +435,7 @@ mlg_rofftail(void *arg, const struct tm *tm, const char *os, if ( ! mlg_newline(p)) return(0); - if ( ! (*p->cbs.ml_end)(p->mbuf, p->args, - tm, os, title, sec, vol)) + if ( ! (*p->cbs.ml_end)(&p->args, tm, os, title, sec, vol)) return(0); mlg_mode(p, MD_BLK_OUT); @@ -466,7 +459,7 @@ mlg_literal_special(struct md_mlg *p, int tok, const char *start, return(0); while (*more) { - if ( ! ml_nputs(p->mbuf, " ", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, " ", 1, &p->pos)) return(0); if ( ! mlg_string(p, start, *more++)) return(0); @@ -485,15 +478,15 @@ mlg_ref_special(struct md_mlg *p, int tok, return(0); assert(*more); - if ( ! ml_puts(p->mbuf, *more++, &p->pos)) + if ( ! ml_puts(p->args.mbuf, *more++, &p->pos)) return(0); if (*more) { - if ( ! ml_nputs(p->mbuf, "(", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, "(", 1, &p->pos)) return(0); if ( ! mlg_string(p, start, *more++)) return(0); - if ( ! ml_nputs(p->mbuf, ")", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, ")", 1, &p->pos)) return(0); } @@ -531,6 +524,13 @@ mlg_atom_special(struct md_mlg *p, int tok, const char *start, const char **more) { + if (ROFFSec_SYNOP == p->args.section) { + if ( ! mlg_begintag(p, MD_NS_INLINE, ROFF_Pp, NULL, more)) + return(0); + if ( ! mlg_endtag(p, MD_NS_INLINE, ROFF_Pp)) + return(0); + } + if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, more)) return(0); @@ -559,7 +559,7 @@ mlg_function_special(struct md_mlg *p, if (NULL == *more) return(1); - if ( ! ml_nputs(p->mbuf, "(", 1, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, "(", 1, &p->pos)) return(0); p->flags |= ML_OVERRIDE_ONE; @@ -572,7 +572,7 @@ mlg_function_special(struct md_mlg *p, return(0); while (*more) { - if ( ! ml_nputs(p->mbuf, ", ", 2, &p->pos)) + if ( ! ml_nputs(p->args.mbuf, ", ", 2, &p->pos)) return(0); if ( ! mlg_begintag(p, MD_NS_INLINE, ROFF_Fa, NULL, more)) return(0); @@ -582,7 +582,7 @@ mlg_function_special(struct md_mlg *p, return(0); } - return(ml_nputs(p->mbuf, ")", 1, &p->pos)); + return(ml_nputs(p->args.mbuf, ")", 1, &p->pos)); } @@ -644,6 +644,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, return(mlg_ref_special(p, tok, start, more)); case (ROFF_Sh): + p->args.section = roff_sec(more); return(mlg_anchor_special(p, tok, more)); case (ROFF_Sx): @@ -816,14 +817,16 @@ static int mlg_msg(struct md_mlg *p, enum roffmsg lvl, const char *buf, const char *pos, const char *msg) { - char *level; - char b[256]; + char *level, b[256]; + size_t sz; int i; + sz = sizeof(b); + switch (lvl) { case (ROFF_WARN): level = "warning"; - if ( ! (MD_WARN_ALL & p->args->warnings)) + if ( ! (MD_WARN_ALL & p->args.args->warnings)) return(1); break; case (ROFF_ERROR): @@ -836,27 +839,28 @@ mlg_msg(struct md_mlg *p, enum roffmsg lvl, 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, + if (0 < p->args.args->verbosity) { + (void)snprintf(b, sz, "%s:%zu: %s: %s\n", + p->args.rbuf->name, + p->args.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)); + (void)strlcat(b, "Error at: ", sz); + (void)strlcat(b, p->args.rbuf->linebuf, sz); + (void)strlcat(b, "\n ", sz); + for (i = 0; i < pos - buf; i++) - (void)strlcat(b, " ", sizeof(b)); - (void)strlcat(b, "^", sizeof(b)); + (void)strlcat(b, " ", sz); + (void)strlcat(b, "^", sz); } else - (void)snprintf(b, sizeof(b), - "%s:%zu: %s: %s (col %zu)", - p->rbuf->name, p->rbuf->line, + (void)snprintf(b, sz, "%s:%zu: %s: %s (%zu)", + p->args.rbuf->name, + p->args.rbuf->line, level, msg, pos - buf); } else - (void)snprintf(b, sizeof(b), "%s: %s: %s", - p->rbuf->name, level, msg); + (void)snprintf(b, sz, "%s: %s: %s", + p->args.rbuf->name, level, msg); (void)fprintf(stderr, "%s\n", b); return(lvl == ROFF_WARN ? 1 : 0); @@ -281,7 +281,7 @@ noop_roffmsg(void *arg, enum roffmsg lvl, } else (void)snprintf(b, sizeof(b), - "%s:%zu: %s: %s (col %zu)", + "%s:%zu: %s: %s (%zu)", p->rbuf->name, p->rbuf->line, level, msg, pos - buf); } else @@ -125,7 +125,7 @@ static const struct rofftok tokens[ROFF_MAX] = { { roff_noop, NULL, NULL, roffparent_El, NULL, ROFF_Bl, ROFF_LAYOUT, 0 }, /* El */ { roff_layout, NULL, NULL, roffparent_It, NULL, ROFF_It, ROFF_LAYOUT, ROFF_PARSED | ROFF_SHALLOW }, /* It */ { roff_text, NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ad */ /* FIXME */ - { roff_text, NULL, roffarg_An, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* An */ /* FIXME: no-args? */ + { roff_text, NULL, roffarg_An, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* An */ /* FIXME: args/no-args, yech. */ /*Ok*/ { roff_text, NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ar */ /*Ok*/ { roff_text, roffmsec_Cd, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Cd */ /*Ok*/ { roff_text, NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Cm */ @@ -26,38 +26,27 @@ static int xml_alloc(void **); static void xml_free(void *); -static ssize_t xml_endtag(struct md_mbuf *, void *, - const struct md_args *, - enum md_ns, int); -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 *, +static ssize_t xml_beginstring(struct ml_args *, const char *, size_t); -static ssize_t xml_endstring(struct md_mbuf *, - const struct md_args *, +static ssize_t xml_endstring(struct ml_args *, const char *, size_t); -static int xml_begin(struct md_mbuf *, - const struct md_args *, - const struct tm *, +static int xml_begin(struct ml_args *, const struct tm *, const char *, const char *, enum roffmsec, enum roffvol); -static int xml_end(struct md_mbuf *, - const struct md_args *, - const struct tm *, +static int xml_end(struct ml_args *, const struct tm *, const char *, const char *, enum roffmsec, enum roffvol); -static ssize_t xml_printtagname(struct md_mbuf *, +static ssize_t xml_printtagname(struct ml_args *, enum md_ns, int); -static ssize_t xml_printtagargs(struct md_mbuf *, +static ssize_t xml_printtagargs(struct ml_args *, + const int *, const char **); +static ssize_t xml_endtag(struct ml_args *, enum md_ns, int); +static ssize_t xml_begintag(struct ml_args *, enum md_ns, int, const int *, const char **); static ssize_t -xml_printtagargs(struct md_mbuf *mbuf, const int *argc, - const char **argv) +xml_printtagargs(struct ml_args *p, const int *argc, const char **argv) { int i, c; size_t res; @@ -68,21 +57,21 @@ xml_printtagargs(struct md_mbuf *mbuf, const int *argc, /* LINTED */ for (res = 0, i = 0; ROFF_ARGMAX != (c = argc[i]); i++) { - if ( ! ml_nputs(mbuf, " ", 1, &res)) + if ( ! ml_nputs(p->mbuf, " ", 1, &res)) return(-1); /* FIXME: should puke on some, no? */ - if ( ! ml_puts(mbuf, tokargnames[c], &res)) + if ( ! ml_puts(p->mbuf, tokargnames[c], &res)) return(-1); - if ( ! ml_nputs(mbuf, "=\"", 2, &res)) + if ( ! ml_nputs(p->mbuf, "=\"", 2, &res)) return(-1); if (argv[i]) { - if ( ! ml_putstring(mbuf, argv[i], &res)) + if ( ! ml_putstring(p->mbuf, argv[i], &res)) return(-1); - } else if ( ! ml_nputs(mbuf, "true", 4, &res)) + } else if ( ! ml_nputs(p->mbuf, "true", 4, &res)) return(-1); - if ( ! ml_nputs(mbuf, "\"", 1, &res)) + if ( ! ml_nputs(p->mbuf, "\"", 1, &res)) return(-1); } @@ -91,33 +80,33 @@ xml_printtagargs(struct md_mbuf *mbuf, const int *argc, static ssize_t -xml_printtagname(struct md_mbuf *mbuf, enum md_ns ns, int tok) +xml_printtagname(struct ml_args *p, enum md_ns ns, int tok) { size_t res; res = 0; switch (ns) { case (MD_NS_BLOCK): - if ( ! ml_nputs(mbuf, "block:", 6, &res)) + if ( ! ml_nputs(p->mbuf, "block:", 6, &res)) return(-1); break; case (MD_NS_INLINE): - if ( ! ml_nputs(mbuf, "inline:", 7, &res)) + if ( ! ml_nputs(p->mbuf, "inline:", 7, &res)) return(-1); break; case (MD_NS_BODY): - if ( ! ml_nputs(mbuf, "body:", 5, &res)) + if ( ! ml_nputs(p->mbuf, "body:", 5, &res)) return(-1); break; case (MD_NS_HEAD): - if ( ! ml_nputs(mbuf, "head:", 5, &res)) + if ( ! ml_nputs(p->mbuf, "head:", 5, &res)) return(-1); break; default: break; } - if ( ! ml_puts(mbuf, toknames[tok], &res)) + if ( ! ml_puts(p->mbuf, toknames[tok], &res)) return(-1); return((ssize_t)res); } @@ -125,15 +114,14 @@ xml_printtagname(struct md_mbuf *mbuf, enum md_ns ns, int tok) /* ARGSUSED */ static int -xml_begin(struct md_mbuf *mbuf, const struct md_args *args, - const struct tm *tm, const char *os, +xml_begin(struct ml_args *p, const struct tm *tm, const char *os, const char *title, enum roffmsec sec, enum roffvol vol) { - if ( ! ml_puts(mbuf, "<?xml version=\"1.0\" " + if ( ! ml_puts(p->mbuf, "<?xml version=\"1.0\" " "encoding=\"UTF-8\"?>\n", NULL)) return(0); - return(ml_puts(mbuf, "<mdoc xmlns:block=\"block\" " + return(ml_puts(p->mbuf, "<mdoc xmlns:block=\"block\" " "xmlns:body=\"body\" " "xmlns:head=\"head\" " "xmlns:inline=\"inline\">", NULL)); @@ -142,20 +130,17 @@ xml_begin(struct md_mbuf *mbuf, const struct md_args *args, /* ARGSUSED */ static int -xml_end(struct md_mbuf *mbuf, const struct md_args *args, - const struct tm *tm, const char *os, +xml_end(struct ml_args *p, const struct tm *tm, const char *os, const char *title, enum roffmsec sec, enum roffvol vol) { - return(ml_puts(mbuf, "</mdoc>", NULL)); + return(ml_puts(p->mbuf, "</mdoc>", NULL)); } /* ARGSUSED */ static ssize_t -xml_beginstring(struct md_mbuf *mbuf, - const struct md_args *args, - const char *buf, size_t sz) +xml_beginstring(struct ml_args *p, const char *buf, size_t sz) { return(0); @@ -164,9 +149,7 @@ xml_beginstring(struct md_mbuf *mbuf, /* ARGSUSED */ static ssize_t -xml_endstring(struct md_mbuf *mbuf, - const struct md_args *args, - const char *buf, size_t sz) +xml_endstring(struct ml_args *p, const char *buf, size_t sz) { return(0); @@ -175,15 +158,14 @@ xml_endstring(struct md_mbuf *mbuf, /* ARGSUSED */ static ssize_t -xml_begintag(struct md_mbuf *mbuf, void *data, - const struct md_args *args, enum md_ns ns, +xml_begintag(struct ml_args *p, enum md_ns ns, int tok, const int *argc, const char **argv) { ssize_t res, sz; - if (-1 == (res = xml_printtagname(mbuf, ns, tok))) + if (-1 == (res = xml_printtagname(p, ns, tok))) return(-1); - if (-1 == (sz = xml_printtagargs(mbuf, argc, argv))) + if (-1 == (sz = xml_printtagargs(p, argc, argv))) return(-1); return(res + sz); } @@ -191,11 +173,10 @@ xml_begintag(struct md_mbuf *mbuf, void *data, /* ARGSUSED */ static ssize_t -xml_endtag(struct md_mbuf *mbuf, void *data, - const struct md_args *args, enum md_ns ns, int tok) +xml_endtag(struct ml_args *p, enum md_ns ns, int tok) { - return(xml_printtagname(mbuf, ns, tok)); + return(xml_printtagname(p, ns, tok)); } |