]> git.cameronkatri.com Git - mandoc.git/commitdiff
Make the default left text margin configurable from the command line,
authorIngo Schwarze <schwarze@openbsd.org>
Sun, 13 Nov 2011 13:15:14 +0000 (13:15 +0000)
committerIngo Schwarze <schwarze@openbsd.org>
Sun, 13 Nov 2011 13:15:14 +0000 (13:15 +0000)
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

man_term.c
mandoc.1
mdoc_term.c
term.h
term_ascii.c

index a4ebb1b447250d423731fef58fe91d8fcad80f87..63662337a246d5818103aaa3bca34180904d1205 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: man_term.c,v 1.121 2011/09/21 09:57:13 schwarze Exp $ */
+/*     $Id: man_term.c,v 1.122 2011/11/13 13:15:14 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -33,8 +33,6 @@
 #include "term.h"
 #include "main.h"
 
 #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. */
 #define        MAXMARGINS        64 /* maximum number of indented scopes */
 
 /* FIXME: have PD set the default vspace width. */
@@ -141,6 +139,9 @@ terminal_man(void *arg, const struct man *man)
 
        p = (struct termp *)arg;
 
 
        p = (struct termp *)arg;
 
+       if (0 == p->defindent)
+               p->defindent = 7;
+
        p->overstep = 0;
        p->maxrmargin = p->defrmargin;
        p->tabwidth = term_len(p, 5);
        p->overstep = 0;
        p->maxrmargin = p->defrmargin;
        p->tabwidth = term_len(p, 5);
@@ -156,8 +157,8 @@ terminal_man(void *arg, const struct man *man)
 
        memset(&mt, 0, sizeof(struct mtermp));
 
 
        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);
 
        if (n->child)
                print_man_nodelist(p, &mt, n->child, m);
@@ -511,7 +512,7 @@ pre_PP(DECL_ARGS)
 
        switch (n->type) {
        case (MAN_BLOCK):
 
        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:
                print_bvspace(p, n);
                break;
        default:
@@ -706,8 +707,8 @@ pre_SS(DECL_ARGS)
        switch (n->type) {
        case (MAN_BLOCK):
                mt->fl &= ~MANT_LITERAL;
        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)
                /* If following a prior empty `SS', no vspace. */
                if (n->prev && MAN_SS == n->prev->tok)
                        if (NULL == n->prev->body->child)
@@ -718,7 +719,7 @@ pre_SS(DECL_ARGS)
                break;
        case (MAN_HEAD):
                term_fontrepl(p, TERMFONT_BOLD);
                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;
                break;
        case (MAN_BODY):
                p->offset = mt->offset;
@@ -757,8 +758,8 @@ pre_SH(DECL_ARGS)
        switch (n->type) {
        case (MAN_BLOCK):
                mt->fl &= ~MANT_LITERAL;
        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)
                /* If following a prior empty `SH', no vspace. */
                if (n->prev && MAN_SH == n->prev->tok)
                        if (NULL == n->prev->body->child)
@@ -817,7 +818,7 @@ pre_RS(DECL_ARGS)
                break;
        }
 
                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) 
 
        if (NULL != (n = n->parent->head->child))
                if ((ival = a2width(p, n->string)) >= 0) 
@@ -851,7 +852,7 @@ post_RS(DECL_ARGS)
                break;
        }
 
                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) 
 
        if (NULL != (n = n->parent->head->child)) 
                if ((ival = a2width(p, n->string)) >= 0) 
index 0dd7c29e52415afc670282d0e63161b38ff77a81..0a5048e7bc30bb3ac19b10c1191cb0f8157439c7 100644 (file)
--- a/mandoc.1
+++ b/mandoc.1
@@ -1,4 +1,4 @@
-.\"    $Id: mandoc.1,v 1.97 2011/10/09 21:37:06 schwarze Exp $
+.\"    $Id: mandoc.1,v 1.98 2011/11/13 13:15:14 schwarze Exp $
 .\"
 .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
 .\"
 .\"
 .\" 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.
 .\"
 .\" 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
 .Dt MANDOC 1
 .Os
 .Sh NAME
