summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.c3
-rw-r--r--mandoc.h4
-rw-r--r--mdoc.76
-rw-r--r--mdoc.h12
-rw-r--r--mdoc_action.c12
-rw-r--r--mdoc_html.c18
-rw-r--r--mdoc_term.c47
-rw-r--r--mdoc_validate.c62
8 files changed, 77 insertions, 87 deletions
diff --git a/main.c b/main.c
index ef3eceab..f8e2e99f 100644
--- a/main.c
+++ b/main.c
@@ -143,12 +143,13 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"macro requires argument(s)",
"no title in document",
"missing list type",
+ "missing display type",
"line argument(s) will be lost",
"body argument(s) will be lost",
"column syntax is inconsistent",
"missing font type",
- "missing display type",
"displays may not be nested",
+ "unsupported display type",
"no scope to rewind: syntax violated",
"scope broken, syntax violated",
"line scope broken, syntax violated",
diff --git a/mandoc.h b/mandoc.h
index 82a7c020..83154f0d 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -74,6 +74,7 @@ enum mandocerr {
MANDOCERR_NOARGV, /* macro requires argument(s) */
MANDOCERR_NOTITLE, /* no title in document */
MANDOCERR_LISTTYPE, /* missing list type */
+ MANDOCERR_DISPTYPE, /* missing display type */
MANDOCERR_ARGSLOST, /* line argument(s) will be lost */
MANDOCERR_BODYLOST, /* body argument(s) will be lost */
#define MANDOCERR_ERROR MANDOCERR_BODYLOST
@@ -82,9 +83,8 @@ enum mandocerr {
/* FIXME: this should be a MANDOCERR_ERROR */
MANDOCERR_FONTTYPE, /* missing font type */
/* FIXME: this should be a MANDOCERR_ERROR */
- MANDOCERR_DISPTYPE, /* missing display type */
- /* FIXME: this should be a MANDOCERR_ERROR */
MANDOCERR_NESTEDDISP, /* displays may not be nested */
+ MANDOCERR_BADDISP, /* unsupported display type */
MANDOCERR_SYNTNOSCOPE, /* request scope close w/none open */
MANDOCERR_SYNTSCOPE, /* scope broken, syntax violated */
MANDOCERR_SYNTLINESCOPE, /* line scope broken, syntax violated */
diff --git a/mdoc.7 b/mdoc.7
index ba8c714b..f2c03c53 100644
--- a/mdoc.7
+++ b/mdoc.7
@@ -2169,6 +2169,12 @@ Heirloom troff, the other significant troff implementation accepting
.Pp
.Bl -dash -compact
.It
+groff supports a
+.Fl file Ar filename
+argument to
+.Sx \&Bd .
+mandoc does not.
+.It
groff behaves inconsistently when encountering
.Pf non- Sx \&Fa
children of
diff --git a/mdoc.h b/mdoc.h
index 9fcc4d5a..07490544 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -263,6 +263,15 @@ enum mdoc_list {
LIST_tag
};
+enum mdoc_disp {
+ DISP__NONE = 0,
+ DISP_centred,
+ DISP_ragged,
+ DISP_unfilled,
+ DISP_filled,
+ DISP_literal
+};
+
/* Node in AST. */
struct mdoc_node {
struct mdoc_node *parent; /* parent AST node */
@@ -290,7 +299,8 @@ struct mdoc_node {
char *string; /* TEXT */
union {
- enum mdoc_list list; /* for `Bl' nodes */
+ enum mdoc_list list; /* `Bl' nodes */
+ enum mdoc_disp disp; /* `Bd' nodes */
} data;
};
diff --git a/mdoc_action.c b/mdoc_action.c
index 43b92d9c..8aa7c92f 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -978,20 +978,16 @@ pre_bl(PRE_ARGS)
static int
pre_bd(PRE_ARGS)
{
- int i;
if (MDOC_BLOCK == n->type)
return(pre_offset(m, n));
if (MDOC_BODY != n->type)
return(1);
- /* Enter literal context if `Bd -literal' or `-unfilled'. */
-
- for (n = n->parent, i = 0; i < (int)n->args->argc; i++)
- if (MDOC_Literal == n->args->argv[i].arg)
- m->flags |= MDOC_LITERAL;
- else if (MDOC_Unfilled == n->args->argv[i].arg)
- m->flags |= MDOC_LITERAL;
+ if (DISP_literal == n->data.disp)
+ m->flags |= MDOC_LITERAL;
+ if (DISP_unfilled == n->data.disp)
+ m->flags |= MDOC_LITERAL;
return(1);
}
diff --git a/mdoc_html.c b/mdoc_html.c
index 1c8bb832..66f005b1 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1353,7 +1353,7 @@ static int
mdoc_bd_pre(MDOC_ARGS)
{
struct htmlpair tag[2];
- int type, comp, i;
+ int comp, i;
const struct mdoc_node *bl, *nn;
struct roffsu su;
@@ -1366,7 +1366,7 @@ mdoc_bd_pre(MDOC_ARGS)
SCALE_VS_INIT(&su, 0);
- type = comp = 0;
+ comp = 0;
for (i = 0; bl->args && i < (int)bl->args->argc; i++)
switch (bl->args->argv[i].arg) {
case (MDOC_Offset):
@@ -1375,17 +1375,6 @@ mdoc_bd_pre(MDOC_ARGS)
case (MDOC_Compact):
comp = 1;
break;
- case (MDOC_Centred):
- /* FALLTHROUGH */
- case (MDOC_Ragged):
- /* FALLTHROUGH */
- case (MDOC_Filled):
- /* FALLTHROUGH */
- case (MDOC_Unfilled):
- /* FALLTHROUGH */
- case (MDOC_Literal):
- type = bl->args->argv[i].arg;
- break;
default:
break;
}
@@ -1415,7 +1404,8 @@ mdoc_bd_pre(MDOC_ARGS)
return(1);
}
- if (MDOC_Unfilled != type && MDOC_Literal != type)
+ if (DISP_unfilled != n->data.disp &&
+ DISP_literal != n->data.disp)
return(1);
PAIR_CLASS_INIT(&tag[0], "lit");
diff --git a/mdoc_term.c b/mdoc_term.c
index b9c61d01..86fdc26f 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -60,7 +60,6 @@ static int arg_hasattr(int, const struct mdoc_node *);
static int arg_getattrs(const int *, int *, size_t,
const struct mdoc_node *);
static int arg_getattr(int, const struct mdoc_node *);
-static int arg_disptype(const struct mdoc_node *);
static void print_bvspace(struct termp *,
const struct mdoc_node *,
const struct mdoc_node *);
@@ -489,35 +488,6 @@ a2width(const struct mdoc_argv *arg, int pos)
}
-static int
-arg_disptype(const struct mdoc_node *n)
-{
- int i, len;
-
- assert(MDOC_BLOCK == n->type);
-
- len = (int)(n->args ? n->args->argc : 0);
-
- for (i = 0; i < len; i++)
- switch (n->args->argv[i].arg) {
- case (MDOC_Centred):
- /* FALLTHROUGH */
- case (MDOC_Ragged):
- /* FALLTHROUGH */
- case (MDOC_Filled):
- /* FALLTHROUGH */
- case (MDOC_Unfilled):
- /* FALLTHROUGH */
- case (MDOC_Literal):
- return(n->args->argv[i].arg);
- default:
- break;
- }
-
- return(-1);
-}
-
-
static size_t
a2offs(const struct mdoc_argv *arg)
{
@@ -1632,7 +1602,7 @@ static int
termp_bd_pre(DECL_ARGS)
{
size_t tabwidth;
- int i, type;
+ int i;
size_t rm, rmax;
const struct mdoc_node *nn;
@@ -1644,9 +1614,6 @@ termp_bd_pre(DECL_ARGS)
nn = n->parent;
- type = arg_disptype(nn);
- assert(-1 != type);
-
if (-1 != (i = arg_getattr(MDOC_Offset, nn)))
p->offset += a2offs(&nn->args->argv[i]);
@@ -1658,7 +1625,8 @@ termp_bd_pre(DECL_ARGS)
* lines are allowed.
*/
- if (MDOC_Literal != type && MDOC_Unfilled != type)
+ if (DISP_literal != n->data.disp &&
+ DISP_unfilled != n->data.disp)
return(1);
tabwidth = p->tabwidth;
@@ -1675,8 +1643,8 @@ termp_bd_pre(DECL_ARGS)
NULL == nn->next)
term_flushln(p);
}
- p->tabwidth = tabwidth;
+ p->tabwidth = tabwidth;
p->rmargin = rm;
p->maxrmargin = rmax;
return(0);
@@ -1687,19 +1655,16 @@ termp_bd_pre(DECL_ARGS)
static void
termp_bd_post(DECL_ARGS)
{
- int type;
size_t rm, rmax;
if (MDOC_BODY != n->type)
return;
- type = arg_disptype(n->parent);
- assert(-1 != type);
-
rm = p->rmargin;
rmax = p->maxrmargin;
- if (MDOC_Literal == type || MDOC_Unfilled == type)
+ if (DISP_literal == n->data.disp ||
+ DISP_unfilled == n->data.disp)
p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
p->flags |= TERMP_NOSPACE;
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 388cb6a7..3c151fb3 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -683,43 +683,65 @@ pre_bl(PRE_ARGS)
static int
pre_bd(PRE_ARGS)
{
- int i, type, err;
+ int i;
+ enum mdoc_disp dt;
- if (MDOC_BLOCK != n->type)
+ if (MDOC_BLOCK != n->type) {
+ assert(n->parent);
+ assert(MDOC_BLOCK == n->parent->type);
+ assert(MDOC_Bd == n->parent->tok);
+ assert(DISP__NONE != n->parent->data.disp);
+ n->data.disp = n->parent->data.disp;
return(1);
- if (NULL == n->args) {
- mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE);
- return(0);
}
- /* Make sure that only one type of display is specified. */
+ assert(DISP__NONE == n->data.disp);
/* LINTED */
- for (i = 0, err = type = 0; ! err &&
- i < (int)n->args->argc; i++)
+ for (i = 0; n->args && i < (int)n->args->argc; i++) {
+ dt = DISP__NONE;
switch (n->args->argv[i].arg) {
case (MDOC_Centred):
- /* FALLTHROUGH */
+ dt = DISP_centred;
+ break;
case (MDOC_Ragged):
- /* FALLTHROUGH */
+ dt = DISP_ragged;
+ break;
case (MDOC_Unfilled):
- /* FALLTHROUGH */
+ dt = DISP_unfilled;
+ break;
case (MDOC_Filled):
- /* FALLTHROUGH */
+ dt = DISP_filled;
+ break;
case (MDOC_Literal):
- if (0 == type++)
- break;
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP))
- return(0);
+ dt = DISP_literal;
break;
+ case (MDOC_File):
+ mdoc_nmsg(mdoc, n, MANDOCERR_BADDISP);
+ return(0);
+ case (MDOC_Offset):
+ /* FALLTHROUGH */
+ case (MDOC_Compact):
+ /* FALLTHROUGH */
default:
break;
}
- if (type)
- return(1);
- mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE);
- return(0);
+ if (DISP__NONE != dt && n->data.disp != DISP__NONE)
+ if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP))
+ return(0);
+
+ if (DISP__NONE != dt && n->data.disp == DISP__NONE)
+ n->data.disp = dt;
+ }
+
+ if (DISP__NONE == n->data.disp) {
+ if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE))
+ return(0);
+ n->data.disp = DISP_ragged;
+ }
+
+ return(1);
}