version 1.209, 2011/01/12 10:43:22 |
version 1.232, 2011/07/21 11:34:53 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
|
|
#include "out.h" |
#include "out.h" |
#include "term.h" |
#include "term.h" |
#include "mdoc.h" |
#include "mdoc.h" |
#include "chars.h" |
|
#include "main.h" |
#include "main.h" |
|
|
#define INDENT 5 |
#define INDENT 5 |
Line 73 static void termp_an_post(DECL_ARGS); |
|
Line 72 static void termp_an_post(DECL_ARGS); |
|
static void termp_bd_post(DECL_ARGS); |
static void termp_bd_post(DECL_ARGS); |
static void termp_bk_post(DECL_ARGS); |
static void termp_bk_post(DECL_ARGS); |
static void termp_bl_post(DECL_ARGS); |
static void termp_bl_post(DECL_ARGS); |
static void termp_bx_post(DECL_ARGS); |
|
static void termp_d1_post(DECL_ARGS); |
static void termp_d1_post(DECL_ARGS); |
static void termp_fo_post(DECL_ARGS); |
static void termp_fo_post(DECL_ARGS); |
static void termp_in_post(DECL_ARGS); |
static void termp_in_post(DECL_ARGS); |
Line 95 static int termp_bk_pre(DECL_ARGS); |
|
Line 93 static int termp_bk_pre(DECL_ARGS); |
|
static int termp_bl_pre(DECL_ARGS); |
static int termp_bl_pre(DECL_ARGS); |
static int termp_bold_pre(DECL_ARGS); |
static int termp_bold_pre(DECL_ARGS); |
static int termp_bt_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_cd_pre(DECL_ARGS); |
static int termp_d1_pre(DECL_ARGS); |
static int termp_d1_pre(DECL_ARGS); |
static int termp_ex_pre(DECL_ARGS); |
static int termp_ex_pre(DECL_ARGS); |
Line 187 static const struct termact termacts[MDOC_MAX] = { |
|
Line 186 static const struct termact termacts[MDOC_MAX] = { |
|
{ termp_quote_pre, termp_quote_post }, /* Bo */ |
{ termp_quote_pre, termp_quote_post }, /* Bo */ |
{ termp_quote_pre, termp_quote_post }, /* Bq */ |
{ termp_quote_pre, termp_quote_post }, /* Bq */ |
{ termp_xx_pre, NULL }, /* Bsx */ |
{ termp_xx_pre, NULL }, /* Bsx */ |
{ NULL, termp_bx_post }, /* Bx */ |
{ termp_bx_pre, NULL }, /* Bx */ |
{ NULL, NULL }, /* Db */ |
{ NULL, NULL }, /* Db */ |
{ NULL, NULL }, /* Dc */ |
{ NULL, NULL }, /* Dc */ |
{ termp_quote_pre, termp_quote_post }, /* Do */ |
{ termp_quote_pre, termp_quote_post }, /* Do */ |
Line 265 terminal_mdoc(void *arg, const struct mdoc *mdoc) |
|
Line 264 terminal_mdoc(void *arg, const struct mdoc *mdoc) |
|
p->tabwidth = term_len(p, 5); |
p->tabwidth = term_len(p, 5); |
|
|
if (NULL == p->symtab) |
if (NULL == p->symtab) |
switch (p->enc) { |
p->symtab = mchars_alloc(); |
case (TERMENC_ASCII): |
|
p->symtab = chars_init(CHARS_ASCII); |
|
break; |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
|
} |
|
|
|
n = mdoc_node(mdoc); |
n = mdoc_node(mdoc); |
m = mdoc_meta(mdoc); |
m = mdoc_meta(mdoc); |
Line 312 print_mdoc_node(DECL_ARGS) |
|
Line 304 print_mdoc_node(DECL_ARGS) |
|
|
|
memset(&npair, 0, sizeof(struct termpair)); |
memset(&npair, 0, sizeof(struct termpair)); |
npair.ppair = pair; |
npair.ppair = pair; |
|
|
switch (n->type) { |
|
case (MDOC_TEXT): |
|
if (' ' == *n->string && MDOC_LINE & n->flags) |
|
term_newln(p); |
|
term_word(p, n->string); |
|
break; |
|
case (MDOC_TBL): |
|
term_tbl(p, n->span); |
|
break; |
|
default: |
|
if (termacts[n->tok].pre && ENDBODY_NOT == n->end) |
|
chld = (*termacts[n->tok].pre) |
|
(p, &npair, m, n); |
|
break; |
|
} |
|
|
|
/* |
/* |
* Keeps only work until the end of a line. If a keep was |
* Keeps only work until the end of a line. If a keep was |
Line 359 print_mdoc_node(DECL_ARGS) |
|
Line 335 print_mdoc_node(DECL_ARGS) |
|
(n->parent && MDOC_SYNPRETTY & n->parent->flags))) |
(n->parent && MDOC_SYNPRETTY & n->parent->flags))) |
p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); |
p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); |
|
|
|
/* |
|
* After the keep flags have been set up, we may now |
|
* produce output. Note that some pre-handlers do so. |
|
*/ |
|
|
|
switch (n->type) { |
|
case (MDOC_TEXT): |
|
if (' ' == *n->string && MDOC_LINE & n->flags) |
|
term_newln(p); |
|
if (MDOC_DELIMC & n->flags) |
|
p->flags |= TERMP_NOSPACE; |
|
term_word(p, n->string); |
|
if (MDOC_DELIMO & n->flags) |
|
p->flags |= TERMP_NOSPACE; |
|
break; |
|
case (MDOC_EQN): |
|
/*term_word(p, n->eqn->data);*/ |
|
break; |
|
case (MDOC_TBL): |
|
term_tbl(p, n->span); |
|
break; |
|
default: |
|
if (termacts[n->tok].pre && ENDBODY_NOT == n->end) |
|
chld = (*termacts[n->tok].pre) |
|
(p, &npair, m, n); |
|
break; |
|
} |
|
|
if (chld && n->child) |
if (chld && n->child) |
print_mdoc_nodelist(p, &npair, m, n->child); |
print_mdoc_nodelist(p, &npair, m, n->child); |
|
|
Line 369 print_mdoc_node(DECL_ARGS) |
|
Line 373 print_mdoc_node(DECL_ARGS) |
|
break; |
break; |
case (MDOC_TBL): |
case (MDOC_TBL): |
break; |
break; |
|
case (MDOC_EQN): |
|
break; |
default: |
default: |
if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags) |
if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags) |
break; |
break; |
Line 403 print_mdoc_node(DECL_ARGS) |
|
Line 409 print_mdoc_node(DECL_ARGS) |
|
static void |
static void |
print_mdoc_foot(struct termp *p, const void *arg) |
print_mdoc_foot(struct termp *p, const void *arg) |
{ |
{ |
char buf[DATESIZ], os[BUFSIZ]; |
|
const struct mdoc_meta *m; |
const struct mdoc_meta *m; |
|
|
m = (const struct mdoc_meta *)arg; |
m = (const struct mdoc_meta *)arg; |
Line 418 print_mdoc_foot(struct termp *p, const void *arg) |
|
Line 423 print_mdoc_foot(struct termp *p, const void *arg) |
|
* SYSTEM DATE SYSTEM |
* SYSTEM DATE SYSTEM |
*/ |
*/ |
|
|
time2a(m->date, buf, DATESIZ); |
|
strlcpy(os, m->os, BUFSIZ); |
|
|
|
term_vspace(p); |
term_vspace(p); |
|
|
p->offset = 0; |
p->offset = 0; |
p->rmargin = (p->maxrmargin - |
p->rmargin = (p->maxrmargin - |
term_strlen(p, buf) + term_len(p, 1)) / 2; |
term_strlen(p, m->date) + term_len(p, 1)) / 2; |
p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; |
p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; |
|
|
term_word(p, os); |
term_word(p, m->os); |
term_flushln(p); |
term_flushln(p); |
|
|
p->offset = p->rmargin; |
p->offset = p->rmargin; |
p->rmargin = p->maxrmargin - term_strlen(p, os); |
p->rmargin = p->maxrmargin - term_strlen(p, m->os); |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
|
|
term_word(p, buf); |
term_word(p, m->date); |
term_flushln(p); |
term_flushln(p); |
|
|
p->offset = p->rmargin; |
p->offset = p->rmargin; |
Line 443 print_mdoc_foot(struct termp *p, const void *arg) |
|
Line 445 print_mdoc_foot(struct termp *p, const void *arg) |
|
p->flags &= ~TERMP_NOBREAK; |
p->flags &= ~TERMP_NOBREAK; |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
|
|
term_word(p, os); |
term_word(p, m->os); |
term_flushln(p); |
term_flushln(p); |
|
|
p->offset = 0; |
p->offset = 0; |
Line 521 a2height(const struct termp *p, const char *v) |
|
Line 523 a2height(const struct termp *p, const char *v) |
|
{ |
{ |
struct roffsu su; |
struct roffsu su; |
|
|
|
|
assert(v); |
assert(v); |
if ( ! a2roffsu(v, &su, SCALE_VS)) |
if ( ! a2roffsu(v, &su, SCALE_VS)) |
SCALE_VS_INIT(&su, term_len(p, 1)); |
SCALE_VS_INIT(&su, atoi(v)); |
|
|
return(term_vspan(p, &su)); |
return(term_vspan(p, &su)); |
} |
} |
|
|
termp_ns_pre(DECL_ARGS) |
termp_ns_pre(DECL_ARGS) |
{ |
{ |
|
|
p->flags |= TERMP_NOSPACE; |
if ( ! (MDOC_LINE & n->flags)) |
|
p->flags |= TERMP_NOSPACE; |
return(1); |
return(1); |
} |
} |
|
|
Line 1173 termp_rs_pre(DECL_ARGS) |
|
Line 1177 termp_rs_pre(DECL_ARGS) |
|
static int |
static int |
termp_rv_pre(DECL_ARGS) |
termp_rv_pre(DECL_ARGS) |
{ |
{ |
const struct mdoc_node *nn; |
int nchild; |
|
|
term_newln(p); |
term_newln(p); |
term_word(p, "The"); |
term_word(p, "The"); |
|
|
for (nn = n->child; nn; nn = nn->next) { |
nchild = n->nchild; |
|
for (n = n->child; n; n = n->next) { |
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
term_word(p, nn->string); |
term_word(p, n->string); |
term_fontpop(p); |
term_fontpop(p); |
|
|
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
if (nn->next && NULL == nn->next->next) |
term_word(p, "()"); |
term_word(p, "(), and"); |
|
else if (nn->next) |
if (nchild > 2 && n->next) { |
term_word(p, "(),"); |
p->flags |= TERMP_NOSPACE; |
else |
term_word(p, ","); |
term_word(p, "()"); |
} |
|
|
|
if (n->next && NULL == n->next->next) |
|
term_word(p, "and"); |
} |
} |
|
|
if (n->child && n->child->next) |
if (nchild > 1) |
term_word(p, "functions return"); |
term_word(p, "functions return"); |
else |
else |
term_word(p, "function returns"); |
term_word(p, "function returns"); |
Line 1214 termp_rv_pre(DECL_ARGS) |
|
Line 1223 termp_rv_pre(DECL_ARGS) |
|
static int |
static int |
termp_ex_pre(DECL_ARGS) |
termp_ex_pre(DECL_ARGS) |
{ |
{ |
const struct mdoc_node *nn; |
int nchild; |
|
|
|
term_newln(p); |
term_word(p, "The"); |
term_word(p, "The"); |
|
|
for (nn = n->child; nn; nn = nn->next) { |
nchild = n->nchild; |
|
for (n = n->child; n; n = n->next) { |
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
term_word(p, nn->string); |
term_word(p, n->string); |
term_fontpop(p); |
term_fontpop(p); |
p->flags |= TERMP_NOSPACE; |
|
if (nn->next && NULL == nn->next->next) |
if (nchild > 2 && n->next) { |
term_word(p, ", and"); |
p->flags |= TERMP_NOSPACE; |
else if (nn->next) |
|
term_word(p, ","); |
term_word(p, ","); |
else |
} |
p->flags &= ~TERMP_NOSPACE; |
|
|
if (n->next && NULL == n->next->next) |
|
term_word(p, "and"); |
} |
} |
|
|
if (n->child && n->child->next) |
if (nchild > 1) |
term_word(p, "utilities exit"); |
term_word(p, "utilities exit"); |
else |
else |
term_word(p, "utility exits"); |
term_word(p, "utility exits"); |
|
|
term_word(p, "0 on success, and >0 if an error occurs."); |
term_word(p, "0 on success, and >0 if an error occurs."); |
p->flags |= TERMP_SENTENCE; |
|
|
|
|
p->flags |= TERMP_SENTENCE; |
return(0); |
return(0); |
} |
} |
|
|
Line 1278 termp_bl_post(DECL_ARGS) |
|
Line 1290 termp_bl_post(DECL_ARGS) |
|
term_newln(p); |
term_newln(p); |
} |
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
static int |
termp_xr_pre(DECL_ARGS) |
termp_xr_pre(DECL_ARGS) |
{ |
{ |
const struct mdoc_node *nn; |
|
|
|
if (NULL == n->child) |
if (NULL == (n = n->child)) |
return(0); |
return(0); |
|
|
assert(MDOC_TEXT == n->child->type); |
assert(MDOC_TEXT == n->type); |
nn = n->child; |
term_word(p, n->string); |
|
|
term_word(p, nn->string); |
if (NULL == (n = n->next)) |
if (NULL == (nn = nn->next)) |
|
return(0); |
return(0); |
|
|
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_word(p, "("); |
term_word(p, "("); |
term_word(p, nn->string); |
p->flags |= TERMP_NOSPACE; |
|
|
|
assert(MDOC_TEXT == n->type); |
|
term_word(p, n->string); |
|
|
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ")"); |
term_word(p, ")"); |
|
|
return(0); |
return(0); |
} |
} |
|
|
|
|
/* |
/* |
* This decides how to assert whitespace before any of the SYNOPSIS set |
* This decides how to assert whitespace before any of the SYNOPSIS set |
* of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain |
* of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain |
Line 1516 termp_ft_pre(DECL_ARGS) |
|
Line 1530 termp_ft_pre(DECL_ARGS) |
|
static int |
static int |
termp_fn_pre(DECL_ARGS) |
termp_fn_pre(DECL_ARGS) |
{ |
{ |
const struct mdoc_node *nn; |
int pretty; |
|
|
|
pretty = MDOC_SYNPRETTY & n->flags; |
|
|
synopsis_pre(p, n); |
synopsis_pre(p, n); |
|
|
|
if (NULL == (n = n->child)) |
|
return(0); |
|
|
|
assert(MDOC_TEXT == n->type); |
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
term_word(p, n->child->string); |
term_word(p, n->string); |
term_fontpop(p); |
term_fontpop(p); |
|
|
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_word(p, "("); |
term_word(p, "("); |
|
p->flags |= TERMP_NOSPACE; |
|
|
for (nn = n->child->next; nn; nn = nn->next) { |
for (n = n->next; n; n = n->next) { |
|
assert(MDOC_TEXT == n->type); |
term_fontpush(p, TERMFONT_UNDER); |
term_fontpush(p, TERMFONT_UNDER); |
term_word(p, nn->string); |
term_word(p, n->string); |
term_fontpop(p); |
term_fontpop(p); |
|
|
if (nn->next) |
if (n->next) { |
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ","); |
term_word(p, ","); |
|
} |
} |
} |
|
|
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ")"); |
term_word(p, ")"); |
|
|
if (MDOC_SYNPRETTY & n->flags) |
if (pretty) { |
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ";"); |
term_word(p, ";"); |
|
} |
|
|
return(0); |
return(0); |
} |
} |
Line 1561 termp_fa_pre(DECL_ARGS) |
|
Line 1588 termp_fa_pre(DECL_ARGS) |
|
term_word(p, nn->string); |
term_word(p, nn->string); |
term_fontpop(p); |
term_fontpop(p); |
|
|
if (nn->next) |
if (nn->next) { |
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ","); |
term_word(p, ","); |
|
} |
} |
} |
|
|
if (n->child && n->next && n->next->tok == MDOC_Fa) |
if (n->child && n->next && n->next->tok == MDOC_Fa) { |
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ","); |
term_word(p, ","); |
|
} |
|
|
return(0); |
return(0); |
} |
} |
Line 1674 termp_bd_post(DECL_ARGS) |
|
Line 1705 termp_bd_post(DECL_ARGS) |
|
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static void |
static int |
termp_bx_post(DECL_ARGS) |
termp_bx_pre(DECL_ARGS) |
{ |
{ |
|
|
if (n->child) |
if (NULL != (n = n->child)) { |
|
term_word(p, n->string); |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_word(p, "BSD"); |
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); |
} |
} |
|
|
|
|
|
|
termp_xx_pre(DECL_ARGS) |
termp_xx_pre(DECL_ARGS) |
{ |
{ |
const char *pp; |
const char *pp; |
|
int flags; |
|
|
pp = NULL; |
pp = NULL; |
switch (n->tok) { |
switch (n->tok) { |
Line 1714 termp_xx_pre(DECL_ARGS) |
|
Line 1760 termp_xx_pre(DECL_ARGS) |
|
break; |
break; |
} |
} |
|
|
assert(pp); |
|
term_word(p, pp); |
term_word(p, pp); |
return(1); |
if (n->child) { |
|
flags = p->flags; |
|
p->flags |= TERMP_KEEP; |
|
term_word(p, n->child->string); |
|
p->flags = flags; |
|
} |
|
return(0); |
} |
} |
|
|
|
|
Line 1981 termp_fo_pre(DECL_ARGS) |
|
Line 2032 termp_fo_pre(DECL_ARGS) |
|
} else if (MDOC_BODY == n->type) { |
} else if (MDOC_BODY == n->type) { |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_word(p, "("); |
term_word(p, "("); |
|
p->flags |= TERMP_NOSPACE; |
return(1); |
return(1); |
} |
} |
|
|
Line 2004 termp_fo_post(DECL_ARGS) |
|
Line 2056 termp_fo_post(DECL_ARGS) |
|
if (MDOC_BODY != n->type) |
if (MDOC_BODY != n->type) |
return; |
return; |
|
|
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ")"); |
term_word(p, ")"); |
|
|
if (MDOC_SYNPRETTY & n->flags) |
if (MDOC_SYNPRETTY & n->flags) { |
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ";"); |
term_word(p, ";"); |
|
} |
} |
} |
|
|
|
|
Line 2081 termp____post(DECL_ARGS) |
|
Line 2136 termp____post(DECL_ARGS) |
|
if (NULL == n->parent || MDOC_Rs != n->parent->tok) |
if (NULL == n->parent || MDOC_Rs != n->parent->tok) |
return; |
return; |
|
|
|
p->flags |= TERMP_NOSPACE; |
if (NULL == n->next) { |
if (NULL == n->next) { |
term_word(p, "."); |
term_word(p, "."); |
p->flags |= TERMP_SENTENCE; |
p->flags |= TERMP_SENTENCE; |
Line 2117 termp_lk_pre(DECL_ARGS) |
|
Line 2173 termp_lk_pre(DECL_ARGS) |
|
|
|
term_fontpop(p); |
term_fontpop(p); |
|
|
|
p->flags |= TERMP_NOSPACE; |
term_word(p, ":"); |
term_word(p, ":"); |
|
|
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
Line 2168 termp__t_post(DECL_ARGS) |
|
Line 2225 termp__t_post(DECL_ARGS) |
|
* If we're in an `Rs' and there's a journal present, then quote |
* If we're in an `Rs' and there's a journal present, then quote |
* us instead of underlining us (for disambiguation). |
* us instead of underlining us (for disambiguation). |
*/ |
*/ |
if (n->parent && MDOC_Rs == n->parent->tok && |
if (n->parent && MDOC_Rs == n->parent->tok && |
n->parent->norm->Rs.child_J) |
n->parent->norm->Rs.quote_T) |
termp_quote_post(p, pair, m, n); |
termp_quote_post(p, pair, m, n); |
|
|
termp____post(p, pair, m, n); |
termp____post(p, pair, m, n); |
Line 2185 termp__t_pre(DECL_ARGS) |
|
Line 2242 termp__t_pre(DECL_ARGS) |
|
* us instead of underlining us (for disambiguation). |
* us instead of underlining us (for disambiguation). |
*/ |
*/ |
if (n->parent && MDOC_Rs == n->parent->tok && |
if (n->parent && MDOC_Rs == n->parent->tok && |
n->parent->norm->Rs.child_J) |
n->parent->norm->Rs.quote_T) |
return(termp_quote_pre(p, pair, m, n)); |
return(termp_quote_pre(p, pair, m, n)); |
|
|
term_fontpush(p, TERMFONT_UNDER); |
term_fontpush(p, TERMFONT_UNDER); |