From 50aba90c460f529396e34797ccd6363e0f246c9c Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Wed, 25 Dec 2013 00:39:31 +0000 Subject: 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 OpenBSD base by a fantastic 7.5%. --- mdoc_man.c | 12 +++++++++++- mdoc_term.c | 4 +++- term.c | 14 ++++++++++++-- term.h | 3 ++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/mdoc_man.c b/mdoc_man.c index d5e1f457..530461d3 100644 --- a/mdoc_man.c +++ b/mdoc_man.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.55 2013/12/24 22:08:50 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.56 2013/12/25 00:39:31 schwarze Exp $ */ /* * Copyright (c) 2011, 2012, 2013 Ingo Schwarze * @@ -256,6 +256,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 @@ -364,6 +365,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; @@ -371,6 +378,7 @@ print_word(const char *s) if (TPremain) TPremain--; } + outflags &= ~MMAN_nbrword; } static void @@ -1028,6 +1036,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/mdoc_term.c b/mdoc_term.c index 04fede10..00a6595e 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.254 2013/12/24 23:04:36 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.255 2013/12/25 00:39:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013 Ingo Schwarze @@ -1564,6 +1564,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/term.c b/term.c index 2321aaac..e7b95578 100644 --- a/term.c +++ b/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.213 2013/12/24 23:04:36 schwarze Exp $ */ +/* $Id: term.c,v 1.214 2013/12/25 00:39:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze @@ -407,6 +407,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; @@ -438,7 +439,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; @@ -513,6 +522,7 @@ term_word(struct termp *p, const char *word) break; } } + p->flags &= ~TERMP_NBRWORD; } static void diff --git a/term.h b/term.h index bded6226..8cad4be8 100644 --- a/term.h +++ b/term.h @@ -1,4 +1,4 @@ -/* $Id: term.h,v 1.96 2013/12/24 23:04:36 schwarze Exp $ */ +/* $Id: term.h,v 1.97 2013/12/25 00:39:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013 Ingo Schwarze @@ -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. */ -- cgit v1.2.3