source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Cached `Bl -offset' into mdoc_bl.
@ 2010-06-12 12:38 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-06-12 12:38 UTC (permalink / raw)
  To: source

Log Message:
-----------
Cached `Bl -offset' into mdoc_bl.  Removed erroneous "-offset defaults
to 6n if no value is specified" and added regression tests for `Bl'
testing against the empty -offset argument.

Modified Files:
--------------
    mdocml:
        mdoc.h
        mdoc_action.c
        mdoc_html.c
        mdoc_term.c
        mdoc_validate.c

Added Files:
-----------
    mdocml/regress/mdoc/Bl:
        empty-offset.in

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.97 -r1.98
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -532,7 +532,8 @@ pre_display(PRE_ARGS)
 static int
 pre_bl(PRE_ARGS)
 {
-	int		 i, width, offs, comp, dup;
+	int		 i, width, comp, dup;
+	const char	*offs;
 	enum mdoc_list	 lt;
 
 	if (MDOC_BLOCK != n->type) {
@@ -552,12 +553,13 @@ pre_bl(PRE_ARGS)
 	 */
 
 	assert(LIST__NONE == n->data.Bl.type);
-	offs = width = -1;
+	width = -1;
 
 	/* LINTED */
 	for (i = 0; n->args && i < (int)n->args->argc; i++) {
 		lt = LIST__NONE;
 		dup = comp = 0;
+		offs = NULL;
 		switch (n->args->argv[i].arg) {
 		/* Set list types. */
 		case (MDOC_Bullet):
@@ -604,9 +606,14 @@ pre_bl(PRE_ARGS)
 			width = i;
 			break;
 		case (MDOC_Offset):
-			if (offs >= 0)
-				dup++;
-			offs = i;
+			/* NB: this can be empty! */
+			if (n->args->argv[i].sz) {
+				offs = n->args->argv[i].value[0];
+				dup = (NULL != n->data.Bd.offs);
+				break;
+			}
+			if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV))
+				return(0);
 			break;
 		}
 
@@ -617,6 +624,8 @@ pre_bl(PRE_ARGS)
 
 		if (comp && ! dup)
 			n->data.Bl.comp = comp;
+		if (offs && ! dup)
+			n->data.Bl.offs = offs;
 
 		/* Check: multiple list types. */
 
@@ -632,7 +641,7 @@ pre_bl(PRE_ARGS)
 		/* The list type should come first. */
 
 		if (n->data.Bl.type == LIST__NONE)
-			if (width >= 0 || offs >= 0 || n->data.Bl.comp)
+			if (width >= 0 || n->data.Bl.offs || n->data.Bl.comp)
 				if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST))
 					return(0);
 
Index: mdoc_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.82 -r1.83
--- mdoc_html.c
+++ mdoc_html.c
@@ -1035,12 +1035,13 @@ mdoc_it_pre(MDOC_ARGS)
 	if (MDOC_BLOCK != n->type)
 		bl = bl->parent;
 
+	SCALE_HS_INIT(&offs, 0);
+
 	type = bl->data.Bl.type;
 	comp = bl->data.Bl.comp;
 
-	/* Set default width and offset. */
-
-	SCALE_HS_INIT(&offs, 0);
+	if (bl->data.Bl.offs)
+		a2offs(bl->data.Bl.offs, &offs);
 
 	switch (type) {
 	case (LIST_enum):
@@ -1057,8 +1058,6 @@ mdoc_it_pre(MDOC_ARGS)
 		break;
 	}
 
