aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-07-02 12:54:33 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-07-02 12:54:33 +0000
commit93a6626101a75d16172b09ad5201078daf1c61b3 (patch)
tree85382023409b33ff7c59b10f3eb8e2545165ef84
parent966c1bc6fc8cf98168d9d17b82cc2e7b414d2e15 (diff)
downloadmandoc-93a6626101a75d16172b09ad5201078daf1c61b3.tar.gz
mandoc-93a6626101a75d16172b09ad5201078daf1c61b3.tar.zst
mandoc-93a6626101a75d16172b09ad5201078daf1c61b3.zip
Stash `Bf' parameters into struct mdoc_bf.
-rw-r--r--TODO1
-rw-r--r--main.c4
-rw-r--r--mandoc.h5
-rw-r--r--mdoc.c11
-rw-r--r--mdoc.h16
-rw-r--r--mdoc_html.c47
-rw-r--r--mdoc_term.c21
-rw-r--r--mdoc_validate.c80
8 files changed, 107 insertions, 78 deletions
diff --git a/TODO b/TODO
index d027403d..70a45ef3 100644
--- a/TODO
+++ b/TODO
@@ -105,7 +105,6 @@ Several areas can be cleaned up to make mandoc even faster. These are
that they need not be recalculated between front- and back-ends (also
reduces code size and complexity):
`Bl -column' pointer
- `Bf' font type
- improve hashing mechanism for macros (quite important: performance)
diff --git a/main.c b/main.c
index 2f5ff8dd..b0f6769b 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.95 2010/07/01 15:38:56 schwarze Exp $ */
+/* $Id: main.c,v 1.96 2010/07/02 12:54:33 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -153,13 +153,13 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"no title in document",
"missing list type",
"missing display type",
+ "missing font type",
"line argument(s) will be lost",
"body argument(s) will be lost",
"generic fatal error",
"column syntax is inconsistent",
- "missing font type",
"displays may not be nested",
"unsupported display type",
"blocks badly nested",
diff --git a/mandoc.h b/mandoc.h
index 948fb078..94af3741 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.14 2010/07/01 15:38:56 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.15 2010/07/02 12:54:33 kristaps Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -81,6 +81,7 @@ enum mandocerr {
MANDOCERR_NOTITLE, /* no title in document */
MANDOCERR_LISTTYPE, /* missing list type */
MANDOCERR_DISPTYPE, /* missing display type */
+ MANDOCERR_FONTTYPE, /* missing font type */
MANDOCERR_ARGSLOST, /* line argument(s) will be lost */
MANDOCERR_BODYLOST, /* body argument(s) will be lost */
@@ -88,8 +89,6 @@ enum mandocerr {
MANDOCERR_COLUMNS, /* column syntax is inconsistent */
/* FIXME: this should be a MANDOCERR_ERROR */
- MANDOCERR_FONTTYPE, /* missing font type */
- /* FIXME: this should be a MANDOCERR_ERROR */
MANDOCERR_NESTEDDISP, /* displays may not be nested */
MANDOCERR_BADDISP, /* unsupported display type */
MANDOCERR_SCOPEFATAL, /* blocks badly nested */
diff --git a/mdoc.c b/mdoc.c
index 038e0fbd..205bb485 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.155 2010/07/01 23:01:47 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.156 2010/07/02 12:54:33 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -518,12 +518,21 @@ 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 (p->string)
free(p->string);
diff --git a/mdoc.h b/mdoc.h
index a2083fbe..224ad1ba 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.97 2010/07/02 10:53:28 kristaps Exp $ */
+/* $Id: mdoc.h,v 1.98 2010/07/02 12:54:33 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -279,6 +279,13 @@ enum mdoc_disp {
DISP_literal
};
+enum mdoc_font {
+ FONT__NONE = 0,
+ FONT_Em,
+ FONT_Li,
+ FONT_Sy
+};
+
struct mdoc_bd {
const char *offs; /* -offset */
enum mdoc_disp type; /* -ragged, etc. */
@@ -292,6 +299,10 @@ struct mdoc_bl {
int comp; /* -compact */
};
+struct mdoc_bf {
+ enum mdoc_font font; /* font */
+};
+
/* Node in AST. */
struct mdoc_node {
struct mdoc_node *parent; /* parent AST node */
@@ -321,8 +332,9 @@ struct mdoc_node {
enum mdoc_endbody end; /* BODY */
union {
- struct mdoc_bl *Bl;
struct mdoc_bd *Bd;
+ struct mdoc_bf *Bf;
+ struct mdoc_bl *Bl;
} data;
};
diff --git a/mdoc_html.c b/mdoc_html.c
index b3839870..9f63019d 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.91 2010/07/02 10:42:46 kristaps Exp $ */
+/* $Id: mdoc_html.c,v 1.92 2010/07/02 12:54:33 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -2015,46 +2015,33 @@ mdoc_ap_pre(MDOC_ARGS)
static int
mdoc_bf_pre(MDOC_ARGS)
{
- int i;
struct htmlpair tag[2];
struct roffsu su;
if (MDOC_HEAD == n->type)
return(0);
- else if (MDOC_BLOCK != n->type)
+ else if (MDOC_BODY != n->type)
return(1);
- PAIR_CLASS_INIT(&tag[0], "lit");
-
- if (n->head->child) {
- if ( ! strcmp("Em", n->head->child->string))
- PAIR_CLASS_INIT(&tag[0], "emph");
- else if ( ! strcmp("Sy", n->head->child->string))
- PAIR_CLASS_INIT(&tag[0], "symb");
- else if ( ! strcmp("Li", n->head->child->string))
- PAIR_CLASS_INIT(&tag[0], "lit");
- } else {
- for (i = 0; n->args && i < (int)n->args->argc; i++)
- switch (n->args->argv[i].arg) {
- case (MDOC_Symbolic):
- PAIR_CLASS_INIT(&tag[0], "symb");
- break;
- case (MDOC_Literal):
- PAIR_CLASS_INIT(&tag[0], "lit");
- break;
- case (MDOC_Emphasis):
- PAIR_CLASS_INIT(&tag[0], "emph");
- break;
- default:
- break;
- }
- }
+ assert(n->data.Bf);
- /* FIXME: div's have spaces stripped--we want them. */
+ if (FONT_Em == n->data.Bf->font)
+ PAIR_CLASS_INIT(&tag[0], "emph");
+ else if (FONT_Sy == n->data.Bf->font)
+ PAIR_CLASS_INIT(&tag[0], "symb");
+ else if (FONT_Li == n->data.Bf->font)
+ PAIR_CLASS_INIT(&tag[0], "lit");
+ else
+ PAIR_CLASS_INIT(&tag[0], "none");
+ /*
+ * We want this to be inline-formatted, but needs to be div to
+ * accept block children.
+ */
bufcat_style(h, "display", "inline");
SCALE_HS_INIT(&su, 1);
- bufcat_su(h, "margin-right", &su);
+ /* Needs a left-margin for spacing. */
+ bufcat_su(h, "margin-left", &su);
PAIR_STYLE_INIT(&tag[1], h);
print_otag(h, TAG_DIV, 2, tag);
return(1);
diff --git a/mdoc_term.c b/mdoc_term.c
index 6a174bee..62414099 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.166 2010/07/02 10:53:28 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.167 2010/07/02 12:54:33 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -2057,30 +2057,19 @@ termp_fo_post(DECL_ARGS)
static int
termp_bf_pre(DECL_ARGS)
{
- const struct mdoc_node *nn;
if (MDOC_HEAD == n->type)
return(0);
else if (MDOC_BLOCK != n->type)
return(1);
- if (NULL == (nn = n->head->child)) {
- if (arg_hasattr(MDOC_Emphasis, n))
- term_fontpush(p, TERMFONT_UNDER);
- else if (arg_hasattr(MDOC_Symbolic, n))
- term_fontpush(p, TERMFONT_BOLD);
- else
- term_fontpush(p, TERMFONT_NONE);
+ assert(n->data.Bf);
- return(1);
- }
-
- assert(MDOC_TEXT == nn->type);
- if (0 == strcmp("Em", nn->string))
+ if (FONT_Em == n->data.Bf->font)
term_fontpush(p, TERMFONT_UNDER);
- else if (0 == strcmp("Sy", nn->string))
+ else if (FONT_Sy == n->data.Bf->font)
term_fontpush(p, TERMFONT_BOLD);
- else
+ else
term_fontpush(p, TERMFONT_NONE);
return(1);
diff --git a/mdoc_validate.c b/mdoc_validate.c
index d9de3f9f..6e839e78 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.104 2010/07/01 22:56:17 kristaps Exp $ */
+/* $Id: mdoc_validate.c,v 1.105 2010/07/02 12:54:33 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -931,38 +931,72 @@ pre_dd(PRE_ARGS)
static int
post_bf(POST_ARGS)
{
- char *p;
- struct mdoc_node *head;
+ struct mdoc_node *np;
+ int arg;
- if (MDOC_BLOCK != mdoc->last->type)
- return(1);
+ /*
+ * Unlike other data pointers, these are "housed" by the HEAD
+ * element, which contains the goods.
+ */
- head = mdoc->last->head;
+ if (MDOC_HEAD != mdoc->last->type) {
+ if (ENDBODY_NOT != mdoc->last->end) {
+ assert(mdoc->last->pending);
+ np = mdoc->last->pending->parent->head;
+ } else if (MDOC_BLOCK != mdoc->last->type) {
+ np = mdoc->last->parent->head;
+ } else
+ np = mdoc->last->head;
- if (mdoc->last->args && head->child) {
- /* FIXME: this should provide a default. */
- mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SYNTARGVCOUNT);
- return(0);
- } else if (mdoc->last->args)
+ assert(np);
+ assert(MDOC_HEAD == np->type);
+ assert(MDOC_Bf == np->tok);
+ assert(np->data.Bf);
+ mdoc->last->data.Bf = np->data.Bf;
return(1);
+ }
+
+ np = mdoc->last;
+ np->data.Bf = mandoc_calloc(1, sizeof(struct mdoc_bf));
+
+ /*
+ * Cannot have both argument and parameter.
+ * If neither is specified, let it through with a warning.
+ */
- if (NULL == head->child || MDOC_TEXT != head->child->type) {
- /* FIXME: this should provide a default. */
- mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SYNTARGVCOUNT);
+ if (np->args && np->child) {
+ mdoc_nmsg(mdoc, np, MANDOCERR_SYNTARGVCOUNT);
return(0);
+ } else if (NULL == np->args && NULL == np->child)
+ return(mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE));
+
+ /* Extract argument into data. */
+
+ if (np->args) {
+ arg = np->args->argv[0].arg;
+ if (MDOC_Emphasis == arg)
+ np->data.Bf->font = FONT_Em;
+ else if (MDOC_Literal == arg)
+ np->data.Bf->font = FONT_Li;
+ else if (MDOC_Symbolic == arg)
+ np->data.Bf->font = FONT_Sy;
+ else
+ abort();
+ return(1);
}
- p = head->child->string;
+ /* Extract parameter into data. */
- if (0 == strcmp(p, "Em"))
- return(1);
- else if (0 == strcmp(p, "Li"))
- return(1);
- else if (0 == strcmp(p, "Sy"))
- return(1);
+ if (0 == strcmp(np->child->string, "Em"))
+ np->data.Bf->font = FONT_Em;
+ else if (0 == strcmp(np->child->string, "Li"))
+ np->data.Bf->font = FONT_Li;
+ else if (0 == strcmp(np->child->string, "Sy"))
+ np->data.Bf->font = FONT_Sy;
+ else if ( ! mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE))
+ return(0);
- mdoc_nmsg(mdoc, head, MANDOCERR_FONTTYPE);
- return(0);
+ return(1);
}