=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc_term.c,v retrieving revision 1.64 retrieving revision 1.65 diff -c -r1.64 -r1.65 *** src/usr.bin/mandoc/mdoc_term.c 2009/12/23 22:30:17 1.64 --- src/usr.bin/mandoc/mdoc_term.c 2009/12/24 02:08:14 1.65 *************** *** 1,4 **** ! /* $Id: mdoc_term.c,v 1.64 2009/12/23 22:30:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * --- 1,4 ---- ! /* $Id: mdoc_term.c,v 1.65 2009/12/24 02:08:14 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * *************** *** 59,67 **** static void print_bvspace(struct termp *, const struct mdoc_node *, const struct mdoc_node *); ! static void print_node(DECL_ARGS); ! static void print_head(DECL_ARGS); ! static void print_body(DECL_ARGS); static void print_foot(DECL_ARGS); static void termp____post(DECL_ARGS); --- 59,67 ---- static void print_bvspace(struct termp *, const struct mdoc_node *, const struct mdoc_node *); ! static void print_mdoc_node(DECL_ARGS); ! static void print_mdoc_head(DECL_ARGS); ! static void print_mdoc_nodelist(DECL_ARGS); static void print_foot(DECL_ARGS); static void termp____post(DECL_ARGS); *************** *** 111,116 **** --- 111,117 ---- static int termp_ft_pre(DECL_ARGS); static int termp_in_pre(DECL_ARGS); static int termp_it_pre(DECL_ARGS); + static int termp_li_pre(DECL_ARGS); static int termp_lk_pre(DECL_ARGS); static int termp_nd_pre(DECL_ARGS); static int termp_nm_pre(DECL_ARGS); *************** *** 162,168 **** { termp_ft_pre, termp_ft_post }, /* Ft */ { termp_bold_pre, NULL }, /* Ic */ { termp_in_pre, termp_in_post }, /* In */ ! { NULL, NULL }, /* Li */ { termp_nd_pre, NULL }, /* Nd */ { termp_nm_pre, NULL }, /* Nm */ { termp_op_pre, termp_op_post }, /* Op */ --- 163,169 ---- { termp_ft_pre, termp_ft_post }, /* Ft */ { termp_bold_pre, NULL }, /* Ic */ { termp_in_pre, termp_in_post }, /* In */ ! { termp_li_pre, NULL }, /* Li */ { termp_nd_pre, NULL }, /* Nd */ { termp_nm_pre, NULL }, /* Nm */ { termp_op_pre, termp_op_post }, /* Op */ *************** *** 278,313 **** n = mdoc_node(mdoc); m = mdoc_meta(mdoc); ! print_head(p, NULL, m, n); if (n->child) ! print_body(p, NULL, m, n->child); print_foot(p, NULL, m, n); } static void ! print_body(DECL_ARGS) { ! print_node(p, pair, m, n); if (n->next) ! print_body(p, pair, m, n->next); } /* ARGSUSED */ static void ! print_node(DECL_ARGS) { ! int chld, bold, under; struct termpair npair; size_t offset, rmargin; chld = 1; offset = p->offset; rmargin = p->rmargin; ! bold = p->bold; ! under = p->under; memset(&npair, 0, sizeof(struct termpair)); npair.ppair = pair; --- 279,314 ---- n = mdoc_node(mdoc); m = mdoc_meta(mdoc); ! print_mdoc_head(p, NULL, m, n); if (n->child) ! print_mdoc_nodelist(p, NULL, m, n->child); print_foot(p, NULL, m, n); } static void ! print_mdoc_nodelist(DECL_ARGS) { ! print_mdoc_node(p, pair, m, n); if (n->next) ! print_mdoc_nodelist(p, pair, m, n->next); } /* ARGSUSED */ static void ! print_mdoc_node(DECL_ARGS) { ! int chld; ! const void *font; struct termpair npair; size_t offset, rmargin; chld = 1; offset = p->offset; rmargin = p->rmargin; ! font = term_fontq(p); memset(&npair, 0, sizeof(struct termpair)); npair.ppair = pair; *************** *** 317,334 **** chld = (*termacts[n->tok].pre)(p, &npair, m, n); } else term_word(p, n->string); if (chld && n->child) ! print_body(p, &npair, m, n->child); ! /* ! * XXX - if bold/under were to span scopes, this wouldn't be ! * possible, but because decoration is always in-scope, we can ! * get away with this. ! */ - p->bold = bold; - p->under = under; - if (MDOC_TEXT != n->type) if (termacts[n->tok].post) (*termacts[n->tok].post)(p, &npair, m, n); --- 318,329 ---- chld = (*termacts[n->tok].pre)(p, &npair, m, n); } else term_word(p, n->string); + if (chld && n->child) ! print_mdoc_nodelist(p, &npair, m, n->child); ! term_fontpopq(p, font); if (MDOC_TEXT != n->type) if (termacts[n->tok].post) (*termacts[n->tok].post)(p, &npair, m, n); *************** *** 344,349 **** --- 339,346 ---- { char buf[DATESIZ], os[BUFSIZ]; + term_fontrepl(p, TERMFONT_NONE); + /* * Output the footer in new-groff style, that is, three columns * with the middle being the manual date and flanking columns *************** *** 385,394 **** } - /* FIXME: put in utility library. */ /* ARGSUSED */ static void ! print_head(DECL_ARGS) { char buf[BUFSIZ], title[BUFSIZ]; --- 382,390 ---- } /* ARGSUSED */ static void ! print_mdoc_head(DECL_ARGS) { char buf[BUFSIZ], title[BUFSIZ]; *************** *** 774,780 **** switch (type) { case (MDOC_Diag): if (MDOC_HEAD == n->type) ! p->bold++; break; default: break; --- 770,776 ---- switch (type) { case (MDOC_Diag): if (MDOC_HEAD == n->type) ! term_fontpush(p, TERMFONT_BOLD); break; default: break; *************** *** 912,927 **** if (MDOC_HEAD == n->type) switch (type) { case (MDOC_Bullet): ! p->bold++; term_word(p, "\\[bu]"); ! p->bold--; break; case (MDOC_Dash): /* FALLTHROUGH */ case (MDOC_Hyphen): ! p->bold++; term_word(p, "\\(hy"); ! p->bold--; break; case (MDOC_Enum): (pair->ppair->ppair->count)++; --- 908,923 ---- if (MDOC_HEAD == n->type) switch (type) { case (MDOC_Bullet): ! term_fontpush(p, TERMFONT_BOLD); term_word(p, "\\[bu]"); ! term_fontpop(p); break; case (MDOC_Dash): /* FALLTHROUGH */ case (MDOC_Hyphen): ! term_fontpush(p, TERMFONT_BOLD); term_word(p, "\\(hy"); ! term_fontpop(p); break; case (MDOC_Enum): (pair->ppair->ppair->count)++; *************** *** 1003,1009 **** if (SEC_SYNOPSIS == n->sec) term_newln(p); ! p->bold++; if (NULL == n->child) term_word(p, m->name); return(1); --- 999,1007 ---- if (SEC_SYNOPSIS == n->sec) term_newln(p); ! ! term_fontpush(p, TERMFONT_BOLD); ! if (NULL == n->child) term_word(p, m->name); return(1); *************** *** 1015,1021 **** termp_fl_pre(DECL_ARGS) { ! p->bold++; term_word(p, "\\-"); p->flags |= TERMP_NOSPACE; return(1); --- 1013,1019 ---- termp_fl_pre(DECL_ARGS) { ! term_fontpush(p, TERMFONT_BOLD); term_word(p, "\\-"); p->flags |= TERMP_NOSPACE; return(1); *************** *** 1113,1121 **** term_word(p, "The"); for (nn = n->child; nn; nn = nn->next) { ! p->bold++; term_word(p, nn->string); ! p->bold--; p->flags |= TERMP_NOSPACE; if (nn->next && NULL == nn->next->next) term_word(p, "(), and"); --- 1111,1119 ---- term_word(p, "The"); for (nn = n->child; nn; nn = nn->next) { ! term_fontpush(p, TERMFONT_BOLD); term_word(p, nn->string); ! term_fontpop(p); p->flags |= TERMP_NOSPACE; if (nn->next && NULL == nn->next->next) term_word(p, "(), and"); *************** *** 1133,1141 **** term_word(p, "the value 0 if successful; otherwise the value " "-1 is returned and the global variable"); ! p->under++; term_word(p, "errno"); ! p->under--; term_word(p, "is set to indicate the error."); --- 1131,1139 ---- term_word(p, "the value 0 if successful; otherwise the value " "-1 is returned and the global variable"); ! term_fontpush(p, TERMFONT_UNDER); term_word(p, "errno"); ! term_fontpop(p); term_word(p, "is set to indicate the error."); *************** *** 1152,1160 **** term_word(p, "The"); for (nn = n->child; nn; nn = nn->next) { ! p->bold++; term_word(p, nn->string); ! p->bold--; p->flags |= TERMP_NOSPACE; if (nn->next && NULL == nn->next->next) term_word(p, ", and"); --- 1150,1158 ---- term_word(p, "The"); for (nn = n->child; nn; nn = nn->next) { ! term_fontpush(p, TERMFONT_BOLD); term_word(p, nn->string); ! term_fontpop(p); p->flags |= TERMP_NOSPACE; if (nn->next && NULL == nn->next->next) term_word(p, ", and"); *************** *** 1256,1262 **** termp_bold_pre(DECL_ARGS) { ! p->bold++; return(1); } --- 1254,1260 ---- termp_bold_pre(DECL_ARGS) { ! term_fontpush(p, TERMFONT_BOLD); return(1); } *************** *** 1290,1296 **** term_vspace(p); break; case (MDOC_HEAD): ! p->bold++; break; case (MDOC_BODY): p->offset = INDENT; --- 1288,1294 ---- term_vspace(p); break; case (MDOC_HEAD): ! term_fontpush(p, TERMFONT_BOLD); break; case (MDOC_BODY): p->offset = INDENT; *************** *** 1425,1431 **** if (SEC_SYNOPSIS == n->sec) if (n->prev && MDOC_Fo == n->prev->tok) term_vspace(p); ! p->under++; return(1); } --- 1423,1430 ---- if (SEC_SYNOPSIS == n->sec) if (n->prev && MDOC_Fo == n->prev->tok) term_vspace(p); ! ! term_fontpush(p, TERMFONT_UNDER); return(1); } *************** *** 1446,1462 **** { const struct mdoc_node *nn; ! p->bold++; term_word(p, n->child->string); ! p->bold--; p->flags |= TERMP_NOSPACE; term_word(p, "("); for (nn = n->child->next; nn; nn = nn->next) { ! p->under++; term_word(p, nn->string); ! p->under--; if (nn->next) term_word(p, ","); } --- 1445,1462 ---- { const struct mdoc_node *nn; ! term_fontpush(p, TERMFONT_BOLD); term_word(p, n->child->string); ! term_fontpop(p); p->flags |= TERMP_NOSPACE; term_word(p, "("); for (nn = n->child->next; nn; nn = nn->next) { ! term_fontpush(p, TERMFONT_UNDER); term_word(p, nn->string); ! term_fontpop(p); ! if (nn->next) term_word(p, ","); } *************** *** 1487,1500 **** const struct mdoc_node *nn; if (n->parent->tok != MDOC_Fo) { ! p->under++; return(1); } for (nn = n->child; nn; nn = nn->next) { ! p->under++; term_word(p, nn->string); ! p->under--; if (nn->next) term_word(p, ","); } --- 1487,1501 ---- const struct mdoc_node *nn; if (n->parent->tok != MDOC_Fo) { ! term_fontpush(p, TERMFONT_UNDER); return(1); } for (nn = n->child; nn; nn = nn->next) { ! term_fontpush(p, TERMFONT_UNDER); term_word(p, nn->string); ! term_fontpop(p); ! if (nn->next) term_word(p, ","); } *************** *** 1556,1562 **** for (nn = n->child; nn; nn = nn->next) { p->flags |= TERMP_NOSPACE; ! print_node(p, pair, m, nn); if (NULL == nn->next) continue; if (nn->prev && nn->prev->line < nn->line) --- 1557,1563 ---- for (nn = n->child; nn; nn = nn->next) { p->flags |= TERMP_NOSPACE; ! print_mdoc_node(p, pair, m, nn); if (NULL == nn->next) continue; if (nn->prev && nn->prev->line < nn->line) *************** *** 1710,1716 **** term_vspace(p); break; case (MDOC_HEAD): ! p->bold++; p->offset = HALFINDENT; break; default: --- 1711,1717 ---- term_vspace(p); break; case (MDOC_HEAD): ! term_fontpush(p, TERMFONT_BOLD); p->offset = HALFINDENT; break; default: *************** *** 1736,1742 **** termp_cd_pre(DECL_ARGS) { ! p->bold++; term_newln(p); return(1); } --- 1737,1743 ---- termp_cd_pre(DECL_ARGS) { ! term_fontpush(p, TERMFONT_BOLD); term_newln(p); return(1); } *************** *** 1747,1753 **** termp_in_pre(DECL_ARGS) { ! p->bold++; if (SEC_SYNOPSIS == n->sec) term_word(p, "#include"); --- 1748,1754 ---- termp_in_pre(DECL_ARGS) { ! term_fontpush(p, TERMFONT_BOLD); if (SEC_SYNOPSIS == n->sec) term_word(p, "#include"); *************** *** 1762,1771 **** termp_in_post(DECL_ARGS) { ! p->bold++; p->flags |= TERMP_NOSPACE; term_word(p, ">"); ! p->bold--; if (SEC_SYNOPSIS != n->sec) return; --- 1763,1772 ---- termp_in_post(DECL_ARGS) { ! term_fontpush(p, TERMFONT_BOLD); p->flags |= TERMP_NOSPACE; term_word(p, ">"); ! term_fontpop(p); if (SEC_SYNOPSIS != n->sec) return; *************** *** 1897,1908 **** } else if (MDOC_HEAD != n->type) return(1); ! p->bold++; for (nn = n->child; nn; nn = nn->next) { assert(MDOC_TEXT == nn->type); term_word(p, nn->string); } ! p->bold--; return(0); } --- 1898,1909 ---- } else if (MDOC_HEAD != n->type) return(1); ! term_fontpush(p, TERMFONT_BOLD); for (nn = n->child; nn; nn = nn->next) { assert(MDOC_TEXT == nn->type); term_word(p, nn->string); } ! term_fontpop(p); return(0); } *************** *** 1936,1953 **** if (NULL == (nn = n->head->child)) { if (arg_hasattr(MDOC_Emphasis, n)) ! p->under++; else if (arg_hasattr(MDOC_Symbolic, n)) ! p->bold++; return(1); } assert(MDOC_TEXT == nn->type); if (0 == strcmp("Em", nn->string)) ! p->under++; else if (0 == strcmp("Sy", nn->string)) ! p->bold++; return(1); } --- 1937,1958 ---- 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); return(1); } assert(MDOC_TEXT == nn->type); if (0 == strcmp("Em", nn->string)) ! term_fontpush(p, TERMFONT_UNDER); else if (0 == strcmp("Sy", nn->string)) ! term_fontpush(p, TERMFONT_BOLD); ! else ! term_fontpush(p, TERMFONT_NONE); return(1); } *************** *** 2003,2028 **** /* ARGSUSED */ static int termp_lk_pre(DECL_ARGS) { const struct mdoc_node *nn; ! p->under++; nn = n->child; if (NULL == nn->next) return(1); term_word(p, nn->string); ! p->under--; p->flags |= TERMP_NOSPACE; term_word(p, ":"); ! p->bold++; for (nn = nn->next; nn; nn = nn->next) term_word(p, nn->string); ! p->bold--; return(0); } --- 2008,2043 ---- /* ARGSUSED */ static int + termp_li_pre(DECL_ARGS) + { + + term_fontpush(p, TERMFONT_NONE); + return(1); + } + + + /* ARGSUSED */ + static int termp_lk_pre(DECL_ARGS) { const struct mdoc_node *nn; ! term_fontpush(p, TERMFONT_UNDER); nn = n->child; if (NULL == nn->next) return(1); term_word(p, nn->string); ! term_fontpop(p); p->flags |= TERMP_NOSPACE; term_word(p, ":"); ! term_fontpush(p, TERMFONT_BOLD); for (nn = nn->next; nn; nn = nn->next) term_word(p, nn->string); ! term_fontpop(p); return(0); } *************** *** 2033,2039 **** termp_under_pre(DECL_ARGS) { ! p->under++; return(1); } --- 2048,2054 ---- termp_under_pre(DECL_ARGS) { ! term_fontpush(p, TERMFONT_UNDER); return(1); }