version 1.42, 2009/03/05 13:12:12 |
version 1.44, 2009/03/08 13:52:29 |
Line 83 const int ttypes[TTYPE_NMAX] = { |
|
Line 83 const int ttypes[TTYPE_NMAX] = { |
|
TERMP_BOLD /* TTYPE_DIAG */ |
TERMP_BOLD /* TTYPE_DIAG */ |
}; |
}; |
|
|
static int arg_hasattr(int, size_t, |
static int arg_hasattr(int, const struct mdoc_node *); |
const struct mdoc_arg *); |
static int arg_getattr(int, const struct mdoc_node *); |
static int arg_getattr(int, size_t, |
static size_t arg_offset(const struct mdoc_argv *); |
const struct mdoc_arg *); |
static size_t arg_width(const struct mdoc_argv *); |
static size_t arg_offset(const struct mdoc_arg *); |
|
static size_t arg_width(const struct mdoc_arg *); |
|
static int arg_listtype(const struct mdoc_node *); |
static int arg_listtype(const struct mdoc_node *); |
|
|
/* |
/* |
Line 166 DECL_PRE(termp_xr); |
|
Line 164 DECL_PRE(termp_xr); |
|
DECL_POST(termp___); |
DECL_POST(termp___); |
DECL_POST(termp_bl); |
DECL_POST(termp_bl); |
DECL_POST(termp_bx); |
DECL_POST(termp_bx); |
|
DECL_POST(termp_lb); |
|
|
const struct termact __termacts[MDOC_MAX] = { |
const struct termact __termacts[MDOC_MAX] = { |
{ NULL, NULL }, /* \" */ |
{ NULL, NULL }, /* \" */ |
Line 274 const struct termact __termacts[MDOC_MAX] = { |
|
Line 273 const struct termact __termacts[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Hf */ |
{ NULL, NULL }, /* Hf */ |
{ NULL, NULL }, /* Fr */ |
{ NULL, NULL }, /* Fr */ |
{ termp_ud_pre, NULL }, /* Ud */ |
{ termp_ud_pre, NULL }, /* Ud */ |
|
{ NULL, termp_lb_post }, /* lb */ |
}; |
}; |
|
|
const struct termact *termacts = __termacts; |
const struct termact *termacts = __termacts; |
|
|
|
|
static size_t |
static size_t |
arg_width(const struct mdoc_arg *arg) |
arg_width(const struct mdoc_argv *arg) |
{ |
{ |
size_t v; |
size_t v; |
int i, len; |
int i, len; |
Line 312 arg_width(const struct mdoc_arg *arg) |
|
Line 312 arg_width(const struct mdoc_arg *arg) |
|
static int |
static int |
arg_listtype(const struct mdoc_node *n) |
arg_listtype(const struct mdoc_node *n) |
{ |
{ |
const struct mdoc_block *bl; |
|
int i, len; |
int i, len; |
|
|
bl = &n->data.block; |
assert(MDOC_BLOCK == n->type); |
len = (int)bl->argc; |
|
|
|
|
len = n->args ? n->args->argc : 0; |
|
|
for (i = 0; i < len; i++) |
for (i = 0; i < len; i++) |
switch (bl->argv[i].arg) { |
switch (n->args->argv[i].arg) { |
case (MDOC_Bullet): |
case (MDOC_Bullet): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Dash): |
case (MDOC_Dash): |
Line 337 arg_listtype(const struct mdoc_node *n) |
|
Line 337 arg_listtype(const struct mdoc_node *n) |
|
case (MDOC_Item): |
case (MDOC_Item): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Ohang): |
case (MDOC_Ohang): |
return(bl->argv[i].arg); |
return(n->args->argv[i].arg); |
default: |
default: |
break; |
break; |
} |
} |
Line 348 arg_listtype(const struct mdoc_node *n) |
|
Line 348 arg_listtype(const struct mdoc_node *n) |
|
|
|
|
|
static size_t |
static size_t |
arg_offset(const struct mdoc_arg *arg) |
arg_offset(const struct mdoc_argv *arg) |
{ |
{ |
|
|
/* TODO */ |
/* TODO */ |
Line 362 arg_offset(const struct mdoc_arg *arg) |
|
Line 362 arg_offset(const struct mdoc_arg *arg) |
|
|
|
|
|
static int |
static int |
arg_hasattr(int arg, size_t argc, const struct mdoc_arg *argv) |
arg_hasattr(int arg, const struct mdoc_node *n) |
{ |
{ |
|
|
return(-1 != arg_getattr(arg, argc, argv)); |
return(-1 != arg_getattr(arg, n)); |
} |
} |
|
|
|
|
static int |
static int |
arg_getattr(int arg, size_t argc, const struct mdoc_arg *argv) |
arg_getattr(int arg, const struct mdoc_node *n) |
{ |
{ |
int i; |
int i; |
|
|
for (i = 0; i < (int)argc; i++) |
if (NULL == n->args) |
if (argv[i].arg == arg) |
return(-1); |
|
for (i = 0; i < (int)n->args->argc; i++) |
|
if (n->args->argv[i].arg == arg) |
return(i); |
return(i); |
return(-1); |
return(-1); |
} |
} |
Line 412 termp_dq_post(DECL_ARGS) |
|
Line 414 termp_dq_post(DECL_ARGS) |
|
static int |
static int |
termp_it_pre_block(DECL_ARGS) |
termp_it_pre_block(DECL_ARGS) |
{ |
{ |
const struct mdoc_node *n; |
|
const struct mdoc_block *bl; |
|
|
|
n = node->parent->parent; |
|
bl = &n->data.block; |
|
|
|
newln(p); |
newln(p); |
if ( ! arg_hasattr(MDOC_Compact, bl->argc, bl->argv)) |
if ( ! arg_hasattr(MDOC_Compact, node->parent->parent)) |
if (node->prev || n->prev) |
if (node->prev || node->parent->parent->prev) |
vspace(p); |
vspace(p); |
|
|
return(1); |
return(1); |
Line 431 termp_it_pre_block(DECL_ARGS) |
|
Line 428 termp_it_pre_block(DECL_ARGS) |
|
static int |
static int |
termp_it_pre(DECL_ARGS) |
termp_it_pre(DECL_ARGS) |
{ |
{ |
const struct mdoc_block *bl; |
const struct mdoc_node *bl; |
char buf[7]; |
char buf[7]; |
int i, type; |
int i, type; |
size_t width, offset; |
size_t width, offset; |
Line 441 termp_it_pre(DECL_ARGS) |
|
Line 438 termp_it_pre(DECL_ARGS) |
|
|
|
/* Get ptr to list block, type, etc. */ |
/* Get ptr to list block, type, etc. */ |
|
|
bl = &node->parent->parent->parent->data.block; |
bl = node->parent->parent->parent; |
type = arg_listtype(node->parent->parent->parent); |
type = arg_listtype(bl); |
|
|
/* Save parent attributes. */ |
/* Save parent attributes. */ |
|
|
Line 452 termp_it_pre(DECL_ARGS) |
|
Line 449 termp_it_pre(DECL_ARGS) |
|
|
|
/* Get list width and offset. */ |
/* Get list width and offset. */ |
|
|
i = arg_getattr(MDOC_Width, bl->argc, bl->argv); |
i = arg_getattr(MDOC_Width, bl); |
width = i >= 0 ? arg_width(&bl->argv[i]) : 0; |
width = i >= 0 ? arg_width(&bl->args->argv[i]) : 0; |
|
|
i = arg_getattr(MDOC_Offset, bl->argc, bl->argv); |
i = arg_getattr(MDOC_Offset, bl); |
offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0; |
offset = i >= 0 ? arg_offset(&bl->args->argv[i]) : 0; |
|
|
/* |
/* |
* List-type can override the width in the case of fixed-head |
* List-type can override the width in the case of fixed-head |
Line 721 termp_pp_pre(DECL_ARGS) |
|
Line 718 termp_pp_pre(DECL_ARGS) |
|
static int |
static int |
termp_st_pre(DECL_ARGS) |
termp_st_pre(DECL_ARGS) |
{ |
{ |
const char *tp; |
const char *cp; |
|
|
assert(1 == node->data.elem.argc); |
if (node->child) { |
|
if (MDOC_TEXT != node->child->type) |
tp = mdoc_st2a(node->data.elem.argv[0].arg); |
errx(1, "expected text line arguments"); |
word(p, tp); |
if ((cp = mdoc_a2st(node->child->string))) |
|
word(p, cp); |
return(1); |
} |
|
return(0); |
} |
} |
|
|
|
|
Line 749 termp_rv_pre(DECL_ARGS) |
|
Line 747 termp_rv_pre(DECL_ARGS) |
|
{ |
{ |
int i; |
int i; |
|
|
i = arg_getattr(MDOC_Std, node->data.elem.argc, |
if (-1 == (i = arg_getattr(MDOC_Std, node))) |
node->data.elem.argv); |
errx(1, "expected -std argument"); |
assert(i >= 0); |
if (1 != node->args->argv[i].sz) |
|
errx(1, "expected -std argument"); |
|
|
newln(p); |
newln(p); |
word(p, "The"); |
word(p, "The"); |
|
|
p->flags |= ttypes[TTYPE_FUNC_NAME]; |
p->flags |= ttypes[TTYPE_FUNC_NAME]; |
word(p, *node->data.elem.argv[i].value); |
word(p, *node->args->argv[i].value); |
p->flags &= ~ttypes[TTYPE_FUNC_NAME]; |
p->flags &= ~ttypes[TTYPE_FUNC_NAME]; |
|
|
word(p, "() function returns the value 0 if successful;"); |
word(p, "() function returns the value 0 if successful;"); |
Line 780 termp_ex_pre(DECL_ARGS) |
|
Line 779 termp_ex_pre(DECL_ARGS) |
|
{ |
{ |
int i; |
int i; |
|
|
i = arg_getattr(MDOC_Std, node->data.elem.argc, |
if (-1 == (i = arg_getattr(MDOC_Std, node))) |
node->data.elem.argv); |
errx(1, "expected -std argument"); |
assert(i >= 0); |
if (1 != node->args->argv[i].sz) |
|
errx(1, "expected -std argument"); |
|
|
word(p, "The"); |
word(p, "The"); |
p->flags |= ttypes[TTYPE_PROG]; |
p->flags |= ttypes[TTYPE_PROG]; |
word(p, *node->data.elem.argv[i].value); |
word(p, *node->args->argv[i].value); |
p->flags &= ~ttypes[TTYPE_PROG]; |
p->flags &= ~ttypes[TTYPE_PROG]; |
word(p, "utility exits 0 on success, and >0 if an error occurs."); |
word(p, "utility exits 0 on success, and >0 if an error occurs."); |
|
|
Line 832 termp_xr_pre(DECL_ARGS) |
|
Line 832 termp_xr_pre(DECL_ARGS) |
|
{ |
{ |
const struct mdoc_node *n; |
const struct mdoc_node *n; |
|
|
n = node->child; |
if (NULL == (n = node->child)) |
assert(n); |
errx(1, "expected text line argument"); |
|
if (MDOC_TEXT != n->type) |
|
errx(1, "expected text line argument"); |
|
|
assert(MDOC_TEXT == n->type); |
word(p, n->string); |
word(p, n->data.text.string); |
|
|
|
if (NULL == (n = n->next)) |
if (NULL == (n = n->next)) |
return(0); |
return(0); |
|
if (MDOC_TEXT != n->type) |
|
errx(1, "expected text line argument"); |
|
|
assert(MDOC_TEXT == n->type); |
|
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
word(p, "("); |
word(p, "("); |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
word(p, n->data.text.string); |
word(p, n->string); |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
word(p, ")"); |
word(p, ")"); |
|
|
Line 968 termp_bt_pre(DECL_ARGS) |
|
Line 970 termp_bt_pre(DECL_ARGS) |
|
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
|
static void |
|
termp_lb_post(DECL_ARGS) |
|
{ |
|
|
|
newln(p); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
static int |
static int |
termp_ud_pre(DECL_ARGS) |
termp_ud_pre(DECL_ARGS) |
{ |
{ |
Line 1056 termp_fn_pre(DECL_ARGS) |
|
Line 1067 termp_fn_pre(DECL_ARGS) |
|
{ |
{ |
const struct mdoc_node *n; |
const struct mdoc_node *n; |
|
|
assert(node->child); |
if (NULL == node->child) |
assert(MDOC_TEXT == node->child->type); |
errx(1, "expected text line arguments"); |
|
if (MDOC_TEXT != node->child->type) |
|
errx(1, "expected text line arguments"); |
|
|
/* FIXME: can be "type funcname" "type varname"... */ |
/* FIXME: can be "type funcname" "type varname"... */ |
|
|
p->flags |= ttypes[TTYPE_FUNC_NAME]; |
p->flags |= ttypes[TTYPE_FUNC_NAME]; |
word(p, node->child->data.text.string); |
word(p, node->child->string); |
p->flags &= ~ttypes[TTYPE_FUNC_NAME]; |
p->flags &= ~ttypes[TTYPE_FUNC_NAME]; |
|
|
word(p, "("); |
word(p, "("); |
|
|
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
for (n = node->child->next; n; n = n->next) { |
for (n = node->child->next; n; n = n->next) { |
assert(MDOC_TEXT == n->type); |
if (MDOC_TEXT != n->type) |
|
errx(1, "expected text line arguments"); |
p->flags |= ttypes[TTYPE_FUNC_ARG]; |
p->flags |= ttypes[TTYPE_FUNC_ARG]; |
word(p, n->data.text.string); |
word(p, n->string); |
p->flags &= ~ttypes[TTYPE_FUNC_ARG]; |
p->flags &= ~ttypes[TTYPE_FUNC_ARG]; |
if (n->next) |
if (n->next) |
word(p, ","); |
word(p, ","); |
Line 1119 termp_fa_pre(DECL_ARGS) |
|
Line 1133 termp_fa_pre(DECL_ARGS) |
|
} |
} |
|
|
for (n = node->child; n; n = n->next) { |
for (n = node->child; n; n = n->next) { |
assert(MDOC_TEXT == n->type); |
if (MDOC_TEXT != n->type) |
|
errx(1, "expected text line arguments"); |
|
|
p->flags |= ttypes[TTYPE_FUNC_ARG]; |
p->flags |= ttypes[TTYPE_FUNC_ARG]; |
word(p, n->data.text.string); |
word(p, n->string); |
p->flags &= ~ttypes[TTYPE_FUNC_ARG]; |
p->flags &= ~ttypes[TTYPE_FUNC_ARG]; |
|
|
if (n->next) |
if (n->next) |
Line 1150 termp_va_pre(DECL_ARGS) |
|
Line 1165 termp_va_pre(DECL_ARGS) |
|
static int |
static int |
termp_bd_pre(DECL_ARGS) |
termp_bd_pre(DECL_ARGS) |
{ |
{ |
const struct mdoc_block *bl; |
|
const struct mdoc_node *n; |
const struct mdoc_node *n; |
int i, type; |
int i, type; |
|
|
if (MDOC_BLOCK == node->type) { |
if (MDOC_BLOCK == node->type) { |
if (node->prev) |
if (node->prev) |
Line 1161 termp_bd_pre(DECL_ARGS) |
|
Line 1175 termp_bd_pre(DECL_ARGS) |
|
} else if (MDOC_BODY != node->type) |
} else if (MDOC_BODY != node->type) |
return(1); |
return(1); |
|
|
|
if (NULL == node->parent->args) |
|
errx(1, "missing display type"); |
|
|
pair->offset = p->offset; |
pair->offset = p->offset; |
bl = &node->parent->data.block; |
|
|
|
for (type = -1, i = 0; i < (int)bl->argc; i++) { |
for (type = -1, i = 0; |
switch (bl->argv[i].arg) { |
i < (int)node->parent->args->argc; i++) { |
|
switch (node->parent->args->argv[i].arg) { |
case (MDOC_Ragged): |
case (MDOC_Ragged): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Filled): |
case (MDOC_Filled): |
Line 1173 termp_bd_pre(DECL_ARGS) |
|
Line 1190 termp_bd_pre(DECL_ARGS) |
|
case (MDOC_Unfilled): |
case (MDOC_Unfilled): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Literal): |
case (MDOC_Literal): |
type = bl->argv[i].arg; |
type = node->parent->args->argv[i].arg; |
i = (int)bl->argc; |
i = (int)node->parent->args->argc; |
break; |
break; |
default: |
default: |
errx(1, "display type not supported"); |
break; |
} |
} |
} |
} |
|
|
assert(-1 != type); |
if (NULL == node->parent->args) |
|
errx(1, "missing display type"); |
|
|
i = arg_getattr(MDOC_Offset, bl->argc, bl->argv); |
i = arg_getattr(MDOC_Offset, node->parent); |
if (-1 != i) { |
if (-1 != i) { |
assert(1 == bl->argv[i].sz); |
if (1 != node->args->argv[i].sz) |
p->offset += arg_offset(&bl->argv[i]); |
errx(1, "expected single value"); |
|
p->offset += arg_offset(&node->args->argv[i]); |
} |
} |
|
|
|
|
switch (type) { |
switch (type) { |
case (MDOC_Literal): |
case (MDOC_Literal): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
Line 1206 termp_bd_pre(DECL_ARGS) |
|
Line 1224 termp_bd_pre(DECL_ARGS) |
|
warnx("non-text children not yet allowed"); |
warnx("non-text children not yet allowed"); |
continue; |
continue; |
} |
} |
word(p, n->data.text.string); |
word(p, n->string); |
flushln(p); |
flushln(p); |
} |
} |
|
|
Line 1480 termp_in_post(DECL_ARGS) |
|
Line 1498 termp_in_post(DECL_ARGS) |
|
static int |
static int |
termp_at_pre(DECL_ARGS) |
termp_at_pre(DECL_ARGS) |
{ |
{ |
enum mdoc_att c; |
const char *att; |
|
|
c = ATT_DEFAULT; |
att = NULL; |
|
|
if (node->child) { |
if (node->child) { |
assert(MDOC_TEXT == node->child->type); |
if (MDOC_TEXT != node->child->type) |
c = mdoc_atoatt(node->child->data.text.string); |
errx(1, "expected text line argument"); |
|
att = mdoc_a2att(node->child->string); |
} |
} |
|
|
word(p, mdoc_att2a(c)); |
if (NULL == att) |
|
att = "AT&T UNIX"; |
|
|
|
word(p, att); |
return(0); |
return(0); |
} |
} |
|
|
Line 1558 termp_fo_pre(DECL_ARGS) |
|
Line 1581 termp_fo_pre(DECL_ARGS) |
|
|
|
p->flags |= ttypes[TTYPE_FUNC_NAME]; |
p->flags |= ttypes[TTYPE_FUNC_NAME]; |
for (n = node->child; n; n = n->next) { |
for (n = node->child; n; n = n->next) { |
assert(MDOC_TEXT == n->type); |
if (MDOC_TEXT != n->type) |
word(p, n->data.text.string); |
errx(1, "expected text line argument"); |
|
word(p, n->string); |
} |
} |
p->flags &= ~ttypes[TTYPE_FUNC_NAME]; |
p->flags &= ~ttypes[TTYPE_FUNC_NAME]; |
|
|
|
|
termp_bf_pre(DECL_ARGS) |
termp_bf_pre(DECL_ARGS) |
{ |
{ |
const struct mdoc_node *n; |
const struct mdoc_node *n; |
const struct mdoc_block *b; |
|
|
|
/* XXX - we skip over possible trailing HEAD tokens. */ |
if (MDOC_HEAD == node->type) { |
|
|
if (MDOC_HEAD == node->type) |
|
return(0); |
return(0); |
else if (MDOC_BLOCK != node->type) |
} else if (MDOC_BLOCK != node->type) |
return(1); |
return(1); |
|
|
b = &node->data.block; |
if (NULL == (n = node->head->child)) { |
|
if (arg_hasattr(MDOC_Emphasis, node)) |
if (NULL == (n = b->head->child)) { |
|
if (arg_hasattr(MDOC_Emphasis, b->argc, b->argv)) |
|
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); |
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); |
else if (arg_hasattr(MDOC_Symbolic, b->argc, b->argv)) |
else if (arg_hasattr(MDOC_Symbolic, node)) |
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]); |
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]); |
|
|
return(1); |
return(1); |
} |
} |
|
|
assert(MDOC_TEXT == n->type); |
if (MDOC_TEXT != n->type) |
|
errx(1, "expected text line arguments"); |
|
|
if (0 == strcmp("Em", n->data.text.string)) |
if (0 == strcmp("Em", n->string)) |
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); |
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); |
else if (0 == strcmp("Sy", n->data.text.string)) |
else if (0 == strcmp("Sy", n->string)) |
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); |
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); |
|
|
return(1); |
return(1); |