version 1.89, 2010/12/06 15:31:19 |
version 1.100, 2011/01/23 14:54:21 |
|
|
/* $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, 2011 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 |
Line 125 static const struct termact termacts[MAN_MAX] = { |
|
Line 126 static const struct termact termacts[MAN_MAX] = { |
|
{ pre_I, NULL, 0 }, /* I */ |
{ pre_I, NULL, 0 }, /* I */ |
{ pre_alternate, NULL, 0 }, /* IR */ |
{ pre_alternate, NULL, 0 }, /* IR */ |
{ pre_alternate, NULL, 0 }, /* RI */ |
{ pre_alternate, NULL, 0 }, /* RI */ |
{ NULL, NULL, MAN_NOTEXT }, /* na */ |
{ pre_ign, NULL, MAN_NOTEXT }, /* na */ |
{ pre_I, NULL, 0 }, /* i */ |
|
{ pre_sp, NULL, MAN_NOTEXT }, /* sp */ |
{ pre_sp, NULL, MAN_NOTEXT }, /* sp */ |
{ pre_literal, NULL, 0 }, /* nf */ |
{ pre_literal, NULL, 0 }, /* nf */ |
{ pre_literal, NULL, 0 }, /* fi */ |
{ pre_literal, NULL, 0 }, /* fi */ |
{ NULL, NULL, 0 }, /* r */ |
|
{ NULL, NULL, 0 }, /* RE */ |
{ NULL, NULL, 0 }, /* RE */ |
{ pre_RS, post_RS, 0 }, /* RS */ |
{ pre_RS, post_RS, 0 }, /* RS */ |
{ pre_ign, NULL, 0 }, /* DT */ |
{ pre_ign, NULL, 0 }, /* DT */ |
Line 256 pre_literal(DECL_ARGS) |
|
Line 255 pre_literal(DECL_ARGS) |
|
else |
else |
mt->fl &= ~MANT_LITERAL; |
mt->fl &= ~MANT_LITERAL; |
|
|
return(1); |
return(0); |
} |
} |
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
Line 398 pre_in(DECL_ARGS) |
|
Line 397 pre_in(DECL_ARGS) |
|
else |
else |
p->offset = v; |
p->offset = v; |
|
|
|
/* Don't let this creep beyond the right margin. */ |
|
|
|
if (p->offset > p->rmargin) |
|
p->offset = p->rmargin; |
|
|
return(0); |
return(0); |
} |
} |
|
|
Line 515 pre_IP(DECL_ARGS) |
|
Line 519 pre_IP(DECL_ARGS) |
|
{ |
{ |
const struct man_node *nn; |
const struct man_node *nn; |
size_t len; |
size_t len; |
int ival; |
int savelit, ival; |
|
|
switch (n->type) { |
switch (n->type) { |
case (MAN_BODY): |
case (MAN_BODY): |
Line 535 pre_IP(DECL_ARGS) |
|
Line 539 pre_IP(DECL_ARGS) |
|
len = mt->lmargin; |
len = mt->lmargin; |
ival = -1; |
ival = -1; |
|
|
/* Calculate offset. */ |
/* Calculate the offset from the optional second argument. */ |
|
|
if (NULL != (nn = n->parent->head->child)) |
if (NULL != (nn = n->parent->head->child)) |
if (NULL != (nn = nn->next)) { |
if (NULL != (nn = nn->next)) |
for ( ; nn->next; nn = nn->next) |
|
/* Do nothing. */ ; |
|
if ((ival = a2width(p, nn->string)) >= 0) |
if ((ival = a2width(p, nn->string)) >= 0) |
len = (size_t)ival; |
len = (size_t)ival; |
} |
|
|
|
switch (n->type) { |
switch (n->type) { |
case (MAN_HEAD): |
case (MAN_HEAD): |
Line 559 pre_IP(DECL_ARGS) |
|
Line 559 pre_IP(DECL_ARGS) |
|
/* Set the saved left-margin. */ |
/* Set the saved left-margin. */ |
mt->lmargin = (size_t)ival; |
mt->lmargin = (size_t)ival; |
|
|
/* Don't print the length value. */ |
savelit = MANT_LITERAL & mt->fl; |
for (nn = n->child; nn->next; nn = nn->next) |
mt->fl &= ~MANT_LITERAL; |
print_man_node(p, mt, nn, m); |
|
|
if (n->child) |
|
print_man_node(p, mt, n->child, m); |
|
|
|
if (savelit) |
|
mt->fl |= MANT_LITERAL; |
|
|
return(0); |
return(0); |
case (MAN_BODY): |
case (MAN_BODY): |
p->offset = mt->offset + len; |
p->offset = mt->offset + len; |
Line 587 post_IP(DECL_ARGS) |
|
Line 593 post_IP(DECL_ARGS) |
|
p->rmargin = p->maxrmargin; |
p->rmargin = p->maxrmargin; |
break; |
break; |
case (MAN_BODY): |
case (MAN_BODY): |
term_flushln(p); |
term_newln(p); |
p->flags &= ~TERMP_NOLPAD; |
p->flags &= ~TERMP_NOLPAD; |
break; |
break; |
default: |
default: |
Line 602 pre_TP(DECL_ARGS) |
|
Line 608 pre_TP(DECL_ARGS) |
|
{ |
{ |
const struct man_node *nn; |
const struct man_node *nn; |
size_t len; |
size_t len; |
int ival; |
int savelit, ival; |
|
|
switch (n->type) { |
switch (n->type) { |
case (MAN_HEAD): |
case (MAN_HEAD): |
p->flags |= TERMP_NOBREAK; |
p->flags |= TERMP_NOBREAK; |
p->flags |= TERMP_TWOSPACE; |
|
break; |
break; |
case (MAN_BODY): |
case (MAN_BODY): |
p->flags |= TERMP_NOLPAD; |
p->flags |= TERMP_NOLPAD; |
Line 642 pre_TP(DECL_ARGS) |
|
Line 647 pre_TP(DECL_ARGS) |
|
p->offset = mt->offset; |
p->offset = mt->offset; |
p->rmargin = mt->offset + len; |
p->rmargin = mt->offset + len; |
|
|
|
savelit = MANT_LITERAL & mt->fl; |
|
mt->fl &= ~MANT_LITERAL; |
|
|
/* Don't print same-line elements. */ |
/* Don't print same-line elements. */ |
for (nn = n->child; nn; nn = nn->next) |
for (nn = n->child; nn; nn = nn->next) |
if (nn->line > n->line) |
if (nn->line > n->line) |
print_man_node(p, mt, nn, m); |
print_man_node(p, mt, nn, m); |
|
|
|
if (savelit) |
|
mt->fl |= MANT_LITERAL; |
|
|
if (ival >= 0) |
if (ival >= 0) |
mt->lmargin = (size_t)ival; |
mt->lmargin = (size_t)ival; |
|
|
Line 676 post_TP(DECL_ARGS) |
|
Line 687 post_TP(DECL_ARGS) |
|
p->rmargin = p->maxrmargin; |
p->rmargin = p->maxrmargin; |
break; |
break; |
case (MAN_BODY): |
case (MAN_BODY): |
term_flushln(p); |
term_newln(p); |
p->flags &= ~TERMP_NOLPAD; |
p->flags &= ~TERMP_NOLPAD; |
break; |
break; |
default: |
default: |
Line 844 print_man_node(DECL_ARGS) |
|
Line 855 print_man_node(DECL_ARGS) |
|
size_t rm, rmax; |
size_t rm, rmax; |
int c; |
int c; |
|
|
c = 1; |
|
|
|
switch (n->type) { |
switch (n->type) { |
case(MAN_TEXT): |
case(MAN_TEXT): |
if (0 == *n->string) { |
/* |
|
* If we have a blank line, output a vertical space. |
|
* If we have a space as the first character, break |
|
* before printing the line's data. |
|
*/ |
|
if ('\0' == *n->string) { |
term_vspace(p); |
term_vspace(p); |
break; |
return; |
} |
} else if (' ' == *n->string && MAN_LINE & n->flags) |
|
term_newln(p); |
|
|
term_word(p, n->string); |
term_word(p, n->string); |
|
|
/* FIXME: this means that macro lines are munged! */ |
/* |
|
* If we're in a literal context, make sure that words |
if (MANT_LITERAL & mt->fl) { |
* 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 && |
|
(NULL == n->next || |
|
n->next->line > n->line)) { |
rm = p->rmargin; |
rm = p->rmargin; |
rmax = p->maxrmargin; |
rmax = p->maxrmargin; |
p->rmargin = p->maxrmargin = TERM_MAXMARGIN; |
p->rmargin = p->maxrmargin = TERM_MAXMARGIN; |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_flushln(p); |
term_flushln(p); |
|
p->flags &= ~TERMP_NOLPAD; |
p->rmargin = rm; |
p->rmargin = rm; |
p->maxrmargin = rmax; |
p->maxrmargin = rmax; |
} |
} |
break; |
|
|
if (MAN_EOS & n->flags) |
|
p->flags |= TERMP_SENTENCE; |
|
return; |
|
case (MAN_TBL): |
|
/* |
|
* Tables are preceded by a newline. Then process a |
|
* table line, which will cause line termination, |
|
*/ |
|
if (TBL_SPAN_FIRST & n->span->flags) |
|
term_newln(p); |
|
term_tbl(p, n->span); |
|
return; |
default: |
default: |
if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) |
|
term_fontrepl(p, TERMFONT_NONE); |
|
if (termacts[n->tok].pre) |
|
c = (*termacts[n->tok].pre)(p, mt, n, m); |
|
break; |
break; |
} |
} |
|
|
|
if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) |
|
term_fontrepl(p, TERMFONT_NONE); |
|
|
|
c = 1; |
|
if (termacts[n->tok].pre) |
|
c = (*termacts[n->tok].pre)(p, mt, n, m); |
|
|
if (c && n->child) |
if (c && n->child) |
print_man_nodelist(p, mt, n->child, m); |
print_man_nodelist(p, mt, n->child, m); |
|
|
if (MAN_TEXT != n->type) { |
if (termacts[n->tok].post) |
if (termacts[n->tok].post) |
(*termacts[n->tok].post)(p, mt, n, m); |
(*termacts[n->tok].post)(p, mt, n, m); |
if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) |
if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) |
term_fontrepl(p, TERMFONT_NONE); |
term_fontrepl(p, TERMFONT_NONE); |
|
} |
|
|
|
if (MAN_EOS & n->flags) |
if (MAN_EOS & n->flags) |
p->flags |= TERMP_SENTENCE; |
p->flags |= TERMP_SENTENCE; |