summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-11-30 18:50:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-11-30 18:50:44 +0000
commit4bbdbe91830ef70f8e2412f6f13baa347956208b (patch)
tree97d07a935809a68388c62945354b4160d2827b68
parent8a90e3149d99de9d2b20d61307f7d4951ef18bf0 (diff)
downloadmandoc-4bbdbe91830ef70f8e2412f6f13baa347956208b.tar.gz
Fixed spacing (almost there).
-rw-r--r--mdocml.111
-rw-r--r--private.h2
-rw-r--r--roff.c115
-rw-r--r--validate.c29
4 files changed, 114 insertions, 43 deletions
diff --git a/mdocml.1 b/mdocml.1
index 7f507fdb..c5f86d66 100644
--- a/mdocml.1
+++ b/mdocml.1
@@ -53,10 +53,6 @@ The validate filter, specified by
is the default filter. It produces no output, so specifying
.Fl o Ar outfile
results in an empty file.
-.Qq Op Op Fl a ) , Fl b ,
-.Bf Em
-.Qq Op Op Fl a ) , Fl b ,
-.Ef
.\" 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
@@ -78,7 +74,7 @@ results in an empty file.
The
.Nm
utility was written by
-.An Kristaps Dzonsons Aq kristaps@kth.se .
+.An Em Kristaps Dzonsons Aq kristaps@kth.se .
.\"
.Sh CAVEATS
Most caveats of
@@ -99,6 +95,9 @@ All macro arguments may be quoted, instead of only some.
.It
Blank lines raise warnings.
.It
-Non-ascii characters may cause issues.
+If terminating punctuation is found, then
+.Em all
+remaining tokens are flushed after line scope is closed, not just the
+last one.
.El
.\" .Sh BUGS
diff --git a/private.h b/private.h
index 628f4c98..40d39270 100644
--- a/private.h
+++ b/private.h
@@ -214,7 +214,7 @@ struct roffcb {
int (*roffhead)(void *);
int (*rofftail)(void *);
int (*roffin)(void *, int, int *, char **);
- int (*roffdata)(void *, char *);
+ int (*roffdata)(void *, int, char *);
int (*roffout)(void *, int);
int (*roffblkin)(void *, int, int *, char **);
int (*roffblkout)(void *, int);
diff --git a/roff.c b/roff.c
index 6b77f35a..d692dad2 100644
--- a/roff.c
+++ b/roff.c
@@ -34,12 +34,10 @@
/* FIXME: warn about empty lists. */
-/* FIXME: ; : } ) (etc.) after text macros? */
+/* FIXME: roff_layout and roff_text have identical-ish lower bodies. */
/* FIXME: NAME section needs specific elements. */
-/* FIXME: don't print Os, just do roffbegin. */
-
#define ROFF_MAXARG 32
enum roffd {
@@ -70,8 +68,7 @@ struct rofftok {
int flags;
#define ROFF_PARSED (1 << 0) /* "Parsed". */
#define ROFF_CALLABLE (1 << 1) /* "Callable". */
-#define ROFF_QUOTES (1 << 2) /* Quoted args. */
-#define ROFF_SHALLOW (1 << 3) /* Nesting block. */
+#define ROFF_SHALLOW (1 << 2) /* Nesting block. */
};
struct roffarg {
@@ -179,9 +176,9 @@ static const struct rofftok tokens[ROFF_MAX] = {
{roff_comment, NULL, NULL, NULL, 0, ROFF_COMMENT, 0 }, /* \" */
{ roff_Dd, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Dd */
{ roff_Dt, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Dt */
- { roff_Os, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_QUOTES }, /* Os */
- { roff_layout, NULL, NULL, NULL, ROFF_Sh, ROFF_LAYOUT, ROFF_PARSED }, /* Sh */
- { roff_layout, NULL, NULL, NULL, ROFF_Ss, ROFF_LAYOUT, ROFF_PARSED }, /* Ss */
+ { roff_Os, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Os */
+ { roff_layout, NULL, NULL, NULL, ROFF_Sh, ROFF_LAYOUT, 0 }, /* Sh */
+ { roff_layout, NULL, NULL, NULL, ROFF_Ss, ROFF_LAYOUT, 0 }, /* Ss */
{ roff_text, NULL, NULL, NULL, ROFF_Pp, ROFF_TEXT, 0 }, /* Pp */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* D1 */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Dl */
@@ -189,11 +186,11 @@ static const struct rofftok tokens[ROFF_MAX] = {
{ roff_close, NULL, NULL, NULL, ROFF_Bd, ROFF_LAYOUT, 0 }, /* Ed */
{ roff_layout, roffarg_Bl, NULL, roffchild_Bl, 0, ROFF_LAYOUT, 0 }, /* Bl */
{ roff_close, NULL, roffparent_El, NULL, ROFF_Bl, ROFF_LAYOUT, 0 }, /* El */
- { roff_layout, NULL, roffparent_It, NULL, ROFF_It, ROFF_LAYOUT, ROFF_SHALLOW }, /* It */
+ { roff_layout, NULL, roffparent_It, NULL, ROFF_It, ROFF_LAYOUT, ROFF_PARSED | ROFF_SHALLOW }, /* It */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ad */ /* FIXME */
{ roff_text, roffarg_An, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* An */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ar */
- { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_QUOTES }, /* Cd */ /* XXX man.4 only */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Cd */ /* XXX man.4 only */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Cm */
{ 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 */
@@ -207,7 +204,7 @@ static const struct rofftok tokens[ROFF_MAX] = {
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ic */ /* XXX needs arg */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* In */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Li */
- { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_QUOTES }, /* Nd */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Nd */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Nm */ /* FIXME */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Op */
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ot */ /* XXX deprecated */
@@ -441,7 +438,7 @@ static int
textparse(const struct rofftree *tree, char *buf)
{
- return((*tree->cb.roffdata)(tree->arg, buf));
+ return((*tree->cb.roffdata)(tree->arg, 1, buf));
}
@@ -696,7 +693,6 @@ rofffindtok(const char *buf)
}
-#if notyet
static int
roffispunct(const char *p)
{
@@ -737,7 +733,6 @@ roffispunct(const char *p)
return(0);
}
-#endif
static int
@@ -985,13 +980,16 @@ roff_layout(ROFFCALL_ARGS)
return(0);
if ( ! (ROFF_PARSED & tokens[tok].flags)) {
+ i = 0;
while (*argv) {
- if ( ! (*tree->cb.roffdata)(tree->arg, *argv++))
+ if ( ! (*tree->cb.roffdata)(tree->arg, i, *argv++))
return(0);
+ i = 1;
}
return((*tree->cb.roffout)(tree->arg, tok));
}
+ i = 0;
while (*argv) {
if (ROFF_MAX != (c = rofffindcallable(*argv))) {
if (NULL == tokens[c].cb) {
@@ -1006,8 +1004,35 @@ roff_layout(ROFFCALL_ARGS)
}
assert(tree->arg);
- if ( ! (*tree->cb.roffdata)(tree->arg, *argv++))
+ if ( ! (*tree->cb.roffdata)(tree->arg, i, *argv++))
return(0);
+ i = 1;
+ }
+
+ /*
+ * If we're the first parser (*argv == tree->cur) then purge out
+ * any additional punctuation, should there be any remaining at
+ * the end of line.
+ */
+
+ if (ROFF_PARSED & tokens[tok].flags && *argv) {
+ i = 0;
+ while (argv[i])
+ i++;
+
+ assert(i > 0);
+ if ( ! roffispunct(argv[--i]))
+ return(1);
+
+ while (i >= 0 && roffispunct(argv[i]))
+ i--;
+
+ assert(0 != i);
+ i++;
+
+ while (argv[i])
+ if ( ! (*tree->cb.roffdata)(tree->arg, 0, argv[i++]))
+ return(0);
}
return((*tree->cb.roffout)(tree->arg, tok));
@@ -1018,7 +1043,7 @@ roff_layout(ROFFCALL_ARGS)
static int
roff_text(ROFFCALL_ARGS)
{
- int i, c, argcp[ROFF_MAXARG];
+ int i, j, first, c, argcp[ROFF_MAXARG];
char *v, *argvp[ROFF_MAXARG];
if (ROFF_PRELUDE & tree->state) {
@@ -1027,6 +1052,9 @@ roff_text(ROFFCALL_ARGS)
return(0);
}
+ /* FIXME: breaks if passed from roff_layout. */
+ first = *argv == tree->cur;
+
i = 0;
argv++;
@@ -1047,17 +1075,35 @@ roff_text(ROFFCALL_ARGS)
return(0);
if ( ! (ROFF_PARSED & tokens[tok].flags)) {
+ i = 0;
while (*argv) {
- if ( ! (*tree->cb.roffdata)(tree->arg, *argv++))
+ if ( ! (*tree->cb.roffdata)(tree->arg, i, *argv++))
return(0);
+ i = 1;
}
return((*tree->cb.roffout)(tree->arg, tok));
}
+ i = 0;
while (*argv) {
if (ROFF_MAX == (c = rofffindcallable(*argv))) {
- if ( ! (*tree->cb.roffdata)(tree->arg, *argv++))
+ /*
+ * If all that remains is roff punctuation, then
+ * close out our scope and return.
+ */
+ if (roffispunct(*argv)) {
+ for (j = 0; argv[j]; j++)
+ if ( ! roffispunct(argv[j]))
+ break;
+ if (NULL == argv[j])
+ break;
+ i = 1;
+ }
+
+ if ( ! (*tree->cb.roffdata)(tree->arg, i, *argv++))
return(0);
+
+ i = 1;
continue;
}
@@ -1078,7 +1124,36 @@ roff_text(ROFFCALL_ARGS)
break;
}
- return((*tree->cb.roffout)(tree->arg, tok));
+ if ( ! (*tree->cb.roffout)(tree->arg, tok))
+ return(0);
+
+ /*
+ * If we're the first parser (*argv == tree->cur) then purge out
+ * any additional punctuation, should there be any remaining at
+ * the end of line.
+ */
+
+ if (first && *argv) {
+ i = 0;
+ while (argv[i])
+ i++;
+
+ assert(i > 0);
+ if ( ! roffispunct(argv[--i]))
+ return(1);
+
+ while (i >= 0 && roffispunct(argv[i]))
+ i--;
+
+ assert(0 != i);
+ i++;
+
+ while (argv[i])
+ if ( ! (*tree->cb.roffdata)(tree->arg, 0, argv[i++]))
+ return(0);
+ }
+
+ return(1);
}
diff --git a/validate.c b/validate.c
index e5ca3a50..e8f9cec8 100644
--- a/validate.c
+++ b/validate.c
@@ -52,7 +52,7 @@ static void roffmsg(void *arg, enum roffmsg,
static int roffhead(void *);
static int rofftail(void *);
static int roffin(void *, int, int *, char **);
-static int roffdata(void *, char *);
+static int roffdata(void *, int, char *);
static int roffout(void *, int);
static int roffblkin(void *, int, int *, char **);
static int roffblkout(void *, int);
@@ -60,7 +60,7 @@ static int roffspecial(void *, int);
static int mbuf_newline(struct md_valid *);
static int mbuf_indent(struct md_valid *);
-static int mbuf_data(struct md_valid *, char *);
+static int mbuf_data(struct md_valid *, int, char *);
static int
@@ -92,14 +92,11 @@ mbuf_newline(struct md_valid *p)
static int
-mbuf_data(struct md_valid *p, char *buf)
+mbuf_data(struct md_valid *p, int space, char *buf)
{
- int space;
size_t sz;
char *bufp;
- space = 1; /* FIXME */
-
assert(p->mbuf);
assert(0 != p->indent);
@@ -227,13 +224,15 @@ roffhead(void *arg)
assert(arg);
p = (struct md_valid *)arg;
- if ( ! md_buf_putstring(p->mbuf, "BEGIN"))
+ if ( ! md_buf_putstring(p->mbuf, "<?xml version=\"1.0\" "
+ "encoding=\"UTF-8\"?>\n"))
return(0);
- p->indent++;
- if ( ! mbuf_newline(p))
+
+ if ( ! md_buf_putstring(p->mbuf, "<mdoc>"))
return(0);
+ p->indent++;
- return(1);
+ return(mbuf_newline(p));
}
@@ -247,10 +246,7 @@ rofftail(void *arg)
if (0 != p->pos && ! mbuf_newline(p))
return(0);
-
- if ( ! md_buf_putstring(p->mbuf, "END\n"))
- return(0);
- return(1);
+ return(md_buf_putstring(p->mbuf, "</mdoc>\n"));
}
@@ -334,6 +330,7 @@ roffin(void *arg, int tok, int *argcp, char **argvp)
if (0 == p->pos && ! mbuf_indent(p))
return(0);
+ /* FIXME: not always with a space... */
if ( ! md_buf_putstring(p->mbuf, " <"))
return(0);
if ( ! md_buf_putstring(p->mbuf, toknames[tok]))
@@ -406,11 +403,11 @@ roffmsg(void *arg, enum roffmsg lvl,
static int
-roffdata(void *arg, char *buf)
+roffdata(void *arg, int space, char *buf)
{
struct md_valid *p;
assert(arg);
p = (struct md_valid *)arg;
- return(mbuf_data(p, buf));
+ return(mbuf_data(p, space, buf));
}