summaryrefslogtreecommitdiffstats
path: root/html.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-12-05 17:43:14 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-12-05 17:43:14 +0000
commit57ed1544ce7edde6d0812e0c870f03e6b1e7204f (patch)
treef0901e95a0cbbd7383ebde2739459cdba0e7c8da /html.c
parenta4880c4fea2cc33d9168cb96bc44c1b3670ef402 (diff)
downloadmandoc-57ed1544ce7edde6d0812e0c870f03e6b1e7204f.tar.gz
*** empty log message ***
Diffstat (limited to 'html.c')
-rw-r--r--html.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/html.c b/html.c
index de0b5e8e..985eadc2 100644
--- a/html.c
+++ b/html.c
@@ -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_args *args,
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 *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;
+
+ if (NULL == (q = calloc(1, sizeof(struct htmlq)))) {
+ warn("calloc");
+ return(NULL);
+ }
- return(mlg_alloc(args, rbuf, mbuf, html_begintag,
+ return(mlg_alloc(args, q, rbuf, mbuf, html_begintag,
html_endtag, html_begin, html_end));
}