-	/* Get width, offset, and compact arguments. */
-
 	wp = -1;
 	for (i = 0; bl->args && i < (int)bl->args->argc; i++) 
 		switch (bl->args->argv[i].arg) {
@@ -1067,9 +1066,6 @@ mdoc_it_pre(MDOC_ARGS)
 			break;
 		case (MDOC_Width):
 			a2width(bl->args->argv[i].value[0], &width);
-			break;
-		case (MDOC_Offset):
-			a2offs(bl->args->argv[i].value[0], &offs);
 			break;
 		default:
 			break;
Index: mdoc_action.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_action.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -Lmdoc_action.c -Lmdoc_action.c -u -p -r1.67 -r1.68
--- mdoc_action.c
+++ mdoc_action.c
@@ -68,9 +68,7 @@ static	int	  post_st(POST_ARGS);
 static	int	  post_std(POST_ARGS);
 
 static	int	  pre_bd(PRE_ARGS);
-static	int	  pre_bl(PRE_ARGS);
 static	int	  pre_dl(PRE_ARGS);
-static	int	  pre_offset(PRE_ARGS);
 
 static	const struct actions mdoc_actions[MDOC_MAX] = {
 	{ NULL, NULL }, /* Ap */
@@ -84,7 +82,7 @@ static	const struct actions mdoc_actions
 	{ pre_dl, post_display }, /* Dl */
 	{ pre_bd, post_display }, /* Bd */ 
 	{ NULL, NULL }, /* Ed */
-	{ pre_bl, post_bl }, /* Bl */ 
+	{ NULL, post_bl }, /* Bl */ 
 	{ NULL, NULL }, /* El */
 	{ NULL, NULL }, /* It */
 	{ NULL, NULL }, /* Ad */ 
@@ -933,44 +931,6 @@ pre_dl(PRE_ARGS)
 
 	if (MDOC_BODY == n->type)
 		m->flags |= MDOC_LITERAL;
-	return(1);
-}
-
-
-/* ARGSUSED */
-static int
-pre_offset(PRE_ARGS)
-{
-	int		 i;
-
-	/* 
-	 * Make sure that an empty offset produces an 8n length space as
-	 * stipulated by mdoc.samples. 
-	 */
-
-	for (i = 0; n->args && i < (int)n->args->argc; i++) {
-		if (MDOC_Offset != n->args->argv[i].arg) 
-			continue;
-		if (n->args->argv[i].sz)
-			break;
-		assert(1 == n->args->refcnt);
-		/* If no value set, length of <string>. */
-		n->args->argv[i].sz++;
-		n->args->argv[i].value = mandoc_malloc(sizeof(char *));
-		n->args->argv[i].value[0] = mandoc_strdup("8n");
-		break;
-	}
-
-	return(1);
-}
-
-
-static int
-pre_bl(PRE_ARGS)
-{
-
-	if (MDOC_BLOCK == n->type)
-		return(pre_offset(m, n));
 	return(1);
 }
 
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.151
retrieving revision 1.152
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.151 -r1.152
--- mdoc_term.c
+++ mdoc_term.c
@@ -643,7 +643,7 @@ termp_it_pre(DECL_ARGS)
 {
 	const struct mdoc_node *bl, *nn;
 	char		        buf[7];
-	int		        i, keys[3], vals[3];
+	int		        i, keys[2], vals[2];
 	size_t		        width, offset, ncols, dcol;
 	enum mdoc_list		type;
 
@@ -657,12 +657,11 @@ termp_it_pre(DECL_ARGS)
 	/* Get list width, offset, and list type from argument list. */
 
 	keys[0] = MDOC_Width;
-	keys[1] = MDOC_Offset;
-	keys[2] = MDOC_Column;
+	keys[1] = MDOC_Column;
 
-	vals[0] = vals[1] = vals[2] = -1;
+	vals[0] = vals[1] = -1;
 
-	arg_getattrs(keys, vals, 3, bl);
+	arg_getattrs(keys, vals, 2, bl);
 
 	type = bl->data.Bl.type;
 
@@ -674,8 +673,9 @@ termp_it_pre(DECL_ARGS)
 
 	width = offset = 0;
 
-	if (vals[1] >= 0) 
-		offset = a2offs(bl->args->argv[vals[1]].value[0]);
+	if (bl->data.Bl.offs)
+		offset = a2offs(bl->data.Bl.offs);
+
 
 	switch (type) {
 	case (LIST_column):
@@ -690,7 +690,7 @@ termp_it_pre(DECL_ARGS)
 		 *   column.
 		 * - For more than 5 columns, add only one column.
 		 */
-		ncols = bl->args->argv[vals[2]].sz;
+		ncols = bl->args->argv[vals[1]].sz;
 		/* LINTED */
 		dcol = ncols < 5 ? 4 : ncols == 5 ? 3 : 1;
 
@@ -703,7 +703,7 @@ termp_it_pre(DECL_ARGS)
 				nn->prev && i < (int)ncols; 
 				nn = nn->prev, i++)
 			offset += dcol + a2width
-				(&bl->args->argv[vals[2]], i);
+				(&bl->args->argv[vals[1]], i);
 
 
 		/*
@@ -719,7 +719,7 @@ termp_it_pre(DECL_ARGS)
 		 * Use the declared column widths, extended as explained
 		 * in the preceding paragraph.
 		 */
-		width = a2width(&bl->args->argv[vals[2]], i) + dcol;
+		width = a2width(&bl->args->argv[vals[1]], i) + dcol;
 		break;
 	default:
 		if (vals[0] < 0) 
Index: mdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v
retrieving revision 1.87
retrieving revision 1.88
diff -Lmdoc.h -Lmdoc.h -u -p -r1.87 -r1.88
--- mdoc.h
+++ mdoc.h
@@ -279,6 +279,7 @@ struct	mdoc_bd {
 };
 
 struct	mdoc_bl {
+	const char	 *offs; /* -offset */
 	enum mdoc_list	  type; /* -tag, -enum, etc. */
 	int		  comp; /* -compact */
 };
--- /dev/null
+++ regress/mdoc/Bl/empty-offset.in
@@ -0,0 +1,15 @@
+.Dd $Mdocdate: June 12 2010 $
+.Dt FOO 1
+.Os
+.Sh NAME
+.Nm foo
+.Nd bar
+.Sh DESCRIPTION
+.Bl -tag -width Ds -offset
+.It foo
+bar
+.El
+.Bl -tag -width Ds
+.It foo
+bar
+.El
--
 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:[~2010-06-12 12:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-12 12:38 mdocml: Cached `Bl -offset' into mdoc_bl kristaps

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).