version 1.220, 2011/03/07 01:35:51 |
version 1.236, 2011/10/16 12:20:34 |
|
|
#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 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 352 print_mdoc_node(DECL_ARGS) |
|
Line 344 print_mdoc_node(DECL_ARGS) |
|
case (MDOC_TEXT): |
case (MDOC_TEXT): |
if (' ' == *n->string && MDOC_LINE & n->flags) |
if (' ' == *n->string && MDOC_LINE & n->flags) |
term_newln(p); |
term_newln(p); |
|
if (MDOC_DELIMC & n->flags) |
|
p->flags |= TERMP_NOSPACE; |
term_word(p, n->string); |
term_word(p, n->string); |
|
if (MDOC_DELIMO & n->flags) |
|
p->flags |= TERMP_NOSPACE; |
break; |
break; |
case (MDOC_EQN): |
case (MDOC_EQN): |
term_word(p, n->eqn->data); |
term_eqn(p, n->eqn); |
break; |
break; |
case (MDOC_TBL): |
case (MDOC_TBL): |
term_tbl(p, n->span); |
term_tbl(p, n->span); |
Line 439 print_mdoc_foot(struct termp *p, const void *arg) |
|
Line 435 print_mdoc_foot(struct termp *p, const void *arg) |
|
|
|
p->offset = p->rmargin; |
p->offset = p->rmargin; |
p->rmargin = p->maxrmargin - term_strlen(p, m->os); |
p->rmargin = p->maxrmargin - term_strlen(p, m->os); |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
|
|
term_word(p, m->date); |
term_word(p, m->date); |
term_flushln(p); |
term_flushln(p); |
Line 447 print_mdoc_foot(struct termp *p, const void *arg) |
|
Line 443 print_mdoc_foot(struct termp *p, const void *arg) |
|
p->offset = p->rmargin; |
p->offset = p->rmargin; |
p->rmargin = p->maxrmargin; |
p->rmargin = p->maxrmargin; |
p->flags &= ~TERMP_NOBREAK; |
p->flags &= ~TERMP_NOBREAK; |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
|
|
term_word(p, m->os); |
term_word(p, m->os); |
term_flushln(p); |
term_flushln(p); |
|
|
print_mdoc_head(struct termp *p, const void *arg) |
print_mdoc_head(struct termp *p, const void *arg) |
{ |
{ |
char buf[BUFSIZ], title[BUFSIZ]; |
char buf[BUFSIZ], title[BUFSIZ]; |
|
size_t buflen, titlen; |
const struct mdoc_meta *m; |
const struct mdoc_meta *m; |
|
|
m = (const struct mdoc_meta *)arg; |
m = (const struct mdoc_meta *)arg; |
|
|
p->rmargin = p->maxrmargin; |
|
p->offset = 0; |
|
|
|
/* |
/* |
* The header is strange. It has three components, which are |
* The header is strange. It has three components, which are |
* really two with the first duplicated. It goes like this: |
* really two with the first duplicated. It goes like this: |
Line 482 print_mdoc_head(struct termp *p, const void *arg) |
|
Line 476 print_mdoc_head(struct termp *p, const void *arg) |
|
* switches on the manual section. |
* switches on the manual section. |
*/ |
*/ |
|
|
|
p->offset = 0; |
|
p->rmargin = p->maxrmargin; |
|
|
assert(m->vol); |
assert(m->vol); |
strlcpy(buf, m->vol, BUFSIZ); |
strlcpy(buf, m->vol, BUFSIZ); |
|
buflen = term_strlen(p, buf); |
|
|
if (m->arch) { |
if (m->arch) { |
strlcat(buf, " (", BUFSIZ); |
strlcat(buf, " (", BUFSIZ); |
Line 492 print_mdoc_head(struct termp *p, const void *arg) |
|
Line 490 print_mdoc_head(struct termp *p, const void *arg) |
|
} |
} |
|
|
snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec); |
snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec); |
|
titlen = term_strlen(p, title); |
|
|
p->offset = 0; |
|
p->rmargin = (p->maxrmargin - |
|
term_strlen(p, buf) + term_len(p, 1)) / 2; |
|
p->flags |= TERMP_NOBREAK | TERMP_NOSPACE; |
p->flags |= TERMP_NOBREAK | TERMP_NOSPACE; |
|
p->offset = 0; |
|
p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ? |
|
(p->maxrmargin - |
|
term_strlen(p, buf) + term_len(p, 1)) / 2 : |
|
p->maxrmargin - buflen; |
|
|
term_word(p, title); |
term_word(p, title); |
term_flushln(p); |
term_flushln(p); |
|
|
|
p->flags |= TERMP_NOSPACE; |
p->offset = p->rmargin; |
p->offset = p->rmargin; |
p->rmargin = p->maxrmargin - term_strlen(p, title); |
p->rmargin = p->offset + buflen + titlen < p->maxrmargin ? |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
p->maxrmargin - titlen : p->maxrmargin; |
|
|
term_word(p, buf); |
term_word(p, buf); |
term_flushln(p); |
term_flushln(p); |
|
|
p->offset = p->rmargin; |
|
p->rmargin = p->maxrmargin; |
|
p->flags &= ~TERMP_NOBREAK; |
p->flags &= ~TERMP_NOBREAK; |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
if (p->rmargin + titlen <= p->maxrmargin) { |
|
p->flags |= TERMP_NOSPACE; |
|
p->offset = p->rmargin; |
|
p->rmargin = p->maxrmargin; |
|
term_word(p, title); |
|
term_flushln(p); |
|
} |
|
|
term_word(p, title); |
p->flags &= ~TERMP_NOSPACE; |
term_flushln(p); |
|
|
|
p->offset = 0; |
p->offset = 0; |
p->rmargin = p->maxrmargin; |
p->rmargin = p->maxrmargin; |
p->flags &= ~TERMP_NOSPACE; |
|
} |
} |
|
|
|
|
Line 527 a2height(const struct termp *p, const char *v) |
|
Line 530 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)); |
} |
} |
Line 580 print_bvspace(struct termp *p, |
|
Line 584 print_bvspace(struct termp *p, |
|
{ |
{ |
const struct mdoc_node *nn; |
const struct mdoc_node *nn; |
|
|
|
assert(n); |
|
|
term_newln(p); |
term_newln(p); |
|
|
if (MDOC_Bd == bl->tok && bl->norm->Bd.comp) |
if (MDOC_Bd == bl->tok && bl->norm->Bd.comp) |
Line 790 termp_it_pre(DECL_ARGS) |
|
Line 796 termp_it_pre(DECL_ARGS) |
|
case (LIST_hyphen): |
case (LIST_hyphen): |
if (MDOC_HEAD == n->type) |
if (MDOC_HEAD == n->type) |
p->flags |= TERMP_NOBREAK; |
p->flags |= TERMP_NOBREAK; |
else |
|
p->flags |= TERMP_NOLPAD; |
|
break; |
break; |
case (LIST_hang): |
case (LIST_hang): |
if (MDOC_HEAD == n->type) |
if (MDOC_HEAD == n->type) |
p->flags |= TERMP_NOBREAK; |
p->flags |= TERMP_NOBREAK; |
else |
else |
p->flags |= TERMP_NOLPAD; |
|
|
|
if (MDOC_HEAD != n->type) |
|
break; |
break; |
|
|
/* |
/* |
Line 810 termp_it_pre(DECL_ARGS) |
|
Line 811 termp_it_pre(DECL_ARGS) |
|
*/ |
*/ |
if (n->next->child && |
if (n->next->child && |
(MDOC_Bl == n->next->child->tok || |
(MDOC_Bl == n->next->child->tok || |
MDOC_Bd == n->next->child->tok)) { |
MDOC_Bd == n->next->child->tok)) |
p->flags &= ~TERMP_NOBREAK; |
p->flags &= ~TERMP_NOBREAK; |
p->flags &= ~TERMP_NOLPAD; |
else |
} else |
|
p->flags |= TERMP_HANG; |
p->flags |= TERMP_HANG; |
break; |
break; |
case (LIST_tag): |
case (LIST_tag): |
if (MDOC_HEAD == n->type) |
if (MDOC_HEAD == n->type) |
p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE; |
p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE; |
else |
|
p->flags |= TERMP_NOLPAD; |
|
|
|
if (MDOC_HEAD != n->type) |
if (MDOC_HEAD != n->type) |
break; |
break; |
Line 836 termp_it_pre(DECL_ARGS) |
|
Line 834 termp_it_pre(DECL_ARGS) |
|
else |
else |
p->flags |= TERMP_NOBREAK; |
p->flags |= TERMP_NOBREAK; |
|
|
assert(n->prev); |
|
if (MDOC_BODY == n->prev->type) |
|
p->flags |= TERMP_NOLPAD; |
|
|
|
break; |
break; |
case (LIST_diag): |
case (LIST_diag): |
if (MDOC_HEAD == n->type) |
if (MDOC_HEAD == n->type) |
Line 996 termp_it_post(DECL_ARGS) |
|
Line 990 termp_it_post(DECL_ARGS) |
|
p->flags &= ~TERMP_DANGLE; |
p->flags &= ~TERMP_DANGLE; |
p->flags &= ~TERMP_NOBREAK; |
p->flags &= ~TERMP_NOBREAK; |
p->flags &= ~TERMP_TWOSPACE; |
p->flags &= ~TERMP_TWOSPACE; |
p->flags &= ~TERMP_NOLPAD; |
|
p->flags &= ~TERMP_HANG; |
p->flags &= ~TERMP_HANG; |
} |
} |
|
|
Line 1012 termp_nm_pre(DECL_ARGS) |
|
Line 1005 termp_nm_pre(DECL_ARGS) |
|
if (MDOC_BODY == n->type) { |
if (MDOC_BODY == n->type) { |
if (NULL == n->child) |
if (NULL == n->child) |
return(0); |
return(0); |
p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
p->offset += term_len(p, 1) + |
p->offset += term_len(p, 1) + |
(NULL == n->prev->child ? term_strlen(p, m->name) : |
(NULL == n->prev->child ? term_strlen(p, m->name) : |
MDOC_TEXT == n->prev->child->type ? |
MDOC_TEXT == n->prev->child->type ? |
Line 1057 termp_nm_post(DECL_ARGS) |
|
Line 1050 termp_nm_post(DECL_ARGS) |
|
if (MDOC_HEAD == n->type && n->next->child) { |
if (MDOC_HEAD == n->type && n->next->child) { |
term_flushln(p); |
term_flushln(p); |
p->flags &= ~(TERMP_NOBREAK | TERMP_HANG); |
p->flags &= ~(TERMP_NOBREAK | TERMP_HANG); |
} else if (MDOC_BODY == n->type && n->child) { |
} else if (MDOC_BODY == n->type && n->child) |
term_flushln(p); |
term_flushln(p); |
p->flags &= ~TERMP_NOLPAD; |
|
} |
|
} |
} |
|
|
|
|
Line 1180 termp_rs_pre(DECL_ARGS) |
|
Line 1171 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 1221 termp_rv_pre(DECL_ARGS) |
|
Line 1217 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 1285 termp_bl_post(DECL_ARGS) |
|
Line 1284 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 1523 termp_ft_pre(DECL_ARGS) |
|
Line 1524 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 1568 termp_fa_pre(DECL_ARGS) |
|
Line 1582 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 2008 termp_fo_pre(DECL_ARGS) |
|
Line 2026 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 2031 termp_fo_post(DECL_ARGS) |
|
Line 2050 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 2108 termp____post(DECL_ARGS) |
|
Line 2130 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 2144 termp_lk_pre(DECL_ARGS) |
|
Line 2167 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); |