summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2013-12-25 00:39:15 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2013-12-25 00:39:15 +0000
commit0998a1ee6782b30d7fc056811c148549490bf797 (patch)
treefdbaa575d9ca98fcded6cd2d2132113790ef771d
parent6e99e2673b8aa7d46827a967c8ad9f84b9d9d8aa (diff)
Do not break output lines in .Fn function arguments in SYNOPSIS mode.
Following an idea from Franco Fichtner, but implemented more cleanly. This reduces groff-mandoc-differences in base by a fantastic 7.5%.
-rw-r--r--regress/usr.bin/mandoc/mdoc/Fo/Makefile6
-rw-r--r--regress/usr.bin/mandoc/mdoc/Fo/break.in11
-rw-r--r--regress/usr.bin/mandoc/mdoc/Fo/break.out_ascii15
-rw-r--r--usr.bin/mandoc/mdoc_man.c12
-rw-r--r--usr.bin/mandoc/mdoc_term.c4
-rw-r--r--usr.bin/mandoc/term.c14
-rw-r--r--usr.bin/mandoc/term.h3
7 files changed, 57 insertions, 8 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Fo/Makefile b/regress/usr.bin/mandoc/mdoc/Fo/Makefile
index 48facb8351c..88adf0c6490 100644
--- a/regress/usr.bin/mandoc/mdoc/Fo/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Fo/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.6 2012/11/18 00:05:28 schwarze Exp $
+# $OpenBSD: Makefile,v 1.7 2013/12/25 00:39:14 schwarze Exp $
-REGRESS_TARGETS = basic section noarg font eos
+REGRESS_TARGETS = basic section break noarg font eos
-# groff 1.21 does not handle .nr nS
+# groff does not handle .nr nS
SKIP_GROFF ?= section
diff --git a/regress/usr.bin/mandoc/mdoc/Fo/break.in b/regress/usr.bin/mandoc/mdoc/Fo/break.in
new file mode 100644
index 00000000000..2a5d1dcd699
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Fo/break.in
@@ -0,0 +1,11 @@
+.Dd December 25, 2013
+.Dt FO-BREAK 1
+.Os OpenBSD
+.Sh NAME
+.Nm Fo-break
+.Nd line breaks in function blocks
+.Sh SYNOPSIS
+.Ft my_long_return_type *
+.Fn my_long_function "my_long_type first_argument" "my_long_type second_argument"
+.Sh DESCRIPTION
+.Fn my_long_function "my_long_type first_argument" "my_long_type second_argument"
diff --git a/regress/usr.bin/mandoc/mdoc/Fo/break.out_ascii b/regress/usr.bin/mandoc/mdoc/Fo/break.out_ascii
new file mode 100644
index 00000000000..a3379b74989
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Fo/break.out_ascii
@@ -0,0 +1,15 @@
+FO-BREAK(1) OpenBSD Reference Manual FO-BREAK(1)
+
+NNAAMMEE
+ FFoo--bbrreeaakk - line breaks in function blocks
+
+SSYYNNOOPPSSIISS
+ _m_y___l_o_n_g___r_e_t_u_r_n___t_y_p_e _*
+ mmyy__lloonngg__ffuunnccttiioonn(_m_y___l_o_n_g___t_y_p_e _f_i_r_s_t___a_r_g_u_m_e_n_t,
+ _m_y___l_o_n_g___t_y_p_e _s_e_c_o_n_d___a_r_g_u_m_e_n_t);
+
+DDEESSCCRRIIPPTTIIOONN
+ mmyy__lloonngg__ffuunnccttiioonn(_m_y___l_o_n_g___t_y_p_e _f_i_r_s_t___a_r_g_u_m_e_n_t, _m_y___l_o_n_g___t_y_p_e
+ _s_e_c_o_n_d___a_r_g_u_m_e_n_t)
+
+OpenBSD December 25, 2013 OpenBSD
diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c
index 2cc23418785..5b713b3a596 100644
--- a/usr.bin/mandoc/mdoc_man.c
+++ b/usr.bin/mandoc/mdoc_man.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_man.c,v 1.54 2013/12/24 22:08:23 schwarze Exp $ */
+/* $Id: mdoc_man.c,v 1.55 2013/12/25 00:39:13 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -252,6 +252,7 @@ static int outflags;
#define MMAN_An_split (1 << 9) /* author mode is "split" */
#define MMAN_An_nosplit (1 << 10) /* author mode is "nosplit" */
#define MMAN_PD (1 << 11) /* inter-paragraph spacing disabled */
+#define MMAN_nbrword (1 << 12) /* do not break the next word */
#define BL_STACK_MAX 32
@@ -360,6 +361,12 @@ print_word(const char *s)
case (ASCII_HYPH):
putchar('-');
break;
+ case (' '):
+ if (MMAN_nbrword & outflags) {
+ printf("\\ ");
+ break;
+ }
+ /* FALLTHROUGH */
default:
putchar((unsigned char)*s);
break;
@@ -367,6 +374,7 @@ print_word(const char *s)
if (TPremain)
TPremain--;
}
+ outflags &= ~MMAN_nbrword;
}
static void
@@ -1024,6 +1032,8 @@ pre_fa(DECL_ARGS)
while (NULL != n) {
font_push('I');
+ if (MDOC_SYNPRETTY & n->flags)
+ outflags |= MMAN_nbrword;
print_node(meta, n);
font_pop();
if (NULL != (n = n->next))
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 162a832a916..ac5b7e0d0c7 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.156 2013/12/24 23:04:29 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.157 2013/12/25 00:39:13 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -1560,6 +1560,8 @@ termp_fn_pre(DECL_ARGS)
for (n = n->next; n; n = n->next) {
assert(MDOC_TEXT == n->type);
term_fontpush(p, TERMFONT_UNDER);
+ if (pretty)
+ p->flags |= TERMP_NBRWORD;
term_word(p, n->string);
term_fontpop(p);
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index 0a6a2232877..795a3fdb167 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.74 2013/12/24 23:04:29 schwarze Exp $ */
+/* $Id: term.c,v 1.75 2013/12/25 00:39:13 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -403,6 +403,7 @@ term_fontpop(struct termp *p)
void
term_word(struct termp *p, const char *word)
{
+ const char nbrsp[2] = { ASCII_NBRSP, 0 };
const char *seq, *cp;
char c;
int sz, uc;
@@ -434,7 +435,15 @@ term_word(struct termp *p, const char *word)
word++;
continue;
}
- ssz = strcspn(word, "\\");
+ if (TERMP_NBRWORD & p->flags) {
+ if (' ' == *word) {
+ encode(p, nbrsp, 1);
+ word++;
+ continue;
+ }
+ ssz = strcspn(word, "\\ ");
+ } else
+ ssz = strcspn(word, "\\");
encode(p, word, ssz);
word += (int)ssz;
continue;
@@ -509,6 +518,7 @@ term_word(struct termp *p, const char *word)
break;
}
}
+ p->flags &= ~TERMP_NBRWORD;
}
static void
diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h
index d890c4b7703..4da26f96ac5 100644
--- a/usr.bin/mandoc/term.h
+++ b/usr.bin/mandoc/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.40 2013/12/24 23:04:29 schwarze Exp $ */
+/* $Id: term.h,v 1.41 2013/12/25 00:39:13 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -71,6 +71,7 @@ struct termp {
#define TERMP_SENTENCE (1 << 1) /* Space before a sentence. */
#define TERMP_NOSPACE (1 << 2) /* No space before words. */
#define TERMP_NONOSPACE (1 << 3) /* No space (no autounset). */
+#define TERMP_NBRWORD (1 << 4) /* Make next word nonbreaking. */
#define TERMP_KEEP (1 << 5) /* Keep words together. */
#define TERMP_PREKEEP (1 << 6) /* ...starting with the next one. */
#define TERMP_SKIPCHAR (1 << 7) /* Skip the next character. */