summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-12-01 15:32:36 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-12-01 15:32:36 +0000
commit78514c9d13534db5603803edfe8e818d9fe11597 (patch)
treef0e785a8b8d887714133902422483411e6b15a04
parent995867c9d1e4701682433bd43406c27cdc59599d (diff)
downloadmandoc-78514c9d13534db5603803edfe8e818d9fe11597.tar.gz
Considerably improved roff_text parser.
Consolidated noop roff macros.
-rw-r--r--Makefile4
-rw-r--r--dummy.c251
-rw-r--r--mdocml.16
-rw-r--r--private.h6
-rw-r--r--roff.c308
-rw-r--r--xml.c1
6 files changed, 164 insertions, 412 deletions
diff --git a/Makefile b/Makefile
index b138633b..b39beec1 100644
--- a/Makefile
+++ b/Makefile
@@ -21,10 +21,10 @@ CLEAN = mdocml mdocml.tgz $(LLNS) $(LNS) $(OBJS) $(LIBS)
INSTALL = Makefile $(HEADS) $(SRCS) $(MANS)
FAIL = test.0 test.1 test.2 test.3 test.4 test.5 test.6 \
- test.15 test.20
+ test.15 test.20 test.22
SUCCEED = test.7 test.8 test.9 test.10 test.11 test.12 test.13 \
- test.14 test.16 test.17 test.18 test.19 test.21
+ test.14 test.16 test.17 test.18 test.19 test.21 test.23
all: mdocml
diff --git a/dummy.c b/dummy.c
deleted file mode 100644
index 4930980c..00000000
--- a/dummy.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/* $Id$ */
-/*
- * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the
- * above copyright notice and this permission notice appear in all
- * copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
- * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-#include <assert.h>
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "libmdocml.h"
-#include "private.h"
-
-#ifdef __linux__
-#define strlcat strncat
-#endif
-
-static int md_dummy_blk_in(const struct md_args *, int);
-static int md_dummy_blk_out(const struct md_args *, int);
-static int md_dummy_text_in(const struct md_args *, int,
- int *, char **);
-static int md_dummy_text_out(const struct md_args *, int);
-static int md_dummy_special(int);
-static int md_dummy_head(void);
-static int md_dummy_tail(void);
-static void md_dummy_msg(const struct md_args *,
- enum roffmsg, const char *,
- const char *, const char *,
- int, char *);
-
-static void dbg_prologue(const char *);
-static void dbg_epilogue(void);
-
-static int dbg_lvl = 0;
-static char dbg_line[72];
-
-struct md_dummy {
- struct rofftree *tree;
- struct roffcb cb;
-};
-
-
-int
-md_line_dummy(void *arg, char *buf, size_t sz)
-{
- struct md_dummy *p;
-
- p = (struct md_dummy *)arg;
- return(roff_engine(p->tree, buf, sz));
-}
-
-
-int
-md_exit_dummy(void *data, int flush)
-{
- int c;
- struct md_dummy *p;
-
- p = (struct md_dummy *)data;
- c = roff_free(p->tree, flush);
- free(p);
-
- return(c);
-}
-
-
-void *
-md_init_dummy(const struct md_args *args,
- struct md_mbuf *mbuf, const struct md_rbuf *rbuf)
-{
- struct md_dummy *p;
-
- if (NULL == (p = malloc(sizeof(struct md_dummy)))) {
- warn("malloc");
- return(NULL);
- }
-
- p->cb.roffhead = md_dummy_head;
- p->cb.rofftail = md_dummy_tail;
- p->cb.roffin = md_dummy_text_in;
- p->cb.roffout = md_dummy_text_out;
- p->cb.roffblkin = md_dummy_blk_in;
- p->cb.roffblkout = md_dummy_blk_out;
- p->cb.roffspecial = md_dummy_special;
- p->cb.roffmsg = md_dummy_msg;
-
- p->tree = roff_alloc(args, mbuf, rbuf, &p->cb);
-
- if (NULL == p->tree) {
- free(p);
- return(NULL);
- }
-
- return(p);
-}
-
-
-static void
-dbg_prologue(const char *p)
-{
- int i;
-
- (void)snprintf(dbg_line, sizeof(dbg_line) - 1, "%6s", p);
- (void)strlcat(dbg_line, ": ", sizeof(dbg_line) - 1);
- /* LINTED */
- for (i = 0; i < dbg_lvl; i++)
- (void)strlcat(dbg_line, " ", sizeof(dbg_line) - 1);
-}
-
-
-static void
-dbg_epilogue(void)
-{
-
- assert(0 != dbg_line[0]);
- (void)printf("%s\n", dbg_line);
-}
-
-
-static int
-md_dummy_head(void)
-{
-
- return(1);
-}
-
-
-static int
-md_dummy_tail(void)
-{
-
- return(1);
-}
-
-
-static int
-md_dummy_special(int tok)
-{
-
- dbg_prologue("noop");
- (void)strlcat(dbg_line, toknames[tok], sizeof(dbg_line) - 1);
- dbg_epilogue();
-
- return(1);
-}
-
-
-static int
-md_dummy_blk_in(const struct md_args *args, int tok)
-{
-
- if (args->verbosity < 1)
- return(1);
-
- dbg_prologue("blk");
- (void)strlcat(dbg_line, toknames[tok], sizeof(dbg_line) - 1);
- dbg_epilogue();
-
- dbg_lvl++;
- return(1);
-}
-
-
-static int
-md_dummy_blk_out(const struct md_args *args, int tok)
-{
-
- if (args->verbosity < 1)
- return(1);
-
- dbg_lvl--;
- return(1);
-}
-
-
-static int
-md_dummy_text_in(const struct md_args *args,
- int tok, int *argcp, char **argvp)
-{
-
- if (args->verbosity < 1)
- return(1);
-
- dbg_prologue("text");
- (void)strlcat(dbg_line, toknames[tok], sizeof(dbg_line) - 1);
- (void)strlcat(dbg_line, " ", sizeof(dbg_line) - 1);
- while (ROFF_ARGMAX != *argcp) {
- (void)strlcat(dbg_line, "[", sizeof(dbg_line) - 1);
- (void)strlcat(dbg_line, tokargnames[*argcp],
- sizeof(dbg_line) - 1);
- if (*argvp) {
- (void)strlcat(dbg_line, " [",
- sizeof(dbg_line) - 1);
- (void)strlcat(dbg_line, *argvp,
- sizeof(dbg_line) - 1);
- (void)strlcat(dbg_line, "]",
- sizeof(dbg_line) - 1);
- }
- (void)strlcat(dbg_line, "]", sizeof(dbg_line) - 1);
- argcp++;
- argvp++;
- }
- dbg_epilogue();
- return(1);
-}
-
-
-static int
-md_dummy_text_out(const struct md_args *args, int tok)
-{
-
- return(1);
-}
-
-
-static void
-md_dummy_msg(const struct md_args *args, enum roffmsg lvl,
- const char *buf, const char *pos,
- const char *name, int line, char *msg)
-{
- char *p;
-
- switch (lvl) {
- case (ROFF_WARN):
- if ( ! (MD_WARN_ALL & args->warnings))
- return;
- p = "warning";
- break;
- case (ROFF_ERROR):
- p = "error";
- break;
- }
-
- assert(pos >= buf);
- (void)fprintf(stderr, "%s:%d: %s: %s\n", name, line, p, msg);
-}
-
diff --git a/mdocml.1 b/mdocml.1
index efccd422..765b3a41 100644
--- a/mdocml.1
+++ b/mdocml.1
@@ -17,10 +17,8 @@
.Sh DESCRIPTION
The
.Nm
-utility parses
-.Xr mdoc
-formatted manual source and passes results into an output filter. The
-only current output filter is
+utility parses mdoc formatted manual source and passes results into an
+output filter. The only current output filter is
.Ar xml ,
the default. The arguments are as follows:
.Bl -tag -width "\-o outfile"
diff --git a/private.h b/private.h
index 7811e843..020a5779 100644
--- a/private.h
+++ b/private.h
@@ -139,7 +139,11 @@ struct md_mbuf {
#define ROFF_Oc 99
#define ROFF_Bk 100
#define ROFF_Ek 101
-#define ROFF_MAX 102
+#define ROFF_Bt 102
+#define ROFF_Hf 103
+#define ROFF_Fr 104
+#define ROFF_Ud 105
+#define ROFF_MAX 106
#define ROFF_Split 0
#define ROFF_Nosplit 1
diff --git a/roff.c b/roff.c
index 3880d80a..eedc24c0 100644
--- a/roff.c
+++ b/roff.c
@@ -28,15 +28,19 @@
#include "libmdocml.h"
#include "private.h"
-/* FIXME: warn if Pp occurs before/after Sh etc. (see mdoc.samples). */
+/* TODO: warn if Pp occurs before/after Sh etc. (see mdoc.samples). */
-/* FIXME: warn about "X section only" macros. */
+/* TODO: warn about "X section only" macros. */
-/* FIXME: warn about empty lists. */
+/* TODO: warn about empty lists. */
-/* FIXME: roff_layout and roff_text have identical-ish lower bodies. */
+/* TODO: (warn) some sections need specific elements. */
-/* FIXME: NAME section needs specific elements. */
+/* TODO: (warn) NAME section has particular order. */
+
+/* TODO: unify empty-content tags a la <br />. */
+
+/* TODO: macros with a set number of arguments? */
#define ROFF_MAXARG 32
@@ -69,6 +73,7 @@ struct rofftok {
#define ROFF_PARSED (1 << 0) /* "Parsed". */
#define ROFF_CALLABLE (1 << 1) /* "Callable". */
#define ROFF_SHALLOW (1 << 2) /* Nesting block. */
+#define ROFF_LSCOPE (1 << 3)
};
struct roffarg {
@@ -105,14 +110,11 @@ struct rofftree {
static int roff_Dd(ROFFCALL_ARGS);
static int roff_Dt(ROFFCALL_ARGS);
static int roff_Os(ROFFCALL_ARGS);
-#ifdef notyet
-static int roff_Ns(ROFFCALL_ARGS);
-#endif
static int roff_layout(ROFFCALL_ARGS);
static int roff_text(ROFFCALL_ARGS);
-static int roff_comment(ROFFCALL_ARGS);
-static int roff_close(ROFFCALL_ARGS);
+static int roff_noop(ROFFCALL_ARGS);
+static int roff_depr(ROFFCALL_ARGS);
static struct roffnode *roffnode_new(int, struct rofftree *);
static void roffnode_free(struct rofftree *);
@@ -131,6 +133,8 @@ static int roffargs(const struct rofftree *,
static int roffargok(int, int);
static int roffnextopt(const struct rofftree *,
int, char ***, char **);
+static int roffparseopts(struct rofftree *, int,
+ char ***, int *, char **);
static int roffparse(struct rofftree *, char *);
static int textparse(const struct rofftree *, char *);
@@ -175,19 +179,19 @@ static const int roffparent_Re[] = { ROFF_Rs, ROFF_MAX };
/* Table of all known tokens. */
static const struct rofftok tokens[ROFF_MAX] = {
- {roff_comment, NULL, NULL, NULL, 0, ROFF_COMMENT, 0 }, /* \" */
+ { roff_noop, 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, 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 */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Pp */ /* XXX 0 args */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_LSCOPE }, /* D1 */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_LSCOPE }, /* Dl */
{ roff_layout, roffarg_Bd, NULL, NULL, 0, ROFF_LAYOUT, 0 }, /* Bd */
- { roff_close, NULL, NULL, NULL, ROFF_Bd, ROFF_LAYOUT, 0 }, /* Ed */
+ { roff_noop, 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_noop, NULL, roffparent_El, NULL, ROFF_Bl, ROFF_LAYOUT, 0 }, /* El */
{ 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 */
@@ -208,8 +212,8 @@ static const struct rofftok tokens[ROFF_MAX] = {
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Li */
{ 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 */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Op */
+ { roff_depr, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ot */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Pa */
{ roff_text, roffarg_Rv, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Rv */
{ roff_text, roffarg_St, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* St */
@@ -229,18 +233,18 @@ static const struct rofftok tokens[ROFF_MAX] = {
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* %V */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ac */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ao */
- { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Aq */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Aq */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* At */ /* XXX at most 2 args */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bc */
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Bf */ /* FIXME */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bo */
- { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bq */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Bq */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bsx */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bx */
{ NULL, NULL, NULL, NULL, 0, ROFF_SPECIAL, 0 }, /* Db */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Dc */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Do */
- { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Dq */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Dq */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ec */
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ef */ /* FIXME */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Em */ /* XXX needs arg */
@@ -254,16 +258,16 @@ static const struct rofftok tokens[ROFF_MAX] = {
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Pc */
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Pf */
{ roff_text, NULL, NULL, NULL, 0, ROFF_LAYOUT, ROFF_PARSED | ROFF_CALLABLE }, /* Po */
- { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Pq */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Pq */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Qc */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ql */
- { roff_layout, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Qo */
- { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Qq */
- { roff_close, NULL, roffparent_Re, NULL, ROFF_Rs, ROFF_LAYOUT, 0 }, /* Re */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Qo */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Qq */
+ { roff_noop, NULL, roffparent_Re, NULL, ROFF_Rs, ROFF_LAYOUT, 0 }, /* Re */
{ roff_layout, NULL, NULL, roffchild_Rs, 0, ROFF_LAYOUT, 0 }, /* Rs */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Sc */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* So */
- { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Sq */
+ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_LSCOPE }, /* Sq */
{ NULL, NULL, NULL, NULL, 0, ROFF_SPECIAL, 0 }, /* Sm */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Sx */
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Sy */
@@ -272,11 +276,15 @@ static const struct rofftok tokens[ROFF_MAX] = {
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Xc */
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Xo */
{ roff_layout, NULL, NULL, roffchild_Fo, 0, ROFF_LAYOUT, 0 }, /* Fo */
- { roff_close, NULL, roffparent_Fc, NULL, ROFF_Fo, ROFF_LAYOUT, 0 }, /* Fc */
+ { roff_noop, NULL, roffparent_Fc, NULL, ROFF_Fo, ROFF_LAYOUT, 0 }, /* Fc */
{ roff_layout, NULL, NULL, roffchild_Oo, 0, ROFF_LAYOUT, 0 }, /* Oo */
- { roff_close, NULL, roffparent_Oc, NULL, ROFF_Oo, ROFF_LAYOUT, 0 }, /* Oc */
+ { roff_noop, NULL, roffparent_Oc, NULL, ROFF_Oo, ROFF_LAYOUT, 0 }, /* Oc */
{ roff_layout, roffarg_Bk, NULL, NULL, 0, ROFF_LAYOUT, 0 }, /* Bk */
- { roff_close, NULL, NULL, NULL, ROFF_Bk, ROFF_LAYOUT, 0 }, /* Ek */
+ { roff_noop, NULL, NULL, NULL, ROFF_Bk, ROFF_LAYOUT, 0 }, /* Ek */
+ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Bt */
+ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Hf */
+ { roff_depr, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Fr */
+ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ud */
};
/* Table of all known token arguments. */
@@ -327,7 +335,8 @@ const char *const toknamesp[ROFF_MAX] = {
"Sq", "Sm", "Sx", "Sy",
"Tn", "Ux", "Xc", "Xo",
"Fo", "Fc", "Oo", "Oc",
- "Bk", "Ek",
+ "Bk", "Ek", "Bt", "Hf",
+ "Fr", "Ud",
};
const char *const tokargnamesp[ROFF_ARGMAX] = {
@@ -575,11 +584,6 @@ roffparse(struct rofftree *tree, char *buf)
if (ROFF_LAYOUT != tokens[tok].type)
return((*tokens[tok].cb)(tok, tree, argvp, ROFF_ENTER));
-
- /*
- * Check our scope rules.
- */
-
if (0 == tokens[tok].ctx)
return((*tokens[tok].cb)(tok, tree, argvp, ROFF_ENTER));
@@ -843,6 +847,31 @@ roffnextopt(const struct rofftree *tree, int tok,
}
+static int
+roffparseopts(struct rofftree *tree, int tok,
+ char ***args, int *argc, char **argv)
+{
+ int i, c;
+ char *v;
+
+ i = 0;
+
+ while (-1 != (c = roffnextopt(tree, tok, args, &v))) {
+ if (ROFF_ARGMAX == c)
+ return(0);
+
+ argc[i] = c;
+ argv[i] = v;
+ i++;
+ *args = *args + 1;
+ }
+
+ argc[i] = ROFF_ARGMAX;
+ argv[i] = NULL;
+ return(1);
+}
+
+
/* ARGSUSED */
static int
roff_Dd(ROFFCALL_ARGS)
@@ -946,47 +975,44 @@ static int
roff_layout(ROFFCALL_ARGS)
{
int i, c, argcp[ROFF_MAXARG];
- char *v, *argvp[ROFF_MAXARG];
+ char *argvp[ROFF_MAXARG];
if (ROFF_PRELUDE & tree->state) {
- roff_err(tree, *argv, "`%s' disallowed in prelude",
+ roff_err(tree, *argv, "bad `%s' in prelude",
toknames[tok]);
return(0);
- }
-
- if (ROFF_EXIT == type) {
+ } else if (ROFF_EXIT == type) {
roffnode_free(tree);
return((*tree->cb.roffblkout)(tree->arg, tok));
}
- i = 0;
- argv++;
-
- while (-1 != (c = roffnextopt(tree, tok, &argv, &v))) {
- if (ROFF_ARGMAX == c)
- return(0);
+ assert( ! (ROFF_CALLABLE & tokens[tok].flags));
- argcp[i] = c;
- argvp[i] = v;
- i++;
- argv++;
- }
-
- argcp[i] = ROFF_ARGMAX;
- argvp[i] = NULL;
+ ++argv;
+ if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))
+ return(0);
if (NULL == roffnode_new(tok, tree))
return(0);
+ /*
+ * Layouts have two parts: the layout body and header. The
+ * layout header is the trailing text of the line macro, while
+ * the layout body is everything following until termination.
+ */
+
if ( ! (*tree->cb.roffblkin)(tree->arg, tok, argcp, argvp))
return(0);
-
if (NULL == *argv)
return(1);
-
if ( ! (*tree->cb.roffin)(tree->arg, tok, argcp, argvp))
return(0);
+ /*
+ * If there are no parsable parts, then write remaining tokens
+ * into the layout header and exit.
+ */
+
if ( ! (ROFF_PARSED & tokens[tok].flags)) {
i = 0;
while (*argv) {
@@ -997,6 +1023,11 @@ roff_layout(ROFFCALL_ARGS)
return((*tree->cb.roffout)(tree->arg, tok));
}
+ /*
+ * Parsable elements may be in the header (or be the header, for
+ * that matter). Follow the regular parsing rules for these.
+ */
+
i = 0;
while (*argv) {
if (ROFF_MAX == (c = rofffindcallable(*argv))) {
@@ -1021,14 +1052,19 @@ roff_layout(ROFFCALL_ARGS)
}
/*
- * 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 there's trailing punctuation in the header, then write it
+ * out now. Here we mimic the behaviour of a line-dominant text
+ * macro.
*/
- if ( ! (ROFF_PARSED & tokens[tok].flags && *argv))
+ if (NULL == *argv)
return((*tree->cb.roffout)(tree->arg, tok));
+ /*
+ * Expensive. Scan to the end of line then work backwards until
+ * a token isn't punctuation.
+ */
+
i = 0;
while (argv[i])
i++;
@@ -1057,7 +1093,7 @@ static int
roff_text(ROFFCALL_ARGS)
{
int i, j, first, c, argcp[ROFF_MAXARG];
- char *v, *argvp[ROFF_MAXARG];
+ char *argvp[ROFF_MAXARG];
if (ROFF_PRELUDE & tree->state) {
roff_err(tree, *argv, "`%s' disallowed in prelude",
@@ -1065,27 +1101,15 @@ roff_text(ROFFCALL_ARGS)
return(0);
}
- /* FIXME: breaks if passed from roff_layout. */
- first = *argv == tree->cur;
-
- i = 0;
+ first = (*argv == tree->cur);
argv++;
- while (-1 != (c = roffnextopt(tree, tok, &argv, &v))) {
- if (ROFF_ARGMAX == c)
- return(0);
-
- argcp[i] = c;
- argvp[i] = v;
- i++;
- argv++;
- }
-
- argcp[i] = ROFF_ARGMAX;
- argvp[i] = NULL;
-
+ if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))
+ return(0);
if ( ! (*tree->cb.roffin)(tree->arg, tok, argcp, argvp))
return(0);
+ if (NULL == *argv)
+ return((*tree->cb.roffout)(tree->arg, tok));
if ( ! (ROFF_PARSED & tokens[tok].flags)) {
i = 0;
@@ -1097,33 +1121,50 @@ roff_text(ROFFCALL_ARGS)
return((*tree->cb.roffout)(tree->arg, tok));
}
+ /*
+ * Deal with punctuation. Ugly. Work ahead until we encounter
+ * terminating punctuation. If we encounter it and all
+ * subsequent tokens are punctuation, then stop processing (the
+ * line-dominant macro will print these tokens after closure).
+ */
+
i = 0;
while (*argv) {
if (ROFF_MAX == (c = rofffindcallable(*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;
+ if ( ! roffispunct(*argv)) {
+ if ( ! (*tree->cb.roffdata)
+ (tree->arg, i, *argv++))
+ return(0);
i = 1;
+ continue;
}
-
- if ( ! (*tree->cb.roffdata)
- (tree->arg, i, *argv++))
- return(0);
+
+ /* See if only punctuation remains. */
i = 1;
- continue;
+ for (j = 0; argv[j]; j++)
+ if ( ! roffispunct(argv[j]))
+ break;
+
+ if (argv[j]) {
+ if ( ! (*tree->cb.roffdata)
+ (tree->arg, 0, *argv++))
+ return(0);
+ continue;
+ }
+
+ /* Only punctuation remains. */
+
+ if ( ! (*tree->cb.roffout)(tree->arg, tok))
+ return(0);
+ break;
}
/*
* A sub-command has been found. Execute it and
- * discontinue parsing for arguments.
+ * discontinue parsing for arguments. If we're
+ * line-scoped, then close out after it returns; if we
+ * aren't, then close out before.
*/
if (NULL == tokens[c].cb) {
@@ -1132,24 +1173,30 @@ roff_text(ROFFCALL_ARGS)
return(0);
}
+ if ( ! (ROFF_LSCOPE & tokens[tok].flags))
+ if ( ! (*tree->cb.roffout)(tree->arg, tok))
+ return(0);
+
if ( ! (*tokens[c].cb)(c, tree, argv, ROFF_ENTER))
return(0);
+ if (ROFF_LSCOPE & tokens[tok].flags)
+ if ( ! (*tree->cb.roffout)(tree->arg, tok))
+ return(0);
+
break;
}
- if ( ! (*tree->cb.roffout)(tree->arg, tok))
- return(0);
+ if (NULL == *argv)
+ return((*tree->cb.roffout)(tree->arg, tok));
+ if ( ! first)
+ return(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.
+ /*
+ * We're the line-dominant macro. Check if there's remaining
+ * punctuation. If there is, then flush it out before exiting.
*/
- if ( ! (first && *argv))
- return(1);
-
i = 0;
while (argv[i])
i++;
@@ -1175,68 +1222,21 @@ roff_text(ROFFCALL_ARGS)
/* ARGSUSED */
static int
-roff_comment(ROFFCALL_ARGS)
-{
-
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-roff_close(ROFFCALL_ARGS)
+roff_noop(ROFFCALL_ARGS)
{
return(1);
}
-#if notyet
/* ARGSUSED */
static int
-roff_Ns(ROFFCALL_ARGS)
+roff_depr(ROFFCALL_ARGS)
{
- int c;
-
- argv++;
- if (ROFF_MAX != (c = rofffindcallable(*argv))) {
- if (NULL == tokens[c].cb) {
- roff_err(tree, *argv, "unsupported macro `%s'",
- toknames[c]);
- return(0);
- }
- if ( ! (*tree->cb.roffspecial)(tree->arg, tok))
- return(0);
- if ( ! (*tokens[c].cb)(c, tree, argv, ROFF_ENTER))
- return(0);
-
- return(1);
- } else if ( ! (*tree->cb.roffdata)(tree->arg, 0, *argv++))
- return(0);
-
- while (*argv) {
- if (ROFF_MAX == (c = rofffindcallable(*argv))) {
- assert(tree->arg);
- if ( ! (*tree->cb.roffdata)
- (tree->arg, 1, *argv++))
- return(0);
- continue;
- }
- if (NULL == tokens[c].cb) {
- roff_err(tree, *argv, "unsupported macro `%s'",
- toknames[c]);
- return(0);
- }
- if ( ! (*tokens[c].cb)(c, tree, argv, ROFF_ENTER))
- return(0);
-
- break;
- }
-
- return(1);
+ roff_err(tree, *argv, "`%s' is deprecated", toknames[tok]);
+ return(0);
}
-#endif
static void
diff --git a/xml.c b/xml.c
index 858ebcc4..c3a9f7bd 100644
--- a/xml.c
+++ b/xml.c
@@ -557,3 +557,4 @@ roffdata(void *arg, int space, char *buf)
p->last = MD_TEXT;
return(1);
}
+