version 1.171, 2015/04/02 21:36:50 |
version 1.182, 2015/04/19 14:00:19 |
|
|
|
|
#define DECL_ARGS struct termp *p, \ |
#define DECL_ARGS struct termp *p, \ |
struct mtermp *mt, \ |
struct mtermp *mt, \ |
struct man_node *n, \ |
struct roff_node *n, \ |
const struct man_meta *meta |
const struct roff_meta *meta |
|
|
struct termact { |
struct termact { |
int (*pre)(DECL_ARGS); |
int (*pre)(DECL_ARGS); |
|
|
|
|
static void print_man_nodelist(DECL_ARGS); |
static void print_man_nodelist(DECL_ARGS); |
static void print_man_node(DECL_ARGS); |
static void print_man_node(DECL_ARGS); |
static void print_man_head(struct termp *, const void *); |
static void print_man_head(struct termp *, |
static void print_man_foot(struct termp *, const void *); |
const struct roff_meta *); |
|
static void print_man_foot(struct termp *, |
|
const struct roff_meta *); |
static void print_bvspace(struct termp *, |
static void print_bvspace(struct termp *, |
const struct man_node *, int); |
const struct roff_node *, int); |
|
|
static int pre_B(DECL_ARGS); |
static int pre_B(DECL_ARGS); |
static int pre_HP(DECL_ARGS); |
static int pre_HP(DECL_ARGS); |
Line 136 static const struct termact termacts[MAN_MAX] = { |
|
Line 138 static const struct termact termacts[MAN_MAX] = { |
|
|
|
|
|
void |
void |
terminal_man(void *arg, const struct man *man) |
terminal_man(void *arg, const struct roff_man *man) |
{ |
{ |
struct termp *p; |
struct termp *p; |
const struct man_meta *meta; |
struct roff_node *n; |
struct man_node *n; |
|
struct mtermp mt; |
struct mtermp mt; |
|
|
p = (struct termp *)arg; |
p = (struct termp *)arg; |
|
|
p->overstep = 0; |
p->overstep = 0; |
p->rmargin = p->maxrmargin = p->defrmargin; |
p->rmargin = p->maxrmargin = p->defrmargin; |
p->tabwidth = term_len(p, 5); |
p->tabwidth = term_len(p, 5); |
|
|
n = man_node(man)->child; |
|
meta = man_meta(man); |
|
|
|
memset(&mt, 0, sizeof(struct mtermp)); |
memset(&mt, 0, sizeof(struct mtermp)); |
|
|
mt.lmargin[mt.lmargincur] = term_len(p, p->defindent); |
mt.lmargin[mt.lmargincur] = term_len(p, p->defindent); |
mt.offset = term_len(p, p->defindent); |
mt.offset = term_len(p, p->defindent); |
mt.pardist = 1; |
mt.pardist = 1; |
|
|
|
n = man->first->child; |
if (p->synopsisonly) { |
if (p->synopsisonly) { |
while (n != NULL) { |
while (n != NULL) { |
if (n->tok == MAN_SH && |
if (n->tok == MAN_SH && |
Line 165 terminal_man(void *arg, const struct man *man) |
|
Line 162 terminal_man(void *arg, const struct man *man) |
|
!strcmp(n->child->child->string, "SYNOPSIS")) { |
!strcmp(n->child->child->string, "SYNOPSIS")) { |
if (n->child->next->child != NULL) |
if (n->child->next->child != NULL) |
print_man_nodelist(p, &mt, |
print_man_nodelist(p, &mt, |
n->child->next->child, meta); |
n->child->next->child, |
|
&man->meta); |
term_newln(p); |
term_newln(p); |
break; |
break; |
} |
} |
Line 174 terminal_man(void *arg, const struct man *man) |
|
Line 172 terminal_man(void *arg, const struct man *man) |
|
} else { |
} else { |
if (p->defindent == 0) |
if (p->defindent == 0) |
p->defindent = 7; |
p->defindent = 7; |
term_begin(p, print_man_head, print_man_foot, meta); |
term_begin(p, print_man_head, print_man_foot, &man->meta); |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
if (n != NULL) |
if (n != NULL) |
print_man_nodelist(p, &mt, n, meta); |
print_man_nodelist(p, &mt, n, &man->meta); |
term_end(p); |
term_end(p); |
} |
} |
} |
} |
Line 191 terminal_man(void *arg, const struct man *man) |
|
Line 189 terminal_man(void *arg, const struct man *man) |
|
* first, print it. |
* first, print it. |
*/ |
*/ |
static void |
static void |
print_bvspace(struct termp *p, const struct man_node *n, int pardist) |
print_bvspace(struct termp *p, const struct roff_node *n, int pardist) |
{ |
{ |
int i; |
int i; |
|
|
|
|
pre_alternate(DECL_ARGS) |
pre_alternate(DECL_ARGS) |
{ |
{ |
enum termfont font[2]; |
enum termfont font[2]; |
struct man_node *nn; |
struct roff_node *nn; |
int savelit, i; |
int savelit, i; |
|
|
switch (n->tok) { |
switch (n->tok) { |
Line 319 pre_alternate(DECL_ARGS) |
|
Line 317 pre_alternate(DECL_ARGS) |
|
term_fontrepl(p, font[i]); |
term_fontrepl(p, font[i]); |
if (savelit && NULL == nn->next) |
if (savelit && NULL == nn->next) |
mt->fl |= MANT_LITERAL; |
mt->fl |= MANT_LITERAL; |
print_man_node(p, mt, nn, meta); |
assert(nn->type == ROFFT_TEXT); |
|
term_word(p, nn->string); |
|
if (nn->flags & MAN_EOS) |
|
p->flags |= TERMP_SENTENCE; |
if (nn->next) |
if (nn->next) |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
} |
} |
Line 425 pre_in(DECL_ARGS) |
|
Line 426 pre_in(DECL_ARGS) |
|
if ( ! a2roffsu(++cp, &su, SCALE_EN)) |
if ( ! a2roffsu(++cp, &su, SCALE_EN)) |
return(0); |
return(0); |
|
|
v = term_hspan(p, &su); |
v = (term_hspan(p, &su) + 11) / 24; |
|
|
if (less < 0) |
if (less < 0) |
p->offset -= p->offset > v ? v : p->offset; |
p->offset -= p->offset > v ? v : p->offset; |
|
|
pre_HP(DECL_ARGS) |
pre_HP(DECL_ARGS) |
{ |
{ |
struct roffsu su; |
struct roffsu su; |
const struct man_node *nn; |
const struct roff_node *nn; |
int len; |
int len; |
|
|
switch (n->type) { |
switch (n->type) { |
Line 510 pre_HP(DECL_ARGS) |
|
Line 511 pre_HP(DECL_ARGS) |
|
|
|
if ((nn = n->parent->head->child) != NULL && |
if ((nn = n->parent->head->child) != NULL && |
a2roffsu(nn->string, &su, SCALE_EN)) { |
a2roffsu(nn->string, &su, SCALE_EN)) { |
len = term_hspan(p, &su); |
len = term_hspan(p, &su) / 24; |
if (len < 0 && (size_t)(-len) > mt->offset) |
if (len < 0 && (size_t)(-len) > mt->offset) |
len = -mt->offset; |
len = -mt->offset; |
else if (len > SHRT_MAX) |
else if (len > SHRT_MAX) |
Line 531 post_HP(DECL_ARGS) |
|
Line 532 post_HP(DECL_ARGS) |
|
switch (n->type) { |
switch (n->type) { |
case ROFFT_BODY: |
case ROFFT_BODY: |
term_newln(p); |
term_newln(p); |
|
|
|
/* |
|
* Compatibility with a groff bug. |
|
* The .HP macro uses the undocumented .tag request |
|
* which causes a line break and cancels no-space |
|
* mode even if there isn't any output. |
|
*/ |
|
|
|
if (n->child == NULL) |
|
term_vspace(p); |
|
|
p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); |
p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); |
p->trailspace = 0; |
p->trailspace = 0; |
p->offset = mt->offset; |
p->offset = mt->offset; |
|
|
pre_IP(DECL_ARGS) |
pre_IP(DECL_ARGS) |
{ |
{ |
struct roffsu su; |
struct roffsu su; |
const struct man_node *nn; |
const struct roff_node *nn; |
int len, savelit; |
int len, savelit; |
|
|
switch (n->type) { |
switch (n->type) { |
Line 584 pre_IP(DECL_ARGS) |
|
Line 596 pre_IP(DECL_ARGS) |
|
if ((nn = n->parent->head->child) != NULL && |
if ((nn = n->parent->head->child) != NULL && |
(nn = nn->next) != NULL && |
(nn = nn->next) != NULL && |
a2roffsu(nn->string, &su, SCALE_EN)) { |
a2roffsu(nn->string, &su, SCALE_EN)) { |
len = term_hspan(p, &su); |
len = term_hspan(p, &su) / 24; |
if (len < 0 && (size_t)(-len) > mt->offset) |
if (len < 0 && (size_t)(-len) > mt->offset) |
len = -mt->offset; |
len = -mt->offset; |
else if (len > SHRT_MAX) |
else if (len > SHRT_MAX) |
|
|
pre_TP(DECL_ARGS) |
pre_TP(DECL_ARGS) |
{ |
{ |
struct roffsu su; |
struct roffsu su; |
struct man_node *nn; |
struct roff_node *nn; |
int len, savelit; |
int len, savelit; |
|
|
switch (n->type) { |
switch (n->type) { |
Line 666 pre_TP(DECL_ARGS) |
|
Line 678 pre_TP(DECL_ARGS) |
|
if ((nn = n->parent->head->child) != NULL && |
if ((nn = n->parent->head->child) != NULL && |
nn->string != NULL && ! (MAN_LINE & nn->flags) && |
nn->string != NULL && ! (MAN_LINE & nn->flags) && |
a2roffsu(nn->string, &su, SCALE_EN)) { |
a2roffsu(nn->string, &su, SCALE_EN)) { |
len = term_hspan(p, &su); |
len = term_hspan(p, &su) / 24; |
if (len < 0 && (size_t)(-len) > mt->offset) |
if (len < 0 && (size_t)(-len) > mt->offset) |
len = -mt->offset; |
len = -mt->offset; |
else if (len > SHRT_MAX) |
else if (len > SHRT_MAX) |
Line 744 pre_SS(DECL_ARGS) |
|
Line 756 pre_SS(DECL_ARGS) |
|
|
|
do { |
do { |
n = n->prev; |
n = n->prev; |
} while (n != NULL && n->tok != MAN_MAX && |
} while (n != NULL && n->tok != TOKEN_NONE && |
termacts[n->tok].flags & MAN_NOTEXT); |
termacts[n->tok].flags & MAN_NOTEXT); |
if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL)) |
if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL)) |
break; |
break; |
Line 755 pre_SS(DECL_ARGS) |
|
Line 767 pre_SS(DECL_ARGS) |
|
case ROFFT_HEAD: |
case ROFFT_HEAD: |
term_fontrepl(p, TERMFONT_BOLD); |
term_fontrepl(p, TERMFONT_BOLD); |
p->offset = term_len(p, 3); |
p->offset = term_len(p, 3); |
|
p->rmargin = mt->offset; |
|
p->trailspace = mt->offset; |
|
p->flags |= TERMP_NOBREAK | TERMP_BRIND; |
break; |
break; |
case ROFFT_BODY: |
case ROFFT_BODY: |
p->offset = mt->offset; |
p->offset = mt->offset; |
|
p->rmargin = p->maxrmargin; |
|
p->trailspace = 0; |
|
p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); |
break; |
break; |
default: |
default: |
break; |
break; |
Line 810 pre_SH(DECL_ARGS) |
|
Line 828 pre_SH(DECL_ARGS) |
|
case ROFFT_HEAD: |
case ROFFT_HEAD: |
term_fontrepl(p, TERMFONT_BOLD); |
term_fontrepl(p, TERMFONT_BOLD); |
p->offset = 0; |
p->offset = 0; |
|
p->rmargin = mt->offset; |
|
p->trailspace = mt->offset; |
|
p->flags |= TERMP_NOBREAK | TERMP_BRIND; |
break; |
break; |
case ROFFT_BODY: |
case ROFFT_BODY: |
p->offset = mt->offset; |
p->offset = mt->offset; |
|
p->rmargin = p->maxrmargin; |
|
p->trailspace = 0; |
|
p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND); |
break; |
break; |
default: |
default: |
break; |
break; |
Line 854 pre_RS(DECL_ARGS) |
|
Line 878 pre_RS(DECL_ARGS) |
|
|
|
n = n->parent->head; |
n = n->parent->head; |
n->aux = SHRT_MAX + 1; |
n->aux = SHRT_MAX + 1; |
if (n->child != NULL && a2roffsu(n->child->string, &su, SCALE_EN)) |
if (n->child == NULL) |
n->aux = term_hspan(p, &su); |
n->aux = mt->lmargin[mt->lmargincur]; |
|
else if (a2roffsu(n->child->string, &su, SCALE_EN)) |
|
n->aux = term_hspan(p, &su) / 24; |
if (n->aux < 0 && (size_t)(-n->aux) > mt->offset) |
if (n->aux < 0 && (size_t)(-n->aux) > mt->offset) |
n->aux = -mt->offset; |
n->aux = -mt->offset; |
else if (n->aux > SHRT_MAX) |
else if (n->aux > SHRT_MAX) |
Line 868 pre_RS(DECL_ARGS) |
|
Line 894 pre_RS(DECL_ARGS) |
|
if (++mt->lmarginsz < MAXMARGINS) |
if (++mt->lmarginsz < MAXMARGINS) |
mt->lmargincur = mt->lmarginsz; |
mt->lmargincur = mt->lmarginsz; |
|
|
mt->lmargin[mt->lmargincur] = mt->lmargin[mt->lmargincur - 1]; |
mt->lmargin[mt->lmargincur] = term_len(p, p->defindent); |
return(1); |
return(1); |
} |
} |
|
|
Line 1012 print_man_nodelist(DECL_ARGS) |
|
Line 1038 print_man_nodelist(DECL_ARGS) |
|
} |
} |
|
|
static void |
static void |
print_man_foot(struct termp *p, const void *arg) |
print_man_foot(struct termp *p, const struct roff_meta *meta) |
{ |
{ |
const struct man_meta *meta; |
|
char *title; |
char *title; |
size_t datelen, titlen; |
size_t datelen, titlen; |
|
|
meta = (const struct man_meta *)arg; |
|
assert(meta->title); |
assert(meta->title); |
assert(meta->msec); |
assert(meta->msec); |
assert(meta->date); |
assert(meta->date); |
Line 1030 print_man_foot(struct termp *p, const void *arg) |
|
Line 1054 print_man_foot(struct termp *p, const void *arg) |
|
|
|
/* |
/* |
* Temporary, undocumented option to imitate mdoc(7) output. |
* Temporary, undocumented option to imitate mdoc(7) output. |
* In the bottom right corner, use the source instead of |
* In the bottom right corner, use the operating system |
* the title. |
* instead of the title. |
*/ |
*/ |
|
|
if ( ! p->mdocstyle) { |
if ( ! p->mdocstyle) { |
Line 1041 print_man_foot(struct termp *p, const void *arg) |
|
Line 1065 print_man_foot(struct termp *p, const void *arg) |
|
} |
} |
mandoc_asprintf(&title, "%s(%s)", |
mandoc_asprintf(&title, "%s(%s)", |
meta->title, meta->msec); |
meta->title, meta->msec); |
} else if (meta->source) { |
} else if (meta->os) { |
title = mandoc_strdup(meta->source); |
title = mandoc_strdup(meta->os); |
} else { |
} else { |
title = mandoc_strdup(""); |
title = mandoc_strdup(""); |
} |
} |
datelen = term_strlen(p, meta->date); |
datelen = term_strlen(p, meta->date); |
|
|
/* Bottom left corner: manual source. */ |
/* Bottom left corner: operating system. */ |
|
|
p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; |
p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; |
p->trailspace = 1; |
p->trailspace = 1; |
Line 1056 print_man_foot(struct termp *p, const void *arg) |
|
Line 1080 print_man_foot(struct termp *p, const void *arg) |
|
p->rmargin = p->maxrmargin > datelen ? |
p->rmargin = p->maxrmargin > datelen ? |
(p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0; |
(p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0; |
|
|
if (meta->source) |
if (meta->os) |
term_word(p, meta->source); |
term_word(p, meta->os); |
term_flushln(p); |
term_flushln(p); |
|
|
/* At the bottom in the middle: manual date. */ |
/* At the bottom in the middle: manual date. */ |
Line 1084 print_man_foot(struct termp *p, const void *arg) |
|
Line 1108 print_man_foot(struct termp *p, const void *arg) |
|
} |
} |
|
|
static void |
static void |
print_man_head(struct termp *p, const void *arg) |
print_man_head(struct termp *p, const struct roff_meta *meta) |
{ |
{ |
const struct man_meta *meta; |
|
const char *volume; |
const char *volume; |
char *title; |
char *title; |
size_t vollen, titlen; |
size_t vollen, titlen; |
|
|
meta = (const struct man_meta *)arg; |
|
assert(meta->title); |
assert(meta->title); |
assert(meta->msec); |
assert(meta->msec); |
|
|