-/* $Id: mdoc_term.c,v 1.346 2017/02/17 19:15:41 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.353 2017/05/05 02:06:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
static int termp_xr_pre(DECL_ARGS);
static int termp_xx_pre(DECL_ARGS);
-static const struct termact termacts[MDOC_MAX] = {
- { termp_ap_pre, NULL }, /* Ap */
+static const struct termact __termacts[MDOC_MAX - MDOC_Dd] = {
{ NULL, NULL }, /* Dd */
{ NULL, NULL }, /* Dt */
{ NULL, NULL }, /* Os */
{ termp_it_pre, termp_it_post }, /* It */
{ termp_under_pre, NULL }, /* Ad */
{ termp_an_pre, NULL }, /* An */
+ { termp_ap_pre, NULL }, /* Ap */
{ termp_under_pre, NULL }, /* Ar */
{ termp_cd_pre, NULL }, /* Cd */
{ termp_bold_pre, NULL }, /* Cm */
{ termp_quote_pre, termp_quote_post }, /* En */
{ termp_xx_pre, termp_xx_post }, /* Dx */
{ NULL, termp____post }, /* %Q */
- { termp_sp_pre, NULL }, /* br */
{ termp_sp_pre, NULL }, /* sp */
{ NULL, termp____post }, /* %U */
{ NULL, NULL }, /* Ta */
{ termp_ll_pre, NULL }, /* ll */
};
+static const struct termact *const termacts = __termacts - MDOC_Dd;
static int fn_prio;
+
void
terminal_mdoc(void *arg, const struct roff_man *mdoc)
{
term_tbl(p, n->span);
break;
default:
- if (termacts[n->tok].pre &&
+ if (n->tok < ROFF_MAX) {
+ roff_term_pre(p, n);
+ chld = 0;
+ break;
+ }
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
+ if (termacts[n->tok].pre != NULL &&
(n->end == ENDBODY_NOT || n->child != NULL))
chld = (*termacts[n->tok].pre)
(p, &npair, meta, n);
case ROFFT_EQN:
break;
default:
- if ( ! termacts[n->tok].post || NODE_ENDED & n->flags)
+ if (n->tok < ROFF_MAX ||
+ termacts[n->tok].post == NULL ||
+ n->flags & NODE_ENDED)
break;
(void)(*termacts[n->tok].post)(p, &npair, meta, n);
*/
switch (nn->tok) {
case MDOC_Sm:
- case MDOC_br:
+ case ROFF_br:
case MDOC_sp:
case MDOC_Bl:
case MDOC_D1:
} else
len = 1;
break;
- case MDOC_br:
+ case ROFF_br:
len = 0;
break;
default:
termp_lk_pre(DECL_ARGS)
{
const struct roff_node *link, *descr;
+ int display;
- if (NULL == (link = n->child))
+ if ((link = n->child) == NULL)
return 0;
- if (NULL != (descr = link->next)) {
+ /* Link text. */
+ if ((descr = link->next) != NULL && !(descr->flags & NODE_DELIMC)) {
term_fontpush(p, TERMFONT_UNDER);
- while (NULL != descr) {
+ while (descr != NULL && !(descr->flags & NODE_DELIMC)) {
term_word(p, descr->string);
descr = descr->next;
}
+ term_fontpop(p);
p->flags |= TERMP_NOSPACE;
term_word(p, ":");
- term_fontpop(p);
}
+ /* Link target. */
+ display = term_strlen(p, link->string) >= 26;
+ if (display) {
+ term_newln(p);
+ p->offset += term_len(p, p->defindent + 1);
+ }
term_fontpush(p, TERMFONT_BOLD);
term_word(p, link->string);
term_fontpop(p);
+ /* Trailing punctuation. */
+ while (descr != NULL) {
+ p->flags |= TERMP_NOSPACE;
+ term_word(p, descr->string);
+ descr = descr->next;
+ }
+ if (display)
+ term_newln(p);
return 0;
}