summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-12-22 11:15:16 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-12-22 11:15:16 +0000
commit544a766eb06bf03fc9ae275a02575c4dc54c8d32 (patch)
tree5094d1a10b9a3243e5713b32cd76f383eb2dd04d
parent89a32203ddc128f3448f944bcb1a47eac62514d9 (diff)
downloadmandoc-544a766eb06bf03fc9ae275a02575c4dc54c8d32.tar.gz
Implement reference-counted version of original union mdoc_data. This
simplifies clean-up and allows for more types without extra hassle. Also made in-line literal types in -T[x]html use CODE instead of SPAN to match how literal blocks use PRE.
-rw-r--r--example.style.css4
-rw-r--r--html.c3
-rw-r--r--html.h1
-rw-r--r--mdoc.c28
-rw-r--r--mdoc.h21
-rw-r--r--mdoc_argv.c3
-rw-r--r--mdoc_html.c62
-rw-r--r--mdoc_term.c53
-rw-r--r--mdoc_validate.c150
9 files changed, 158 insertions, 167 deletions
diff --git a/example.style.css b/example.style.css
index ddcd21c1..e1e86a29 100644
--- a/example.style.css
+++ b/example.style.css
@@ -25,17 +25,16 @@ h2 { margin-bottom: 0px; font-size: medium; margin-left: -2ex; } /* Sub-section
div.section { margin-bottom: 2ex; margin-left: 4ex; } /* Sections (Sh, SH). */
div.subsection { } /* Sub-sections (Ss, SS). */
table.synopsis { } /* SYNOPSIS section table. */
-table.synopsis td { vertical-align: top; } /* SYNOPSIS section table. */
/* Vertical spacing. */
p { } /* Paragraph: Pp, Lp. */
blockquote { margin-top: 0px; margin-bottom: 0px; }
table { margin-top: 0px; margin-bottom: 0px; }
+td { vertical-align: top; }
/* General font modes. */
-.lit { font-style: normal; font-weight: normal; font-family: monospace; } /* Literal: Dl, Li, Bf -literal, Bl -literal, Bl -unfilled. */
.italic { font-style: italic; font-weight: normal; } /* Italic: BI, IB, I, (implicit). */
.emph { font-style: italic; font-weight: normal; } /* Emphasis: Em, Bl -emphasis. */
.bold { font-style: normal; font-weight: bold; } /* Bold: SB, BI, IB, BR, RB, B, (implicit). */
@@ -68,6 +67,7 @@ i.ftype { font-weight: normal; } /* Function types (Ft, Fn). */
b.includes { font-style: normal; } /* Header includes (In). */
span.lib { } /* Library (Lb). */
i.link-sec { font-weight: normal; } /* Section links (Sx). */
+code.lit { font-style: normal; font-weight: normal; } /* Literal: Dl, Li, Bf -literal, Bl -literal, Bl -unfilled. */
b.macro { font-style: normal; } /* Macro-ish thing (Fd). */
b.name { font-style: normal; } /* Name of utility (Nm). */
span.opt { } /* Options (Op, Oo/Oc). */
diff --git a/html.c b/html.c
index db840652..d8fddc81 100644
--- a/html.c
+++ b/html.c
@@ -73,6 +73,7 @@ static const struct htmldata htmltags[TAG_MAX] = {
{"b", 0 }, /* TAG_B */
{"i", 0 }, /* TAG_I */
{"u", 0 }, /* TAG_U */
+ {"code", 0 }, /* TAG_CODE */
};
static const char *const htmlfonts[HTMLFONT_MAX] = {
@@ -486,7 +487,7 @@ print_xmltype(struct html *h)
{
if (HTML_XHTML_1_0_STRICT == h->type)
- printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
}
diff --git a/html.h b/html.h
index 62b8541d..1cc98caf 100644
--- a/html.h
+++ b/html.h
@@ -49,6 +49,7 @@ enum htmltag {
TAG_B,
TAG_I,
TAG_U,
+ TAG_CODE,
TAG_MAX
};
diff --git a/mdoc.c b/mdoc.c
index a78bb5d0..91248872 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -511,24 +511,8 @@ static void
mdoc_node_free(struct mdoc_node *p)
{
- /*
- * XXX: if these end up being problematic in terms of memory
- * management and dereferencing freed blocks, then make them
- * into reference-counted double-pointers.
- */
-
- if (MDOC_Bd == p->tok && MDOC_BLOCK == p->type)
- if (p->data.Bd)
- free(p->data.Bd);
- if (MDOC_Bl == p->tok && MDOC_BLOCK == p->type)
- if (p->data.Bl)
- free(p->data.Bl);
- if (MDOC_Bf == p->tok && MDOC_HEAD == p->type)
- if (p->data.Bf)
- free(p->data.Bf);
- if (MDOC_An == p->tok)
- if (p->data.An)
- free(p->data.An);
+ if (p->norm && 0 == --(p->norm->refcnt))
+ free(p->norm);
if (p->string)
free(p->string);
@@ -624,7 +608,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
*/
if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
- LIST_column == n->data.Bl->type) {
+ LIST_column == n->norm->d.Bl.type) {
/* `Bl' is open without any children. */
m->flags |= MDOC_FREECOL;
return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
@@ -633,7 +617,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
NULL != n->parent &&
MDOC_Bl == n->parent->tok &&
- LIST_column == n->parent->data.Bl->type) {
+ LIST_column == n->parent->norm->d.Bl.type) {
/* `Bl' has block-level `It' children. */
m->flags |= MDOC_FREECOL;
return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
@@ -814,7 +798,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs)
*/
if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
- LIST_column == n->data.Bl->type) {
+ LIST_column == n->norm->d.Bl.type) {
m->flags |= MDOC_FREECOL;
if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf))
goto err;
@@ -830,7 +814,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs)
if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
NULL != n->parent &&
MDOC_Bl == n->parent->tok &&
- LIST_column == n->parent->data.Bl->type) {
+ LIST_column == n->parent->norm->d.Bl.type) {
m->flags |= MDOC_FREECOL;
if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf))
goto err;
diff --git a/mdoc.h b/mdoc.h
index 6c019073..126bf3d9 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -358,11 +358,20 @@ struct mdoc_an {
* of iterating through the mdoc_arg pointers of a node: defaults are
* provided, etc.
*/
-union mdoc_data {
- struct mdoc_an *An;
- struct mdoc_bd *Bd;
- struct mdoc_bf *Bf;
- struct mdoc_bl *Bl;
+union mdoc_data {
+ struct mdoc_an An;
+ struct mdoc_bd Bd;
+ struct mdoc_bf Bf;
+ struct mdoc_bl Bl;
+};
+
+/*
+ * Reference-counted structure for containing normalised arguments of
+ * certain macros (those listed in union mdoc_data).
+ */
+struct mdoc_norm {
+ int refcnt;
+ union mdoc_data d;
};
/*
@@ -387,6 +396,7 @@ struct mdoc_node {
#define MDOC_ENDED (1 << 5) /* rendering has been ended */
enum mdoc_type type; /* AST node type */
enum mdoc_sec sec; /* current named section */
+ struct mdoc_norm *norm; /* ref-counted, normalised args */
/* FIXME: these can be union'd to shave a few bytes. */
struct mdoc_arg *args; /* BLOCK/ELEM */
struct mdoc_node *pending; /* BLOCK */
@@ -395,7 +405,6 @@ struct mdoc_node {
struct mdoc_node *tail; /* BLOCK */
char *string; /* TEXT */
enum mdoc_endbody end; /* BODY */
- union mdoc_data data;
};
/*
diff --git a/mdoc_argv.c b/mdoc_argv.c
index cb13ea88..3762c876 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -361,8 +361,7 @@ mdoc_args(struct mdoc *m, int line, int *pos,
if (MDOC_Bl == n->tok)
break;
- assert(n->data.Bl);
- if (n && LIST_column == n->data.Bl->type) {
+ if (n && LIST_column == n->norm->d.Bl.type) {
fl |= ARGS_TABSEP;
fl &= ~ARGS_DELIM;
}
diff --git a/mdoc_html.c b/mdoc_html.c
index fbfcf002..1d57958a 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -470,8 +470,8 @@ mdoc_root_post(MDOC_ARGS)
PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
PAIR_CLASS_INIT(&tag[1], "foot");
if (NULL == h->style) {
- PAIR_INIT(&tag[1], ATTR_WIDTH, "100%");
- t = print_otag(h, TAG_TABLE, 2, tag);
+ PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
+ t = print_otag(h, TAG_TABLE, 3, tag);
PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
print_otag(h, TAG_COL, 1, tag);
print_otag(h, TAG_COL, 1, tag);
@@ -839,7 +839,7 @@ mdoc_it_pre(MDOC_ARGS)
assert(bl);
- type = bl->data.Bl->type;
+ type = bl->norm->d.Bl.type;
assert(lists[type]);
PAIR_CLASS_INIT(&tag[0], lists[type]);
@@ -865,7 +865,7 @@ mdoc_it_pre(MDOC_ARGS)
case(LIST_ohang):
/* FALLTHROUGH */
case(LIST_tag):
- SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
+ SCALE_VS_INIT(&su, ! bl->norm->d.Bl.comp);
bufcat_su(h, "margin-top", &su);
PAIR_STYLE_INIT(&tag[1], h);
print_otag(h, TAG_DT, 2, tag);
@@ -890,7 +890,7 @@ mdoc_it_pre(MDOC_ARGS)
case(LIST_enum):
/* FALLTHROUGH */
case(LIST_item):
- SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
+ SCALE_VS_INIT(&su, ! bl->norm->d.Bl.comp);
bufcat_su(h, "margin-top", &su);
PAIR_STYLE_INIT(&tag[1], h);
print_otag(h, TAG_LI, 2, tag);
@@ -904,17 +904,17 @@ mdoc_it_pre(MDOC_ARGS)
case(LIST_ohang):
/* FALLTHROUGH */
case(LIST_tag):
- if (NULL == bl->data.Bl->width) {
+ if (NULL == bl->norm->d.Bl.width) {
print_otag(h, TAG_DD, 1, tag);
break;
}
- a2width(bl->data.Bl->width, &su);
+ a2width(bl->norm->d.Bl.width, &su);
bufcat_su(h, "margin-left", &su);
PAIR_STYLE_INIT(&tag[1], h);
print_otag(h, TAG_DD, 2, tag);
break;
case(LIST_column):
- SCALE_VS_INIT(&su, ! bl->data.Bl->comp);
+ SCALE_VS_INIT(&su, ! bl->norm->d.Bl.comp);
bufcat_su(h, "margin-top", &su);
PAIR_STYLE_INIT(&tag[1], h);
print_otag(h, TAG_TD, 2, tag);
@@ -945,13 +945,13 @@ mdoc_bl_pre(MDOC_ARGS)
char buf[BUFSIZ];
if (MDOC_BODY == n->type) {
- if (LIST_column == n->data.Bl->type)
+ if (LIST_column == n->norm->d.Bl.type)
print_otag(h, TAG_TBODY, 0, NULL);
return(1);
}
if (MDOC_HEAD == n->type) {
- if (LIST_column != n->data.Bl->type)
+ if (LIST_column != n->norm->d.Bl.type)
return(0);
/*
@@ -961,10 +961,10 @@ mdoc_bl_pre(MDOC_ARGS)
* screen and we want to preserve that behaviour.
*/
- for (i = 0; i < n->data.Bl->ncols; i++) {
- a2width(n->data.Bl->cols[i], &su);
+ for (i = 0; i < n->norm->d.Bl.ncols; i++) {
+ a2width(n->norm->d.Bl.cols[i], &su);
bufinit(h);
- if (i < n->data.Bl->ncols - 1)
+ if (i < n->norm->d.Bl.ncols - 1)
bufcat_su(h, "width", &su);
else
bufcat_su(h, "min-width", &su);
@@ -980,19 +980,19 @@ mdoc_bl_pre(MDOC_ARGS)
bufcat_su(h, "margin-bottom", &su);
PAIR_STYLE_INIT(&tag[0], h);
- assert(lists[n->data.Bl->type]);
+ assert(lists[n->norm->d.Bl.type]);
strlcpy(buf, "list ", BUFSIZ);
- strlcat(buf, lists[n->data.Bl->type], BUFSIZ);
+ strlcat(buf, lists[n->norm->d.Bl.type], BUFSIZ);
PAIR_INIT(&tag[1], ATTR_CLASS, buf);
/* Set the block's left-hand margin. */
- if (n->data.Bl->offs) {
- a2offs(n->data.Bl->offs, &su);
+ if (n->norm->d.Bl.offs) {
+ a2offs(n->norm->d.Bl.offs, &su);
bufcat_su(h, "margin-left", &su);
}
- switch (n->data.Bl->type) {
+ switch (n->norm->d.Bl.type) {
case(LIST_bullet):
/* FALLTHROUGH */
case(LIST_dash):
@@ -1096,12 +1096,14 @@ mdoc_d1_pre(MDOC_ARGS)
/* BLOCKQUOTE needs a block body. */
- if (MDOC_Dl == n->tok)
+ if (MDOC_Dl == n->tok) {
PAIR_CLASS_INIT(&tag[0], "lit display");
- else
+ print_otag(h, TAG_CODE, 1, tag);
+ } else {
PAIR_CLASS_INIT(&tag[0], "display");
+ print_otag(h, TAG_DIV, 1, tag);
+ }
- print_otag(h, TAG_DIV, 1, tag);
return(1);
}
@@ -1143,7 +1145,7 @@ mdoc_bd_pre(MDOC_ARGS)
return(0);
if (MDOC_BLOCK == n->type) {
- comp = n->data.Bd->comp;
+ comp = n->norm->d.Bd.comp;
for (nn = n; nn && ! comp; nn = nn->parent) {
if (MDOC_BLOCK != nn->type)
continue;
@@ -1158,14 +1160,14 @@ mdoc_bd_pre(MDOC_ARGS)
}
SCALE_HS_INIT(&su, 0);
- if (n->data.Bd->offs)
- a2offs(n->data.Bd->offs, &su);
+ if (n->norm->d.Bd.offs)
+ a2offs(n->norm->d.Bd.offs, &su);
bufcat_su(h, "margin-left", &su);
PAIR_STYLE_INIT(&tag[0], h);
- if (DISP_unfilled != n->data.Bd->type &&
- DISP_literal != n->data.Bd->type) {
+ if (DISP_unfilled != n->norm->d.Bd.type &&
+ DISP_literal != n->norm->d.Bd.type) {
PAIR_CLASS_INIT(&tag[1], "display");
print_otag(h, TAG_DIV, 2, tag);
return(1);
@@ -1748,13 +1750,11 @@ mdoc_bf_pre(MDOC_ARGS)
else if (MDOC_BODY != n->type)
return(1);
- assert(n->data.Bf);
-
- if (FONT_Em == n->data.Bf->font)
+ if (FONT_Em == n->norm->d.Bf.font)
PAIR_CLASS_INIT(&tag[0], "emph");
- else if (FONT_Sy == n->data.Bf->font)
+ else if (FONT_Sy == n->norm->d.Bf.font)
PAIR_CLASS_INIT(&tag[0], "symb");
- else if (FONT_Li == n->data.Bf->font)
+ else if (FONT_Li == n->norm->d.Bf.font)
PAIR_CLASS_INIT(&tag[0], "lit");
else
PAIR_CLASS_INIT(&tag[0], "none");
diff --git a/mdoc_term.c b/mdoc_term.c
index e83494db..dbd5ac5e 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -556,9 +556,9 @@ print_bvspace(struct termp *p,
term_newln(p);
- if (MDOC_Bd == bl->tok && bl->data.Bd->comp)
+ if (MDOC_Bd == bl->tok && bl->norm->d.Bd.comp)
return;
- if (MDOC_Bl == bl->tok && bl->data.Bl->comp)
+ if (MDOC_Bl == bl->tok && bl->norm->d.Bl.comp)
return;
/* Do not vspace directly after Ss/Sh. */
@@ -577,13 +577,13 @@ print_bvspace(struct termp *p,
/* A `-column' does not assert vspace within the list. */
- if (MDOC_Bl == bl->tok && LIST_column == bl->data.Bl->type)
+ if (MDOC_Bl == bl->tok && LIST_column == bl->norm->d.Bl.type)
if (n->prev && MDOC_It == n->prev->tok)
return;
/* A `-diag' without body does not vspace. */
- if (MDOC_Bl == bl->tok && LIST_diag == bl->data.Bl->type)
+ if (MDOC_Bl == bl->tok && LIST_diag == bl->norm->d.Bl.type)
if (n->prev && MDOC_It == n->prev->tok) {
assert(n->prev->body);
if (NULL == n->prev->body->child)
@@ -610,8 +610,7 @@ termp_it_pre(DECL_ARGS)
}
bl = n->parent->parent->parent;
- assert(bl->data.Bl);
- type = bl->data.Bl->type;
+ type = bl->norm->d.Bl.type;
/*
* First calculate width and offset. This is pretty easy unless
@@ -621,8 +620,8 @@ termp_it_pre(DECL_ARGS)
width = offset = 0;
- if (bl->data.Bl->offs)
- offset = a2offs(p, bl->data.Bl->offs);
+ if (bl->norm->d.Bl.offs)
+ offset = a2offs(p, bl->norm->d.Bl.offs);
switch (type) {
case (LIST_column):
@@ -638,7 +637,7 @@ termp_it_pre(DECL_ARGS)
* column.
* - For more than 5 columns, add only one column.
*/
- ncols = bl->data.Bl->ncols;
+ ncols = bl->norm->d.Bl.ncols;
/* LINTED */
dcol = ncols < 5 ? term_len(p, 4) :
@@ -653,7 +652,7 @@ termp_it_pre(DECL_ARGS)
nn->prev && i < (int)ncols;
nn = nn->prev, i++)
offset += dcol + a2width
- (p, bl->data.Bl->cols[i]);
+ (p, bl->norm->d.Bl.cols[i]);
/*
* When exceeding the declared number of columns, leave
@@ -668,10 +667,10 @@ termp_it_pre(DECL_ARGS)
* Use the declared column widths, extended as explained
* in the preceding paragraph.
*/
- width = a2width(p, bl->data.Bl->cols[i]) + dcol;
+ width = a2width(p, bl->norm->d.Bl.cols[i]) + dcol;
break;
default:
- if (NULL == bl->data.Bl->width)
+ if (NULL == bl->norm->d.Bl.width)
break;
/*
@@ -679,8 +678,8 @@ termp_it_pre(DECL_ARGS)
* number for buffering single arguments. See the above
* handling for column for how this changes.
*/
- assert(bl->data.Bl->width);
- width = a2width(p, bl->data.Bl->width) + term_len(p, 2);
+ assert(bl->norm->d.Bl.width);
+ width = a2width(p, bl->norm->d.Bl.width) + term_len(p, 2);
break;
}
@@ -942,7 +941,7 @@ termp_it_post(DECL_ARGS)
if (MDOC_BLOCK == n->type)
return;
- type = n->parent->parent->parent->data.Bl->type;
+ type = n->parent->parent->parent->norm->d.Bl.type;
switch (type) {
case (LIST_item):
@@ -1116,10 +1115,10 @@ termp_an_post(DECL_ARGS)
return;
}
- if (AUTH_split == n->data.An->auth) {
+ if (AUTH_split == n->norm->d.An.auth) {
p->flags &= ~TERMP_NOSPLIT;
p->flags |= TERMP_SPLIT;
- } else if (AUTH_nosplit == n->data.An->auth) {
+ } else if (AUTH_nosplit == n->norm->d.An.auth) {
p->flags &= ~TERMP_SPLIT;
p->flags |= TERMP_NOSPLIT;
}
@@ -1566,9 +1565,8 @@ termp_bd_pre(DECL_ARGS)
} else if (MDOC_HEAD == n->type)
return(0);
- assert(n->data.Bd);
- if (n->data.Bd->offs)
- p->offset += a2offs(p, n->data.Bd->offs);
+ if (n->norm->d.Bd.offs)
+ p->offset += a2offs(p, n->norm->d.Bd.offs);
/*
* If -ragged or -filled are specified, the block does nothing
@@ -1578,8 +1576,8 @@ termp_bd_pre(DECL_ARGS)
* lines are allowed.
*/
- if (DISP_literal != n->data.Bd->type &&
- DISP_unfilled != n->data.Bd->type)
+ if (DISP_literal != n->norm->d.Bd.type &&
+ DISP_unfilled != n->norm->d.Bd.type)
return(1);
tabwidth = p->tabwidth;
@@ -1641,9 +1639,8 @@ termp_bd_post(DECL_ARGS)
rm = p->rmargin;
rmax = p->maxrmargin;
- assert(n->data.Bd);
- if (DISP_literal == n->data.Bd->type ||
- DISP_unfilled == n->data.Bd->type)
+ if (DISP_literal == n->norm->d.Bd.type ||
+ DISP_unfilled == n->norm->d.Bd.type)
p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
p->flags |= TERMP_NOSPACE;
@@ -1998,11 +1995,9 @@ termp_bf_pre(DECL_ARGS)
else if (MDOC_BLOCK != n->type)
return(1);
- assert(n->data.Bf);
-
- if (FONT_Em == n->data.Bf->font)
+ if (FONT_Em == n->norm->d.Bf.font)
term_fontpush(p, TERMFONT_UNDER);
- else if (FONT_Sy == n->data.Bf->font)
+ else if (FONT_Sy == n->norm->d.Bf.font)
term_fontpush(p, TERMFONT_BOLD);
else
term_fontpush(p, TERMFONT_NONE);
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 1093ece3..487a8d3f 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -41,6 +41,16 @@
#define PRE_ARGS struct mdoc *mdoc, struct mdoc_node *n
#define POST_ARGS struct mdoc *mdoc
+#define NORM_BUMP(dst, src) do { \
+ (dst)->norm = (src)->norm; \
+ ((dst)->norm->refcnt)++; \
+ } while (/* CONSTCOND */ 0)
+#define NORM_ALLOC(dst) do { \
+ (dst)->norm = \
+ mandoc_calloc(1, sizeof(struct mdoc_norm)); \
+ (dst)->norm->refcnt = 1; \
+ } while (/* CONSTCOND */ 0)
+
#define NUMSIZ 32
#define DATESIZE 32
@@ -609,20 +619,18 @@ pre_bl(PRE_ARGS)
assert(np);
assert(MDOC_BLOCK == np->type);
assert(MDOC_Bl == np->tok);
- assert(np->data.Bl);
- n->data.Bl = np->data.Bl;
+ NORM_BUMP(n, np);
return(1);
}
+ NORM_ALLOC(n);
+
/*
* First figure out which kind of list to use: bind ourselves to
* the first mentioned list type and warn about any remaining
* ones. If we find no list type, we default to LIST_item.
*/
- assert(NULL == n->data.Bl);
- n->data.Bl = mandoc_calloc(1, sizeof(struct mdoc_bl));
-
/* LINTED */
for (i = 0; n->args && i < (int)n->args->argc; i++) {
lt = LIST__NONE;
@@ -665,18 +673,18 @@ pre_bl(PRE_ARGS)
break;
/* Set list arguments. */
case (MDOC_Compact):
- dup = n->data.Bl->comp;
+ dup = n->norm->d.Bl.comp;
comp = 1;
break;
case (MDOC_Width):
- dup = (NULL != n->data.Bl->width);
+ dup = (NULL != n->norm->d.Bl.width);
width = n->args->argv[i].value[0];
break;
case (MDOC_Offset):
/* NB: this can be empty! */
if (n->args->argv[i].sz) {
offs = n->args->argv[i].value[0];
- dup = (NULL != n->data.Bl->offs);
+ dup = (NULL != n->norm->d.Bl.offs);
break;
}
mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
@@ -691,36 +699,36 @@ pre_bl(PRE_ARGS)
mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP);
if (comp && ! dup)
- n->data.Bl->comp = comp;
+ n->norm->d.Bl.comp = comp;
if (offs && ! dup)
- n->data.Bl->offs = offs;
+ n->norm->d.Bl.offs = offs;
if (width && ! dup)
- n->data.Bl->width = width;
+ n->norm->d.Bl.width = width;
/* Check: multiple list types. */
- if (LIST__NONE != lt && n->data.Bl->type != LIST__NONE)
+ if (LIST__NONE != lt && n->norm->d.Bl.type != LIST__NONE)
mdoc_nmsg(mdoc, n, MANDOCERR_LISTREP);
/* Assign list type. */
- if (LIST__NONE != lt && n->data.Bl->type == LIST__NONE) {
- n->data.Bl->type = lt;
+ if (LIST__NONE != lt && n->norm->d.Bl.type == LIST__NONE) {
+ n->norm->d.Bl.type = lt;
/* Set column information, too. */
if (LIST_column == lt) {
- n->data.Bl->ncols =
+ n->norm->d.Bl.ncols =
n->args->argv[i].sz;
- n->data.Bl->cols = (const char **)
+ n->norm->d.Bl.cols = (const char **)
n->args->argv[i].value;
}
}
/* The list type should come first. */
- if (n->data.Bl->type == LIST__NONE)
- if (n->data.Bl->width ||
- n->data.Bl->offs ||
- n->data.Bl->comp)
+ if (n->norm->d.Bl.type == LIST__NONE)
+ if (n->norm->d.Bl.width ||
+ n->norm->d.Bl.offs ||
+ n->norm->d.Bl.comp)
mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST);
continue;
@@ -728,9 +736,9 @@ pre_bl(PRE_ARGS)
/* Allow lists to default to LIST_item. */
- if (LIST__NONE == n->data.Bl->type) {
+ if (LIST__NONE == n->norm->d.Bl.type) {
mdoc_nmsg(mdoc, n, MANDOCERR_LISTTYPE);
- n->data.Bl->type = LIST_item;
+ n->norm->d.Bl.type = LIST_item;
}
/*
@@ -739,9 +747,9 @@ pre_bl(PRE_ARGS)
* and must also be warned.
*/
- switch (n->data.Bl->type) {
+ switch (n->norm->d.Bl.type) {
case (LIST_tag):
- if (n->data.Bl->width)
+ if (n->norm->d.Bl.width)
break;
mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG);
break;
@@ -754,7 +762,7 @@ pre_bl(PRE_ARGS)
case (LIST_inset):
/* FALLTHROUGH */
case (LIST_item):
- if (n->data.Bl->width)
+ if (n->norm->d.Bl.width)
mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
break;
default:
@@ -783,13 +791,11 @@ pre_bd(PRE_ARGS)
assert(np);
assert(MDOC_BLOCK == np->type);
assert(MDOC_Bd == np->tok);
- assert(np->data.Bd);
- n->data.Bd = np->data.Bd;
+ NORM_BUMP(n, np);
return(1);
}
- assert(NULL == n->data.Bd);
- n->data.Bd = mandoc_calloc(1, sizeof(struct mdoc_bd));
+ NORM_ALLOC(n);
/* LINTED */
for (i = 0; n->args && i < (int)n->args->argc; i++) {
@@ -820,14 +826,14 @@ pre_bd(PRE_ARGS)
/* NB: this can be empty! */
if (n->args->argv[i].sz) {
offs = n->args->argv[i].value[0];
- dup = (NULL != n->data.Bd->offs);
+ dup = (NULL != n->norm->d.Bd.offs);
break;
}
mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
break;
case (MDOC_Compact):
comp = 1;
- dup = n->data.Bd->comp;
+ dup = n->norm->d.Bd.comp;
break;
default:
abort();
@@ -842,24 +848,24 @@ pre_bd(PRE_ARGS)
/* Make our auxiliary assignments. */
if (offs && ! dup)
- n->data.Bd->offs = offs;
+ n->norm->d.Bd.offs = offs;
if (comp && ! dup)
- n->data.Bd->comp = comp;
+ n->norm->d.Bd.comp = comp;
/* Check whether a type has already been assigned. */
- if (DISP__NONE != dt && n->data.Bd->type != DISP__NONE)
+ if (DISP__NONE != dt && n->norm->d.Bd.type != DISP__NONE)
mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP);
/* Make our type assignment. */
- if (DISP__NONE != dt && n->data.Bd->type == DISP__NONE)
- n->data.Bd->type = dt;
+ if (DISP__NONE != dt && n->norm->d.Bd.type == DISP__NONE)
+ n->norm->d.Bd.type = dt;
}
- if (DISP__NONE == n->data.Bd->type) {
+ if (DISP__NONE == n->norm->d.Bd.type) {
mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE);
- n->data.Bd->type = DISP_ragged;
+ n->norm->d.Bd.type = DISP_ragged;
}
return(1);
@@ -904,8 +910,7 @@ pre_an(PRE_ARGS)
{
int i;
- assert(NULL == n->data.An);
- n->data.An = mandoc_calloc(1, sizeof(struct mdoc_an));
+ NORM_ALLOC(n);
if (NULL == n->args)
return(1);
@@ -915,9 +920,9 @@ pre_an(PRE_ARGS)
n->args->argv[i].pos, MANDOCERR_IGNARGV);
if (MDOC_Split == n->args->argv[0].arg)
- n->data.An->auth = AUTH_split;
+ n->norm->d.An.auth = AUTH_split;
else if (MDOC_Nosplit == n->args->argv[0].arg)
- n->data.An->auth = AUTH_nosplit;
+ n->norm->d.An.auth = AUTH_nosplit;
else
abort();
@@ -999,15 +1004,14 @@ post_bf(POST_ARGS)
assert(np);
assert(MDOC_HEAD == np->type);
assert(MDOC_Bf == np->tok);
- assert(np->data.Bf);
- mdoc->last->data.Bf = np->data.Bf;
+ NORM_BUMP(mdoc->last, np);
return(1);
}
np = mdoc->last;
assert(MDOC_BLOCK == np->parent->type);
assert(MDOC_Bf == np->parent->tok);
- np->data.Bf = mandoc_calloc(1, sizeof(struct mdoc_bf));
+ NORM_ALLOC(np);
/*
* Cannot have both argument and parameter.
@@ -1027,11 +1031,11 @@ post_bf(POST_ARGS)
if (np->parent->args) {
arg = np->parent->args->argv[0].arg;
if (MDOC_Emphasis == arg)
- np->data.Bf->font = FONT_Em;
+ np->norm->d.Bf.font = FONT_Em;
else if (MDOC_Literal == arg)
- np->data.Bf->font = FONT_Li;
+ np->norm->d.Bf.font = FONT_Li;
else if (MDOC_Symbolic == arg)
- np->data.Bf->font = FONT_Sy;
+ np->norm->d.Bf.font = FONT_Sy;
else
abort();
return(1);
@@ -1040,11 +1044,11 @@ post_bf(POST_ARGS)
/* Extract parameter into data. */
if (0 == strcmp(np->child->string, "Em"))
- np->data.Bf->font = FONT_Em;
+ np->norm->d.Bf.font = FONT_Em;
else if (0 == strcmp(np->child->string, "Li"))
- np->data.Bf->font = FONT_Li;
+ np->norm->d.Bf.font = FONT_Li;
else if (0 == strcmp(np->child->string, "Sy"))
- np->data.Bf->font = FONT_Sy;
+ np->norm->d.Bf.font = FONT_Sy;
else
mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE);
@@ -1250,14 +1254,14 @@ post_an(POST_ARGS)
struct mdoc_node *np;
np = mdoc->last;
- if (AUTH__NONE != np->data.An->auth && np->child)
+ if (AUTH__NONE != np->norm->d.An.auth && np->child)
return(eerr_eq0(mdoc));
/*
* FIXME: make this ewarn and make sure that the front-ends
* don't print the arguments.
*/
- if (AUTH__NONE != np->data.An->auth || np->child)
+ if (AUTH__NONE != np->norm->d.An.auth || np->child)
return(1);
mdoc_nmsg(mdoc, np, MANDOCERR_NOARGS);
@@ -1277,8 +1281,7 @@ post_it(POST_ARGS)
return(1);
n = mdoc->last->parent->parent;
- assert(n->data.Bl);
- lt = n->data.Bl->type;
+ lt = n->norm->d.Bl.type;
if (LIST__NONE == lt) {
mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE);
@@ -1317,7 +1320,7 @@ post_it(POST_ARGS)
mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST);
break;
case (LIST_column):
- cols = (int)n->data.Bl->ncols;
+ cols = (int)n->norm->d.Bl.ncols;
assert(NULL == mdoc->last->head->child);
@@ -1361,17 +1364,17 @@ post_bl_block(POST_ARGS)
n = mdoc->last;
- if (LIST_tag == n->data.Bl->type &&
- NULL == n->data.Bl->width) {
+ if (LIST_tag == n->norm->d.Bl.type &&
+ NULL == n->norm->d.Bl.width) {
if ( ! post_bl_block_tag(mdoc))
return(0);
- } else if (NULL != n->data.Bl->width) {
+ } else if (NULL != n->norm->d.Bl.width) {
if ( ! post_bl_block_width(mdoc))
return(0);
} else
return(1);
- assert(n->data.Bl->width);
+ assert(n->norm->d.Bl.width);
return(1);
}
@@ -1395,9 +1398,9 @@ post_bl_block_width(POST_ARGS)
* the macro's width as set in share/tmac/mdoc/doc-common.
*/
- if (0 == strcmp(n->data.Bl->width, "Ds"))
+ if (0 == strcmp(n->norm->d.Bl.width, "Ds"))
width = 6;
- else if (MDOC_MAX == (tok = mdoc_hash_find(n->data.Bl->width)))
+ else if (MDOC_MAX == (tok = mdoc_hash_find(n->norm->d.Bl.width)))
return(1);
else if (0 == (width = mdoc_macro2len(tok))) {
mdoc_nmsg(mdoc, n, MANDOCERR_BADWIDTH);
@@ -1419,7 +1422,7 @@ post_bl_block_width(POST_ARGS)
n->args->argv[i].value[0] = mandoc_strdup(buf);
/* Set our width! */
- n->data.Bl->width = n->args->argv[i].value[0];
+ n->norm->d.Bl.width = n->args->argv[i].value[0];
return(1);
}
@@ -1485,7 +1488,7 @@ post_bl_block_tag(POST_ARGS)
n->args->argv[i].value[0] = mandoc_strdup(buf);
/* Set our width! */
- n->data.Bl->width = n->args->argv[i].value[0];
+ n->norm->d.Bl.width = n->args->argv[i].value[0];
return(1);
}
@@ -1496,7 +1499,7 @@ post_bl_head(POST_ARGS)
struct mdoc_node *np, *nn, *nnp;
int i, j;
- if (LIST_column != mdoc->last->data.Bl->type)
+ if (LIST_column != mdoc->last->norm->d.Bl.type)
/* FIXME: this should be ERROR class... */
return(hwarn_eq0(mdoc));
@@ -1513,7 +1516,7 @@ post_bl_head(POST_ARGS)
* lists, but I'll leave that for another day.
*/
- if (mdoc->last->data.Bl->ncols && mdoc->last->nchild) {
+ if (mdoc->last->norm->d.Bl.ncols && mdoc->last->nchild) {
mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_COLUMNS);
return(0);
} else if (NULL == mdoc->last->child)
@@ -1539,8 +1542,8 @@ post_bl_head(POST_ARGS)
np->args->argv[j].value = mandoc_malloc
((size_t)mdoc->last->nchild * sizeof(char *));
- mdoc->last->data.Bl->ncols = np->args->argv[j].sz;
- mdoc->last->data.Bl->cols = (const char **)np->args->argv[j].value;
+ mdoc->last->norm->d.Bl.ncols = np->args->argv[j].sz;
+ mdoc->last->norm->d.Bl.cols = (const char **)np->args->argv[j].value;
for (i = 0, nn = mdoc->last->child; nn; i++) {
np->args->argv[j].value[i] = nn->string;
@@ -1920,11 +1923,11 @@ pre_par(PRE_ARGS)
if (MDOC_Pp != mdoc->last->tok && MDOC_Lp != mdoc->last->tok)
return(1);
- if (MDOC_Bl == n->tok && n->data.Bl->comp)
+ if (MDOC_Bl == n->tok && n->norm->d.Bl.comp)
return(1);
- if (MDOC_Bd == n->tok && n->data.Bd->comp)
+ if (MDOC_Bd == n->tok && n->norm->d.Bd.comp)
return(1);
- if (MDOC_It == n->tok && n->parent->data.Bl->comp)
+ if (MDOC_It == n->tok && n->parent->norm->d.Bl.comp)
return(1);
mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_IGNPAR);
@@ -1949,10 +1952,9 @@ pre_literal(PRE_ARGS)
mdoc->flags |= MDOC_LITERAL;
break;
case (MDOC_Bd):
- assert(n->data.Bd);
- if (DISP_literal == n->data.Bd->type)
+ if (DISP_literal == n->norm->d.Bd.type)
mdoc->flags |= MDOC_LITERAL;
- if (DISP_unfilled == n->data.Bd->type)
+ if (DISP_unfilled == n->norm->d.Bd.type)
mdoc->flags |= MDOC_LITERAL;
break;
default: