summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-12-06 13:18:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-12-06 13:18:44 +0000
commitc88b46a1d151f56cb6253e239d00705af0b1087f (patch)
tree7124679f9deaac91b698ea9cba7dd94d29c1935c
parentc73b01760898700572c851925723527b7c637c8a (diff)
downloadmandoc-c88b46a1d151f56cb6253e239d00705af0b1087f.tar.gz
*** empty log message ***
-rw-r--r--index.73
-rw-r--r--mdocml.12
-rw-r--r--mlg.c68
-rw-r--r--roff.c140
-rw-r--r--roff.h2
5 files changed, 125 insertions, 90 deletions
diff --git a/index.7 b/index.7
index 71f77d2f..323b7282 100644
--- a/index.7
+++ b/index.7
@@ -41,8 +41,7 @@ macros clobbering a pending
.Sq \&.Bl
scope),
.It
-predefined characters (such as \\*(>= and \\*q, rendering as \*(>= and \*q,
-respectively),
+predefined characters (such as \\*(>= and \\*q),
.It
correctly-ordered document prelude,
.It
diff --git a/mdocml.1 b/mdocml.1
index 79468461..a964a91c 100644
--- a/mdocml.1
+++ b/mdocml.1
@@ -45,6 +45,8 @@ for stdin.
By default,
.Nm
reads from stdin and writes to stdout using the xml filter.
+.Pp
+.Ex -std mdocml
.\"
.Ss XML Filter
The XML filter, specified by
diff --git a/mlg.c b/mlg.c
index 8be61e3e..2cca010d 100644
--- a/mlg.c
+++ b/mlg.c
@@ -19,6 +19,7 @@
#include <assert.h>
#include <ctype.h>
#include <err.h>
+#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -89,11 +90,14 @@ static void mlg_mode(struct md_mlg *, enum md_tok);
static int mlg_data(struct md_mlg *, int,
const char *, char *);
static void mlg_err(struct md_mlg *, const char *,
- const char *, char *);
+ const char *, const char *, ...);
static void mlg_warn(struct md_mlg *, const char *,
- const char *, char *);
+ const char *, const char *, ...);
static void mlg_msg(struct md_mlg *, enum roffmsg,
const char *, const char *, char *);
+static void mlg_vmsg(struct md_mlg *, enum roffmsg,
+ const char *, const char *,
+ const char *, va_list);
#ifdef __linux__
extern size_t strlcat(char *, const char *, size_t);
@@ -446,9 +450,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, char **more)
if ( ! mlg_endtag(p, MD_NS_INLINE, tok))
return(0);
break;
- case (ROFF_Fn):
- abort(); /* TODO */
- break;
+
case (ROFF_Nm):
assert(*more);
if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, NULL))
@@ -459,9 +461,11 @@ mlg_roffspecial(void *arg, int tok, const char *start, char **more)
if ( ! mlg_endtag(p, MD_NS_INLINE, tok))
return(0);
break;
+
case (ROFF_Ns):
p->flags |= ML_OVERRIDE_ONE;
break;
+
case (ROFF_Sm):
assert(*more);
if (0 == strcmp(*more, "on"))
@@ -469,8 +473,32 @@ mlg_roffspecial(void *arg, int tok, const char *start, char **more)
else
p->flags &= ~ML_OVERRIDE_ALL;
break;
- default:
+
+ case (ROFF_Ex):
+ assert(*more);
+ if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, NULL))
+ return(0);
+ if ( ! ml_puts(p->mbuf, "The ", &p->pos))
+ return(0);
+ if ( ! mlg_begintag(p, MD_NS_INLINE, ROFF_Xr, NULL, NULL))
+ return(0);
+ if ( ! ml_puts(p->mbuf, *more++, &p->pos))
+ return(0);
+ if ( ! mlg_endtag(p, MD_NS_INLINE, ROFF_Xr))
+ return(0);
+ if ( ! ml_puts(p->mbuf, " utility exits 0 on success, "
+ "and &gt;0 if an error "
+ "occurs.", &p->pos))
+ return(0);
+ assert(NULL == *more);
+ if ( ! mlg_endtag(p, MD_NS_INLINE, tok))
+ return(0);
break;
+
+ default:
+ mlg_err(p, start, start, "`%s' not yet supported",
+ toknames[tok]);
+ return(0);
}
return(1);
@@ -572,18 +600,37 @@ mlg_roffdata(void *arg, int space, const char *start, char *buf)
static void
-mlg_err(struct md_mlg *p, const char *buf, const char *pos, char *msg)
+mlg_vmsg(struct md_mlg *p, enum roffmsg lvl, const char *start,
+ const char *pos, const char *fmt, va_list ap)
{
+ char buf[128];
- mlg_msg(p, ROFF_ERROR, buf, pos, msg);
+ (void)vsnprintf(buf, sizeof(buf), fmt, ap);
+ mlg_msg(p, lvl, start, pos, buf);
}
static void
-mlg_warn(struct md_mlg *p, const char *buf, const char *pos, char *msg)
+mlg_warn(struct md_mlg *p, const char *start,
+ const char *pos, const char *fmt, ...)
{
+ va_list ap;
- mlg_msg(p, ROFF_WARN, buf, pos, msg);
+ va_start(ap, fmt);
+ mlg_vmsg(p, ROFF_WARN, start, pos, fmt, ap);
+ va_end(ap);
+}
+
+
+static void
+mlg_err(struct md_mlg *p, const char *start,
+ const char *pos, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ mlg_vmsg(p, ROFF_ERROR, start, pos, fmt, ap);
+ va_end(ap);
}
@@ -613,5 +660,4 @@ mlg_msg(struct md_mlg *p, enum roffmsg lvl,
else
(void)fprintf(stderr, "%s: %s: %s\n",
p->rbuf->name, level, msg);
-
}
diff --git a/roff.c b/roff.c
index 643ec681..aef5f45d 100644
--- a/roff.c
+++ b/roff.c
@@ -91,10 +91,9 @@ static int roffcall(struct rofftree *, int, char **);
static int roffparse(struct rofftree *, char *);
static int textparse(struct rofftree *, char *);
static int roffdata(struct rofftree *, int, char *);
-static int roffspecial(struct rofftree *, int, char **);
+static int roffspecial(struct rofftree *, int,
+ const char *, size_t, char **);
static int roffsetname(struct rofftree *, char **);
-static int roffgetname(struct rofftree *, char **,
- const char *);
#ifdef __linux__
extern size_t strlcat(char *, const char *, size_t);
@@ -619,11 +618,54 @@ roffnode_free(struct rofftree *tree)
static int
-roffspecial(struct rofftree *tree, int tok, char **ordp)
+roffspecial(struct rofftree *tree, int tok,
+ const char *start, size_t sz, char **ordp)
{
- return((*tree->cb.roffspecial)(tree->arg, tok,
- tree->cur, ordp));
+ switch (tok) {
+ case (ROFF_Nm):
+ if (0 == sz) {
+ if (0 == tree->name[0]) {
+ roff_err(tree, start, "`Nm' not set");
+ return(0);
+ }
+ ordp[0] = tree->name;
+ ordp[1] = NULL;
+ } else if ( ! roffsetname(tree, ordp))
+ return(0);
+ break;
+
+ case (ROFF_Ex):
+ if (0 == sz) {
+ roff_err(tree, start, "`Ex' expects an arg");
+ return(0);
+ } else if (1 != sz) {
+ roff_err(tree, start, "`Ex' expects one arg");
+ return(0);
+ }
+ break;
+
+ case (ROFF_Sm):
+ if (0 == sz) {
+ roff_err(tree, start, "`Sm' expects an arg");
+ return(0);
+ } else if (1 != sz) {
+ roff_err(tree, start, "`Sm' expects one arg");
+ return(0);
+ }
+
+ if (0 != strcmp(ordp[0], "on") &&
+ 0 != strcmp(ordp[0], "off")) {
+ roff_err(tree, start, "`Sm' has invalid argument");
+ return(0);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return((*tree->cb.roffspecial)
+ (tree->arg, tok, tree->cur, ordp));
}
@@ -888,19 +930,6 @@ roff_Dt(ROFFCALL_ARGS)
static int
-roffgetname(struct rofftree *tree, char **ordp, const char *start)
-{
- if (0 == tree->name[0]) {
- roff_err(tree, start, "`Nm' name not set");
- return(0);
- }
- *ordp++ = tree->name;
- *ordp = NULL;
- return(1);
-}
-
-
-static int
roffsetname(struct rofftree *tree, char **ordp)
{
@@ -927,30 +956,12 @@ roffsetname(struct rofftree *tree, char **ordp)
static int
roff_Sm(ROFFCALL_ARGS)
{
- char *morep[1], *p;
+ char *ordp[1], *p;
p = *argv++;
+ *ordp = *argv;
- if (NULL == (morep[0] = *argv++)) {
- roff_err(tree, p, "`Sm' expects an argument");
- return(0);
- } else if (0 != strcmp(morep[0], "on") &&
- 0 != strcmp(morep[0], "off")) {
- roff_err(tree, p, "`Sm' has invalid argument");
- return(0);
- }
-
- if (*argv)
- roff_warn(tree, *argv, "`Sm' shouldn't have arguments");
-
- if ( ! roffspecial(tree, tok, morep))
- return(0);
-
- while (*argv)
- if ( ! roffdata(tree, 1, *argv++))
- return(0);
-
- return(1);
+ return(roffspecial(tree, tok, p, *ordp ? 1 : 0, ordp));
}
@@ -964,7 +975,7 @@ roff_Ns(ROFFCALL_ARGS)
first = (*argv++ == tree->cur);
morep[0] = NULL;
- if ( ! roffspecial(tree, tok, morep))
+ if ( ! roffspecial(tree, tok, *argv, 0, morep))
return(0);
while (*argv) {
@@ -1159,8 +1170,11 @@ roff_layout(ROFFCALL_ARGS)
static int
roff_ordered(ROFFCALL_ARGS)
{
- int i, first, c;
- char *ordp[ROFF_MAXLINEARG];
+ /* FIXME: the tail-switch statement is in two different places:
+ * consolidate. */
+ int i, first, c, argcp[ROFF_MAXLINEARG];
+ char *ordp[ROFF_MAXLINEARG], *p,
+ *argvp[ROFF_MAXLINEARG];
if (ROFF_PRELUDE & tree->state) {
roff_err(tree, *argv, "`%s' disallowed in prelude",
@@ -1169,21 +1183,13 @@ roff_ordered(ROFFCALL_ARGS)
}
first = (*argv == tree->cur);
- argv++;
+ p = *argv++;
- if (NULL == *argv) {
- switch (tok) {
- case (ROFF_Nm):
- if ( ! roffgetname(tree, ordp, *(argv - 1)))
- return(0);
- break;
- default:
- *ordp = NULL;
- break;
- }
+ if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))
+ return(0);
- return(roffspecial(tree, tok, ordp));
- }
+ if (NULL == *argv)
+ return(roffspecial(tree, tok, p, 0, ordp));
i = 0;
while (*argv && i < ROFF_MAXLINEARG) {
@@ -1198,16 +1204,7 @@ roff_ordered(ROFFCALL_ARGS)
if (ROFF_MAX == c)
break;
- switch (tok) {
- case (ROFF_Nm):
- if ( ! roffsetname(tree, ordp))
- return(0);
- break;
- default:
- break;
- }
-
- if ( ! roffspecial(tree, tok, ordp))
+ if ( ! roffspecial(tree, tok, p, (size_t)i, ordp))
return(0);
return(roffcall(tree, c, ordp));
@@ -1216,16 +1213,7 @@ roff_ordered(ROFFCALL_ARGS)
assert(i != ROFF_MAXLINEARG);
ordp[i] = NULL;
- switch (tok) {
- case (ROFF_Nm):
- if ( ! roffsetname(tree, ordp))
- return(0);
- break;
- default:
- break;
- }
-
- if ( ! roffspecial(tree, tok, ordp))
+ if ( ! roffspecial(tree, tok, p, (size_t)i, ordp))
return(0);
/* FIXME: error if there's stuff after the punctuation. */
diff --git a/roff.h b/roff.h
index bfa65fe5..ec9de7f4 100644
--- a/roff.h
+++ b/roff.h
@@ -119,7 +119,7 @@ static const struct rofftok tokens[ROFF_MAX] = {
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Dv */ /* XXX needs arg */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Er */ /* XXX needs arg */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ev */ /* XXX needs arg */
- { roff_text, roffarg_Ex, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ex */
+ {roff_ordered, roffarg_Ex, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ex */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Fa */ /* XXX needs arg */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Fd */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Fl */