aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--mdocml.111
-rw-r--r--roff.c12
-rw-r--r--xml.c103
3 files changed, 81 insertions, 45 deletions
diff --git a/mdocml.1 b/mdocml.1
index 9ed02692..df86183c 100644
--- a/mdocml.1
+++ b/mdocml.1
@@ -59,17 +59,6 @@ namespace, which is one of
or
.Qq special ,
corresponding to the display mode of a node.
-.Pp
-Sample output follows:
-.Bd -literal
-<?xml version="1.0" encoding="UTF-8"?>
-<block:mdoc>
- <block:Sh>
- <inline:Sh>NAME</inline:Sh> <inline:Nm>example</inline:Nm>
- <inline:Nd>example text</inline:Nd>
- </block:Sh>
-</block:mdoc>
-.Ed
.\" The following requests should be uncommented and used where appropriate.
.\" This next request is for sections 2, 3, and 9 function return values only.
.\" .Sh RETURN VALUES
diff --git a/roff.c b/roff.c
index 457dd699..fce705f5 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.24 2008/11/30 21:41:35 kristaps Exp $ */
+/* $Id: roff.c,v 1.25 2008/11/30 23:05:57 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -518,6 +518,10 @@ roffparse(struct rofftree *tree, char *buf)
char *argv[ROFF_MAXARG];
char **argvp;
+ if (0 != *buf && 0 != *(buf + 1) && 0 != *(buf + 2))
+ if (0 == strncmp(buf, ".\\\"", 3))
+ return(1);
+
if (ROFF_MAX == (tok = rofffindtok(buf + 1))) {
roff_err(tree, buf + 1, "bogus line macro");
return(0);
@@ -525,9 +529,9 @@ roffparse(struct rofftree *tree, char *buf)
roff_err(tree, buf + 1, "unsupported macro `%s'",
toknames[tok]);
return(0);
- } else if (ROFF_COMMENT == tokens[tok].type)
- return(1);
-
+ }
+
+ assert(ROFF___ != tok);
if ( ! roffargs(tree, tok, buf, argv))
return(0);
diff --git a/xml.c b/xml.c
index 2e87ae44..257192c7 100644
--- a/xml.c
+++ b/xml.c
@@ -1,4 +1,4 @@
-/* $Id: xml.c,v 1.1 2008/11/30 21:41:35 kristaps Exp $ */
+/* $Id: xml.c,v 1.2 2008/11/30 23:05:57 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -74,6 +74,9 @@ static int mbuf_putstring(struct md_xml *,
const char *);
static int mbuf_nputstring(struct md_xml *,
const char *, size_t);
+static int mbuf_puts(struct md_xml *, const char *);
+static int mbuf_nputs(struct md_xml *,
+ const char *, size_t);
static int
@@ -87,6 +90,34 @@ mbuf_putstring(struct md_xml *p, const char *buf)
static int
mbuf_nputstring(struct md_xml *p, const char *buf, size_t sz)
{
+ size_t i;
+
+ for (i = 0; i < sz; i++) {
+ switch (buf[i]) {
+ case ('&'):
+ if ( ! md_buf_puts(p->mbuf, "&amp;", 5))
+ return(0);
+ p->pos += 5;
+ break;
+ case ('"'):
+ if ( ! md_buf_puts(p->mbuf, "&quot;", 6))
+ return(0);
+ p->pos += 6;
+ break;
+ default:
+ if ( ! md_buf_putchar(p->mbuf, buf[i]))
+ return(0);
+ p->pos++;
+ break;
+ }
+ }
+ return(1);
+}
+
+
+static int
+mbuf_nputs(struct md_xml *p, const char *buf, size_t sz)
+{
p->pos += sz;
return(md_buf_puts(p->mbuf, buf, sz));
@@ -94,6 +125,14 @@ mbuf_nputstring(struct md_xml *p, const char *buf, size_t sz)
static int
+mbuf_puts(struct md_xml *p, const char *buf)
+{
+
+ return(mbuf_nputs(p, buf, strlen(buf)));
+}
+
+
+static int
mbuf_indent(struct md_xml *p)
{
size_t i;
@@ -169,7 +208,7 @@ mbuf_data(struct md_xml *p, int space, char *buf)
if ( ! mbuf_indent(p))
return(0);
} else if (space) {
- if ( ! mbuf_nputstring(p, " ", 1))
+ if ( ! mbuf_nputs(p, " ", 1))
return(0);
}
@@ -253,10 +292,12 @@ roffhead(void *arg)
assert(arg);
p = (struct md_xml *)arg;
- if ( ! mbuf_putstring(p, "<?xml version=\"1.0\" "
+ if ( ! mbuf_puts(p, "<?xml version=\"1.0\" "
"encoding=\"UTF-8\"?>\n"))
return(0);
- if ( ! mbuf_nputstring(p, "<block:mdoc>", 12))
+ if ( ! mbuf_puts(p, "<mdoc xmlns:block=\"block\" "
+ "xmlns:special=\"special\" "
+ "xmlns:inline=\"inline\">"))
return(0);
p->indent++;
@@ -276,7 +317,7 @@ rofftail(void *arg)
if (0 != p->pos && ! mbuf_newline(p))
return(0);
- if ( ! mbuf_nputstring(p, "</block:mdoc>", 13))
+ if ( ! mbuf_puts(p, "</mdoc>"))
return(0);
p->last = MD_BLKOUT;
@@ -311,27 +352,29 @@ roffblkin(void *arg, int tok, int *argc, char **argv)
} else if ( ! mbuf_indent(p))
return(0);
- if ( ! mbuf_nputstring(p, "<", 1))
+ if ( ! mbuf_nputs(p, "<", 1))
return(0);
- if ( ! mbuf_nputstring(p, "block:", 6))
+ if ( ! mbuf_nputs(p, "block:", 6))
return(0);
- if ( ! mbuf_putstring(p, toknames[tok]))
+ if ( ! mbuf_puts(p, toknames[tok]))
return(0);
+ /* FIXME: xml won't like standards args (e.g., p1003.1-90). */
+
for (i = 0; ROFF_ARGMAX != argc[i]; i++) {
- if ( ! mbuf_nputstring(p, " ", 1))
+ if ( ! mbuf_nputs(p, " ", 1))
return(0);
- if ( ! mbuf_putstring(p, tokargnames[argc[i]]))
+ if ( ! mbuf_puts(p, tokargnames[argc[i]]))
return(0);
- if ( ! mbuf_nputstring(p, "=\"", 2))
+ if ( ! mbuf_nputs(p, "=\"", 2))
return(0);
if ( ! mbuf_putstring(p, argv[i] ? argv[i] : "true"))
return(0);
- if ( ! mbuf_nputstring(p, "\"", 1))
+ if ( ! mbuf_nputs(p, "\"", 1))
return(0);
}
- if ( ! mbuf_nputstring(p, ">", 1))
+ if ( ! mbuf_nputs(p, ">", 1))
return(0);
p->last = MD_BLKIN;
@@ -358,13 +401,13 @@ roffblkout(void *arg, int tok)
} else if ( ! mbuf_indent(p))
return(0);
- if ( ! mbuf_nputstring(p, "</", 2))
+ if ( ! mbuf_nputs(p, "</", 2))
return(0);
- if ( ! mbuf_nputstring(p, "block:", 6))
+ if ( ! mbuf_nputs(p, "block:", 6))
return(0);
- if ( ! mbuf_putstring(p, toknames[tok]))
+ if ( ! mbuf_puts(p, toknames[tok]))
return(0);
- if ( ! mbuf_nputstring(p, ">", 1))
+ if ( ! mbuf_nputs(p, ">", 1))
return(0);
p->last = MD_BLKOUT;
@@ -396,7 +439,7 @@ roffin(void *arg, int tok, int *argc, char **argv)
case (MD_TEXT):
/* FALLTHROUGH */
case (MD_OUT):
- if ( ! mbuf_nputstring(p, " ", 1))
+ if ( ! mbuf_nputs(p, " ", 1))
return(0);
break;
default:
@@ -407,26 +450,26 @@ roffin(void *arg, int tok, int *argc, char **argv)
p->last = MD_IN;
- if ( ! mbuf_nputstring(p, "<", 1))
+ if ( ! mbuf_nputs(p, "<", 1))
return(0);
- if ( ! mbuf_nputstring(p, "inline:", 7))
+ if ( ! mbuf_nputs(p, "inline:", 7))
return(0);
- if ( ! mbuf_putstring(p, toknames[tok]))
+ if ( ! mbuf_puts(p, toknames[tok]))
return(0);
for (i = 0; ROFF_ARGMAX != argc[i]; i++) {
- if ( ! mbuf_nputstring(p, " ", 1))
+ if ( ! mbuf_nputs(p, " ", 1))
return(0);
- if ( ! mbuf_putstring(p, tokargnames[argc[i]]))
+ if ( ! mbuf_puts(p, tokargnames[argc[i]]))
return(0);
- if ( ! mbuf_nputstring(p, "=\"", 2))
+ if ( ! mbuf_nputs(p, "=\"", 2))
return(0);
if ( ! mbuf_putstring(p, argv[i] ? argv[i] : "true"))
return(0);
- if ( ! mbuf_nputstring(p, "\"", 1))
+ if ( ! mbuf_nputs(p, "\"", 1))
return(0);
}
- return(mbuf_nputstring(p, ">", 1));
+ return(mbuf_nputs(p, ">", 1));
}
@@ -443,13 +486,13 @@ roffout(void *arg, int tok)
p->last = MD_OUT;
- if ( ! mbuf_nputstring(p, "</", 2))
+ if ( ! mbuf_nputs(p, "</", 2))
return(0);
- if ( ! mbuf_nputstring(p, "inline:", 7))
+ if ( ! mbuf_nputs(p, "inline:", 7))
return(0);
- if ( ! mbuf_putstring(p, toknames[tok]))
+ if ( ! mbuf_puts(p, toknames[tok]))
return(0);
- return(mbuf_nputstring(p, ">", 1));
+ return(mbuf_nputs(p, ">", 1));
}