diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-02-25 13:30:53 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-02-25 13:30:53 +0000 |
commit | 4d021113ebf58cd7c14d5296060c615c99450f9c (patch) | |
tree | c730feffc38ab970487d7f8010a8d044f189cdc0 | |
parent | 3591841468d0e60204416fa1ff53ed7c28ad88c4 (diff) | |
download | mandoc-4d021113ebf58cd7c14d5296060c615c99450f9c.tar.gz |
Support for nested lists added.
-rw-r--r-- | mdocterm.1 | 3 | ||||
-rw-r--r-- | mdocterm.c | 7 | ||||
-rw-r--r-- | term.c | 150 | ||||
-rw-r--r-- | term.h | 1 |
4 files changed, 66 insertions, 95 deletions
@@ -117,4 +117,5 @@ utility was written by .Sh CAVEATS See .Xr mdoc 3 -for a list of bugs, caveats, and incomplete macros. +for a list of bugs, caveats, and incomplete macros regarding the +document parse. @@ -1,4 +1,4 @@ - /* $Id$ */ +/* $Id$ */ /* * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> * @@ -200,7 +200,7 @@ flushln(struct termp *p) */ if (p->flags & TERMP_NOBREAK) { - for ( ; vis <= maxvis; vis++) + for ( ; vis < maxvis; vis++) putchar(' '); } else putchar('\n'); @@ -221,6 +221,7 @@ newln(struct termp *p) if (0 == p->col) return; flushln(p); + p->flags &= ~TERMP_NOLPAD; } @@ -416,7 +417,7 @@ body(struct termp *p, const struct mdoc_meta *meta, dochild = 1; pair.type = 0; - pair.offset = 0; + pair.offset = pair.rmargin = 0; pair.flag = 0; if (MDOC_TEXT != node->type) { @@ -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; } @@ -45,6 +45,7 @@ struct termpair { #define TERMPAIR_FLAG (1 << 0) int flag; size_t offset; + size_t rmargin; }; #define TERMPAIR_SETFLAG(p, fl) \ |