summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/mdoc_term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2013-12-22 23:33:53 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2013-12-22 23:33:53 +0000
commit820ac390a24b43ad03bf201c9adebb423c5765ed (patch)
tree676a569fbe245fc4b5dc2ee4d1572a0222c2ec9b /usr.bin/mandoc/mdoc_term.c
parent40511a43998dc2401c4a8476d80282cfcd6fd5ee (diff)
Polishing the worms in my favourite can, term_flushln().
The TERMP_TWOSPACE flag i introduced in August 2009 was idiosyncratic and served only a very narrow purpose. Replace it by a more intuitive and more general termp attribute "trailspace", to be used together with TERMP_NOBREAK, to request a minimum amount of whitespace at the end of the current column. Adapt all code to the new interface. No functional change intended; code reviews to confirm that are welcome *eg*.
Diffstat (limited to 'usr.bin/mandoc/mdoc_term.c')
-rw-r--r--usr.bin/mandoc/mdoc_term.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 39d7314994f..aa1a687af1d 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,7 +1,7 @@
-/* $Id: mdoc_term.c,v 1.151 2013/06/02 18:16:51 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.152 2013/12/22 23:33:52 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -420,6 +420,7 @@ print_mdoc_foot(struct termp *p, const void *arg)
p->offset = 0;
p->rmargin = (p->maxrmargin -
term_strlen(p, meta->date) + term_len(p, 1)) / 2;
+ p->trailspace = 1;
p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
term_word(p, meta->os);
@@ -434,6 +435,7 @@ print_mdoc_foot(struct termp *p, const void *arg)
p->offset = p->rmargin;
p->rmargin = p->maxrmargin;
+ p->trailspace = 0;
p->flags &= ~TERMP_NOBREAK;
p->flags |= TERMP_NOSPACE;
@@ -485,6 +487,7 @@ print_mdoc_head(struct termp *p, const void *arg)
titlen = term_strlen(p, title);
p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
+ p->trailspace = 1;
p->offset = 0;
p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
(p->maxrmargin -
@@ -503,6 +506,7 @@ print_mdoc_head(struct termp *p, const void *arg)
term_flushln(p);
p->flags &= ~TERMP_NOBREAK;
+ p->trailspace = 0;
if (p->rmargin + titlen <= p->maxrmargin) {
p->flags |= TERMP_NOSPACE;
p->offset = p->rmargin;
@@ -790,13 +794,13 @@ termp_it_pre(DECL_ARGS)
case (LIST_dash):
/* FALLTHROUGH */
case (LIST_hyphen):
- if (MDOC_HEAD == n->type)
- p->flags |= TERMP_NOBREAK;
+ if (MDOC_HEAD != n->type)
+ break;
+ p->flags |= TERMP_NOBREAK;
+ p->trailspace = 1;
break;
case (LIST_hang):
- if (MDOC_HEAD == n->type)
- p->flags |= TERMP_NOBREAK;
- else
+ if (MDOC_HEAD != n->type)
break;
/*
@@ -808,16 +812,18 @@ termp_it_pre(DECL_ARGS)
if (n->next->child &&
(MDOC_Bl == n->next->child->tok ||
MDOC_Bd == n->next->child->tok))
- p->flags &= ~TERMP_NOBREAK;
- else
- p->flags |= TERMP_HANG;
+ break;
+
+ p->flags |= TERMP_NOBREAK | TERMP_HANG;
+ p->trailspace = 1;
break;
case (LIST_tag):
- if (MDOC_HEAD == n->type)
- p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE;
-
if (MDOC_HEAD != n->type)
break;
+
+ p->flags |= TERMP_NOBREAK;
+ p->trailspace = 2;
+
if (NULL == n->next || NULL == n->next->child)
p->flags |= TERMP_DANGLE;
break;
@@ -825,15 +831,20 @@ termp_it_pre(DECL_ARGS)
if (MDOC_HEAD == n->type)
break;
- if (NULL == n->next)
+ if (NULL == n->next) {
p->flags &= ~TERMP_NOBREAK;
- else
+ p->trailspace = 0;
+ } else {
p->flags |= TERMP_NOBREAK;
+ p->trailspace = 1;
+ }
break;
case (LIST_diag):
- if (MDOC_HEAD == n->type)
- p->flags |= TERMP_NOBREAK;
+ if (MDOC_HEAD != n->type)
+ break;
+ p->flags |= TERMP_NOBREAK;
+ p->trailspace = 1;
break;
default:
break;
@@ -985,8 +996,8 @@ termp_it_post(DECL_ARGS)
p->flags &= ~TERMP_DANGLE;
p->flags &= ~TERMP_NOBREAK;
- p->flags &= ~TERMP_TWOSPACE;
p->flags &= ~TERMP_HANG;
+ p->trailspace = 0;
}
@@ -1019,6 +1030,7 @@ termp_nm_pre(DECL_ARGS)
if (MDOC_HEAD == n->type && n->next->child) {
p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
+ p->trailspace = 1;
p->rmargin = p->offset + term_len(p, 1);
if (NULL == n->child) {
p->rmargin += term_strlen(p, meta->name);
@@ -1047,6 +1059,7 @@ termp_nm_post(DECL_ARGS)
if (MDOC_HEAD == n->type && n->next->child) {
term_flushln(p);
p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
+ p->trailspace = 0;
} else if (MDOC_BODY == n->type && n->child)
term_flushln(p);
}