summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-12-05 11:28:16 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-12-05 11:28:16 +0000
commita4880c4fea2cc33d9168cb96bc44c1b3670ef402 (patch)
treef68ea8b8c6de9b8ee2cce4b9d68abfe3550f2000
parentc7c7577b0630cf19afb01b6bcfbe376e6b9d7cbf (diff)
downloadmandoc-a4880c4fea2cc33d9168cb96bc44c1b3670ef402.tar.gz
*** empty log message ***
-rw-r--r--html.c299
-rw-r--r--mdocml.15
-rw-r--r--ml.c8
-rw-r--r--ml.h3
-rw-r--r--mlg.c81
-rw-r--r--roff.c1
6 files changed, 196 insertions, 201 deletions
diff --git a/html.c b/html.c
index 9b5d1630..de0b5e8e 100644
--- a/html.c
+++ b/html.c
@@ -32,6 +32,19 @@
#include "ml.h"
+struct htmlnode {
+ int type;
+ int *argc[ROFF_MAXLINEARG];
+ char *argv[ROFF_MAXLINEARG];
+ struct htmlnode *parent;
+};
+
+
+struct htmlq {
+ struct htmlnode *last;
+};
+
+
static int html_loadcss(struct md_mbuf *, const char *);
static ssize_t html_endtag(struct md_mbuf *,
@@ -46,28 +59,31 @@ static int html_begin(struct md_mbuf *,
const struct tm *,
const char *, const char *,
const char *, const char *);
+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 ssize_t html_blocktagname(struct md_mbuf *,
- const struct md_args *, int);
-static ssize_t html_blocktagargs(struct md_mbuf *,
+static int html_blocktagname(struct md_mbuf *,
+ const struct md_args *, int, size_t *);
+static int html_blocktagargs(struct md_mbuf *,
const struct md_args *, int,
- const int *, const char **);
-static ssize_t html_blockheadtagname(struct md_mbuf *,
- const struct md_args *, int);
-static ssize_t html_blockheadtagargs(struct md_mbuf *,
+ const int *, const char **, size_t *);
+static int html_blockheadtagname(struct md_mbuf *,
+ const struct md_args *, int, size_t *);
+static int html_blockheadtagargs(struct md_mbuf *,
const struct md_args *, int,
- const int *, const char **);
-static ssize_t html_blockbodytagname(struct md_mbuf *,
- const struct md_args *, int);
-static ssize_t html_blockbodytagargs(struct md_mbuf *,
+ const int *, const char **, size_t *);
+static int html_blockbodytagname(struct md_mbuf *,
+ const struct md_args *, int, size_t *);
+static int html_blockbodytagargs(struct md_mbuf *,
const struct md_args *, int,
- const int *, const char **);
-static ssize_t html_inlinetagname(struct md_mbuf *,
- const struct md_args *, int);
-static ssize_t html_inlinetagargs(struct md_mbuf *,
+ const int *, const char **, size_t *);
+static int html_inlinetagname(struct md_mbuf *,
+ const struct md_args *, int, size_t *);
+static int html_inlinetagargs(struct md_mbuf *,
const struct md_args *, int,
- const int *, const char **);
+ const int *, const char **, size_t *);
static int
@@ -198,174 +214,140 @@ html_end(struct md_mbuf *mbuf, const struct md_args *args)
/* ARGSUSED */
-static ssize_t
+static int
html_blockbodytagname(struct md_mbuf *mbuf,
- const struct md_args *args, int tok)
+ const struct md_args *args, int tok, size_t *res)
{
- size_t res;
-
- res = 0;
- if ( ! ml_puts(mbuf, "div", &res))
- return(-1);
- return((ssize_t)res);
+ return(ml_puts(mbuf, "div", res));
}
/* ARGSUSED */
-static ssize_t
+static int
html_blockheadtagname(struct md_mbuf *mbuf,
- const struct md_args *args, int tok)
+ const struct md_args *args, int tok, size_t *res)
{
- size_t res;
-
- res = 0;
- if ( ! ml_puts(mbuf, "div", &res))
- return(-1);
- return((ssize_t)res);
+ return(ml_puts(mbuf, "div", res));
}
/* ARGSUSED */
-static ssize_t
+static int
html_blocktagname(struct md_mbuf *mbuf,
- const struct md_args *args, int tok)
+ const struct md_args *args, int tok, size_t *res)
{
- size_t res;
- res = 0;
- if ( ! ml_puts(mbuf, "div", &res))
- return(-1);
-
- return((ssize_t)res);
+ return(ml_puts(mbuf, "div", res));
}
-/* ARGSUSED */
-static ssize_t
-html_blockheadtagargs(struct md_mbuf *mbuf, const struct md_args *args,
- int tok, const int *argc, const char **argv)
+static int
+html_printargs(struct md_mbuf *mbuf, int tok, const char *ns,
+ const int *argc, const char **argv, size_t *res)
{
- size_t res;
-
- res = 0;
+ int i, c;
- if ( ! ml_puts(mbuf, " class=\"head-", &res))
+ if ( ! ml_puts(mbuf, " class=\"", res))
return(0);
- if ( ! ml_puts(mbuf, toknames[tok], &res))
+ if ( ! ml_puts(mbuf, ns, res))
return(0);
- if ( ! ml_puts(mbuf, "\"", &res))
+ if ( ! ml_puts(mbuf, "-", res))
+ return(0);
+ if ( ! ml_puts(mbuf, toknames[tok], res))
+ return(0);
+ if ( ! ml_puts(mbuf, "\"", res))
return(0);
- switch (tok) {
- default:
- break;
+ if (NULL == argv || NULL == argc)
+ return(1);
+ assert(argv && argc);
+
+ /* FIXME: ignores values. */
+
+ for (i = 0; ROFF_ARGMAX != (c = argc[i]); i++) {
+ if (argv[i])
+ continue;
+ if ( ! ml_puts(mbuf, " class=\"", res))
+ return(0);
+ if ( ! ml_puts(mbuf, ns, res))
+ return(0);
+ if ( ! ml_puts(mbuf, "-", res))
+ return(0);
+ if ( ! ml_puts(mbuf, toknames[tok], res))
+ return(0);
+ if ( ! ml_puts(mbuf, "-", res))
+ return(0);
+ if ( ! ml_puts(mbuf, tokargnames[c], res))
+ return(0);
+ if ( ! ml_puts(mbuf, "\"", res))
+ return(0);
}
- return(0);
+ return(1);
}
/* ARGSUSED */
-static ssize_t
-html_blockbodytagargs(struct md_mbuf *mbuf, const struct md_args *args,
- int tok, const int *argc, const char **argv)
+static int
+html_blockheadtagargs(struct md_mbuf *mbuf,
+ const struct md_args *args, int tok,
+ const int *argc, const char **argv, size_t *res)
{
- size_t res;
-
- res = 0;
- if ( ! ml_puts(mbuf, " class=\"body-", &res))
- return(0);
- if ( ! ml_puts(mbuf, toknames[tok], &res))
- return(0);
- if ( ! ml_puts(mbuf, "\"", &res))
- return(0);
-
- switch (tok) {
- default:
- break;
- }
-
- return(res);
+ return(html_printargs(mbuf, tok, "head", argc, argv, res));
}
/* ARGSUSED */
-static ssize_t
-html_blocktagargs(struct md_mbuf *mbuf, const struct md_args *args,
- int tok, const int *argc, const char **argv)
+static int
+html_blockbodytagargs(struct md_mbuf *mbuf,
+ const struct md_args *args, int tok,
+ const int *argc, const char **argv, size_t *res)
{
- size_t res;
-
- res = 0;
- if ( ! ml_puts(mbuf, " class=\"block-", &res))
- return(0);
- if ( ! ml_puts(mbuf, toknames[tok], &res))
- return(0);
- if ( ! ml_puts(mbuf, "\"", &res))
- return(0);
-
- switch (tok) {
- default:
- break;
- }
-
- return(0);
+ return(html_printargs(mbuf, tok, "body", argc, argv, res));
}
/* ARGSUSED */
-static ssize_t
-html_inlinetagargs(struct md_mbuf *mbuf, const struct md_args *args,
- int tok, const int *argc, const char **argv)
+static int
+html_blocktagargs(struct md_mbuf *mbuf,
+ const struct md_args *args, int tok,
+ const int *argc, const char **argv, size_t *res)
{
- size_t res;
- res = 0;
-
- if ( ! ml_puts(mbuf, " class=\"inline-", &res))
- return(0);
- if ( ! ml_puts(mbuf, toknames[tok], &res))
- return(0);
- if ( ! ml_puts(mbuf, "\"", &res))
- return(0);
+ return(html_printargs(mbuf, tok, "block", argc, argv, res));
+}
- switch (tok) {
- default:
- break;
- }
+/* ARGSUSED */
+static int
+html_inlinetagargs(struct md_mbuf *mbuf,
+ const struct md_args *args, int tok,
+ const int *argc, const char **argv, size_t *res)
+{
- return(0);
+ return(html_printargs(mbuf, tok, "inline", argc, argv, res));
}
/* ARGSUSED */
-static ssize_t
+static int
html_inlinetagname(struct md_mbuf *mbuf,
- const struct md_args *args, int tok)
+ const struct md_args *args, int tok, size_t *res)
{
- size_t res;
-
- res = 0;
switch (tok) {
case (ROFF_Pp):
- if ( ! ml_puts(mbuf, "div", &res))
- return(-1);
- break;
+ return(ml_puts(mbuf, "div", res));
default:
- if ( ! ml_puts(mbuf, "span", &res))
- return(-1);
- break;
+ return(ml_puts(mbuf, "span", res));
}
-
- return((ssize_t)res);
+ return(1);
}
@@ -374,43 +356,43 @@ html_begintag(struct md_mbuf *mbuf, const struct md_args *args,
enum md_ns ns, int tok,
const int *argc, const char **argv)
{
+ size_t res;
assert(ns != MD_NS_DEFAULT);
+ res = 0;
+
switch (ns) {
case (MD_NS_BLOCK):
- if ( ! html_blocktagname(mbuf, args, tok))
- return(0);
- if (NULL == argc || NULL == argv)
- return(1);
- assert(argc && argv);
- return(html_blocktagargs(mbuf, args,
- tok, argc, argv));
+ if ( ! html_blocktagname(mbuf, args, tok, &res))
+ return(-1);
+ if ( ! html_blocktagargs(mbuf, args, tok,
+ argc, argv, &res))
+ return(-1);
+ break;
case (MD_NS_BODY):
- if ( ! html_blockbodytagname(mbuf, args, tok))
- return(0);
- if (NULL == argc || NULL == argv)
- return(1);
- assert(argc && argv);
- return(html_blockbodytagargs(mbuf, args,
- tok, argc, argv));
+ if ( ! html_blockbodytagname(mbuf, args, tok, &res))
+ return(-1);
+ if ( ! html_blockbodytagargs(mbuf, args, tok,
+ argc, argv, &res))
+ return(-1);
+ break;
case (MD_NS_HEAD):
- if ( ! html_blockheadtagname(mbuf, args, tok))
- return(0);
- if (NULL == argc || NULL == argv)
- return(1);
- assert(argc && argv);
- return(html_blockheadtagargs(mbuf, args,
- tok, argc, argv));
+ if ( ! html_blockheadtagname(mbuf, args, tok, &res))
+ return(-1);
+ if ( ! html_blockheadtagargs(mbuf, args, tok,
+ argc, argv, &res))
+ return(-1);
+ break;
default:
+ if ( ! html_inlinetagname(mbuf, args, tok, &res))
+ return(-1);
+ if ( ! html_inlinetagargs(mbuf, args, tok,
+ argc, argv, &res))
+ return(-1);
break;
}
- if ( ! html_inlinetagname(mbuf, args, tok))
- return(0);
- if (NULL == argc || NULL == argv)
- return(1);
- assert(argc && argv);
- return(html_inlinetagargs(mbuf, args, tok, argc, argv));
+ return((ssize_t)res);
}
@@ -418,20 +400,31 @@ static ssize_t
html_endtag(struct md_mbuf *mbuf, const struct md_args *args,
enum md_ns ns, int tok)
{
+ size_t res;
assert(ns != MD_NS_DEFAULT);
+ res = 0;
+
switch (ns) {
case (MD_NS_BLOCK):
- return(html_blocktagname(mbuf, args, tok));
+ if ( ! html_blocktagname(mbuf, args, tok, &res))
+ return(-1);
+ break;
case (MD_NS_BODY):
- return(html_blockbodytagname(mbuf, args, tok));
+ if ( ! html_blockbodytagname(mbuf, args, tok, &res))
+ return(-1);
+ break;
case (MD_NS_HEAD):
- return(html_blockheadtagname(mbuf, args, tok));
+ if ( ! html_blockheadtagname(mbuf, args, tok, &res))
+ return(-1);
+ break;
default:
+ if ( ! html_inlinetagname(mbuf, args, tok, &res))
+ return(-1);
break;
}
- return(html_inlinetagname(mbuf, args, tok));
+ return((ssize_t)res);
}
diff --git a/mdocml.1 b/mdocml.1
index 4e492f1a..920dfe9b 100644
--- a/mdocml.1
+++ b/mdocml.1
@@ -85,8 +85,7 @@ The CSS file location, which defaults to
.It Fl e
Whether to embed the CSS file into the HTML prologue.
.El
-.\" This next request is for sections 1, 6, 7 & 8 only.
-.\" .Sh ENVIRONMENT
+.\"
.Sh EXAMPLES
To produce an HTML4-strict document
.Pa mdocml.html
@@ -94,7 +93,7 @@ for
.Pa mdocml.1
with the default, embedded style-sheet:
.Pp
-.D1 % mdocml -fhtml -e mdocml.1 -o mdocml.html
+.D1 % mdocml -fhtml -e -o mdocml.html mdocml.1
.Pp
To create an XML document on standard output from
.Pa mdocml.1
diff --git a/ml.c b/ml.c
index ff047d79..5822edd3 100644
--- a/ml.c
+++ b/ml.c
@@ -31,6 +31,14 @@ extern size_t strlcpy(char *, const char *, size_t);
int
+ml_putstring(struct md_mbuf *p, const char *buf, size_t *pos)
+{
+
+ return(ml_nputstring(p, buf, strlen(buf), pos));
+}
+
+
+int
ml_nputstring(struct md_mbuf *p,
const char *buf, size_t sz, size_t *pos)
{
diff --git a/ml.h b/ml.h
index b2306cce..8168440a 100644
--- a/ml.h
+++ b/ml.h
@@ -29,7 +29,6 @@ enum md_ns {
MD_NS_DEFAULT,
};
-
typedef int (*ml_begin)(struct md_mbuf *, const struct md_args *,
const struct tm *, const char *, const char *,
const char *, const char *);
@@ -43,6 +42,8 @@ typedef ssize_t (*ml_begintag)(struct md_mbuf *,
__BEGIN_DECLS
+int ml_putstring(struct md_mbuf *,
+ const char *, size_t *);
int ml_nputstring(struct md_mbuf *,
const char *, size_t, size_t *);
int ml_nputs(struct md_mbuf *,
diff --git a/mlg.c b/mlg.c
index 71c3f825..7fb7d74d 100644
--- a/mlg.c
+++ b/mlg.c
@@ -82,7 +82,6 @@ static int mlg_roffblkbodyin(void *, int,
int *, char **);
static int mlg_roffblkbodyout(void *, int);
-static int mlg_endblk(struct md_mlg *, enum md_ns, int);
static int mlg_begintag(struct md_mlg *, enum md_ns,
int, int *, char **);
static int mlg_endtag(struct md_mlg *, enum md_ns, int);
@@ -105,27 +104,6 @@ extern size_t strlcpy(char *, const char *, size_t);
static int
-mlg_endblk(struct md_mlg *p, enum md_ns ns, int tok)
-{
-
- p->indent--;
-
- if (0 != p->pos) {
- if ( ! mlg_newline(p))
- return(0);
- if ( ! mlg_indent(p))
- return(0);
- } else if ( ! mlg_indent(p))
- return(0);
-
- mlg_mode(p, MD_BLK_OUT);
- if ( ! mlg_endtag(p, ns, tok))
- return(0);
- return(mlg_newline(p));
-}
-
-
-static int
mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,
int *argc, char **argv)
{
@@ -137,7 +115,7 @@ mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,
case (MD_NS_INLINE):
if ( ! (ML_OVERRIDE_ONE & p->flags) &&
! (ML_OVERRIDE_ALL & p->flags) &&
- p->pos + 11 > COLUMNS)
+ p->pos + 11 >= COLUMNS)
if ( ! mlg_newline(p))
return(0);
if (0 != p->pos && (MD_TEXT == p->last ||
@@ -195,7 +173,22 @@ mlg_endtag(struct md_mlg *p, enum md_ns ns, int tok)
{
ssize_t res;
- /* TODO: extra rules for block/inline. */
+ assert(MD_NS_DEFAULT != ns);
+
+ switch (ns) {
+ case (MD_NS_INLINE):
+ break;
+ default:
+ p->indent--;
+ if (0 != p->pos) {
+ if ( ! mlg_newline(p))
+ return(0);
+ if ( ! mlg_indent(p))
+ return(0);
+ } else if ( ! mlg_indent(p))
+ return(0);
+ break;
+ }
if ( ! ml_nputs(p->mbuf, "</", 2, &p->pos))
return(0);
@@ -207,9 +200,19 @@ mlg_endtag(struct md_mlg *p, enum md_ns ns, int tok)
assert(res >= 0);
p->pos += (size_t)res;
- /* TODO: extra rules for block/inline. */
+ if ( ! ml_nputs(p->mbuf, ">", 1, &p->pos))
+ return(0);
+
+ switch (ns) {
+ case (MD_NS_INLINE):
+ mlg_mode(p, MD_INLINE_OUT);
+ break;
+ default:
+ mlg_mode(p, MD_BLK_OUT);
+ break;
+ }
- return(ml_nputs(p->mbuf, ">", 1, &p->pos));
+ return(1);
}
@@ -218,7 +221,8 @@ mlg_indent(struct md_mlg *p)
{
size_t count;
- count = p->indent > MAXINDENT ? (size_t)MAXINDENT : p->indent;
+ count = p->indent > MAXINDENT ?
+ (size_t)MAXINDENT : p->indent;
count *= INDENT;
assert(0 == p->pos);
@@ -409,7 +413,6 @@ mlg_rofftail(void *arg)
}
-/* ARGSUSED */
static int
mlg_roffspecial(void *arg, int tok, const char *start, char **more)
{
@@ -421,8 +424,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, char **more)
switch (tok) {
case (ROFF_Xr):
if ( ! *more) {
- mlg_err(p, start, start,
- "missing required argument");
+ mlg_err(p, start, start, "missing argument");
return(0);
}
if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, NULL))
@@ -432,7 +434,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, char **more)
if (*more) {
if ( ! ml_nputs(p->mbuf, "(", 1, &p->pos))
return(0);
- if ( ! mlg_data(p, 0, start, *more++))
+ if ( ! ml_puts(p->mbuf, *more++, &p->pos))
return(0);
if ( ! ml_nputs(p->mbuf, ")", 1, &p->pos))
return(0);
@@ -443,7 +445,6 @@ mlg_roffspecial(void *arg, int tok, const char *start, char **more)
}
if ( ! mlg_endtag(p, MD_NS_INLINE, tok))
return(0);
- mlg_mode(p, MD_INLINE_OUT);
break;
case (ROFF_Fn):
break;
@@ -478,7 +479,7 @@ static int
mlg_roffblkout(void *arg, int tok)
{
- return(mlg_endblk((struct md_mlg *)arg, MD_NS_BLOCK, tok));
+ return(mlg_endtag((struct md_mlg *)arg, MD_NS_BLOCK, tok));
}
@@ -495,7 +496,7 @@ static int
mlg_roffblkbodyout(void *arg, int tok)
{
- return(mlg_endblk((struct md_mlg *)arg, MD_NS_BODY, tok));
+ return(mlg_endtag((struct md_mlg *)arg, MD_NS_BODY, tok));
}
@@ -512,7 +513,7 @@ static int
mlg_roffblkheadout(void *arg, int tok)
{
- return(mlg_endblk((struct md_mlg *)arg, MD_NS_HEAD, tok));
+ return(mlg_endtag((struct md_mlg *)arg, MD_NS_HEAD, tok));
}
@@ -528,16 +529,8 @@ mlg_roffin(void *arg, int tok, int *argc, char **argv)
static int
mlg_roffout(void *arg, int tok)
{
- struct md_mlg *p;
-
- assert(arg);
- p = (struct md_mlg *)arg;
-
- if (0 == p->pos && ! mlg_indent(p))
- return(0);
- mlg_mode(p, MD_INLINE_OUT);
- return(mlg_endtag(p, MD_NS_INLINE, tok));
+ return(mlg_endtag((struct md_mlg *)arg, MD_NS_INLINE, tok));
}
diff --git a/roff.c b/roff.c
index 3bf83bb4..104ff6a5 100644
--- a/roff.c
+++ b/roff.c
@@ -41,6 +41,7 @@
/* TODO: unify empty-content tags a la <br />. */
/* TODO: macros with a set number of arguments? */
/* TODO: validate Dt macro arguments. */
+/* FIXME: Bl -diag ignore callable children. */
enum roffd {
ROFF_ENTER = 0,