diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-11-13 13:05:24 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-11-13 13:05:24 +0000 |
commit | 9a96128800ce0a7bcaafbc5ab806c729a27dfa4b (patch) | |
tree | a5d0312b7a9bd2d6258ae1fa34c839e268829ed3 /usr.bin/mandoc | |
parent | abdd351d168fdba9684e1574a2fc6a3c3d138cd7 (diff) |
Make the default left text margin configurable from the command line,
just like the default right margin already is. This may be useful for
people with expensive screen real estate. Besides, it helps automated
man(7) to mdoc(7) output comparisons to validate -Tman output.
ok kristaps@ on an earlier version
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/man_term.c | 27 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.1 | 13 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 18 | ||||
-rw-r--r-- | usr.bin/mandoc/term.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/term_ascii.c | 12 |
5 files changed, 44 insertions, 29 deletions
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index a616ebd511e..cda72369adf 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.76 2011/09/21 09:57:11 schwarze Exp $ */ +/* $Id: man_term.c,v 1.77 2011/11/13 13:05:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -29,8 +29,6 @@ #include "term.h" #include "main.h" -#define INDENT 7 /* fixed-width char full-indent */ -#define HALFINDENT 3 /* fixed-width char half-indent */ #define MAXMARGINS 64 /* maximum number of indented scopes */ /* FIXME: have PD set the default vspace width. */ @@ -137,6 +135,9 @@ terminal_man(void *arg, const struct man *man) p = (struct termp *)arg; + if (0 == p->defindent) + p->defindent = 7; + p->overstep = 0; p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); @@ -152,8 +153,8 @@ terminal_man(void *arg, const struct man *man) memset(&mt, 0, sizeof(struct mtermp)); - mt.lmargin[mt.lmargincur] = term_len(p, INDENT); - mt.offset = term_len(p, INDENT); + mt.lmargin[mt.lmargincur] = term_len(p, p->defindent); + mt.offset = term_len(p, p->defindent); if (n->child) print_man_nodelist(p, &mt, n->child, m); @@ -507,7 +508,7 @@ pre_PP(DECL_ARGS) switch (n->type) { case (MAN_BLOCK): - mt->lmargin[mt->lmargincur] = term_len(p, INDENT); + mt->lmargin[mt->lmargincur] = term_len(p, p->defindent); print_bvspace(p, n); break; default: @@ -702,8 +703,8 @@ pre_SS(DECL_ARGS) switch (n->type) { case (MAN_BLOCK): mt->fl &= ~MANT_LITERAL; - mt->lmargin[mt->lmargincur] = term_len(p, INDENT); - mt->offset = term_len(p, INDENT); + mt->lmargin[mt->lmargincur] = term_len(p, p->defindent); + mt->offset = term_len(p, p->defindent); /* If following a prior empty `SS', no vspace. */ if (n->prev && MAN_SS == n->prev->tok) if (NULL == n->prev->body->child) @@ -714,7 +715,7 @@ pre_SS(DECL_ARGS) break; case (MAN_HEAD): term_fontrepl(p, TERMFONT_BOLD); - p->offset = term_len(p, HALFINDENT); + p->offset = term_len(p, p->defindent/2); break; case (MAN_BODY): p->offset = mt->offset; @@ -753,8 +754,8 @@ pre_SH(DECL_ARGS) switch (n->type) { case (MAN_BLOCK): mt->fl &= ~MANT_LITERAL; - mt->lmargin[mt->lmargincur] = term_len(p, INDENT); - mt->offset = term_len(p, INDENT); + mt->lmargin[mt->lmargincur] = term_len(p, p->defindent); + mt->offset = term_len(p, p->defindent); /* If following a prior empty `SH', no vspace. */ if (n->prev && MAN_SH == n->prev->tok) if (NULL == n->prev->body->child) @@ -813,7 +814,7 @@ pre_RS(DECL_ARGS) break; } - sz = term_len(p, INDENT); + sz = term_len(p, p->defindent); if (NULL != (n = n->parent->head->child)) if ((ival = a2width(p, n->string)) >= 0) @@ -847,7 +848,7 @@ post_RS(DECL_ARGS) break; } - sz = term_len(p, INDENT); + sz = term_len(p, p->defindent); if (NULL != (n = n->parent->head->child)) if ((ival = a2width(p, n->string)) >= 0) diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 46ea4a8932f..ab696a8d909 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.50 2011/10/09 21:37:04 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.51 2011/11/13 13:05:23 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> .\" @@ -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: October 9 2011 $ +.Dd $Mdocdate: November 13 2011 $ .Dt MANDOC 1 .Os .Sh NAME @@ -234,6 +234,15 @@ The following .Fl O arguments are accepted: .Bl -tag -width Ds +.It Cm indent Ns = Ns Ar indent +The left margin for normal text is set to +.Ar indent +blank characters instead of the default of five for +.Xr mdoc 7 +and seven for +.Xr man 7 . +Increasing this is not recommended; it may result in degraded formatting, +for example overful lines or ugly line breaks. .It Cm width Ns = Ns Ar width The output width is set to .Ar width , diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index c65960c8c57..fd2b07e5796 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.139 2011/11/03 20:32:33 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.140 2011/11/13 13:05:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -30,9 +30,6 @@ #include "mdoc.h" #include "main.h" -#define INDENT 5 -#define HALFINDENT 3 - struct termpair { struct termpair *ppair; int count; @@ -255,6 +252,9 @@ terminal_mdoc(void *arg, const struct mdoc *mdoc) p = (struct termp *)arg; + if (0 == p->defindent) + p->defindent = 5; + p->overstep = 0; p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); @@ -558,9 +558,9 @@ a2offs(const struct termp *p, const char *v) else if (0 == strcmp(v, "left")) return(0); else if (0 == strcmp(v, "indent")) - return(term_len(p, INDENT + 1)); + return(term_len(p, p->defindent + 1)); else if (0 == strcmp(v, "indent-two")) - return(term_len(p, (INDENT + 1) * 2)); + return(term_len(p, (p->defindent + 1) * 2)); else if ( ! a2roffsu(v, &su, SCALE_MAX)) SCALE_HS_INIT(&su, term_strlen(p, v)); @@ -1420,7 +1420,7 @@ termp_sh_pre(DECL_ARGS) term_fontpush(p, TERMFONT_BOLD); break; case (MDOC_BODY): - p->offset = term_len(p, INDENT); + p->offset = term_len(p, p->defindent); break; default: break; @@ -1488,7 +1488,7 @@ termp_d1_pre(DECL_ARGS) if (MDOC_BLOCK != n->type) return(1); term_newln(p); - p->offset += term_len(p, (INDENT + 1)); + p->offset += term_len(p, p->defindent + 1); return(1); } @@ -1793,7 +1793,7 @@ termp_ss_pre(DECL_ARGS) break; case (MDOC_HEAD): term_fontpush(p, TERMFONT_BOLD); - p->offset = term_len(p, HALFINDENT); + p->offset = term_len(p, (p->defindent+1)/2); break; default: break; diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h index 7301c942233..1a16bee152d 100644 --- a/usr.bin/mandoc/term.h +++ b/usr.bin/mandoc/term.h @@ -1,4 +1,4 @@ -/* $Id: term.h,v 1.32 2011/09/19 22:36:11 schwarze Exp $ */ +/* $Id: term.h,v 1.33 2011/11/13 13:05:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -52,6 +52,7 @@ struct termp_tbl { struct termp { enum termtype type; struct rofftbl tbl; /* table configuration */ + size_t defindent; /* Default indent for text. */ size_t defrmargin; /* Right margin of the device. */ size_t rmargin; /* Current right margin. */ size_t maxrmargin; /* Max right margin. */ diff --git a/usr.bin/mandoc/term_ascii.c b/usr.bin/mandoc/term_ascii.c index 7d70dc4a86a..af83b5e69dc 100644 --- a/usr.bin/mandoc/term_ascii.c +++ b/usr.bin/mandoc/term_ascii.c @@ -1,4 +1,4 @@ -/* $Id: term_ascii.c,v 1.6 2011/05/29 21:22:18 schwarze Exp $ */ +/* $Id: term_ascii.c,v 1.7 2011/11/13 13:05:23 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -47,7 +47,7 @@ static size_t locale_width(const struct termp *, int); static struct termp * ascii_init(enum termenc enc, char *outopts) { - const char *toks[2]; + const char *toks[3]; char *v; struct termp *p; @@ -81,12 +81,16 @@ ascii_init(enum termenc enc, char *outopts) } } - toks[0] = "width"; - toks[1] = NULL; + toks[0] = "indent"; + toks[1] = "width"; + toks[2] = NULL; while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { case (0): + p->defindent = (size_t)atoi(v); + break; + case (1): p->defrmargin = (size_t)atoi(v); break; default: |