tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdoc(7) output style for man(7)
@ 2011-11-01 17:53 Ingo Schwarze
  0 siblings, 0 replies; only message in thread
From: Ingo Schwarze @ 2011-11-01 17:53 UTC (permalink / raw)
  To: tech

Hi,

while working on -Tman, i felt the need to set up unit tests
because the more features the module gets, the more potential
arises for inadvertently breaking existing functionality.

Of course, i don't want to set up a completely new test suite
just for -Tman, but instead use the existing test files in
src/regress/usr.bin/mandoc/mdoc.  I have (unpublished) tweaks
to the Makefiles to run

  mandoc -Tman foo.in > foo.in_man
  mandoc foo.in_man > foo.mandoc_man

and then, of course, i want to compore foo.mandoc_man to
foo.out_ascii just like i'm currently comparing foo.mandoc_ascii
to foo.out_ascii.

It almost works, except for two details:

 (1) The default indentation for normal text is five characters
     for mdoc (reflected in foo.out_ascii), but seven characters
     for man (reflected in foo.mandoc_man).

 (2) The mdoc and man footers differ from each other.

Hence, what i need is an alternative man(7) output style using
mdoc(7) conventions with respect to indentation and footers.
I suggest to add an output option

  -man -Omdoc

to achieve that.  Long term, after convincing the groff crowd
to do the same, we might even make that the default and drop
the option again.

Regarding the indentation, obviously, INDENT must be replaced
by a new struct member in termp, alongside defrmargin.
Given that we already have -Owidth, why not provide -Oindent
as well and let -Omdoc imply -Oindent=5?  That's cheap.

The following patch
 - implements -Oindent
 - uses it for -man -Tascii
 - implements -Omdoc
 - does not use the latter yet (see the next patch)

OK?
  Ingo


Index: man_term.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/man_term.c,v
retrieving revision 1.76
diff -u -p -r1.76 man_term.c
--- man_term.c	21 Sep 2011 09:57:11 -0000	1.76
+++ man_term.c	1 Nov 2011 17:55:39 -0000
@@ -137,6 +137,9 @@ terminal_man(void *arg, const struct man
 
 	p = (struct termp *)arg;
 
+	if (0 == p->defindent)
+		p->defindent = INDENT;
+
 	p->overstep = 0;
 	p->maxrmargin = p->defrmargin;
 	p->tabwidth = term_len(p, 5);
@@ -152,8 +155,8 @@ terminal_man(void *arg, const struct 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 +510,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 +705,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)
@@ -753,8 +756,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 +816,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 +850,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) 
Index: term.h
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/term.h,v
retrieving revision 1.32
diff -u -p -r1.32 term.h
--- term.h	19 Sep 2011 22:36:11 -0000	1.32
+++ term.h	1 Nov 2011 17:55:43 -0000
@@ -52,6 +52,8 @@ struct	termp_tbl {
 struct	termp {
 	enum termtype	  type;
 	struct rofftbl	  tbl;		/* table configuration */
+	int		  mdocstyle;	/* imitate mdoc(7) output */
+	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. */
Index: term_ascii.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/term_ascii.c,v
retrieving revision 1.6
diff -u -p -r1.6 term_ascii.c
--- term_ascii.c	29 May 2011 21:22:18 -0000	1.6
+++ term_ascii.c	1 Nov 2011 17:55:43 -0000
@@ -47,7 +47,7 @@ static	size_t		  locale_width(const stru
 static struct termp *
 ascii_init(enum termenc enc, char *outopts)
 {
-	const char	*toks[2];
+	const char	*toks[4];
 	char		*v;
 	struct termp	*p;
 
@@ -81,13 +81,22 @@ ascii_init(enum termenc enc, char *outop
 		}
 	}
 
-	toks[0] = "width";
-	toks[1] = NULL;
+	toks[0] = "indent";
+	toks[1] = "width";
+	toks[2] = "mdoc";
+	toks[3] = 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;
+		case (2):
+			p->mdocstyle = 1;
+			p->defindent = 5;
 			break;
 		default:
 			break;
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-11-01 18:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-01 17:53 mdoc(7) output style for man(7) Ingo Schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).