version 1.330, 2015/10/12 15:29:35 |
version 1.337, 2017/01/10 12:53:07 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012-2016 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de> |
* Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
Line 95 static int termp_bx_pre(DECL_ARGS); |
|
Line 95 static int termp_bx_pre(DECL_ARGS); |
|
static int termp_cd_pre(DECL_ARGS); |
static int termp_cd_pre(DECL_ARGS); |
static int termp_d1_pre(DECL_ARGS); |
static int termp_d1_pre(DECL_ARGS); |
static int termp_eo_pre(DECL_ARGS); |
static int termp_eo_pre(DECL_ARGS); |
|
static int termp_em_pre(DECL_ARGS); |
static int termp_er_pre(DECL_ARGS); |
static int termp_er_pre(DECL_ARGS); |
static int termp_ex_pre(DECL_ARGS); |
static int termp_ex_pre(DECL_ARGS); |
static int termp_fa_pre(DECL_ARGS); |
static int termp_fa_pre(DECL_ARGS); |
Line 119 static int termp_skip_pre(DECL_ARGS); |
|
Line 120 static int termp_skip_pre(DECL_ARGS); |
|
static int termp_sm_pre(DECL_ARGS); |
static int termp_sm_pre(DECL_ARGS); |
static int termp_sp_pre(DECL_ARGS); |
static int termp_sp_pre(DECL_ARGS); |
static int termp_ss_pre(DECL_ARGS); |
static int termp_ss_pre(DECL_ARGS); |
|
static int termp_sy_pre(DECL_ARGS); |
static int termp_tag_pre(DECL_ARGS); |
static int termp_tag_pre(DECL_ARGS); |
static int termp_under_pre(DECL_ARGS); |
static int termp_under_pre(DECL_ARGS); |
static int termp_ud_pre(DECL_ARGS); |
static int termp_ud_pre(DECL_ARGS); |
Line 195 static const struct termact termacts[MDOC_MAX] = { |
|
Line 197 static const struct termact termacts[MDOC_MAX] = { |
|
{ termp_quote_pre, termp_quote_post }, /* Dq */ |
{ termp_quote_pre, termp_quote_post }, /* Dq */ |
{ NULL, NULL }, /* Ec */ /* FIXME: no space */ |
{ NULL, NULL }, /* Ec */ /* FIXME: no space */ |
{ NULL, NULL }, /* Ef */ |
{ NULL, NULL }, /* Ef */ |
{ termp_under_pre, NULL }, /* Em */ |
{ termp_em_pre, NULL }, /* Em */ |
{ termp_eo_pre, termp_eo_post }, /* Eo */ |
{ termp_eo_pre, termp_eo_post }, /* Eo */ |
{ termp_xx_pre, NULL }, /* Fx */ |
{ termp_xx_pre, NULL }, /* Fx */ |
{ termp_bold_pre, NULL }, /* Ms */ |
{ termp_bold_pre, NULL }, /* Ms */ |
Line 218 static const struct termact termacts[MDOC_MAX] = { |
|
Line 220 static const struct termact termacts[MDOC_MAX] = { |
|
{ termp_quote_pre, termp_quote_post }, /* Sq */ |
{ termp_quote_pre, termp_quote_post }, /* Sq */ |
{ termp_sm_pre, NULL }, /* Sm */ |
{ termp_sm_pre, NULL }, /* Sm */ |
{ termp_under_pre, NULL }, /* Sx */ |
{ termp_under_pre, NULL }, /* Sx */ |
{ termp_bold_pre, NULL }, /* Sy */ |
{ termp_sy_pre, NULL }, /* Sy */ |
{ NULL, NULL }, /* Tn */ |
{ NULL, NULL }, /* Tn */ |
{ termp_xx_pre, NULL }, /* Ux */ |
{ termp_xx_pre, NULL }, /* Ux */ |
{ NULL, NULL }, /* Xc */ |
{ NULL, NULL }, /* Xc */ |
Line 283 terminal_mdoc(void *arg, const struct roff_man *mdoc) |
|
Line 285 terminal_mdoc(void *arg, const struct roff_man *mdoc) |
|
p->defindent = 5; |
p->defindent = 5; |
term_begin(p, print_mdoc_head, print_mdoc_foot, |
term_begin(p, print_mdoc_head, print_mdoc_foot, |
&mdoc->meta); |
&mdoc->meta); |
|
while (n != NULL && n->flags & NODE_NOPRT) |
|
n = n->next; |
if (n != NULL) { |
if (n != NULL) { |
if (n->tok != MDOC_Sh) |
if (n->tok != MDOC_Sh) |
term_vspace(p); |
term_vspace(p); |
Line 309 print_mdoc_node(DECL_ARGS) |
|
Line 313 print_mdoc_node(DECL_ARGS) |
|
struct termpair npair; |
struct termpair npair; |
size_t offset, rmargin; |
size_t offset, rmargin; |
|
|
|
if (n->flags & NODE_NOPRT) |
|
return; |
|
|
chld = 1; |
chld = 1; |
offset = p->offset; |
offset = p->offset; |
rmargin = p->rmargin; |
rmargin = p->rmargin; |
Line 357 print_mdoc_node(DECL_ARGS) |
|
Line 364 print_mdoc_node(DECL_ARGS) |
|
break; |
break; |
default: |
default: |
if (termacts[n->tok].pre && |
if (termacts[n->tok].pre && |
(n->end == ENDBODY_NOT || n->nchild)) |
(n->end == ENDBODY_NOT || n->child != NULL)) |
chld = (*termacts[n->tok].pre) |
chld = (*termacts[n->tok].pre) |
(p, &npair, meta, n); |
(p, &npair, meta, n); |
break; |
break; |
Line 562 print_bvspace(struct termp *p, |
|
Line 569 print_bvspace(struct termp *p, |
|
/* Do not vspace directly after Ss/Sh. */ |
/* Do not vspace directly after Ss/Sh. */ |
|
|
nn = n; |
nn = n; |
|
while (nn->prev != NULL && nn->prev->flags & NODE_NOPRT) |
|
nn = nn->prev; |
while (nn->prev == NULL) { |
while (nn->prev == NULL) { |
do { |
do { |
nn = nn->parent; |
nn = nn->parent; |
|
|
termp_ll_pre(DECL_ARGS) |
termp_ll_pre(DECL_ARGS) |
{ |
{ |
|
|
term_setwidth(p, n->nchild ? n->child->string : NULL); |
term_setwidth(p, n->child != NULL ? n->child->string : NULL); |
return 0; |
return 0; |
} |
} |
|
|
Line 631 termp_it_pre(DECL_ARGS) |
|
Line 640 termp_it_pre(DECL_ARGS) |
|
width = term_len(p, 2); |
width = term_len(p, 2); |
break; |
break; |
case LIST_hang: |
case LIST_hang: |
|
case LIST_tag: |
width = term_len(p, 8); |
width = term_len(p, 8); |
break; |
break; |
case LIST_column: |
case LIST_column: |
case LIST_tag: |
|
width = term_len(p, 10); |
width = term_len(p, 10); |
break; |
break; |
default: |
default: |
Line 731 termp_it_pre(DECL_ARGS) |
|
Line 740 termp_it_pre(DECL_ARGS) |
|
term_word(p, "\\ \\ "); |
term_word(p, "\\ \\ "); |
break; |
break; |
case LIST_inset: |
case LIST_inset: |
if (n->type == ROFFT_BODY && n->parent->head->nchild) |
if (n->type == ROFFT_BODY && n->parent->head->child != NULL) |
term_word(p, "\\ "); |
term_word(p, "\\ "); |
break; |
break; |
default: |
default: |
Line 1039 termp_fl_pre(DECL_ARGS) |
|
Line 1048 termp_fl_pre(DECL_ARGS) |
|
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
term_word(p, "\\-"); |
term_word(p, "\\-"); |
|
|
if ( ! (n->nchild == 0 && |
if (!(n->child == NULL && |
(n->next == NULL || |
(n->next == NULL || |
n->next->type == ROFFT_TEXT || |
n->next->type == ROFFT_TEXT || |
n->next->flags & MDOC_LINE))) |
n->next->flags & MDOC_LINE))) |
Line 1106 termp_rs_pre(DECL_ARGS) |
|
Line 1115 termp_rs_pre(DECL_ARGS) |
|
static int |
static int |
termp_rv_pre(DECL_ARGS) |
termp_rv_pre(DECL_ARGS) |
{ |
{ |
int nchild; |
struct roff_node *nch; |
|
|
term_newln(p); |
term_newln(p); |
|
|
nchild = n->nchild; |
if (n->child != NULL) { |
if (nchild > 0) { |
|
term_word(p, "The"); |
term_word(p, "The"); |
|
|
for (n = n->child; n; n = n->next) { |
for (nch = n->child; nch != NULL; nch = nch->next) { |
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
term_word(p, n->string); |
term_word(p, nch->string); |
term_fontpop(p); |
term_fontpop(p); |
|
|
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_word(p, "()"); |
term_word(p, "()"); |
|
|
if (n->next == NULL) |
if (nch->next == NULL) |
continue; |
continue; |
|
|
if (nchild > 2) { |
if (nch->prev != NULL || nch->next->next != NULL) { |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_word(p, ","); |
term_word(p, ","); |
} |
} |
if (n->next->next == NULL) |
if (nch->next->next == NULL) |
term_word(p, "and"); |
term_word(p, "and"); |
} |
} |
|
|
if (nchild > 1) |
if (n->child != NULL && n->child->next != NULL) |
term_word(p, "functions return"); |
term_word(p, "functions return"); |
else |
else |
term_word(p, "function returns"); |
term_word(p, "function returns"); |
Line 1159 termp_rv_pre(DECL_ARGS) |
|
Line 1167 termp_rv_pre(DECL_ARGS) |
|
static int |
static int |
termp_ex_pre(DECL_ARGS) |
termp_ex_pre(DECL_ARGS) |
{ |
{ |
int nchild; |
struct roff_node *nch; |
|
|
term_newln(p); |
term_newln(p); |
term_word(p, "The"); |
term_word(p, "The"); |
|
|
nchild = n->nchild; |
for (nch = n->child; nch != NULL; nch = nch->next) { |
for (n = n->child; n; n = n->next) { |
|
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
term_word(p, n->string); |
term_word(p, nch->string); |
term_fontpop(p); |
term_fontpop(p); |
|
|
if (nchild > 2 && n->next) { |
if (nch->next == NULL) |
|
continue; |
|
|
|
if (nch->prev != NULL || nch->next->next != NULL) { |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_word(p, ","); |
term_word(p, ","); |
} |
} |
|
|
if (n->next && NULL == n->next->next) |
if (nch->next->next == NULL) |
term_word(p, "and"); |
term_word(p, "and"); |
} |
} |
|
|
if (nchild > 1) |
if (n->child != NULL && n->child->next != NULL) |
term_word(p, "utilities exit\\~0"); |
term_word(p, "utilities exit\\~0"); |
else |
else |
term_word(p, "utility exits\\~0"); |
term_word(p, "utility exits\\~0"); |
Line 1459 termp_fn_pre(DECL_ARGS) |
|
Line 1469 termp_fn_pre(DECL_ARGS) |
|
term_word(p, n->string); |
term_word(p, n->string); |
term_fontpop(p); |
term_fontpop(p); |
|
|
if (n->sec == SEC_DESCRIPTION) |
if (n->sec == SEC_DESCRIPTION || n->sec == SEC_CUSTOM) |
tag_put(n->string, ++fn_prio, p->line); |
tag_put(n->string, ++fn_prio, p->line); |
|
|
if (pretty) { |
if (pretty) { |
Line 1715 termp_pf_post(DECL_ARGS) |
|
Line 1725 termp_pf_post(DECL_ARGS) |
|
static int |
static int |
termp_ss_pre(DECL_ARGS) |
termp_ss_pre(DECL_ARGS) |
{ |
{ |
|
struct roff_node *nn; |
|
|
switch (n->type) { |
switch (n->type) { |
case ROFFT_BLOCK: |
case ROFFT_BLOCK: |
term_newln(p); |
term_newln(p); |
if (n->prev) |
for (nn = n->prev; nn != NULL; nn = nn->prev) |
|
if ((nn->flags & NODE_NOPRT) == 0) |
|
break; |
|
if (nn != NULL) |
term_vspace(p); |
term_vspace(p); |
break; |
break; |
case ROFFT_HEAD: |
case ROFFT_HEAD: |
Line 1838 termp_quote_pre(DECL_ARGS) |
|
Line 1852 termp_quote_pre(DECL_ARGS) |
|
switch (n->tok) { |
switch (n->tok) { |
case MDOC_Ao: |
case MDOC_Ao: |
case MDOC_Aq: |
case MDOC_Aq: |
term_word(p, n->nchild == 1 && |
term_word(p, n->child != NULL && n->child->next == NULL && |
n->child->tok == MDOC_Mt ? "<" : "\\(la"); |
n->child->tok == MDOC_Mt ? "<" : "\\(la"); |
break; |
break; |
case MDOC_Bro: |
case MDOC_Bro: |
Line 1895 termp_quote_post(DECL_ARGS) |
|
Line 1909 termp_quote_post(DECL_ARGS) |
|
switch (n->tok) { |
switch (n->tok) { |
case MDOC_Ao: |
case MDOC_Ao: |
case MDOC_Aq: |
case MDOC_Aq: |
term_word(p, n->nchild == 1 && |
term_word(p, n->child != NULL && n->child->next == NULL && |
n->child->tok == MDOC_Mt ? ">" : "\\(ra"); |
n->child->tok == MDOC_Mt ? ">" : "\\(ra"); |
break; |
break; |
case MDOC_Bro: |
case MDOC_Bro: |
|
|
termp_li_pre(DECL_ARGS) |
termp_li_pre(DECL_ARGS) |
{ |
{ |
|
|
|
termp_tag_pre(p, pair, meta, n); |
term_fontpush(p, TERMFONT_NONE); |
term_fontpush(p, TERMFONT_NONE); |
return 1; |
return 1; |
} |
} |
Line 2159 termp_bk_pre(DECL_ARGS) |
|
Line 2174 termp_bk_pre(DECL_ARGS) |
|
case ROFFT_HEAD: |
case ROFFT_HEAD: |
return 0; |
return 0; |
case ROFFT_BODY: |
case ROFFT_BODY: |
if (n->parent->args || 0 == n->prev->nchild) |
if (n->parent->args != NULL || n->prev->child == NULL) |
p->flags |= TERMP_PREKEEP; |
p->flags |= TERMP_PREKEEP; |
break; |
break; |
default: |
default: |
Line 2217 termp_under_pre(DECL_ARGS) |
|
Line 2232 termp_under_pre(DECL_ARGS) |
|
} |
} |
|
|
static int |
static int |
|
termp_em_pre(DECL_ARGS) |
|
{ |
|
if (n->child != NULL && |
|
n->child->type == ROFFT_TEXT) |
|
tag_put(n->child->string, 0, p->line); |
|
term_fontpush(p, TERMFONT_UNDER); |
|
return 1; |
|
} |
|
|
|
static int |
|
termp_sy_pre(DECL_ARGS) |
|
{ |
|
if (n->child != NULL && |
|
n->child->type == ROFFT_TEXT) |
|
tag_put(n->child->string, 0, p->line); |
|
term_fontpush(p, TERMFONT_BOLD); |
|
return 1; |
|
} |
|
|
|
static int |
termp_er_pre(DECL_ARGS) |
termp_er_pre(DECL_ARGS) |
{ |
{ |
|
|
Line 2234 termp_tag_pre(DECL_ARGS) |
|
Line 2269 termp_tag_pre(DECL_ARGS) |
|
|
|
if (n->child != NULL && |
if (n->child != NULL && |
n->child->type == ROFFT_TEXT && |
n->child->type == ROFFT_TEXT && |
n->prev == NULL && |
(n->prev == NULL || |
|
(n->prev->type == ROFFT_TEXT && |
|
strcmp(n->prev->string, "|") == 0)) && |
(n->parent->tok == MDOC_It || |
(n->parent->tok == MDOC_It || |
(n->parent->tok == MDOC_Xo && |
(n->parent->tok == MDOC_Xo && |
n->parent->parent->prev == NULL && |
n->parent->parent->prev == NULL && |