version 1.91, 2011/01/01 12:59:17 |
version 1.98, 2011/01/16 20:12:45 |
|
|
/* $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 396 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 513 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 533 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 557 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 585 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 600 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 640 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 674 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 842 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; |
return; |
case (MAN_TBL): |
case (MAN_TBL): |
break; |
/* |
|
* 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); |
|
|
switch (n->type) { |
if (termacts[n->tok].post) |
case (MAN_TEXT): |
(*termacts[n->tok].post)(p, mt, n, m); |
/* FALLTHROUGH */ |
if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) |
case (MAN_TBL): |
term_fontrepl(p, TERMFONT_NONE); |
break; |
|
default: |
|
if (termacts[n->tok].post) |
|
(*termacts[n->tok].post)(p, mt, n, m); |
|
if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) |
|
term_fontrepl(p, TERMFONT_NONE); |
|
break; |
|
} |
|
|
|
if (MAN_EOS & n->flags) |
if (MAN_EOS & n->flags) |
p->flags |= TERMP_SENTENCE; |
p->flags |= TERMP_SENTENCE; |