aboutsummaryrefslogtreecommitdiffstatshomepage
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
commit0b88f4946af1f4e8139f42758323aee89474bdc9 (patch)
treeb8deeb22c3d091df01ff4ae655abcb26deec4db1 /html.c
parentf50249ac0c8b039ba90b0be44970e3700a8d4ad8 (diff)
downloadmandoc-0b88f4946af1f4e8139f42758323aee89474bdc9.tar.gz
mandoc-0b88f4946af1f4e8139f42758323aee89474bdc9.tar.zst
mandoc-0b88f4946af1f4e8139f42758323aee89474bdc9.zip
*** empty log message ***
Diffstat (limited to 'html.c')
-rw-r--r--html.c59
1 files changed, 49 insertions, 10 deletions
diff --git a/html.c b/html.c
index 8403dea9..049817a3 100644
--- a/html.c
+++ b/html.c
@@ -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 <kristaps@kth.se>
*
@@ -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));
}