summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-02-25 12:27:37 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-02-25 12:27:37 +0000
commit8f3ec82bd3ba7aa8787e16c8c71de3b052b4866a (patch)
tree96b81baf67cff089fdf6a6420ddaa14ad443b893
parent17758e0da9b52fb54e22c38cf77b36a01e52eb66 (diff)
downloadmandoc-8f3ec82bd3ba7aa8787e16c8c71de3b052b4866a.tar.gz
Some offsets built into termpair.
-rw-r--r--mdocterm.c20
-rw-r--r--term.c60
-rw-r--r--term.h10
3 files changed, 36 insertions, 54 deletions
diff --git a/mdocterm.c b/mdocterm.c
index 014a010f..2f14ef44 100644
--- a/mdocterm.c
+++ b/mdocterm.c
@@ -416,6 +416,8 @@ body(struct termp *p, const struct mdoc_meta *meta,
dochild = 1;
pair.type = 0;
+ pair.offset = 0;
+ pair.flag = 0;
if (MDOC_TEXT != node->type) {
if (termacts[node->tok].pre)
@@ -426,24 +428,14 @@ body(struct termp *p, const struct mdoc_meta *meta,
/* Children. */
- switch (pair.type) {
- case (TERMPAIR_FLAG):
- p->flags |= pair.data.flag;
- break;
- default:
- break;
- }
+ if (TERMPAIR_FLAG & pair.type)
+ p->flags |= pair.flag;
if (dochild && node->child)
body(p, meta, node->child);
- switch (pair.type) {
- case (TERMPAIR_FLAG):
- p->flags &= ~pair.data.flag;
- break;
- default:
- break;
- }
+ if (TERMPAIR_FLAG & pair.type)
+ p->flags &= ~pair.flag;
/* Post-processing. */
diff --git a/term.c b/term.c
index 42817d55..ab0cb0ea 100644
--- a/term.c
+++ b/term.c
@@ -654,25 +654,6 @@ termp_op_post(DECL_ARGS)
/* ARGSUSED */
-static void
-termp_sh_post(DECL_ARGS)
-{
-
- switch (node->type) {
- case (MDOC_HEAD):
- newln(p);
- break;
- case (MDOC_BODY):
- newln(p);
- p->offset = 0;
- break;
- default:
- break;
- }
-}
-
-
-/* ARGSUSED */
static int
termp_xr_pre(DECL_ARGS)
{
@@ -765,6 +746,25 @@ termp_sh_pre(DECL_ARGS)
/* ARGSUSED */
+static void
+termp_sh_post(DECL_ARGS)
+{
+
+ switch (node->type) {
+ case (MDOC_HEAD):
+ newln(p);
+ break;
+ case (MDOC_BODY):
+ newln(p);
+ p->offset = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+
+/* ARGSUSED */
static int
termp_op_pre(DECL_ARGS)
{
@@ -809,7 +809,7 @@ termp_d1_pre(DECL_ARGS)
if (MDOC_BODY != node->type)
return(1);
newln(p);
- p->offset += INDENT;
+ p->offset += (pair->offset = INDENT);
return(1);
}
@@ -822,7 +822,7 @@ termp_d1_post(DECL_ARGS)
if (MDOC_BODY != node->type)
return;
newln(p);
- p->offset -= INDENT;
+ p->offset -= pair->offset;
}
@@ -988,7 +988,8 @@ termp_bd_pre(DECL_ARGS)
i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
if (-1 != i) {
assert(1 == bl->argv[i].sz);
- p->offset += arg_offset(&bl->argv[i]);
+ pair->offset = arg_offset(&bl->argv[i]);
+ p->offset += pair->offset;
}
if ( ! arg_hasattr(MDOC_Literal, bl->argc, bl->argv))
@@ -1015,20 +1016,9 @@ termp_bd_pre(DECL_ARGS)
static void
termp_bd_post(DECL_ARGS)
{
- int i;
- const struct mdoc_block *bl;
-
- if (MDOC_BODY != node->type)
- return;
-
- assert(MDOC_BLOCK == node->parent->type);
- bl = &node->parent->data.block;
- i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
- if (-1 != i) {
- assert(1 == bl->argv[i].sz);
- p->offset -= arg_offset(&bl->argv[i]);
- }
+ if (MDOC_BODY == node->type)
+ p->offset -= pair->offset;
}
diff --git a/term.h b/term.h
index 59eef170..9e850495 100644
--- a/term.h
+++ b/term.h
@@ -43,15 +43,15 @@ struct termp {
struct termpair {
int type;
#define TERMPAIR_FLAG (1 << 0)
- union {
- int flag;
- } data;
+ int flag;
+ size_t offset;
};
#define TERMPAIR_SETFLAG(p, fl) \
do { \
- (p)->data.flag = (fl); \
- (p)->type = TERMPAIR_FLAG; \
+ assert(! (TERMPAIR_FLAG & (p)->type)); \
+ (p)->flag = (fl); \
+ (p)->type |= TERMPAIR_FLAG; \
} while (0)
struct termact {