version 1.127, 2012/01/03 15:16:24 |
version 1.134, 2012/07/29 12:35:42 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2011, 2012 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 |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
|
|
#define MAXMARGINS 64 /* maximum number of indented scopes */ |
#define MAXMARGINS 64 /* maximum number of indented scopes */ |
|
|
/* FIXME: have PD set the default vspace width. */ |
|
|
|
struct mtermp { |
struct mtermp { |
int fl; |
int fl; |
#define MANT_LITERAL (1 << 0) |
#define MANT_LITERAL (1 << 0) |
|
|
int lmargincur; /* index of current margin */ |
int lmargincur; /* index of current margin */ |
int lmarginsz; /* actual number of nested margins */ |
int lmarginsz; /* actual number of nested margins */ |
size_t offset; /* default offset to visible page */ |
size_t offset; /* default offset to visible page */ |
|
int pardist; /* vert. space before par., unit: [v] */ |
}; |
}; |
|
|
#define DECL_ARGS struct termp *p, \ |
#define DECL_ARGS struct termp *p, \ |
Line 66 static void print_man_node(DECL_ARGS); |
|
Line 65 static void print_man_node(DECL_ARGS); |
|
static void print_man_head(struct termp *, const void *); |
static void print_man_head(struct termp *, const void *); |
static void print_man_foot(struct termp *, const void *); |
static void print_man_foot(struct termp *, const void *); |
static void print_bvspace(struct termp *, |
static void print_bvspace(struct termp *, |
const struct man_node *); |
const struct man_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); |
static int pre_I(DECL_ARGS); |
static int pre_I(DECL_ARGS); |
static int pre_IP(DECL_ARGS); |
static int pre_IP(DECL_ARGS); |
static int pre_OP(DECL_ARGS); |
static int pre_OP(DECL_ARGS); |
|
static int pre_PD(DECL_ARGS); |
static int pre_PP(DECL_ARGS); |
static int pre_PP(DECL_ARGS); |
static int pre_RS(DECL_ARGS); |
static int pre_RS(DECL_ARGS); |
static int pre_SH(DECL_ARGS); |
static int pre_SH(DECL_ARGS); |
Line 122 static const struct termact termacts[MAN_MAX] = { |
|
Line 122 static const struct termact termacts[MAN_MAX] = { |
|
{ pre_RS, post_RS, 0 }, /* RS */ |
{ pre_RS, post_RS, 0 }, /* RS */ |
{ pre_ign, NULL, 0 }, /* DT */ |
{ pre_ign, NULL, 0 }, /* DT */ |
{ pre_ign, NULL, 0 }, /* UC */ |
{ pre_ign, NULL, 0 }, /* UC */ |
{ pre_ign, NULL, 0 }, /* PD */ |
{ pre_PD, NULL, MAN_NOTEXT }, /* PD */ |
{ pre_ign, NULL, 0 }, /* AT */ |
{ pre_ign, NULL, 0 }, /* AT */ |
{ pre_in, NULL, MAN_NOTEXT }, /* in */ |
{ pre_in, NULL, MAN_NOTEXT }, /* in */ |
{ pre_ft, NULL, MAN_NOTEXT }, /* ft */ |
{ pre_ft, NULL, MAN_NOTEXT }, /* ft */ |
{ pre_OP, NULL, 0 }, /* OP */ |
{ pre_OP, NULL, 0 }, /* OP */ |
|
{ pre_literal, NULL, 0 }, /* EX */ |
|
{ pre_literal, NULL, 0 }, /* EE */ |
}; |
}; |
|
|
|
|
Line 161 terminal_man(void *arg, const struct man *man) |
|
Line 163 terminal_man(void *arg, const struct man *man) |
|
|
|
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; |
|
|
if (n->child) |
if (n->child) |
print_man_nodelist(p, &mt, n->child, m); |
print_man_nodelist(p, &mt, n->child, m); |
Line 201 a2width(const struct termp *p, const char *cp) |
|
Line 204 a2width(const struct termp *p, const char *cp) |
|
* first, print it. |
* first, print it. |
*/ |
*/ |
static void |
static void |
print_bvspace(struct termp *p, const struct man_node *n) |
print_bvspace(struct termp *p, const struct man_node *n, int pardist) |
{ |
{ |
|
int i; |
|
|
term_newln(p); |
term_newln(p); |
|
|
Line 214 print_bvspace(struct termp *p, const struct man_node * |
|
Line 218 print_bvspace(struct termp *p, const struct man_node * |
|
if (NULL == n->prev) |
if (NULL == n->prev) |
return; |
return; |
|
|
term_vspace(p); |
for (i = 0; i < pardist; i++) |
|
term_vspace(p); |
} |
} |
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
Line 243 pre_literal(DECL_ARGS) |
|
Line 248 pre_literal(DECL_ARGS) |
|
|
|
term_newln(p); |
term_newln(p); |
|
|
if (MAN_nf == n->tok) |
if (MAN_nf == n->tok || MAN_EX == n->tok) |
mt->fl |= MANT_LITERAL; |
mt->fl |= MANT_LITERAL; |
else |
else |
mt->fl &= ~MANT_LITERAL; |
mt->fl &= ~MANT_LITERAL; |
Line 265 pre_literal(DECL_ARGS) |
|
Line 270 pre_literal(DECL_ARGS) |
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
static int |
|
pre_PD(DECL_ARGS) |
|
{ |
|
|
|
n = n->child; |
|
if (0 == n) { |
|
mt->pardist = 1; |
|
return(0); |
|
} |
|
assert(MAN_TEXT == n->type); |
|
mt->pardist = atoi(n->string); |
|
return(0); |
|
} |
|
|
|
/* ARGSUSED */ |
|
static int |
pre_alternate(DECL_ARGS) |
pre_alternate(DECL_ARGS) |
{ |
{ |
enum termfont font[2]; |
enum termfont font[2]; |
Line 438 pre_in(DECL_ARGS) |
|
Line 458 pre_in(DECL_ARGS) |
|
static int |
static int |
pre_sp(DECL_ARGS) |
pre_sp(DECL_ARGS) |
{ |
{ |
|
char *s; |
size_t i, len; |
size_t i, len; |
|
int neg; |
|
|
if ((NULL == n->prev && n->parent)) { |
if ((NULL == n->prev && n->parent)) { |
if (MAN_SS == n->parent->tok) |
switch (n->parent->tok) { |
|
case (MAN_SH): |
|
/* FALLTHROUGH */ |
|
case (MAN_SS): |
|
/* FALLTHROUGH */ |
|
case (MAN_PP): |
|
/* FALLTHROUGH */ |
|
case (MAN_LP): |
|
/* FALLTHROUGH */ |
|
case (MAN_P): |
|
/* FALLTHROUGH */ |
return(0); |
return(0); |
if (MAN_SH == n->parent->tok) |
default: |
return(0); |
break; |
|
} |
} |
} |
|
|
|
neg = 0; |
switch (n->tok) { |
switch (n->tok) { |
case (MAN_br): |
case (MAN_br): |
len = 0; |
len = 0; |
break; |
break; |
default: |
default: |
len = n->child ? a2height(p, n->child->string) : 1; |
if (NULL == n->child) { |
|
len = 1; |
|
break; |
|
} |
|
s = n->child->string; |
|
if ('-' == *s) { |
|
neg = 1; |
|
s++; |
|
} |
|
len = a2height(p, s); |
break; |
break; |
} |
} |
|
|
if (0 == len) |
if (0 == len) |
term_newln(p); |
term_newln(p); |
for (i = 0; i < len; i++) |
else if (neg) |
term_vspace(p); |
p->skipvsp += len; |
|
else |
|
for (i = 0; i < len; i++) |
|
term_vspace(p); |
|
|
return(0); |
return(0); |
} |
} |
Line 475 pre_HP(DECL_ARGS) |
|
Line 521 pre_HP(DECL_ARGS) |
|
|
|
switch (n->type) { |
switch (n->type) { |
case (MAN_BLOCK): |
case (MAN_BLOCK): |
print_bvspace(p, n); |
print_bvspace(p, n, mt->pardist); |
return(1); |
return(1); |
case (MAN_BODY): |
case (MAN_BODY): |
p->flags |= TERMP_NOBREAK; |
|
p->flags |= TERMP_TWOSPACE; |
|
break; |
break; |
default: |
default: |
return(0); |
return(0); |
} |
} |
|
|
|
if ( ! (MANT_LITERAL & mt->fl)) { |
|
p->flags |= TERMP_NOBREAK; |
|
p->flags |= TERMP_TWOSPACE; |
|
} |
|
|
len = mt->lmargin[mt->lmargincur]; |
len = mt->lmargin[mt->lmargincur]; |
ival = -1; |
ival = -1; |
|
|
Line 514 post_HP(DECL_ARGS) |
|
Line 563 post_HP(DECL_ARGS) |
|
{ |
{ |
|
|
switch (n->type) { |
switch (n->type) { |
case (MAN_BLOCK): |
|
term_flushln(p); |
|
break; |
|
case (MAN_BODY): |
case (MAN_BODY): |
term_flushln(p); |
term_flushln(p); |
p->flags &= ~TERMP_NOBREAK; |
p->flags &= ~TERMP_NOBREAK; |
Line 538 pre_PP(DECL_ARGS) |
|
Line 584 pre_PP(DECL_ARGS) |
|
switch (n->type) { |
switch (n->type) { |
case (MAN_BLOCK): |
case (MAN_BLOCK): |
mt->lmargin[mt->lmargincur] = term_len(p, p->defindent); |
mt->lmargin[mt->lmargincur] = term_len(p, p->defindent); |
print_bvspace(p, n); |
print_bvspace(p, n, mt->pardist); |
break; |
break; |
default: |
default: |
p->offset = mt->offset; |
p->offset = mt->offset; |
Line 565 pre_IP(DECL_ARGS) |
|
Line 611 pre_IP(DECL_ARGS) |
|
p->flags |= TERMP_NOBREAK; |
p->flags |= TERMP_NOBREAK; |
break; |
break; |
case (MAN_BLOCK): |
case (MAN_BLOCK): |
print_bvspace(p, n); |
print_bvspace(p, n, mt->pardist); |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
default: |
default: |
return(1); |
return(1); |
Line 652 pre_TP(DECL_ARGS) |
|
Line 698 pre_TP(DECL_ARGS) |
|
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
break; |
break; |
case (MAN_BLOCK): |
case (MAN_BLOCK): |
print_bvspace(p, n); |
print_bvspace(p, n, mt->pardist); |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
default: |
default: |
return(1); |
return(1); |
Line 694 pre_TP(DECL_ARGS) |
|
Line 740 pre_TP(DECL_ARGS) |
|
case (MAN_BODY): |
case (MAN_BODY): |
p->offset = mt->offset + len; |
p->offset = mt->offset + len; |
p->rmargin = p->maxrmargin; |
p->rmargin = p->maxrmargin; |
|
p->flags &= ~TERMP_NOBREAK; |
|
p->flags &= ~TERMP_TWOSPACE; |
break; |
break; |
default: |
default: |
break; |
break; |
Line 711 post_TP(DECL_ARGS) |
|
Line 759 post_TP(DECL_ARGS) |
|
switch (n->type) { |
switch (n->type) { |
case (MAN_HEAD): |
case (MAN_HEAD): |
term_flushln(p); |
term_flushln(p); |
p->flags &= ~TERMP_NOBREAK; |
|
p->flags &= ~TERMP_TWOSPACE; |
|
p->rmargin = p->maxrmargin; |
|
break; |
break; |
case (MAN_BODY): |
case (MAN_BODY): |
term_newln(p); |
term_newln(p); |
Line 728 post_TP(DECL_ARGS) |
|
Line 773 post_TP(DECL_ARGS) |
|
static int |
static int |
pre_SS(DECL_ARGS) |
pre_SS(DECL_ARGS) |
{ |
{ |
|
int i; |
|
|
switch (n->type) { |
switch (n->type) { |
case (MAN_BLOCK): |
case (MAN_BLOCK): |
Line 740 pre_SS(DECL_ARGS) |
|
Line 786 pre_SS(DECL_ARGS) |
|
break; |
break; |
if (NULL == n->prev) |
if (NULL == n->prev) |
break; |
break; |
term_vspace(p); |
for (i = 0; i < mt->pardist; i++) |
|
term_vspace(p); |
break; |
break; |
case (MAN_HEAD): |
case (MAN_HEAD): |
term_fontrepl(p, TERMFONT_BOLD); |
term_fontrepl(p, TERMFONT_BOLD); |
p->offset = term_len(p, p->defindent/2); |
p->offset = term_len(p, 3); |
break; |
break; |
case (MAN_BODY): |
case (MAN_BODY): |
p->offset = mt->offset; |
p->offset = mt->offset; |
Line 779 post_SS(DECL_ARGS) |
|
Line 826 post_SS(DECL_ARGS) |
|
static int |
static int |
pre_SH(DECL_ARGS) |
pre_SH(DECL_ARGS) |
{ |
{ |
|
int i; |
|
|
switch (n->type) { |
switch (n->type) { |
case (MAN_BLOCK): |
case (MAN_BLOCK): |
Line 792 pre_SH(DECL_ARGS) |
|
Line 840 pre_SH(DECL_ARGS) |
|
/* If the first macro, no vspae. */ |
/* If the first macro, no vspae. */ |
if (NULL == n->prev) |
if (NULL == n->prev) |
break; |
break; |
term_vspace(p); |
for (i = 0; i < mt->pardist; i++) |
|
term_vspace(p); |
break; |
break; |
case (MAN_HEAD): |
case (MAN_HEAD): |
term_fontrepl(p, TERMFONT_BOLD); |
term_fontrepl(p, TERMFONT_BOLD); |
Line 910 print_man_node(DECL_ARGS) |
|
Line 959 print_man_node(DECL_ARGS) |
|
term_newln(p); |
term_newln(p); |
|
|
term_word(p, n->string); |
term_word(p, n->string); |
|
goto out; |
|
|
/* |
|
* If we're in a literal context, make sure that words |
|
* togehter on the same line stay together. This is a |
|
* POST-printing call, so we check the NEXT word. Since |
|
* -man doesn't have nested macros, we don't need to be |
|
* more specific than this. |
|
*/ |
|
if (MANT_LITERAL & mt->fl && ! (TERMP_NOBREAK & p->flags) && |
|
(NULL == n->next || |
|
n->next->line > n->line)) { |
|
rm = p->rmargin; |
|
rmax = p->maxrmargin; |
|
p->rmargin = p->maxrmargin = TERM_MAXMARGIN; |
|
p->flags |= TERMP_NOSPACE; |
|
term_flushln(p); |
|
p->rmargin = rm; |
|
p->maxrmargin = rmax; |
|
} |
|
|
|
if (MAN_EOS & n->flags) |
|
p->flags |= TERMP_SENTENCE; |
|
return; |
|
case (MAN_EQN): |
case (MAN_EQN): |
term_eqn(p, n->eqn); |
term_eqn(p, n->eqn); |
return; |
return; |
Line 964 print_man_node(DECL_ARGS) |
|
Line 992 print_man_node(DECL_ARGS) |
|
if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) |
if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) |
term_fontrepl(p, TERMFONT_NONE); |
term_fontrepl(p, TERMFONT_NONE); |
|
|
|
out: |
|
/* |
|
* If we're in a literal context, make sure that words |
|
* together on the same line stay together. This is a |
|
* POST-printing call, so we check the NEXT word. Since |
|
* -man doesn't have nested macros, we don't need to be |
|
* more specific than this. |
|
*/ |
|
if (MANT_LITERAL & mt->fl && ! (TERMP_NOBREAK & p->flags) && |
|
NULL != n->next && n->next->line > n->line) { |
|
rm = p->rmargin; |
|
rmax = p->maxrmargin; |
|
p->rmargin = p->maxrmargin = TERM_MAXMARGIN; |
|
p->flags |= TERMP_NOSPACE; |
|
if (NULL != n->string && '\0' != *n->string) |
|
term_flushln(p); |
|
else |
|
term_newln(p); |
|
if (rm < rmax && n->parent->tok == MAN_HP) { |
|
p->offset = rm; |
|
p->rmargin = rmax; |
|
} else |
|
p->rmargin = rm; |
|
p->maxrmargin = rmax; |
|
} |
if (MAN_EOS & n->flags) |
if (MAN_EOS & n->flags) |
p->flags |= TERMP_SENTENCE; |
p->flags |= TERMP_SENTENCE; |
} |
} |