summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2009-07-18 20:50:39 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2009-07-18 20:50:39 +0000
commit766fec4b9f578887f4627d24486b66d9d04f571a (patch)
treec43aaf7582d27b74ddb056c04245f4f3d6f934bd /usr.bin
parent7efea9d11d3cbcab4f6ff7dda93710a0f49b6601 (diff)
sync to 1.8.0: support .Bl -hang
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/mandoc.112
-rw-r--r--usr.bin/mandoc/mdoc_term.c43
-rw-r--r--usr.bin/mandoc/term.c25
-rw-r--r--usr.bin/mandoc/term.h23
4 files changed, 65 insertions, 38 deletions
diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1
index d200120c997..32f669336f2 100644
--- a/usr.bin/mandoc/mandoc.1
+++ b/usr.bin/mandoc/mandoc.1
@@ -1,4 +1,4 @@
-.\" $Id: mandoc.1,v 1.8 2009/07/12 22:44:45 schwarze Exp $
+.\" $Id: mandoc.1,v 1.9 2009/07/18 20:50:37 schwarze Exp $
.\"
.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: July 12 2009 $
+.Dd $Mdocdate: July 18 2009 $
.Dt MANDOC 1
.Os
.\" SECTION
@@ -280,11 +280,3 @@ The
.Nm
utility was written by
.An Kristaps Dzonsons Aq kristaps@kth.se .
-.\" SECTION
-.Sh CAVEATS
-The
-.Nm
-utility doesn't yet know how to display \-hang lists.
-.Pp
-Other macros still aren't supported by virtue of nobody complaining
-about their absence.
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 5a9a1470417..d49391af52a 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.32 2009/07/18 19:44:38 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.33 2009/07/18 20:50:38 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -567,16 +567,15 @@ arg_listtype(const struct mdoc_node *n)
/* FALLTHROUGH */
case (MDOC_Column):
/* FALLTHROUGH */
+ case (MDOC_Hang):
+ /* FALLTHROUGH */
case (MDOC_Ohang):
return(n->args->argv[i].arg);
default:
break;
}
- /* FIXME: mandated by parser. */
-
- errx(1, "list type not supported");
- /* NOTREACHED */
+ return(-1);
}
@@ -722,6 +721,7 @@ termp_it_pre(DECL_ARGS)
(void)arg_getattrs(keys, vals, 3, bl);
type = arg_listtype(bl);
+ assert(-1 != type);
/* Calculate real width and offset. */
@@ -748,7 +748,7 @@ termp_it_pre(DECL_ARGS)
/*
* List-type can override the width in the case of fixed-head
* values (bullet, dash/hyphen, enum). Tags need a non-zero
- * offset.
+ * offset. FIXME: double-check that correct.
*/
switch (type) {
@@ -764,6 +764,10 @@ termp_it_pre(DECL_ARGS)
if (width < 5)
width = 5;
break;
+ case (MDOC_Hang):
+ if (0 == width)
+ width = 8;
+ break;
case (MDOC_Tag):
if (0 == width)
width = 10;
@@ -821,16 +825,30 @@ termp_it_pre(DECL_ARGS)
case (MDOC_Enum):
/* FALLTHROUGH */
case (MDOC_Hyphen):
- /* FALLTHROUGH */
+ if (MDOC_HEAD == node->type)
+ p->flags |= TERMP_NOBREAK;
+ else
+ p->flags |= TERMP_NOLPAD;
+ break;
+ case (MDOC_Hang):
+ if (MDOC_HEAD == node->type)
+ p->flags |= TERMP_NOBREAK;
+ else
+ p->flags |= TERMP_NOLPAD;
+
+ if (MDOC_HEAD == node->type)
+ p->flags |= TERMP_HANG;
+ break;
case (MDOC_Tag):
if (MDOC_HEAD == node->type)
p->flags |= TERMP_NOBREAK;
else
p->flags |= TERMP_NOLPAD;
- if (MDOC_HEAD == node->type && MDOC_Tag == type)
- if (NULL == node->next ||
- NULL == node->next->child)
- p->flags |= TERMP_NONOBREAK;
+
+ if (MDOC_HEAD != node->type)
+ break;
+ if (NULL == node->next || NULL == node->next->child)
+ p->flags |= TERMP_DANGLE;
break;
case (MDOC_Column):
if (MDOC_HEAD == node->type) {
@@ -868,6 +886,8 @@ termp_it_pre(DECL_ARGS)
/* FALLTHROUGH */
case (MDOC_Hyphen):
/* FALLTHROUGH */
+ case (MDOC_Hang):
+ /* FALLTHROUGH */
case (MDOC_Tag):
if (MDOC_HEAD == node->type)
p->rmargin = p->offset + width;
@@ -947,6 +967,7 @@ termp_it_post(DECL_ARGS)
return;
type = arg_listtype(node->parent->parent->parent);
+ assert(-1 != type);
switch (type) {
case (MDOC_Diag):
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index 1a3d0f1ed19..4d0f9ed1e44 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.5 2009/06/23 23:53:43 schwarze Exp $ */
+/* $Id: term.c,v 1.6 2009/07/18 20:50:38 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -176,8 +176,7 @@ term_isopendelim(const char *p, int len)
* Specifically, a line is whatever's in p->buf of length p->col, which
* is zeroed after this function returns.
*
- * The variables TERMP_NOLPAD, TERMP_LITERAL and TERMP_NOBREAK are of
- * critical importance here. Their behaviour follows:
+ * The usage of termp:flags is as follows:
*
* - TERMP_NOLPAD: when beginning to write the line, don't left-pad the
* offset value. This is useful when doing columnar lists where the
@@ -187,7 +186,12 @@ term_isopendelim(const char *p, int len)
* columns. In short: don't print a newline and instead pad to the
* right margin. Used in conjunction with TERMP_NOLPAD.
*
- * - TERMP_NONOBREAK: don't newline when TERMP_NOBREAK is specified.
+ * - TERMP_DANGLE: don't newline when TERMP_NOBREAK is specified and
+ * the line is overrun, and don't pad-right if it's underrun.
+ *
+ * - TERMP_HANG: like TERMP_DANGLE, but doesn't newline when
+ * overruning, instead save the position and continue at that point
+ * when the next invocation.
*
* In-line line breaking:
*
@@ -209,6 +213,7 @@ term_flushln(struct termp *p)
{
int i, j;
size_t vbl, vsz, vis, maxvis, mmax, bp;
+ static int sv = -1;
/*
* First, establish the maximum columns of "visible" content.
@@ -223,6 +228,11 @@ term_flushln(struct termp *p)
bp = TERMP_NOBREAK & p->flags ? mmax : maxvis;
vis = 0;
+ if (sv >= 0) {
+ vis = (size_t)sv;
+ sv = -1;
+ }
+
/*
* If in the standard case (left-justified), then begin with our
* indentation, otherwise (columns, etc.) just start spitting
@@ -298,11 +308,14 @@ term_flushln(struct termp *p)
*/
if ((TERMP_NOBREAK & p->flags) && vis >= maxvis) {
- if ( ! (TERMP_NONOBREAK & p->flags)) {
+ if ( ! (TERMP_DANGLE & p->flags) &&
+ ! (TERMP_HANG & p->flags)) {
putchar('\n');
for (i = 0; i < (int)p->rmargin; i++)
putchar(' ');
}
+ if (TERMP_HANG & p->flags)
+ sv = (int)(vis - maxvis);
p->col = 0;
return;
}
@@ -313,7 +326,7 @@ term_flushln(struct termp *p)
*/
if (p->flags & TERMP_NOBREAK) {
- if ( ! (TERMP_NONOBREAK & p->flags))
+ if ( ! (TERMP_DANGLE & p->flags))
for ( ; vis < maxvis; vis++)
putchar(' ');
} else
diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h
index 78cf736f79f..ed2002838ea 100644
--- a/usr.bin/mandoc/term.h
+++ b/usr.bin/mandoc/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.3 2009/06/15 01:07:46 schwarze Exp $ */
+/* $Id: term.h,v 1.4 2009/07/18 20:50:38 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -37,16 +37,17 @@ struct termp {
size_t offset; /* Margin offest. */
size_t col; /* Bytes in buf. */
int flags;
-#define TERMP_NOSPACE (1 << 0) /* No space before words. */
-#define TERMP_NOLPAD (1 << 1) /* No leftpad before flush. */
-#define TERMP_NOBREAK (1 << 2) /* No break after flush. */
-#define TERMP_LITERAL (1 << 3) /* Literal words. */
-#define TERMP_IGNDELIM (1 << 4) /* Delims like regulars. */
-#define TERMP_NONOSPACE (1 << 5) /* No space (no autounset). */
-#define TERMP_NONOBREAK (1 << 7) /* Don't newln NOBREAK. */
-#define TERMP_STYLE 0x0300 /* Style mask. */
-#define TERMP_BOLD (1 << 8) /* Styles... */
-#define TERMP_UNDER (1 << 9)
+#define TERMP_STYLE 0x3 /* Style mask. */
+#define TERMP_BOLD (1 << 0) /* Styles... */
+#define TERMP_UNDER (1 << 1)
+#define TERMP_NOSPACE (1 << 2) /* No space before words. */
+#define TERMP_NOLPAD (1 << 3) /* See termp_newline(). */
+#define TERMP_NOBREAK (1 << 4) /* See termp_newline(). */
+#define TERMP_LITERAL (1 << 5) /* Literal words. */
+#define TERMP_IGNDELIM (1 << 6) /* Delims like regulars. */
+#define TERMP_NONOSPACE (1 << 7) /* No space (no autounset). */
+#define TERMP_DANGLE (1 << 8) /* See termp_newline(). */
+#define TERMP_HANG (1 << 9) /* See termp_newline(). */
char *buf; /* Output buffer. */
enum termenc enc; /* Type of encoding. */
void *symtab; /* Encoded-symbol table. */