From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id o62CsX8g031707 for ; Fri, 2 Jul 2010 08:54:34 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id o62CsXdQ024956; Fri, 2 Jul 2010 08:54:33 -0400 (EDT) Date: Fri, 2 Jul 2010 08:54:33 -0400 (EDT) Message-Id: <201007021254.o62CsXdQ024956@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Stash `Bf' parameters into struct mdoc_bf. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Stash `Bf' parameters into struct mdoc_bf. Modified Files: -------------- mdocml: TODO main.c mandoc.h mdoc.c mdoc.h mdoc_html.c mdoc_term.c mdoc_validate.c Revision Data ------------- Index: mdoc_html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v retrieving revision 1.91 retrieving revision 1.92 diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.91 -r1.92 --- mdoc_html.c +++ 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"); + assert(n->data.Bf); - 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; - } - } - - /* 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); Index: mdoc.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v retrieving revision 1.155 retrieving revision 1.156 diff -Lmdoc.c -Lmdoc.c -u -p -r1.155 -r1.156 --- mdoc.c +++ mdoc.c @@ -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); Index: mandoc.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v retrieving revision 1.14 retrieving revision 1.15 diff -Lmandoc.h -Lmandoc.h -u -p -r1.14 -r1.15 --- mandoc.h +++ mandoc.h @@ -81,14 +81,13 @@ 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 */ MANDOCERR_FATAL, /* ===== end of fatal errors ===== */ 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 */ Index: main.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v retrieving revision 1.95 retrieving revision 1.96 diff -Lmain.c -Lmain.c -u -p -r1.95 -r1.96 --- main.c +++ main.c @@ -153,13 +153,13 @@ static const char * const mandocerrs[MAN "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", Index: TODO =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/TODO,v retrieving revision 1.20 retrieving revision 1.21 diff -LTODO -LTODO -u -p -r1.20 -r1.21 --- TODO +++ TODO @@ -105,7 +105,6 @@ Several areas can be cleaned up to make 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) Index: mdoc_validate.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v retrieving revision 1.104 retrieving revision 1.105 diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.104 -r1.105 --- mdoc_validate.c +++ 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) + /* + * Unlike other data pointers, these are "housed" by the HEAD + * element, which contains the goods. + */ + + 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; + + 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); + } - head = mdoc->last->head; + np = mdoc->last; + np->data.Bf = mandoc_calloc(1, sizeof(struct mdoc_bf)); - 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) - return(1); + /* + * 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); } Index: mdoc.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v retrieving revision 1.97 retrieving revision 1.98 diff -Lmdoc.h -Lmdoc.h -u -p -r1.97 -r1.98 --- mdoc.h +++ mdoc.h @@ -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; }; Index: mdoc_term.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v retrieving revision 1.166 retrieving revision 1.167 diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.166 -r1.167 --- mdoc_term.c +++ 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); -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv