From 390db1686bea8852d19f42029363d12254349a44 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Thu, 8 Oct 2009 23:00:15 +0000 Subject: Consolidated some -man -Tascii functions. Added many -man -Thtml functions (almost complete). --- example.style.css | 3 ++ man_html.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++------ man_term.c | 87 +++++++++++---------------------- mdoc_html.c | 22 ++++----- 4 files changed, 172 insertions(+), 84 deletions(-) diff --git a/example.style.css b/example.style.css index 9488e22b..86505404 100644 --- a/example.style.css +++ b/example.style.css @@ -12,6 +12,7 @@ div.ssec-block { } span.addr { } /* Address (Ad). */ span.arg { font-style: italic; } /* Command argument (Ar). */ span.author { } /* Author name (An). */ +span.bold { font-weight: bold; } /* Generically bold (SB, BI, IB, BR, RB, B). */ span.cmd { font-weight: bold; } /* Command (Cm). */ span.config { font-weight: bold; } /* Config statement (Cd). */ span.define { } /* Defines (Dv). */ @@ -26,6 +27,7 @@ span.flag { font-weight: bold; } /* Flag (Fl, Cm). */ span.fname { font-weight: bold; } /* Function name (Fa, Fn, Rv). */ span.ftype { font-style: italic; } /* Function types (Ft, Fn). */ span.includes { font-weight: bold; } /* Header includes (In). */ +span.italic { font-style: italic; } /* Generically italic (BI, IB, I). */ span.lib { } /* Library (Lb). */ span.lit { font-family: monospace; } /* Literals (Bf -literal). */ span.macro { font-weight: bold; } /* Macro-ish thing (Fd). */ @@ -45,6 +47,7 @@ span.ref-corp { } /* Reference corporate/foreign author (%Q). */ span.ref-rep { } /* Reference report (%R). */ span.ref-title { } /* Reference title (%T). */ span.ref-vol { } /* Reference volume (%V). */ +span.small { font-size: smaller; } /* Generically small (SB, SM). */ span.symb { font-weight: bold; } /* Symbols. */ span.type { font-style: italic; } /* Variable types (Vt). */ span.unix { } /* Unices (Ux, Ox, Nx, Fx, Bx, Bsx, Dx). */ diff --git a/man_html.c b/man_html.c index 557cc070..d42bebb5 100644 --- a/man_html.c +++ b/man_html.c @@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.7 2009/10/07 12:35:23 kristaps Exp $ */ +/* $Id: man_html.c,v 1.8 2009/10/08 23:00:15 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -50,13 +50,19 @@ static void print_man_node(MAN_ARGS); static int a2width(const struct man_node *, struct roffsu *); +static int man_alt_pre(MAN_ARGS); static int man_br_pre(MAN_ARGS); +static int man_ign_pre(MAN_ARGS); +static void man_root_post(MAN_ARGS); +static int man_root_pre(MAN_ARGS); +static int man_B_pre(MAN_ARGS); static int man_HP_pre(MAN_ARGS); +static int man_I_pre(MAN_ARGS); static int man_IP_pre(MAN_ARGS); static int man_PP_pre(MAN_ARGS); -static void man_root_post(MAN_ARGS); -static int man_root_pre(MAN_ARGS); +static int man_SB_pre(MAN_ARGS); static int man_SH_pre(MAN_ARGS); +static int man_SM_pre(MAN_ARGS); static int man_SS_pre(MAN_ARGS); #ifdef __linux__ @@ -75,17 +81,17 @@ static const struct htmlman mans[MAN_MAX] = { { man_PP_pre, NULL }, /* P */ { man_IP_pre, NULL }, /* IP */ { man_HP_pre, NULL }, /* HP */ - { NULL, NULL }, /* SM */ - { NULL, NULL }, /* SB */ - { NULL, NULL }, /* BI */ - { NULL, NULL }, /* IB */ - { NULL, NULL }, /* BR */ - { NULL, NULL }, /* RB */ + { man_SM_pre, NULL }, /* SM */ + { man_SB_pre, NULL }, /* SB */ + { man_alt_pre, NULL }, /* BI */ + { man_alt_pre, NULL }, /* IB */ + { man_alt_pre, NULL }, /* BR */ + { man_alt_pre, NULL }, /* RB */ { NULL, NULL }, /* R */ - { NULL, NULL }, /* B */ - { NULL, NULL }, /* I */ - { NULL, NULL }, /* IR */ - { NULL, NULL }, /* RI */ + { man_B_pre, NULL }, /* B */ + { man_I_pre, NULL }, /* I */ + { man_alt_pre, NULL }, /* IR */ + { man_alt_pre, NULL }, /* RI */ { NULL, NULL }, /* na */ { NULL, NULL }, /* i */ { man_br_pre, NULL }, /* sp */ @@ -94,8 +100,8 @@ static const struct htmlman mans[MAN_MAX] = { { NULL, NULL }, /* r */ { NULL, NULL }, /* RE */ { NULL, NULL }, /* RS */ - { NULL, NULL }, /* DT */ - { NULL, NULL }, /* UC */ + { man_ign_pre, NULL }, /* DT */ + { man_ign_pre, NULL }, /* UC */ }; @@ -368,6 +374,82 @@ man_SH_pre(MAN_ARGS) } +/* ARGSUSED */ +static int +man_alt_pre(MAN_ARGS) +{ + const struct man_node *nn; + struct tag *t; + int i; + struct htmlpair tagi, tagb, *tagp; + + PAIR_CLASS_INIT(&tagi, "italic"); + PAIR_CLASS_INIT(&tagb, "bold"); + + for (i = 0, nn = n->child; nn; nn = nn->next, i++) { + switch (n->tok) { + case (MAN_BI): + tagp = i % 2 ? &tagi : &tagb; + break; + case (MAN_IB): + tagp = i % 2 ? &tagb : &tagi; + break; + case (MAN_RI): + tagp = i % 2 ? &tagi : NULL; + break; + case (MAN_IR): + tagp = i % 2 ? NULL : &tagi; + break; + case (MAN_BR): + tagp = i % 2 ? NULL : &tagb; + break; + case (MAN_RB): + tagp = i % 2 ? &tagb : NULL; + break; + default: + abort(); + /* NOTREACHED */ + } + + if (i) + h->flags |= HTML_NOSPACE; + + if (tagp) { + t = print_otag(h, TAG_SPAN, 1, tagp); + print_man_node(m, nn, h); + print_tagq(h, t); + } else + print_man_node(m, nn, h); + } + + return(0); +} + + +/* ARGSUSED */ +static int +man_SB_pre(MAN_ARGS) +{ + struct htmlpair tag; + + PAIR_CLASS_INIT(&tag, "small bold"); + print_otag(h, TAG_SPAN, 1, &tag); + return(1); +} + + +/* ARGSUSED */ +static int +man_SM_pre(MAN_ARGS) +{ + struct htmlpair tag; + + PAIR_CLASS_INIT(&tag, "small"); + print_otag(h, TAG_SPAN, 1, &tag); + return(1); +} + + /* ARGSUSED */ static int man_SS_pre(MAN_ARGS) @@ -554,3 +636,35 @@ man_HP_pre(MAN_ARGS) return(1); } + +/* ARGSUSED */ +static int +man_B_pre(MAN_ARGS) +{ + struct htmlpair tag; + + PAIR_CLASS_INIT(&tag, "bold"); + print_otag(h, TAG_SPAN, 1, &tag); + return(1); +} + + +/* ARGSUSED */ +static int +man_I_pre(MAN_ARGS) +{ + struct htmlpair tag; + + PAIR_CLASS_INIT(&tag, "italic"); + print_otag(h, TAG_SPAN, 1, &tag); + return(1); +} + + +/* ARGSUSED */ +static int +man_ign_pre(MAN_ARGS) +{ + + return(0); +} diff --git a/man_term.c b/man_term.c index ab720594..5f6923ec 100644 --- a/man_term.c +++ b/man_term.c @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.34 2009/10/07 12:19:39 kristaps Exp $ */ +/* $Id: man_term.c,v 1.35 2009/10/08 23:00:15 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -61,10 +61,8 @@ struct termact { static int pre_B(DECL_ARGS); static int pre_BI(DECL_ARGS); -static int pre_BR(DECL_ARGS); static int pre_HP(DECL_ARGS); static int pre_I(DECL_ARGS); -static int pre_IB(DECL_ARGS); static int pre_IP(DECL_ARGS); static int pre_IR(DECL_ARGS); static int pre_PP(DECL_ARGS); @@ -105,8 +103,8 @@ static const struct termact termacts[MAN_MAX] = { { NULL, NULL }, /* SM */ { pre_B, post_B }, /* SB */ { pre_BI, NULL }, /* BI */ - { pre_IB, NULL }, /* IB */ - { pre_BR, NULL }, /* BR */ + { pre_BI, NULL }, /* IB */ + { pre_RB, NULL }, /* BR */ { pre_RB, NULL }, /* RB */ { NULL, NULL }, /* R */ { pre_B, post_B }, /* B */ @@ -293,30 +291,6 @@ pre_IR(DECL_ARGS) } -/* ARGSUSED */ -static int -pre_IB(DECL_ARGS) -{ - const struct man_node *nn; - int i; - - for (i = 0, nn = n->child; nn; nn = nn->next, i++) { - if (i % 2) - p->bold++; - else - p->under++; - if (i > 0) - p->flags |= TERMP_NOSPACE; - print_node(p, mt, nn, m); - if (i % 2) - p->bold--; - else - p->under--; - } - return(0); -} - - /* ARGSUSED */ static int pre_RB(DECL_ARGS) @@ -325,12 +299,19 @@ pre_RB(DECL_ARGS) int i; for (i = 0, nn = n->child; nn; nn = nn->next, i++) { - if (i % 2) + if (i % 2 && MAN_RB == n->tok) p->bold++; + else if ( ! (i % 2) && MAN_RB != n->tok) + p->bold++; + if (i > 0) p->flags |= TERMP_NOSPACE; + print_node(p, mt, nn, m); - if (i % 2) + + if (i % 2 && MAN_RB == n->tok) + p->bold--; + else if ( ! (i % 2) && MAN_RB != n->tok) p->bold--; } return(0); @@ -357,45 +338,35 @@ pre_RI(DECL_ARGS) } -/* ARGSUSED */ -static int -pre_BR(DECL_ARGS) -{ - const struct man_node *nn; - int i; - - for (i = 0, nn = n->child; nn; nn = nn->next, i++) { - if ( ! (i % 2)) - p->bold++; - if (i > 0) - p->flags |= TERMP_NOSPACE; - print_node(p, mt, nn, m); - if ( ! (i % 2)) - p->bold--; - } - return(0); -} - - /* ARGSUSED */ static int pre_BI(DECL_ARGS) { - const struct man_node *nn; - int i; + const struct man_node *nn; + int i; for (i = 0, nn = n->child; nn; nn = nn->next, i++) { - if (i % 2) + if (i % 2 && MAN_BI == n->tok) p->under++; - else + else if (i % 2) p->bold++; - if (i > 0) + else if (MAN_BI == n->tok) + p->bold++; + else + p->under++; + + if (i) p->flags |= TERMP_NOSPACE; print_node(p, mt, nn, m); - if (i % 2) + + if (i % 2 && MAN_BI == n->tok) p->under--; - else + else if (i % 2) p->bold--; + else if (MAN_BI == n->tok) + p->bold--; + else + p->under--; } return(0); } diff --git a/mdoc_html.c b/mdoc_html.c index 5704a560..0bb3ea57 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.26 2009/10/07 15:06:03 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.27 2009/10/08 23:00:15 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -49,16 +49,11 @@ static void print_mdoc_nodelist(MDOC_ARGS); static void a2width(const char *, struct roffsu *); static void a2offs(const char *, struct roffsu *); + static int a2list(const struct mdoc_node *); static void mdoc_root_post(MDOC_ARGS); static int mdoc_root_pre(MDOC_ARGS); -static int mdoc_it_block_pre(MDOC_ARGS, int, - struct roffsu *, int, - struct roffsu *); -static int mdoc_it_head_pre(MDOC_ARGS, int, - struct roffsu *); -static int mdoc_it_body_pre(MDOC_ARGS, int); static void mdoc__x_post(MDOC_ARGS); static int mdoc__x_pre(MDOC_ARGS); @@ -96,6 +91,11 @@ static void mdoc_fo_post(MDOC_ARGS); static int mdoc_fo_pre(MDOC_ARGS); static int mdoc_ic_pre(MDOC_ARGS); static int mdoc_in_pre(MDOC_ARGS); +static int mdoc_it_block_pre(MDOC_ARGS, int, int, + struct roffsu *, struct roffsu *); +static int mdoc_it_head_pre(MDOC_ARGS, int, + struct roffsu *); +static int mdoc_it_body_pre(MDOC_ARGS, int); static int mdoc_it_pre(MDOC_ARGS); static int mdoc_lb_pre(MDOC_ARGS); static int mdoc_li_pre(MDOC_ARGS); @@ -855,8 +855,8 @@ mdoc_bx_pre(MDOC_ARGS) /* ARGSUSED */ static int -mdoc_it_block_pre(MDOC_ARGS, int type, struct roffsu *offs, - int comp, struct roffsu *width) +mdoc_it_block_pre(MDOC_ARGS, int type, int comp, + struct roffsu *offs, struct roffsu *width) { struct htmlpair tag; const struct mdoc_node *nn; @@ -1081,8 +1081,8 @@ mdoc_it_pre(MDOC_ARGS) if (MDOC_BODY == n->type) return(mdoc_it_body_pre(m, n, h, type)); if (MDOC_BLOCK == n->type) - return(mdoc_it_block_pre(m, n, h, type, - &offs, comp, &width)); + return(mdoc_it_block_pre(m, n, h, type, comp, + &offs, &width)); /* Override column widths. */ -- cgit v1.2.3-56-ge451