diff options
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | mandoc.h | 3 | ||||
-rw-r--r-- | mdoc.c | 9 | ||||
-rw-r--r-- | mdoc.h | 14 | ||||
-rw-r--r-- | mdoc_html.c | 45 | ||||
-rw-r--r-- | mdoc_term.c | 19 | ||||
-rw-r--r-- | mdoc_validate.c | 78 |
8 files changed, 100 insertions, 71 deletions
@@ -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) @@ -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", @@ -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 */ @@ -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); @@ -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 067d1a46..e88f202e 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -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 642eda34..6ab8bb9c 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -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 7e4d2d32..4f060978 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -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); } |