summaryrefslogtreecommitdiffstats
path: root/term.c
diff options
context:
space:
mode:
Diffstat (limited to 'term.c')
-rw-r--r--term.c150
1 files changed, 59 insertions, 91 deletions
diff --git a/term.c b/term.c
index ab0cb0ea..d5e9d744 100644
--- a/term.c
+++ b/term.c
@@ -343,31 +343,27 @@ termp_dq_post(DECL_ARGS)
/* ARGSUSED */
-static void
-termp_it_post(DECL_ARGS)
+static int
+termp_it_pre(DECL_ARGS)
{
const struct mdoc_node *n, *it;
const struct mdoc_block *bl;
int i;
size_t width, offset;
- /*
- * This (and termp_it_pre()) are the most complicated functions
- * here. They must account for a considerable number of
- * switches that completely change the output behaviour, like
- * -tag versus -column. Yech.
- */
-
switch (node->type) {
case (MDOC_BODY):
/* FALLTHROUGH */
case (MDOC_HEAD):
+ it = node->parent;
+ break;
+ case (MDOC_BLOCK):
+ it = node;
break;
default:
- return;
+ return(1);
}
- it = node->parent;
assert(MDOC_BLOCK == it->type);
assert(MDOC_It == it->tok);
@@ -377,66 +373,67 @@ termp_it_post(DECL_ARGS)
n = n->parent;
bl = &n->data.block;
- /* If `-tag', adjust our margins accordingly. */
+ /* If `-compact', don't assert vertical space. */
- if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv)) {
- flushln(p);
+ if (MDOC_BLOCK == node->type) {
+ if (arg_hasattr(MDOC_Compact, bl->argc, bl->argv))
+ newln(p);
+ else
+ vspace(p);
+ return(1);
+ }
- /* FIXME: this should auto-size. */
- i = arg_getattr(MDOC_Width, bl->argc, bl->argv);
- width = i >= 0 ? arg_width(&bl->argv[i]) : 10;
+ pair->offset = p->offset;
+ pair->rmargin = p->rmargin;
- /* FIXME: nesting! Should happen at block. */
- i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
- offset = i >= 0 ? arg_width(&bl->argv[i]) : 0;
+ /* FIXME: auto-size. */
+ i = arg_getattr(MDOC_Width, bl->argc, bl->argv);
+ width = i >= 0 ? arg_width(&bl->argv[i]) : 10;
+
+ i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
+ offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;
+
+ assert(MDOC_HEAD == node->type ||
+ MDOC_BODY == node->type);
+
+ if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv)) {
+ p->flags |= TERMP_NOSPACE;
if (MDOC_HEAD == node->type) {
- p->rmargin = p->maxrmargin;
- p->offset -= offset;
- p->flags &= ~TERMP_NOBREAK;
+ p->flags |= TERMP_NOBREAK;
+ p->offset += offset;
+ p->rmargin = p->offset + width;
} else {
- p->offset -= width;
- p->flags &= ~TERMP_NOLPAD;
+ p->flags |= TERMP_NOLPAD;
+ p->offset += width;
}
- }
-
- if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) {
- i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
- offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;
- flushln(p);
- p->offset -= offset;
- return;
+ } else if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) {
+ p->flags |= TERMP_NOSPACE;
+ p->offset += offset;
}
+
+ return(1);
}
/* ARGSUSED */
-static int
-termp_it_pre(DECL_ARGS)
+static void
+termp_it_post(DECL_ARGS)
{
const struct mdoc_node *n, *it;
const struct mdoc_block *bl;
- int i;
- size_t width, offset;
-
- /*
- * Also see termp_it_post() for general comments.
- */
switch (node->type) {
case (MDOC_BODY):
/* FALLTHROUGH */
case (MDOC_HEAD):
- it = node->parent;
- break;
- case (MDOC_BLOCK):
- it = node;
break;
default:
- return(1);
+ return;
}
+ it = node->parent;
assert(MDOC_BLOCK == it->type);
assert(MDOC_It == it->tok);
@@ -446,56 +443,24 @@ termp_it_pre(DECL_ARGS)
n = n->parent;
bl = &n->data.block;
- /* If `-compact', don't assert vertical space. */
-
- if (MDOC_BLOCK == node->type) {
- if (arg_hasattr(MDOC_Compact, bl->argc, bl->argv))
- newln(p);
- else
- vspace(p);
- return(1);
- }
-
- assert(MDOC_HEAD == node->type
- || MDOC_BODY == node->type);
-
- /* FIXME: see termp_it_post(). */
-
/* If `-tag', adjust our margins accordingly. */
if (arg_hasattr(MDOC_Tag, bl->argc, bl->argv)) {
- p->flags |= TERMP_NOSPACE;
-
- i = arg_getattr(MDOC_Width, bl->argc, bl->argv);
- width = i >= 0 ? arg_width(&bl->argv[i]) : 10;
-
- i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
- offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;
+ flushln(p);
if (MDOC_HEAD == node->type) {
- p->flags |= TERMP_NOBREAK;
- p->offset += offset;
- p->rmargin = p->offset + width;
+ p->rmargin = pair->rmargin;
+ p->offset = pair->offset;
+ p->flags &= ~TERMP_NOBREAK;
} else {
- p->flags |= TERMP_NOSPACE;
- p->flags |= TERMP_NOLPAD;
- p->offset += width;
+ p->offset = pair->offset;
+ p->flags &= ~TERMP_NOLPAD;
}
- return(1);
- }
- /* If `-ohang', adjust left-margin. */
-
- if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) {
- i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
- offset = i >= 0 ? arg_offset(&bl->argv[i]) : 0;
-
- p->flags |= TERMP_NOSPACE;
- p->offset += offset;
- return(1);
+ } else if (arg_hasattr(MDOC_Ohang, bl->argc, bl->argv)) {
+ flushln(p);
+ p->offset = pair->offset;
}
-
- return(1);
}
@@ -982,14 +947,15 @@ termp_bd_pre(DECL_ARGS)
return(1);
assert(MDOC_BLOCK == node->parent->type);
+ pair->offset = p->offset;
bl = &node->parent->data.block;
+
i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
if (-1 != i) {
assert(1 == bl->argv[i].sz);
- pair->offset = arg_offset(&bl->argv[i]);
- p->offset += pair->offset;
+ p->offset += arg_offset(&bl->argv[i]);
}
if ( ! arg_hasattr(MDOC_Literal, bl->argc, bl->argv))
@@ -1017,8 +983,10 @@ static void
termp_bd_post(DECL_ARGS)
{
- if (MDOC_BODY == node->type)
- p->offset -= pair->offset;
+ if (MDOC_BODY != node->type)
+ return;
+ newln(p);
+ p->offset = pair->offset;
}