@@ -234,6 +234,15 @@ The following
 .Fl O
 arguments are accepted:
 .Bl -tag -width Ds
 .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 ,
 .It Cm width Ns = Ns Ar width
 The output width is set to
 .Ar width ,
index 9b01d651c5cd5be7caf69bc6b38f17ec32c781cd..533356644448ea56e6bf227e8bf7b69203454ede 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: mdoc_term.c,v 1.237 2011/11/03 20:36:59 schwarze Exp $ */
+/*     $Id: mdoc_term.c,v 1.238 2011/11/13 13:15:14 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -34,9 +34,6 @@
 #include "mdoc.h"
 #include "main.h"
 
 #include "mdoc.h"
 #include "main.h"
 
-#define        INDENT            5
-#define        HALFINDENT        3
-
 struct termpair {
        struct termpair  *ppair;
        int               count;
 struct termpair {
        struct termpair  *ppair;
        int               count;
@@ -259,6 +256,9 @@ terminal_mdoc(void *arg, const struct mdoc *mdoc)
 
        p = (struct termp *)arg;
 
 
        p = (struct termp *)arg;
 
+       if (0 == p->defindent)
+               p->defindent = 5;
+
        p->overstep = 0;
        p->maxrmargin = p->defrmargin;
        p->tabwidth = term_len(p, 5);
        p->overstep = 0;
        p->maxrmargin = p->defrmargin;
        p->tabwidth = term_len(p, 5);
@@ -562,9 +562,9 @@ a2offs(const struct termp *p, const char *v)
        else if (0 == strcmp(v, "left"))
                return(0);
        else if (0 == strcmp(v, "indent"))
        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"))
        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));
 
        else if ( ! a2roffsu(v, &su, SCALE_MAX))
                SCALE_HS_INIT(&su, term_strlen(p, v));
 
@@ -1424,7 +1424,7 @@ termp_sh_pre(DECL_ARGS)
                term_fontpush(p, TERMFONT_BOLD);
                break;
        case (MDOC_BODY):
                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;
                break;
        default:
                break;
@@ -1492,7 +1492,7 @@ termp_d1_pre(DECL_ARGS)
        if (MDOC_BLOCK != n->type)
                return(1);
        term_newln(p);
        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);
 }
 
        return(1);
 }
 
@@ -1797,7 +1797,7 @@ termp_ss_pre(DECL_ARGS)
                break;
        case (MDOC_HEAD):
                term_fontpush(p, TERMFONT_BOLD);
                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;
                break;
        default:
                break;
diff --git a/term.h b/term.h
index 685d0962897a70532b8aa81a215df80c5c2ae264..0758f77212cb7814d95bc59db447cfb121230b4a 100644 (file)
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/*     $Id: term.h,v 1.88 2011/09/19 22:36:16 schwarze Exp $ */
+/*     $Id: term.h,v 1.89 2011/11/13 13:15:14 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  *
 /*
  * 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 */
 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. */
        size_t            defrmargin;   /* Right margin of the device. */
        size_t            rmargin;      /* Current right margin. */
        size_t            maxrmargin;   /* Max right margin. */
index 8283aede2742c7cabcfd1410959c4ef30df9e62e..a1d3bc1caf1d06c8328828c8df1bf734af20a024 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: term_ascii.c,v 1.18 2011/09/18 14:14:15 schwarze Exp $ */
+/*     $Id: term_ascii.c,v 1.19 2011/11/13 13:15:14 schwarze Exp $ */
 /*
  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  *
 /*
  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  *
@@ -68,7 +68,7 @@ static        size_t            locale_width(const struct termp *, int);
 static struct termp *
 ascii_init(enum termenc enc, char *outopts)
 {
 static struct termp *
 ascii_init(enum termenc enc, char *outopts)
 {
-       const char      *toks[2];
+       const char      *toks[3];
        char            *v;
        struct termp    *p;
 
        char            *v;
        struct termp    *p;
 
@@ -104,12 +104,16 @@ ascii_init(enum termenc enc, char *outopts)
        }
 #endif
 
        }
 #endif
 
-       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):
 
        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:
                        p->defrmargin = (size_t)atoi(v);
                        break;
                default: