-/* $Id: term.c,v 1.33 2009/03/01 23:27:14 kristaps Exp $ */
+/* $Id: term.c,v 1.35 2009/03/02 17:14:46 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
#include "term.h"
-#define INDENT 6
-
/*
* Performs actions on nodes of the abstract syntax tree. Both pre- and
* post-fix operations are defined here.
termp_ft_pre(DECL_ARGS)
{
+ if (SEC_SYNOPSIS == node->sec)
+ if (node->prev && MDOC_Fo == node->prev->tok)
+ vspace(p);
TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_TYPE]);
return(1);
}
termp_ft_post(DECL_ARGS)
{
- if (node->sec == SEC_SYNOPSIS)
+ if (SEC_SYNOPSIS == node->sec)
newln(p);
}
termp_bd_pre(DECL_ARGS)
{
const struct mdoc_block *bl;
- const struct mdoc_node *n;
- int i;
+ const struct mdoc_node *n;
+ int i, type;
if (MDOC_BLOCK == node->type) {
if (node->prev)
} else if (MDOC_BODY != node->type)
return(1);
- assert(MDOC_BLOCK == node->parent->type);
pair->offset = p->offset;
-
bl = &node->parent->data.block;
+ for (type = -1, i = 0; i < (int)bl->argc; i++) {
+ switch (bl->argv[i].arg) {
+ case (MDOC_Ragged):
+ /* FALLTHROUGH */
+ case (MDOC_Filled):
+ /* FALLTHROUGH */
+ case (MDOC_Unfilled):
+ /* FALLTHROUGH */
+ case (MDOC_Literal):
+ type = bl->argv[i].arg;
+ i = (int)bl->argc;
+ break;
+ default:
+ errx(1, "display type not supported");
+ }
+ }
+
+ assert(-1 != type);
+
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]);
}
+
+ switch (type) {
+ case (MDOC_Literal):
+ /* FALLTHROUGH */
+ case (MDOC_Unfilled):
+ break;
+ default:
+ return(1);
+ }
+
p->flags |= TERMP_LITERAL;
for (n = node->child; n; n = n->next) {
- if (MDOC_TEXT != n->type)
- errx(1, "non-text displays unsupported");
- if ((*n->data.text.string)) {
- word(p, n->data.text.string);
- flushln(p);
- } else
- vspace(p);
-
+ if (MDOC_TEXT != n->type) {
+ warnx("non-text children not yet allowed");
+ continue;
+ }
+ word(p, n->data.text.string);
+ flushln(p);
}
- p->flags &= ~TERMP_LITERAL;
return(0);
}
if (MDOC_BODY != node->type)
return;
- newln(p);
+
+ if ( ! (p->flags & TERMP_LITERAL))
+ flushln(p);
+
+ p->flags &= ~TERMP_LITERAL;
p->offset = pair->offset;
}
termp_bx_post(DECL_ARGS)
{
- p->flags |= TERMP_NOSPACE;
+ if (node->child)
+ p->flags |= TERMP_NOSPACE;
word(p, "BSD");
}