summaryrefslogtreecommitdiffstats
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
parenta4880c4fea2cc33d9168cb96bc44c1b3670ef402 (diff)
downloadmandoc-57ed1544ce7edde6d0812e0c870f03e6b1e7204f.tar.gz
*** empty log message ***
-rw-r--r--html.c57
-rw-r--r--ml.h6
-rw-r--r--mlg.c8
-rw-r--r--xml.c16
4 files changed, 64 insertions, 23 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));
}
diff --git a/ml.h b/ml.h
index 8168440a..91a6b3ff 100644
--- a/ml.h
+++ b/ml.h
@@ -34,9 +34,9 @@ typedef int (*ml_begin)(struct md_mbuf *, const struct md_args *,
const char *, const char *);
typedef int (*ml_end)(struct md_mbuf *,
const struct md_args *);
-typedef ssize_t (*ml_endtag)(struct md_mbuf *,
+typedef ssize_t (*ml_endtag)(struct md_mbuf *, void *,
const struct md_args *, enum md_ns, int);
-typedef ssize_t (*ml_begintag)(struct md_mbuf *,
+typedef ssize_t (*ml_begintag)(struct md_mbuf *, void *,
const struct md_args *, enum md_ns, int,
const int *, const char **);
@@ -52,7 +52,7 @@ int ml_puts(struct md_mbuf *, const char *, size_t *);
int ml_putchars(struct md_mbuf *,
char, size_t, size_t *);
-struct md_mlg *mlg_alloc(const struct md_args *,
+struct md_mlg *mlg_alloc(const struct md_args *, void *,
const struct md_rbuf *, struct md_mbuf *,
ml_begintag, ml_endtag, ml_begin, ml_end);
int mlg_exit(struct md_mlg *, int);
diff --git a/mlg.c b/mlg.c
index 7fb7d74d..7ea1ecf3 100644
--- a/mlg.c
+++ b/mlg.c
@@ -58,6 +58,7 @@ struct md_mlg {
int flags;
#define ML_OVERRIDE_ONE (1 << 0)
#define ML_OVERRIDE_ALL (1 << 1)
+ void *data;
};
@@ -144,7 +145,7 @@ mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,
if ( ! ml_nputs(p->mbuf, "<", 1, &p->pos))
return(0);
- res = (*p->begintag)(p->mbuf, p->args, ns, tok,
+ res = (*p->begintag)(p->mbuf, p->data, p->args, ns, tok,
argc, (const char **)argv);
if (-1 == res)
return(0);
@@ -193,7 +194,7 @@ mlg_endtag(struct md_mlg *p, enum md_ns ns, int tok)
if ( ! ml_nputs(p->mbuf, "</", 2, &p->pos))
return(0);
- res = (*p->endtag)(p->mbuf, p->args, ns, tok);
+ res = (*p->endtag)(p->mbuf, p->data, p->args, ns, tok);
if (-1 == res)
return(0);
@@ -333,7 +334,7 @@ mlg_exit(struct md_mlg *p, int flush)
struct md_mlg *
-mlg_alloc(const struct md_args *args,
+mlg_alloc(const struct md_args *args, void *data,
const struct md_rbuf *rbuf,
struct md_mbuf *mbuf,
ml_begintag begintag, ml_endtag endtag,
@@ -366,6 +367,7 @@ mlg_alloc(const struct md_args *args,
p->endtag = endtag;
p->begin = begin;
p->end = end;
+ p->data = data;
if (NULL == (p->tree = roff_alloc(&cb, p))) {
free(p);
diff --git a/xml.c b/xml.c
index 124c80ae..80d8c428 100644
--- a/xml.c
+++ b/xml.c
@@ -24,10 +24,10 @@
#include "ml.h"
-static ssize_t xml_endtag(struct md_mbuf *,
+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 *,
+static ssize_t xml_begintag(struct md_mbuf *, void *,
const struct md_args *,
enum md_ns, int,
const int *, const char **);
@@ -77,9 +77,9 @@ xml_end(struct md_mbuf *mbuf, const struct md_args *args)
/* ARGSUSED */
static ssize_t
-xml_begintag(struct md_mbuf *mbuf, const struct md_args *args,
- enum md_ns ns, int tok,
- const int *argc, const char **argv)
+xml_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;
@@ -117,8 +117,8 @@ xml_begintag(struct md_mbuf *mbuf, const struct md_args *args,
/* ARGSUSED */
static ssize_t
-xml_endtag(struct md_mbuf *mbuf, const struct md_args *args,
- enum md_ns ns, int tok)
+xml_endtag(struct md_mbuf *mbuf, void *data,
+ const struct md_args *args, enum md_ns ns, int tok)
{
size_t res;
@@ -173,7 +173,7 @@ md_init_xml(const struct md_args *args,
struct md_mbuf *mbuf, const struct md_rbuf *rbuf)
{
- return(mlg_alloc(args, rbuf, mbuf, xml_begintag,
+ return(mlg_alloc(args, NULL, rbuf, mbuf, xml_begintag,
xml_endtag, xml_begin, xml_end));
}