=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -p -r1.7 -r1.8 --- mandoc/html.c 2008/12/05 11:28:16 1.7 +++ mandoc/html.c 2008/12/05 17:43:14 1.8 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.7 2008/12/05 11:28:16 kristaps Exp $ */ +/* $Id: html.c,v 1.8 2008/12/05 17:43:14 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -32,8 +32,12 @@ #include "ml.h" +/* TODO: allow head/tail-less invocations (just "div" start). */ +/* FIXME: free htmlq. */ + struct htmlnode { - int type; + int tok; + enum md_ns ns; int *argc[ROFF_MAXLINEARG]; char *argv[ROFF_MAXLINEARG]; struct htmlnode *parent; @@ -45,12 +49,15 @@ struct htmlq { }; +static void htmlnode_free(struct htmlnode *); +static void htmlnode_free(struct htmlnode *); + static int html_loadcss(struct md_mbuf *, const char *); -static ssize_t html_endtag(struct md_mbuf *, +static ssize_t html_endtag(struct md_mbuf *, void *, const struct md_args *, enum md_ns, int); -static ssize_t html_begintag(struct md_mbuf *, +static ssize_t html_begintag(struct md_mbuf *, void *, const struct md_args *, enum md_ns, int, const int *, const char **); @@ -352,15 +359,31 @@ html_inlinetagname(struct md_mbuf *mbuf, static ssize_t -html_begintag(struct md_mbuf *mbuf, const struct md_args *args, - enum md_ns ns, int tok, - const int *argc, const char **argv) +html_begintag(struct md_mbuf *mbuf, void *data, + const struct md_args *args, enum md_ns ns, + int tok, const int *argc, const char **argv) { size_t res; + struct htmlq *q; + struct htmlnode *node; assert(ns != MD_NS_DEFAULT); res = 0; + assert(data); + q = (struct htmlq *)data; + + if (NULL == (node = calloc(1, sizeof(struct htmlnode)))) { + warn("calloc"); + return(-1); + } + + node->parent = q->last; + node->tok = tok; + node->ns = ns; + + q->last = node; + switch (ns) { case (MD_NS_BLOCK): if ( ! html_blocktagname(mbuf, args, tok, &res)) @@ -397,14 +420,19 @@ html_begintag(struct md_mbuf *mbuf, const struct md_ar static ssize_t -html_endtag(struct md_mbuf *mbuf, const struct md_args *args, - enum md_ns ns, int tok) +html_endtag(struct md_mbuf *mbuf, void *data, + const struct md_args *args, enum md_ns ns, int tok) { size_t res; + struct htmlq *q; + struct htmlnode *node; assert(ns != MD_NS_DEFAULT); res = 0; + assert(data); + q = (struct htmlq *)data; + switch (ns) { case (MD_NS_BLOCK): if ( ! html_blocktagname(mbuf, args, tok, &res)) @@ -424,6 +452,11 @@ html_endtag(struct md_mbuf *mbuf, const struct md_args break; } + node = q->last; + q->last = node->parent; + + htmlnode_free(node); + return((ssize_t)res); } @@ -448,8 +481,14 @@ void * md_init_html(const struct md_args *args, struct md_mbuf *mbuf, const struct md_rbuf *rbuf) { + struct htmlq *q; - return(mlg_alloc(args, rbuf, mbuf, html_begintag, + if (NULL == (q = calloc(1, sizeof(struct htmlq)))) { + warn("calloc"); + return(NULL); + } + + return(mlg_alloc(args, q, rbuf, mbuf, html_begintag, html_endtag, html_begin, html_end)); }