version 1.117, 2010/04/08 08:17:55 |
version 1.125, 2010/05/17 22:11:42 |
|
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
|
#include <stdint.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
|
|
#include "mandoc.h" |
#include "out.h" |
#include "out.h" |
#include "term.h" |
#include "term.h" |
#include "mdoc.h" |
#include "mdoc.h" |
Line 58 static int arg_hasattr(int, const struct mdoc_node * |
|
Line 60 static int arg_hasattr(int, const struct mdoc_node * |
|
static int arg_getattrs(const int *, int *, size_t, |
static int arg_getattrs(const int *, int *, size_t, |
const struct mdoc_node *); |
const struct mdoc_node *); |
static int arg_getattr(int, const struct mdoc_node *); |
static int arg_getattr(int, const struct mdoc_node *); |
|
static int arg_disptype(const struct mdoc_node *); |
static int arg_listtype(const struct mdoc_node *); |
static int arg_listtype(const struct mdoc_node *); |
static void print_bvspace(struct termp *, |
static void print_bvspace(struct termp *, |
const struct mdoc_node *, |
const struct mdoc_node *, |
Line 271 terminal_mdoc(void *arg, const struct mdoc *mdoc) |
|
Line 274 terminal_mdoc(void *arg, const struct mdoc *mdoc) |
|
p = (struct termp *)arg; |
p = (struct termp *)arg; |
|
|
p->overstep = 0; |
p->overstep = 0; |
p->maxrmargin = 78; |
p->maxrmargin = p->defrmargin; |
|
|
if (NULL == p->symtab) |
if (NULL == p->symtab) |
switch (p->enc) { |
switch (p->enc) { |
Line 335 print_mdoc_node(DECL_ARGS) |
|
Line 338 print_mdoc_node(DECL_ARGS) |
|
if (termacts[n->tok].post) |
if (termacts[n->tok].post) |
(*termacts[n->tok].post)(p, &npair, m, n); |
(*termacts[n->tok].post)(p, &npair, m, n); |
|
|
|
if (MDOC_EOS & n->flags) |
|
p->flags |= TERMP_SENTENCE; |
|
|
p->offset = offset; |
p->offset = offset; |
p->rmargin = rmargin; |
p->rmargin = rmargin; |
} |
} |
Line 420 print_mdoc_head(DECL_ARGS) |
|
Line 426 print_mdoc_head(DECL_ARGS) |
|
strlcat(buf, ")", BUFSIZ); |
strlcat(buf, ")", BUFSIZ); |
} |
} |
|
|
snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec); |
snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec); |
|
|
p->offset = 0; |
p->offset = 0; |
p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2; |
p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2; |
Line 478 a2width(const struct mdoc_argv *arg, int pos) |
|
Line 484 a2width(const struct mdoc_argv *arg, int pos) |
|
|
|
|
|
static int |
static int |
|
arg_disptype(const struct mdoc_node *n) |
|
{ |
|
int i, len; |
|
|
|
assert(MDOC_BLOCK == n->type); |
|
|
|
len = (int)(n->args ? n->args->argc : 0); |
|
|
|
for (i = 0; i < len; i++) |
|
switch (n->args->argv[i].arg) { |
|
case (MDOC_Centred): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Ragged): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Filled): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Unfilled): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Literal): |
|
return(n->args->argv[i].arg); |
|
default: |
|
break; |
|
} |
|
|
|
return(-1); |
|
} |
|
|
|
|
|
static int |
arg_listtype(const struct mdoc_node *n) |
arg_listtype(const struct mdoc_node *n) |
{ |
{ |
int i, len; |
int i, len; |
|
|
termp_nm_pre(DECL_ARGS) |
termp_nm_pre(DECL_ARGS) |
{ |
{ |
|
|
if (SEC_SYNOPSIS == n->sec) |
if (NULL == n->child && NULL == m->name) |
|
|
|
if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) |
term_newln(p); |
term_newln(p); |
|
|
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
|
|
if (NULL == n->child) |
if (NULL == n->child) |
term_word(p, m->name); |
term_word(p, m->name); |
|
|
return(1); |
return(1); |
} |
} |
|
|
Line 1126 termp_an_post(DECL_ARGS) |
|
Line 1164 termp_an_post(DECL_ARGS) |
|
return; |
return; |
} |
} |
|
|
if (arg_getattr(MDOC_Split, n) > -1) { |
if (arg_hasattr(MDOC_Split, n)) { |
p->flags &= ~TERMP_NOSPLIT; |
p->flags &= ~TERMP_NOSPLIT; |
p->flags |= TERMP_SPLIT; |
p->flags |= TERMP_SPLIT; |
} else { |
} else { |
Line 1182 termp_rv_pre(DECL_ARGS) |
|
Line 1220 termp_rv_pre(DECL_ARGS) |
|
term_word(p, "()"); |
term_word(p, "()"); |
} |
} |
|
|
if (n->child->next) |
if (n->child && n->child->next) |
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_ex_pre(DECL_ARGS) |
|
Line 1259 termp_ex_pre(DECL_ARGS) |
|
p->flags &= ~TERMP_NOSPACE; |
p->flags &= ~TERMP_NOSPACE; |
} |
} |
|
|
if (n->child->next) |
if (n->child && n->child->next) |
term_word(p, "utilities exit"); |
term_word(p, "utilities exit"); |
else |
else |
term_word(p, "utility exits"); |
term_word(p, "utility exits"); |
|
|
termp_fd_post(DECL_ARGS) |
termp_fd_post(DECL_ARGS) |
{ |
{ |
|
|
if (n->sec != SEC_SYNOPSIS) |
if (n->sec != SEC_SYNOPSIS || ! (MDOC_LINE & n->flags)) |
return; |
return; |
|
|
term_newln(p); |
term_newln(p); |
|
|
termp_lb_post(DECL_ARGS) |
termp_lb_post(DECL_ARGS) |
{ |
{ |
|
|
if (SEC_LIBRARY == n->sec) |
if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags) |
term_newln(p); |
term_newln(p); |
} |
} |
|
|
|
|
termp_ft_pre(DECL_ARGS) |
termp_ft_pre(DECL_ARGS) |
{ |
{ |
|
|
if (SEC_SYNOPSIS == n->sec) |
if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) |
if (n->prev && MDOC_Fo == n->prev->tok) |
if (n->prev && MDOC_Fo == n->prev->tok) |
term_vspace(p); |
term_vspace(p); |
|
|
|
|
termp_ft_post(DECL_ARGS) |
termp_ft_post(DECL_ARGS) |
{ |
{ |
|
|
if (SEC_SYNOPSIS == n->sec) |
if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) |
term_newln(p); |
term_newln(p); |
} |
} |
|
|
|
|
termp_fn_post(DECL_ARGS) |
termp_fn_post(DECL_ARGS) |
{ |
{ |
|
|
if (n->sec == SEC_SYNOPSIS && n->next) |
if (n->sec == SEC_SYNOPSIS && n->next && MDOC_LINE & n->flags) |
term_vspace(p); |
term_vspace(p); |
} |
} |
|
|
|
|
termp_bd_pre(DECL_ARGS) |
termp_bd_pre(DECL_ARGS) |
{ |
{ |
int i, type; |
int i, type; |
|
size_t rm, rmax; |
const struct mdoc_node *nn; |
const struct mdoc_node *nn; |
|
|
if (MDOC_BLOCK == n->type) { |
if (MDOC_BLOCK == n->type) { |
Line 1608 termp_bd_pre(DECL_ARGS) |
|
Line 1647 termp_bd_pre(DECL_ARGS) |
|
|
|
nn = n->parent; |
nn = n->parent; |
|
|
for (type = -1, i = 0; i < (int)nn->args->argc; i++) { |
type = arg_disptype(nn); |
switch (nn->args->argv[i].arg) { |
assert(-1 != type); |
case (MDOC_Centred): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Ragged): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Filled): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Unfilled): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Literal): |
|
type = nn->args->argv[i].arg; |
|
break; |
|
case (MDOC_Offset): |
|
p->offset += a2offs(&nn->args->argv[i]); |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
|
|
|
if (-1 != (i = arg_getattr(MDOC_Offset, nn))) |
|
p->offset += a2offs(&nn->args->argv[i]); |
|
|
/* |
/* |
* If -ragged or -filled are specified, the block does nothing |
* If -ragged or -filled are specified, the block does nothing |
* but change the indentation. If -unfilled or -literal are |
* but change the indentation. If -unfilled or -literal are |
Line 1637 termp_bd_pre(DECL_ARGS) |
|
Line 1661 termp_bd_pre(DECL_ARGS) |
|
* lines are allowed. |
* lines are allowed. |
*/ |
*/ |
|
|
assert(type > -1); |
|
if (MDOC_Literal != type && MDOC_Unfilled != type) |
if (MDOC_Literal != type && MDOC_Unfilled != type) |
return(1); |
return(1); |
|
|
|
rm = p->rmargin; |
|
rmax = p->maxrmargin; |
|
p->rmargin = p->maxrmargin = TERM_MAXMARGIN; |
|
|
for (nn = n->child; nn; nn = nn->next) { |
for (nn = n->child; nn; nn = nn->next) { |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
print_mdoc_node(p, pair, m, nn); |
print_mdoc_node(p, pair, m, nn); |
Line 1652 termp_bd_pre(DECL_ARGS) |
|
Line 1679 termp_bd_pre(DECL_ARGS) |
|
term_flushln(p); |
term_flushln(p); |
} |
} |
|
|
|
p->rmargin = rm; |
|
p->maxrmargin = rmax; |
return(0); |
return(0); |
} |
} |
|
|
Line 1660 termp_bd_pre(DECL_ARGS) |
|
Line 1689 termp_bd_pre(DECL_ARGS) |
|
static void |
static void |
termp_bd_post(DECL_ARGS) |
termp_bd_post(DECL_ARGS) |
{ |
{ |
|
int type; |
|
size_t rm, rmax; |
|
|
if (MDOC_BODY != n->type) |
if (MDOC_BODY != n->type) |
return; |
return; |
|
|
|
type = arg_disptype(n->parent); |
|
assert(-1 != type); |
|
|
|
rm = p->rmargin; |
|
rmax = p->maxrmargin; |
|
|
|
if (MDOC_Literal == type || MDOC_Unfilled == type) |
|
p->rmargin = p->maxrmargin = TERM_MAXMARGIN; |
|
|
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
term_flushln(p); |
term_flushln(p); |
|
|
|
p->rmargin = rm; |
|
p->maxrmargin = rmax; |
} |
} |
|
|
|
|
Line 1854 termp_in_post(DECL_ARGS) |
|
Line 1898 termp_in_post(DECL_ARGS) |
|
term_word(p, ">"); |
term_word(p, ">"); |
term_fontpop(p); |
term_fontpop(p); |
|
|
if (SEC_SYNOPSIS != n->sec) |
if (SEC_SYNOPSIS != n->sec && ! (MDOC_LINE & n->flags)) |
return; |
return; |
|
|
term_newln(p); |
term_newln(p); |