summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-06-22 12:04:05 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-06-22 12:04:05 +0000
commit74605f6540401164e8a214ee34d6de4094e5347f (patch)
tree27dfc45ed0a3d335bbcf0158183a24709339b8e9
parent947f73805b11d9580b0ab9b7cbca918f44567314 (diff)
downloadmandoc-74605f6540401164e8a214ee34d6de4094e5347f.tar.gz
mandoc-74605f6540401164e8a214ee34d6de4094e5347f.tar.zst
mandoc-74605f6540401164e8a214ee34d6de4094e5347f.zip
Added "Spacing" part of "Punctuation and Spacing" in mandoc.1 manual.
Fixed `Ds' meta-macro default width. Fixed -width and -offset "indent", "indent-two", and "left" widths. Fixed -width and -offset literal-word and numeric widths. Fixed off-by-one errors in whitespace output (schwarze@openbsd.org).
-rw-r--r--mandoc.126
-rw-r--r--mdoc_action.c4
-rw-r--r--mdoc_term.c20
-rw-r--r--term.c48
4 files changed, 57 insertions, 41 deletions
diff --git a/mandoc.1 b/mandoc.1
index 60bad373..b0fb6de1 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1,4 +1,4 @@
-.\" $Id: mandoc.1,v 1.21 2009/06/18 08:13:34 kristaps Exp $
+.\" $Id: mandoc.1,v 1.22 2009/06/22 12:04:05 kristaps 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: June 18 2009 $
+.Dd $Mdocdate: June 22 2009 $
.Dt MANDOC 1
.Os
.\" SECTION
@@ -98,19 +98,19 @@ were provided.
.Pp
.Ex -std mandoc
.\" SUB-SECTION
-.Ss Punctuation
+.Ss Punctuation and Spacing
If punctuation is set apart from words, such as in the phrase
.Dq to be \&, or not to be ,
it's processed by
.Nm
-according to the following rules. Opening punctuation
+according to the following rules: opening punctuation
.Po
.Sq \&( ,
.Sq \&[ ,
and
.Sq \&{
.Pc
-is not followed by a space. Closing punctuation
+is not followed by a space; closing punctuation
.Po
.Sq \&. ,
.Sq \&, ,
@@ -128,6 +128,15 @@ is not preceded by whitespace.
If the input is
.Xr mdoc 7 ,
these rules are also applied to macro arguments when appropriate.
+.Pp
+White-space, in non-literal (normal) mode, is stripped from input and
+replaced on output by a single space. Thus, if you wish to preserve
+multiple spaces, they must be space-escaped
+.Sq \e\ .
+or used in a literal display mode, e.g.,
+.Sq \&.Bd \-literal
+in
+.Xr mdoc 7 .
.\" SUB-SECTION
.Ss Input Formats
The
@@ -253,14 +262,17 @@ A list or display following
.Sq \&.Ss
does not assert a prior vertical break, just as it doesn't with
.Sq \&.Sh .
-.\" LIST-ITEM
.It
The \-literal and \-unfilled
.Sq \&.Bd
displays types are synonyms, as are \-filled and \-ragged.
-.\" LIST-ITEM
.It
Words aren't hyphenated.
+.It
+In normal mode (not a literal block), blocks of spaces aren't preserved,
+so double spaces following sentence closure
+.Pq Qq French spacing
+are reduced to a single space.
.El
.\" SECTION
.Sh SEE ALSO
diff --git a/mdoc_action.c b/mdoc_action.c
index 13ce974c..8ee06aeb 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_action.c,v 1.17 2009/06/18 20:46:19 kristaps Exp $ */
+/* $Id: mdoc_action.c,v 1.18 2009/06/22 12:04:05 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -614,7 +614,7 @@ post_bl_width(struct mdoc *m)
*/
if (0 == strcmp(p, "Ds"))
- width = 8;
+ width = 6;
else if (MDOC_MAX == (tok = mdoc_hash_find(m->htab, p)))
return(1);
else if (0 == (width = mdoc_macro2len(tok)))
diff --git a/mdoc_term.c b/mdoc_term.c
index 2f55a2e0..92e2ca87 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.15 2009/06/17 18:42:42 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.16 2009/06/22 12:04:05 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -533,9 +533,9 @@ arg_width(const struct mdoc_argv *arg, int pos)
assert(pos < (int)arg->sz && pos >= 0);
assert(arg->value[pos]);
if (0 == strcmp(arg->value[pos], "indent"))
- return(INDENT);
+ return(INDENT + 3);
if (0 == strcmp(arg->value[pos], "indent-two"))
- return(INDENT * 2);
+ return(INDENT * 2 + 2);
if (0 == (len = (int)strlen(arg->value[pos])))
return(0);
@@ -545,13 +545,14 @@ arg_width(const struct mdoc_argv *arg, int pos)
break;
if (i == len - 1) {
- if ('n' == arg->value[pos][len - 1]) {
+ if ('n' == arg->value[pos][len - 1] ||
+ 'm' == arg->value[pos][len - 1]) {
v = (size_t)atoi(arg->value[pos]);
- return(v);
+ return(v + 2);
}
}
- return(strlen(arg->value[pos]) + 1);
+ return(strlen(arg->value[pos]) + 2);
}
@@ -603,9 +604,9 @@ arg_offset(const struct mdoc_argv *arg)
assert(*arg->value);
if (0 == strcmp(*arg->value, "left"))
- return(0);
+ return(INDENT - 1);
if (0 == strcmp(*arg->value, "indent"))
- return(INDENT);
+ return(INDENT + 1);
if (0 == strcmp(*arg->value, "indent-two"))
return(INDENT * 2);
@@ -1340,7 +1341,8 @@ termp_d1_pre(DECL_ARGS)
if (MDOC_BLOCK != node->type)
return(1);
term_newln(p);
- p->offset += (pair->offset = INDENT);
+ pair->offset = INDENT + 1;
+ p->offset += pair->offset;
return(1);
}
diff --git a/term.c b/term.c
index 3b7fb4c0..d99c990d 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.80 2009/06/22 10:40:04 kristaps Exp $ */
+/* $Id: term.c,v 1.81 2009/06/22 12:04:05 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -205,7 +205,7 @@ void
term_flushln(struct termp *p)
{
int i, j;
- size_t vsz, vis, maxvis, mmax, bp;
+ size_t vbl, vsz, vis, maxvis, mmax, bp;
/*
* First, establish the maximum columns of "visible" content.
@@ -250,35 +250,37 @@ term_flushln(struct termp *p)
}
/*
- * Do line-breaking. If we're greater than our
- * break-point and already in-line, break to the next
- * line and start writing. If we're at the line start,
- * then write out the word (TODO: hyphenate) and break
- * in a subsequent loop invocation.
+ * Choose the number of blanks to prepend: no blank at the
+ * beginning of a line, one between words -- but do not
+ * actually write them yet.
*/
+ vbl = (size_t)(0 == vis ? 0 : 1);
- if ( ! (TERMP_NOBREAK & p->flags)) {
- if (vis && vis + vsz > bp) {
- putchar('\n');
+ /*
+ * Find out whether we would exceed the right margin.
+ * If so, break to the next line. (TODO: hyphenate)
+ * Otherwise, write the chosen number of blanks now.
+ */
+ if (vis && vis + vbl + vsz > bp) {
+ putchar('\n');
+ if (TERMP_NOBREAK & p->flags) {
+ for (j = 0; j < (int)p->rmargin; j++)
+ putchar(' ');
+ vis = p->rmargin - p->offset;
+ } else {
for (j = 0; j < (int)p->offset; j++)
putchar(' ');
vis = 0;
- }
- } else if (vis && vis + vsz > bp) {
- putchar('\n');
- for (j = 0; j < (int)p->rmargin; j++)
+ }
+ } else {
+ for (j = 0; j < (int)vbl; j++)
putchar(' ');
- vis = p->rmargin - p->offset;
+ vis += vbl;
}
/*
- * Prepend a space if we're not already at the beginning
- * of the line, then the word.
+ * Finally, write out the word.
*/
-
- if (0 < vis++)
- putchar(' ');
-
for ( ; i < (int)p->col; i++) {
if (' ' == p->buf[i])
break;
@@ -292,7 +294,7 @@ term_flushln(struct termp *p)
* cause a newline and offset at the right margin.
*/
- if ((TERMP_NOBREAK & p->flags) && vis > maxvis) {
+ if ((TERMP_NOBREAK & p->flags) && vis >= maxvis) {
if ( ! (TERMP_NONOBREAK & p->flags)) {
putchar('\n');
for (i = 0; i < (int)p->rmargin; i++)
@@ -309,7 +311,7 @@ term_flushln(struct termp *p)
if (p->flags & TERMP_NOBREAK) {
if ( ! (TERMP_NONOBREAK & p->flags))
- for ( ; vis <= maxvis; vis++)
+ for ( ; vis < maxvis; vis++)
putchar(' ');
} else
putchar('\n');