-/* $Id: mdoc_term.c,v 1.332 2016/10/09 18:16:56 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.343 2017/02/06 03:44:58 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012-2016 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
*
* Permission to use, copy, modify, and distribute this software for any
static void termp_quote_post(DECL_ARGS);
static void termp_sh_post(DECL_ARGS);
static void termp_ss_post(DECL_ARGS);
+static void termp_xx_post(DECL_ARGS);
static int termp__a_pre(DECL_ARGS);
static int termp__t_pre(DECL_ARGS);
static int termp_bk_pre(DECL_ARGS);
static int termp_bl_pre(DECL_ARGS);
static int termp_bold_pre(DECL_ARGS);
-static int termp_bt_pre(DECL_ARGS);
-static int termp_bx_pre(DECL_ARGS);
static int termp_cd_pre(DECL_ARGS);
static int termp_d1_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_ex_pre(DECL_ARGS);
static int termp_fa_pre(DECL_ARGS);
static int termp_ns_pre(DECL_ARGS);
static int termp_quote_pre(DECL_ARGS);
static int termp_rs_pre(DECL_ARGS);
-static int termp_rv_pre(DECL_ARGS);
static int termp_sh_pre(DECL_ARGS);
static int termp_skip_pre(DECL_ARGS);
static int termp_sm_pre(DECL_ARGS);
static int termp_sp_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_under_pre(DECL_ARGS);
-static int termp_ud_pre(DECL_ARGS);
static int termp_vt_pre(DECL_ARGS);
static int termp_xr_pre(DECL_ARGS);
static int termp_xx_pre(DECL_ARGS);
{ termp_quote_pre, termp_quote_post }, /* Op */
{ termp_ft_pre, NULL }, /* Ot */
{ termp_under_pre, NULL }, /* Pa */
- { termp_rv_pre, NULL }, /* Rv */
+ { termp_ex_pre, NULL }, /* Rv */
{ NULL, NULL }, /* St */
{ termp_under_pre, NULL }, /* Va */
{ termp_vt_pre, NULL }, /* Vt */
{ termp_bf_pre, NULL }, /* Bf */
{ termp_quote_pre, termp_quote_post }, /* Bo */
{ termp_quote_pre, termp_quote_post }, /* Bq */
- { termp_xx_pre, NULL }, /* Bsx */
- { termp_bx_pre, NULL }, /* Bx */
+ { termp_xx_pre, termp_xx_post }, /* Bsx */
+ { NULL, NULL }, /* Bx */
{ termp_skip_pre, NULL }, /* Db */
{ NULL, NULL }, /* Dc */
{ termp_quote_pre, termp_quote_post }, /* Do */
{ termp_quote_pre, termp_quote_post }, /* Dq */
{ NULL, NULL }, /* Ec */ /* FIXME: no space */
{ NULL, NULL }, /* Ef */
- { termp_under_pre, NULL }, /* Em */
+ { termp_em_pre, NULL }, /* Em */
{ termp_eo_pre, termp_eo_post }, /* Eo */
- { termp_xx_pre, NULL }, /* Fx */
+ { termp_xx_pre, termp_xx_post }, /* Fx */
{ termp_bold_pre, NULL }, /* Ms */
{ termp_li_pre, NULL }, /* No */
{ termp_ns_pre, NULL }, /* Ns */
- { termp_xx_pre, NULL }, /* Nx */
- { termp_xx_pre, NULL }, /* Ox */
+ { termp_xx_pre, termp_xx_post }, /* Nx */
+ { termp_xx_pre, termp_xx_post }, /* Ox */
{ NULL, NULL }, /* Pc */
{ NULL, termp_pf_post }, /* Pf */
{ termp_quote_pre, termp_quote_post }, /* Po */
{ termp_quote_pre, termp_quote_post }, /* Sq */
{ termp_sm_pre, NULL }, /* Sm */
{ termp_under_pre, NULL }, /* Sx */
- { termp_bold_pre, NULL }, /* Sy */
+ { termp_sy_pre, NULL }, /* Sy */
{ NULL, NULL }, /* Tn */
- { termp_xx_pre, NULL }, /* Ux */
+ { termp_xx_pre, termp_xx_post }, /* Ux */
{ NULL, NULL }, /* Xc */
{ NULL, NULL }, /* Xo */
{ termp_fo_pre, termp_fo_post }, /* Fo */
{ NULL, NULL }, /* Oc */
{ termp_bk_pre, termp_bk_post }, /* Bk */
{ NULL, NULL }, /* Ek */
- { termp_bt_pre, NULL }, /* Bt */
+ { NULL, NULL }, /* Bt */
{ NULL, NULL }, /* Hf */
{ termp_under_pre, NULL }, /* Fr */
- { termp_ud_pre, NULL }, /* Ud */
+ { NULL, NULL }, /* Ud */
{ NULL, termp_lb_post }, /* Lb */
{ termp_sp_pre, NULL }, /* Lp */
{ termp_lk_pre, NULL }, /* Lk */
{ NULL, termp____post }, /* %C */
{ termp_skip_pre, NULL }, /* Es */
{ termp_quote_pre, termp_quote_post }, /* En */
- { termp_xx_pre, NULL }, /* Dx */
+ { termp_xx_pre, termp_xx_post }, /* Dx */
{ NULL, termp____post }, /* %Q */
{ termp_sp_pre, NULL }, /* br */
{ termp_sp_pre, NULL }, /* sp */
{
struct roff_node *n;
struct termp *p;
+ size_t save_defindent;
p = (struct termp *)arg;
p->overstep = 0;
n = n->next;
}
} else {
+ save_defindent = p->defindent;
if (p->defindent == 0)
p->defindent = 5;
term_begin(p, print_mdoc_head, print_mdoc_foot,
&mdoc->meta);
+ while (n != NULL && n->flags & NODE_NOPRT)
+ n = n->next;
if (n != NULL) {
if (n->tok != MDOC_Sh)
term_vspace(p);
print_mdoc_nodelist(p, NULL, &mdoc->meta, n);
}
term_end(p);
+ p->defindent = save_defindent;
}
}
struct termpair npair;
size_t offset, rmargin;
+ if (n->flags & NODE_NOPRT)
+ return;
+
chld = 1;
offset = p->offset;
rmargin = p->rmargin;
- n->flags &= ~MDOC_ENDED;
+ n->flags &= ~NODE_ENDED;
n->prev_font = p->fonti;
memset(&npair, 0, sizeof(struct termpair));
* invoked in a prior line, revert it to PREKEEP.
*/
- if (p->flags & TERMP_KEEP && n->flags & MDOC_LINE) {
+ if (p->flags & TERMP_KEEP && n->flags & NODE_LINE) {
p->flags &= ~TERMP_KEEP;
p->flags |= TERMP_PREKEEP;
}
switch (n->type) {
case ROFFT_TEXT:
- if (' ' == *n->string && MDOC_LINE & n->flags)
+ if (' ' == *n->string && NODE_LINE & n->flags)
term_newln(p);
- if (MDOC_DELIMC & n->flags)
+ if (NODE_DELIMC & n->flags)
p->flags |= TERMP_NOSPACE;
term_word(p, n->string);
- if (MDOC_DELIMO & n->flags)
+ if (NODE_DELIMO & n->flags)
p->flags |= TERMP_NOSPACE;
break;
case ROFFT_EQN:
- if ( ! (n->flags & MDOC_LINE))
+ if ( ! (n->flags & NODE_LINE))
p->flags |= TERMP_NOSPACE;
term_eqn(p, n->eqn);
- if (n->next != NULL && ! (n->next->flags & MDOC_LINE))
+ if (n->next != NULL && ! (n->next->flags & NODE_LINE))
p->flags |= TERMP_NOSPACE;
break;
case ROFFT_TBL:
case ROFFT_EQN:
break;
default:
- if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)
+ if ( ! termacts[n->tok].post || NODE_ENDED & n->flags)
break;
(void)(*termacts[n->tok].post)(p, &npair, meta, n);
* that it must not call the post handler again.
*/
if (ENDBODY_NOT != n->end)
- n->body->flags |= MDOC_ENDED;
+ n->body->flags |= NODE_ENDED;
/*
* End of line terminating an implicit block
break;
}
- if (MDOC_EOS & n->flags)
+ if (NODE_EOS & n->flags)
p->flags |= TERMP_SENTENCE;
if (MDOC_ll != n->tok) {
/* Do not vspace directly after Ss/Sh. */
nn = n;
+ while (nn->prev != NULL && nn->prev->flags & NODE_NOPRT)
+ nn = nn->prev;
while (nn->prev == NULL) {
do {
nn = nn->parent;
return 1;
}
- if (NULL == n->child && NULL == meta->name)
+ if (n->child == NULL)
return 0;
if (n->type == ROFFT_HEAD)
}
term_fontpush(p, TERMFONT_BOLD);
- if (NULL == n->child)
- term_word(p, meta->name);
return 1;
}
if (!(n->child == NULL &&
(n->next == NULL ||
n->next->type == ROFFT_TEXT ||
- n->next->flags & MDOC_LINE)))
+ n->next->flags & NODE_LINE)))
p->flags |= TERMP_NOSPACE;
return 1;
termp_ns_pre(DECL_ARGS)
{
- if ( ! (MDOC_LINE & n->flags))
+ if ( ! (NODE_LINE & n->flags))
p->flags |= TERMP_NOSPACE;
return 1;
}
return 1;
}
-static int
-termp_rv_pre(DECL_ARGS)
-{
- struct roff_node *nch;
-
- term_newln(p);
-
- if (n->child != NULL) {
- term_word(p, "The");
-
- for (nch = n->child; nch != NULL; nch = nch->next) {
- term_fontpush(p, TERMFONT_BOLD);
- term_word(p, nch->string);
- term_fontpop(p);
-
- p->flags |= TERMP_NOSPACE;
- term_word(p, "()");
-
- if (nch->next == NULL)
- continue;
-
- if (nch->prev != NULL || nch->next->next != NULL) {
- p->flags |= TERMP_NOSPACE;
- term_word(p, ",");
- }
- if (nch->next->next == NULL)
- term_word(p, "and");
- }
-
- if (n->child != NULL && n->child->next != NULL)
- term_word(p, "functions return");
- else
- term_word(p, "function returns");
-
- term_word(p, "the value\\~0 if successful;");
- } else
- term_word(p, "Upon successful completion,"
- " the value\\~0 is returned;");
-
- term_word(p, "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.");
- p->flags |= TERMP_SENTENCE;
-
- return 0;
-}
-
static int
termp_ex_pre(DECL_ARGS)
{
- struct roff_node *nch;
-
term_newln(p);
- term_word(p, "The");
-
- for (nch = n->child; nch != NULL; nch = nch->next) {
- term_fontpush(p, TERMFONT_BOLD);
- term_word(p, nch->string);
- term_fontpop(p);
-
- if (nch->next == NULL)
- continue;
-
- if (nch->prev != NULL || nch->next->next != NULL) {
- p->flags |= TERMP_NOSPACE;
- term_word(p, ",");
- }
-
- if (nch->next->next == NULL)
- term_word(p, "and");
- }
-
- if (n->child != NULL && n->child->next != NULL)
- term_word(p, "utilities exit\\~0");
- else
- term_word(p, "utility exits\\~0");
-
- term_word(p, "on success, and\\~>0 if an error occurs.");
-
- p->flags |= TERMP_SENTENCE;
- return 0;
+ return 1;
}
static int
* Obviously, if we're not in a SYNOPSIS or no prior macros
* exist, do nothing.
*/
- if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
+ if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
return;
/*
}
}
-static int
-termp_bt_pre(DECL_ARGS)
-{
-
- term_word(p, "is currently in beta test.");
- p->flags |= TERMP_SENTENCE;
- return 0;
-}
-
static void
termp_lb_post(DECL_ARGS)
{
- if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
+ if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags)
term_newln(p);
}
-static int
-termp_ud_pre(DECL_ARGS)
-{
-
- term_word(p, "currently under development.");
- p->flags |= TERMP_SENTENCE;
- return 0;
-}
-
static int
termp_d1_pre(DECL_ARGS)
{
termp_ft_pre(DECL_ARGS)
{
- /* NB: MDOC_LINE does not effect this! */
+ /* NB: NODE_LINE does not effect this! */
synopsis_pre(p, n);
term_fontpush(p, TERMFONT_UNDER);
return 1;
size_t rmargin = 0;
int pretty;
- pretty = MDOC_SYNPRETTY & n->flags;
+ pretty = NODE_SYNPRETTY & n->flags;
synopsis_pre(p, n);
term_word(p, n->string);
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);
if (pretty) {
break;
}
if (p->flags & TERMP_NONEWLINE ||
- (nn->next && ! (nn->next->flags & MDOC_LINE)))
+ (nn->next && ! (nn->next->flags & NODE_LINE)))
continue;
term_flushln(p);
p->flags |= TERMP_NOSPACE;
}
static int
-termp_bx_pre(DECL_ARGS)
+termp_xx_pre(DECL_ARGS)
{
-
- if (NULL != (n = n->child)) {
- term_word(p, n->string);
- p->flags |= TERMP_NOSPACE;
- term_word(p, "BSD");
- } else {
- term_word(p, "BSD");
- return 0;
- }
-
- if (NULL != (n = n->next)) {
- p->flags |= TERMP_NOSPACE;
- term_word(p, "-");
- p->flags |= TERMP_NOSPACE;
- term_word(p, n->string);
- }
-
- return 0;
+ if ((n->aux = p->flags & TERMP_PREKEEP) == 0)
+ p->flags |= TERMP_PREKEEP;
+ return 1;
}
-static int
-termp_xx_pre(DECL_ARGS)
+static void
+termp_xx_post(DECL_ARGS)
{
- const char *pp;
- int flags;
-
- pp = NULL;
- switch (n->tok) {
- case MDOC_Bsx:
- pp = "BSD/OS";
- break;
- case MDOC_Dx:
- pp = "DragonFly";
- break;
- case MDOC_Fx:
- pp = "FreeBSD";
- break;
- case MDOC_Nx:
- pp = "NetBSD";
- break;
- case MDOC_Ox:
- pp = "OpenBSD";
- break;
- case MDOC_Ux:
- pp = "UNIX";
- break;
- default:
- abort();
- }
-
- term_word(p, pp);
- if (n->child) {
- flags = p->flags;
- p->flags |= TERMP_KEEP;
- term_word(p, n->child->string);
- p->flags = flags;
- }
- return 0;
+ if (n->aux == 0)
+ p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
}
static void
termp_pf_post(DECL_ARGS)
{
- if ( ! (n->next == NULL || n->next->flags & MDOC_LINE))
+ if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
p->flags |= TERMP_NOSPACE;
}
static int
termp_ss_pre(DECL_ARGS)
{
+ struct roff_node *nn;
switch (n->type) {
case ROFFT_BLOCK:
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);
break;
case ROFFT_HEAD:
synopsis_pre(p, n);
- if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
+ if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags) {
term_fontpush(p, TERMFONT_BOLD);
term_word(p, "#include");
term_word(p, "<");
termp_in_post(DECL_ARGS)
{
- if (MDOC_SYNPRETTY & n->flags)
+ if (NODE_SYNPRETTY & n->flags)
term_fontpush(p, TERMFONT_BOLD);
p->flags |= TERMP_NOSPACE;
term_word(p, ">");
- if (MDOC_SYNPRETTY & n->flags)
+ if (NODE_SYNPRETTY & n->flags)
term_fontpop(p);
}
size_t rmargin = 0;
int pretty;
- pretty = MDOC_SYNPRETTY & n->flags;
+ pretty = NODE_SYNPRETTY & n->flags;
if (n->type == ROFFT_BLOCK) {
synopsis_pre(p, n);
p->flags |= TERMP_NOSPACE;
term_word(p, ")");
- if (MDOC_SYNPRETTY & n->flags) {
+ if (NODE_SYNPRETTY & n->flags) {
p->flags |= TERMP_NOSPACE;
term_word(p, ";");
term_flushln(p);
termp_li_pre(DECL_ARGS)
{
+ termp_tag_pre(p, pair, meta, n);
term_fontpush(p, TERMFONT_NONE);
return 1;
}
return 1;
}
+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)
{
if (n->child != NULL &&
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_Xo &&
n->parent->parent->prev == NULL &&