source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Rewrite indentation handling for nested lists in a more
@ 2012-12-31 22:34 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2012-12-31 22:34 UTC (permalink / raw)
  To: source

Log Message:
-----------
Rewrite indentation handling for nested lists in a more systematic way
to fix multiple issues reported by Todd Miller; thanks!

Specifically,
 - avoid double indentation after .Bd inside .Bl
 - set up correct indentation after .Bl inside .Bl
 - set up correct indentation after .Dl and .D1 inside .Bl

While here, also
 - set up correct indentation *inside* .Dl and .D1 inside .Bl.

Modified Files:
--------------
    mdocml:
        mdoc_man.c

Revision Data
-------------
Index: mdoc_man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_man.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.46 -r1.47
--- mdoc_man.c
+++ mdoc_man.c
@@ -43,6 +43,7 @@ static	int	  cond_body(DECL_ARGS);
 static	int	  cond_head(DECL_ARGS);
 static  void	  font_push(char);
 static	void	  font_pop(void);
+static	void	  mid_it(void);
 static	void	  post__t(DECL_ARGS);
 static	void	  post_bd(DECL_ARGS);
 static	void	  post_bf(DECL_ARGS);
@@ -442,6 +443,9 @@ print_offs(const char *v)
 	print_word(buf);
 }
 
+/*
+ * Set up the indentation for a list item; used from pre_it().
+ */
 void
 print_width(const char *v, const struct mdoc_node *child, size_t defsz)
 {
@@ -470,16 +474,8 @@ print_width(const char *v, const struct 
 	chsz = (NULL != child && MDOC_TEXT == child->type) ?
 			strlen(child->string) : 0;
 
-	/*
-	 * If we are inside an enclosing list,
-	 * preserve its indentation.
-	 */
-	if (Bl_stack_len && Bl_stack[Bl_stack_len - 1]) {
-		print_line(".RS", MMAN_Bk_susp);
-		snprintf(buf, sizeof(buf), "%ldn",
-				Bl_stack[Bl_stack_len - 1]);
-		print_word(buf);
-	}
+	/* Maybe we are inside an enclosing list? */
+	mid_it();
 
 	/*
 	 * Save our own indentation,
@@ -838,7 +834,6 @@ pre_bd(DECL_ARGS)
 static void
 post_bd(DECL_ARGS)
 {
-	char		 buf[24];
 
 	/* Close out this display. */
 	print_line(".RE", MMAN_nl);
@@ -846,20 +841,9 @@ post_bd(DECL_ARGS)
 	    DISP_literal  == n->norm->Bd.type)
 		print_line(".fi", MMAN_nl);
 
-	/*
-	 * If we are inside an enclosing list and the current
-	 * list item is not yet finished, restore the correct
-	 * indentation for what remains of that item.
-	 */
-	if (NULL != n->parent->next &&
-	    Bl_stack_len && Bl_stack[Bl_stack_len - 1]) {
-		print_line(".RS", MMAN_Bk_susp);
-		snprintf(buf, sizeof(buf), "%ldn",
-				Bl_stack[Bl_stack_len - 1]);
-		print_word(buf);
-		/* Remeber to close out this .RS block later. */
-		Bl_stack_post[Bl_stack_len - 1] = 1;
-	}
+	/* Maybe we are inside an enclosing list? */
+	if (NULL != n->parent->next)
+		mid_it();
 }
 
 static int
@@ -958,6 +942,11 @@ post_bl(DECL_ARGS)
 	}
 	outflags |= MMAN_PP | MMAN_nl;
 	outflags &= ~(MMAN_sp | MMAN_br);
+
+	/* Maybe we are inside an enclosing list? */
+	if (NULL != n->parent->next)
+		mid_it();
+
 }
 
 static int
@@ -992,7 +981,9 @@ static int
 pre_dl(DECL_ARGS)
 {
 
-	print_line(".RS 6n", MMAN_nl);
+	print_line(".RS", MMAN_Bk_susp);
+	print_offs("6n");
+	outflags |= MMAN_nl;
 	return(1);
 }
 
@@ -1001,6 +992,10 @@ post_dl(DECL_ARGS)
 {
 
 	print_line(".RE", MMAN_nl);
+
+	/* Maybe we are inside an enclosing list? */
+	if (NULL != n->parent->next)
+		mid_it();
 }
 
 static int
@@ -1263,6 +1258,32 @@ pre_it(DECL_ARGS)
 	return(1);
 }
 
+/*
+ * This function is called after closing out an indented block.
+ * If we are inside an enclosing list, restore its indentation.
+ */
+static void
+mid_it(void)
+{
+	char		 buf[24];
+
+	/* Nothing to do outside a list. */
+	if (0 == Bl_stack_len || 0 == Bl_stack[Bl_stack_len - 1])
+		return;
+
+	/* The indentation has already been set up. */
+	if (Bl_stack_post[Bl_stack_len - 1])
+		return;
+
+	/* Restore the indentation of the enclosing list. */
+	print_line(".RS", MMAN_Bk_susp);
+	snprintf(buf, sizeof(buf), "%ldn", Bl_stack[Bl_stack_len - 1]);
+	print_word(buf);
+
+	/* Remeber to close out this .RS block later. */
+	Bl_stack_post[Bl_stack_len - 1] = 1;
+}
+
 static void
 post_it(DECL_ARGS)
 {
@@ -1302,20 +1323,13 @@ post_it(DECL_ARGS)
 
 			/*
 			 * Our indentation had to be restored
-			 * after a child display.
+			 * after a child display or child list.
 			 * Close out that indentation block now.
 			 */
 			if (Bl_stack_post[Bl_stack_len]) {
 				print_line(".RE", MMAN_nl);
 				Bl_stack_post[Bl_stack_len] = 0;
 			}
-
-			/*
-			 * We are inside an enclosing list.
-			 * Restore the indentation of that list.
-			 */
-			if (Bl_stack_len && Bl_stack[Bl_stack_len - 1])
-				print_line(".RE", MMAN_nl);
 			break;
 		case (LIST_column):
 			if (NULL != n->next) {
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

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

only message in thread, other threads:[~2012-12-31 22:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-31 22:34 mdocml: Rewrite indentation handling for nested lists in a more 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).