version 1.22, 2009/02/25 17:02:47 |
version 1.23, 2009/02/25 23:18:50 |
|
|
* PERFORMANCE OF THIS SOFTWARE. |
* PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#include <assert.h> |
#include <assert.h> |
|
#include <err.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
Line 350 termp_it_pre(DECL_ARGS) |
|
Line 351 termp_it_pre(DECL_ARGS) |
|
{ |
{ |
const struct mdoc_node *n, *it; |
const struct mdoc_node *n, *it; |
const struct mdoc_block *bl; |
const struct mdoc_block *bl; |
char buf[7]; |
char buf[7], *tp; |
int i; |
int i, type; |
size_t width, offset; |
size_t width, offset; |
|
|
switch (node->type) { |
switch (node->type) { |
Line 378 termp_it_pre(DECL_ARGS) |
|
Line 379 termp_it_pre(DECL_ARGS) |
|
return(1); |
return(1); |
} |
} |
|
|
|
/* Get our list type. */ |
|
|
|
for (i = 0; i < (int)bl->argc; i++) |
|
switch (bl->argv[i].arg) { |
|
case (MDOC_Bullet): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Dash): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Enum): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Hyphen): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Item): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Tag): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Ohang): |
|
type = bl->argv[i].arg; |
|
i = (int)bl->argc; |
|
break; |
|
case (MDOC_Inset): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Hang): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Diag): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Column): |
|
errx(1, "list type not supported"); |
|
/* NOTREACHED */ |
|
default: |
|
break; |
|
} |
|
|
|
/* Save our existing (inherited) margin and offset. */ |
|
|
pair->offset = p->offset; |
pair->offset = p->offset; |
pair->rmargin = p->rmargin; |
pair->rmargin = p->rmargin; |
|
|
|
/* Get list width and offset. */ |
|
|
/* FIXME: auto-size. */ |
/* FIXME: auto-size. */ |
i = arg_getattr(MDOC_Width, bl->argc, bl->argv); |
i = arg_getattr(MDOC_Width, bl->argc, bl->argv); |
width = i >= 0 ? arg_width(&bl->argv[i]) : 10; |
width = i >= 0 ? arg_width(&bl->argv[i]) : 0; |
|
|
i = arg_getattr(MDOC_Offset, bl->argc, bl->argv); |
i = arg_getattr(MDOC_Offset, bl->argc, bl->argv); |
offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0; |
offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0; |
|
|
assert(MDOC_HEAD == node->type || |
/* Override the width. */ |
MDOC_BODY == node->type); |
|
|
|
if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv)) { |
switch (type) { |
p->flags |= TERMP_NOSPACE; |
case (MDOC_Bullet): |
if (MDOC_BODY == node->type) { |
/* FALLTHROUGH */ |
p->flags |= TERMP_NOLPAD; |
case (MDOC_Dash): |
p->offset += width; |
/* FALLTHROUGH */ |
} else { |
case (MDOC_Enum): |
p->flags |= TERMP_NOBREAK; |
/* FALLTHROUGH */ |
p->rmargin = p->offset + offset + width; |
case (MDOC_Hyphen): |
} |
width = width > 6 ? width : 6; |
|
break; |
|
case (MDOC_Tag): |
|
if (0 == width) |
|
errx(1, "need non-zero -width"); |
|
break; |
|
default: |
|
break; |
|
} |
|
|
} else if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) { |
/* Word-wrap control. */ |
p->flags |= TERMP_NOSPACE; |
|
|
|
} else if (arg_hasattr(MDOC_Diag, bl->argc, bl->argv)) { |
p->flags |= TERMP_NOSPACE; |
/* TODO. */ |
|
|
|
} else if (arg_hasattr(MDOC_Hang, bl->argc, bl->argv)) { |
switch (type) { |
/* TODO. */ |
case (MDOC_Bullet): |
|
/* FALLTHROUGH */ |
} else if (arg_hasattr(MDOC_Bullet, bl->argc, bl->argv)) { |
case (MDOC_Dash): |
p->flags |= TERMP_NOSPACE; |
/* FALLTHROUGH */ |
if (MDOC_BODY == node->type) { |
case (MDOC_Enum): |
p->flags |= TERMP_NOLPAD; |
/* FALLTHROUGH */ |
p->offset += 6; |
case (MDOC_Hyphen): |
} else { |
/* FALLTHROUGH */ |
word(p, "\\[bu]"); |
case (MDOC_Tag): |
|
if (MDOC_HEAD == node->type) |
p->flags |= TERMP_NOBREAK; |
p->flags |= TERMP_NOBREAK; |
p->rmargin = p->offset + offset + 6; |
else if (MDOC_BODY == node->type) |
} |
|
|
|
} else if (arg_hasattr(MDOC_Enum, bl->argc, bl->argv)) { |
|
p->flags |= TERMP_NOSPACE; |
|
if (MDOC_BODY == node->type) { |
|
p->flags |= TERMP_NOLPAD; |
p->flags |= TERMP_NOLPAD; |
p->offset += 6; |
break; |
} else { |
case (MDOC_Ohang): |
|
break; |
|
} |
|
|
|
/* |
|
* Get a token to use as the HEAD lead-in. If NULL, we use the |
|
* HEAD child. |
|
*/ |
|
|
|
tp = NULL; |
|
if (MDOC_HEAD == node->type) { |
|
if (arg_hasattr(MDOC_Bullet, bl->argc, bl->argv)) |
|
tp = "\\[bu]"; |
|
if (arg_hasattr(MDOC_Dash, bl->argc, bl->argv)) |
|
tp = "\\-"; |
|
if (arg_hasattr(MDOC_Enum, bl->argc, bl->argv)) { |
(pair->ppair->ppair->count)++; |
(pair->ppair->ppair->count)++; |
(void)snprintf(buf, sizeof(buf), "%d.", |
(void)snprintf(buf, sizeof(buf), "%d.", |
pair->ppair->ppair->count); |
pair->ppair->ppair->count); |
word(p, buf); |
tp = buf; |
p->flags |= TERMP_NOBREAK; |
|
p->rmargin = p->offset + offset + 6; |
|
} |
} |
|
if (arg_hasattr(MDOC_Hyphen, bl->argc, bl->argv)) |
|
tp = "\\-"; |
|
if (arg_hasattr(MDOC_Item, bl->argc, bl->argv)) |
|
tp = ""; |
|
} |
|
|
} else if (arg_hasattr(MDOC_Dash, bl->argc, bl->argv) || |
/* Margin control. */ |
arg_hasattr(MDOC_Hyphen, bl->argc, bl->argv)) { |
|
p->flags |= TERMP_NOSPACE; |
|
if (MDOC_BODY == node->type) { |
|
p->flags |= TERMP_NOLPAD; |
|
p->offset += 6; |
|
return(1); |
|
} else { |
|
word(p, "\\-"); |
|
p->flags |= TERMP_NOBREAK; |
|
p->rmargin = p->offset + offset + 6; |
|
} |
|
} |
|
|
|
p->offset += offset; |
p->offset += offset; |
return(1); |
|
|
switch (type) { |
|
case (MDOC_Bullet): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Dash): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Enum): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Hyphen): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Item): |
|
/* FALLTHROUGH */ |
|
case (MDOC_Tag): |
|
if (MDOC_HEAD == node->type) |
|
p->rmargin = p->offset + width; |
|
else if (MDOC_BODY == node->type) |
|
p->offset += width; |
|
break; |
|
case (MDOC_Ohang): |
|
break; |
|
} |
|
|
|
if (NULL == tp) |
|
return(1); |
|
|
|
/* XXX - ignoring children. */ |
|
|
|
word(p, tp); |
|
return(0); |
} |
} |
|
|
|
|
Line 458 termp_it_pre(DECL_ARGS) |
|
Line 531 termp_it_pre(DECL_ARGS) |
|
static void |
static void |
termp_it_post(DECL_ARGS) |
termp_it_post(DECL_ARGS) |
{ |
{ |
const struct mdoc_node *n, *it; |
|
const struct mdoc_block *bl; |
|
|
|
if (MDOC_BODY != node->type && MDOC_HEAD != node->type) |
if (MDOC_BODY != node->type && MDOC_HEAD != node->type) |
return; |
return; |
|
|
it = node->parent; |
flushln(p); |
n = it->parent->parent; |
|
bl = &n->data.block; |
|
|
|
if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv) || |
|
arg_hasattr(MDOC_Bullet, bl->argc, bl->argv) || |
|
arg_hasattr(MDOC_Dash, bl->argc, bl->argv) || |
|
arg_hasattr(MDOC_Enum, bl->argc, bl->argv) || |
|
arg_hasattr(MDOC_Hyphen, bl->argc, bl->argv)) { |
|
flushln(p); |
|
if (MDOC_HEAD == node->type) { |
|
p->rmargin = pair->rmargin; |
|
p->flags &= ~TERMP_NOBREAK; |
|
} else |
|
p->flags &= ~TERMP_NOLPAD; |
|
|
|
} else if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) { |
|
flushln(p); |
|
|
|
} else if (arg_hasattr(MDOC_Inset, bl->argc, bl->argv)) { |
|
if (MDOC_BODY == node->type) |
|
flushln(p); |
|
|
|
} else if (arg_hasattr(MDOC_Item, bl->argc, bl->argv)) { |
|
if (MDOC_BODY == node->type) |
|
flushln(p); |
|
} |
|
|
|
p->offset = pair->offset; |
p->offset = pair->offset; |
|
p->rmargin = pair->rmargin; |
|
|
|
if (MDOC_HEAD == node->type) { |
|
p->flags &= ~TERMP_NOBREAK; |
|
p->flags &= ~TERMP_NORPAD; |
|
} else if (MDOC_BODY == node->type) |
|
p->flags &= ~TERMP_NOLPAD; |
} |
} |
|
|
|
|