source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Added enum mdoc_disp (similar to enum mdoc_list).
@ 2010-06-12 10:09 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-06-12 10:09 UTC (permalink / raw)
  To: source

Log Message:
-----------
Added enum mdoc_disp (similar to enum mdoc_list).  Display types are now
only calculated once in mdoc_validate.c.

Noted that `Bd -file xxx' is not supported:  it now raises a fatal
warning.  This is noted in mdoc.7.

Empty `Bd' now defaults to LIST_ragged, which is not quite what groff
does, but close enough (gross just throws away the `Bd' and gets upset
when it encounters an `Ed').

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

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.92 -r1.93
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -683,43 +683,65 @@ pre_bl(PRE_ARGS)
 static int
 pre_bd(PRE_ARGS)
 {
-	int		 i, type, err;
+	int		 i;
+	enum mdoc_disp 	 dt;
 
-	if (MDOC_BLOCK != n->type)
+	if (MDOC_BLOCK != n->type) {
+		assert(n->parent);
+		assert(MDOC_BLOCK == n->parent->type);
+		assert(MDOC_Bd == n->parent->tok);
+		assert(DISP__NONE != n->parent->data.disp);
+		n->data.disp = n->parent->data.disp;
 		return(1);
-	if (NULL == n->args) {
-		mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE);
-		return(0);
 	}
 
-	/* Make sure that only one type of display is specified.  */
+	assert(DISP__NONE == n->data.disp);
 
 	/* LINTED */
-	for (i = 0, err = type = 0; ! err && 
-			i < (int)n->args->argc; i++)
+	for (i = 0; n->args && i < (int)n->args->argc; i++) {
+		dt = DISP__NONE;
 		switch (n->args->argv[i].arg) {
 		case (MDOC_Centred):
-			/* FALLTHROUGH */
+			dt = DISP_centred;
+			break;
 		case (MDOC_Ragged):
-			/* FALLTHROUGH */
+			dt = DISP_ragged;
+			break;
 		case (MDOC_Unfilled):
-			/* FALLTHROUGH */
+			dt = DISP_unfilled;
+			break;
 		case (MDOC_Filled):
-			/* FALLTHROUGH */
+			dt = DISP_filled;
+			break;
 		case (MDOC_Literal):
-			if (0 == type++) 
-				break;
-			if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP))
-				return(0);
+			dt = DISP_literal;
 			break;
+		case (MDOC_File):
+			mdoc_nmsg(mdoc, n, MANDOCERR_BADDISP);
+			return(0);
+		case (MDOC_Offset):
+			/* FALLTHROUGH */
+		case (MDOC_Compact):
+			/* FALLTHROUGH */
 		default:
 			break;
 		}
 
-	if (type)
-		return(1);
-	mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE);
-	return(0);
+		if (DISP__NONE != dt && n->data.disp != DISP__NONE)
+			if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP))
+				return(0);
+
+		if (DISP__NONE != dt && n->data.disp == DISP__NONE)
+			n->data.disp = dt;
+	}
+
+	if (DISP__NONE == n->data.disp) {
+		if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE))
+			return(0);
+		n->data.disp = DISP_ragged;
+	}
+
+	return(1);
 }
 
 
Index: mdoc_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.78 -r1.79
--- mdoc_html.c
+++ mdoc_html.c
@@ -1353,7 +1353,7 @@ static int
 mdoc_bd_pre(MDOC_ARGS)
 {
 	struct htmlpair	 	 tag[2];
-	int		 	 type, comp, i;
+	int		 	 comp, i;
 	const struct mdoc_node	*bl, *nn;
 	struct roffsu		 su;
 
@@ -1366,7 +1366,7 @@ mdoc_bd_pre(MDOC_ARGS)
 
 	SCALE_VS_INIT(&su, 0);
 
-	type = comp = 0;
+	comp = 0;
 	for (i = 0; bl->args && i < (int)bl->args->argc; i++) 
 		switch (bl->args->argv[i].arg) {
 		case (MDOC_Offset):
@@ -1375,17 +1375,6 @@ mdoc_bd_pre(MDOC_ARGS)
 		case (MDOC_Compact):
 			comp = 1;
 			break;
-		case (MDOC_Centred):
-			/* FALLTHROUGH */
-		case (MDOC_Ragged):
-			/* FALLTHROUGH */
-		case (MDOC_Filled):
-			/* FALLTHROUGH */
-		case (MDOC_Unfilled):
-			/* FALLTHROUGH */
-		case (MDOC_Literal):
-			type = bl->args->argv[i].arg;
-			break;
 		default:
 			break;
 		}
@@ -1415,7 +1404,8 @@ mdoc_bd_pre(MDOC_ARGS)
 		return(1);
 	}
 
-	if (MDOC_Unfilled != type && MDOC_Literal != type)
+	if (DISP_unfilled != n->data.disp && 
+			DISP_literal != n->data.disp)
 		return(1);
 
 	PAIR_CLASS_INIT(&tag[0], "lit");
Index: mdoc_action.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_action.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -Lmdoc_action.c -Lmdoc_action.c -u -p -r1.65 -r1.66
--- mdoc_action.c
+++ mdoc_action.c
@@ -978,20 +978,16 @@ pre_bl(PRE_ARGS)
 static int
 pre_bd(PRE_ARGS)
 {
-	int		 i;
 
 	if (MDOC_BLOCK == n->type)
 		return(pre_offset(m, n));
 	if (MDOC_BODY != n->type)
 		return(1);
 
-	/* Enter literal context if `Bd -literal' or `-unfilled'. */
-
-	for (n = n->parent, i = 0; i < (int)n->args->argc; i++)
-		if (MDOC_Literal == n->args->argv[i].arg)
-			m->flags |= MDOC_LITERAL;
-		else if (MDOC_Unfilled == n->args->argv[i].arg)
-			m->flags |= MDOC_LITERAL;
+	if (DISP_literal == n->data.disp)
+		m->flags |= MDOC_LITERAL;
+	if (DISP_unfilled == n->data.disp)
+		m->flags |= MDOC_LITERAL;
 
 	return(1);
 }
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.146 -r1.147
--- mdoc_term.c
+++ mdoc_term.c
@@ -60,7 +60,6 @@ static	int	  arg_hasattr(int, const stru
 static	int	  arg_getattrs(const int *, int *, size_t,
 			const struct mdoc_node *);
 static	int	  arg_getattr(int, const struct mdoc_node *);
-static	int	  arg_disptype(const struct mdoc_node *);
 static	void	  print_bvspace(struct termp *,
 			const struct mdoc_node *,
 			const struct mdoc_node *);
@@ -489,35 +488,6 @@ a2width(const struct mdoc_argv *arg, int
 }
 
 
-static int
-arg_disptype(const struct mdoc_node *n)
-{
-	int		 i, len;
-
-	assert(MDOC_BLOCK == n->type);
-
-	len = (int)(n->args ? n->args->argc : 0);
-
-	for (i = 0; i < len; i++)
-		switch (n->args->argv[i].arg) {
-		case (MDOC_Centred):
-			/* FALLTHROUGH */
-		case (MDOC_Ragged):
-			/* FALLTHROUGH */
-		case (MDOC_Filled):
-			/* FALLTHROUGH */
-		case (MDOC_Unfilled):
-			/* FALLTHROUGH */
-		case (MDOC_Literal):
-			return(n->args->argv[i].arg);
-		default:
-			break;
-		}
-
-	return(-1);
-}
-
-
 static size_t
 a2offs(const struct mdoc_argv *arg)
 {
@@ -1632,7 +1602,7 @@ static int
 termp_bd_pre(DECL_ARGS)
 {
 	size_t			 tabwidth;
-	int	         	 i, type;
+	int	         	 i;
 	size_t			 rm, rmax;
 	const struct mdoc_node	*nn;
 
@@ -1644,9 +1614,6 @@ termp_bd_pre(DECL_ARGS)
 
 	nn = n->parent;
 
-	type = arg_disptype(nn);
-	assert(-1 != type);
-
 	if (-1 != (i = arg_getattr(MDOC_Offset, nn)))
 		p->offset += a2offs(&nn->args->argv[i]);
 
@@ -1658,7 +1625,8 @@ termp_bd_pre(DECL_ARGS)
 	 * lines are allowed.
 	 */
 	
-	if (MDOC_Literal != type && MDOC_Unfilled != type)
+	if (DISP_literal != n->data.disp && 
+			DISP_unfilled != n->data.disp)
 		return(1);
 
 	tabwidth = p->tabwidth;
@@ -1675,8 +1643,8 @@ termp_bd_pre(DECL_ARGS)
 		    NULL == nn->next)
 			term_flushln(p);
 	}
-	p->tabwidth = tabwidth;
 
+	p->tabwidth = tabwidth;
 	p->rmargin = rm;
 	p->maxrmargin = rmax;
 	return(0);
@@ -1687,19 +1655,16 @@ termp_bd_pre(DECL_ARGS)
 static void
 termp_bd_post(DECL_ARGS)
 {
-	int		 type;
 	size_t		 rm, rmax;
 
 	if (MDOC_BODY != n->type) 
 		return;
 
-	type = arg_disptype(n->parent);
-	assert(-1 != type);
-
 	rm = p->rmargin;
 	rmax = p->maxrmargin;
 
-	if (MDOC_Literal == type || MDOC_Unfilled == type)
+	if (DISP_literal == n->data.disp || 
+			DISP_unfilled == n->data.disp)
 		p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
 
 	p->flags |= TERMP_NOSPACE;
Index: mdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v
retrieving revision 1.83
retrieving revision 1.84
diff -Lmdoc.h -Lmdoc.h -u -p -r1.83 -r1.84
--- mdoc.h
+++ mdoc.h
@@ -263,6 +263,15 @@ enum	mdoc_list {
 	LIST_tag
 };
 
+enum	mdoc_disp {
+	DISP__NONE = 0,
+	DISP_centred,
+	DISP_ragged,
+	DISP_unfilled,
+	DISP_filled,
+	DISP_literal
+};
+
 /* Node in AST. */
 struct	mdoc_node {
 	struct mdoc_node *parent; /* parent AST node */
@@ -290,7 +299,8 @@ struct	mdoc_node {
 	char		 *string;	/* TEXT */
 
 	union {
-		enum mdoc_list list; /* for `Bl' nodes */
+		enum mdoc_list list; /* `Bl' nodes */
+		enum mdoc_disp disp; /* `Bd' nodes */
 	} data;
 };
 
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lmandoc.h -Lmandoc.h -u -p -r1.10 -r1.11
--- mandoc.h
+++ mandoc.h
@@ -74,6 +74,7 @@ enum	mandocerr {
 	MANDOCERR_NOARGV, /* macro requires argument(s) */
 	MANDOCERR_NOTITLE, /* no title in document */
 	MANDOCERR_LISTTYPE, /* missing list type */
+	MANDOCERR_DISPTYPE, /* missing display type */
 	MANDOCERR_ARGSLOST, /* line argument(s) will be lost */
 	MANDOCERR_BODYLOST, /* body argument(s) will be lost */
 #define	MANDOCERR_ERROR		MANDOCERR_BODYLOST
@@ -82,9 +83,8 @@ enum	mandocerr {
 	/* FIXME: this should be a MANDOCERR_ERROR */
 	MANDOCERR_FONTTYPE, /* missing font type */
 	/* FIXME: this should be a MANDOCERR_ERROR */
-	MANDOCERR_DISPTYPE, /* missing display type */
-	/* FIXME: this should be a MANDOCERR_ERROR */
 	MANDOCERR_NESTEDDISP, /* displays may not be nested */
+	MANDOCERR_BADDISP, /* unsupported display type */
 	MANDOCERR_SYNTNOSCOPE, /* request scope close w/none open */
 	MANDOCERR_SYNTSCOPE, /* scope broken, syntax violated */
 	MANDOCERR_SYNTLINESCOPE, /* line scope broken, syntax violated */
Index: mdoc.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.7,v
retrieving revision 1.124
retrieving revision 1.125
diff -Lmdoc.7 -Lmdoc.7 -u -p -r1.124 -r1.125
--- mdoc.7
+++ mdoc.7
@@ -2169,6 +2169,12 @@ Heirloom troff, the other significant tr
 .Pp
 .Bl -dash -compact
 .It
+groff supports a
+.Fl file Ar filename
+argument to
+.Sx \&Bd .
+mandoc does not.
+.It
 groff behaves inconsistently when encountering
 .Pf non- Sx \&Fa
 children of
Index: main.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -Lmain.c -Lmain.c -u -p -r1.86 -r1.87
--- main.c
+++ main.c
@@ -143,12 +143,13 @@ static	const char * const	mandocerrs[MAN
 	"macro requires argument(s)",
 	"no title in document",
 	"missing list type",
+	"missing display type",
 	"line argument(s) will be lost",
 	"body argument(s) will be lost",
 	"column syntax is inconsistent",
 	"missing font type",
-	"missing display type",
 	"displays may not be nested",
+	"unsupported display type",
 	"no scope to rewind: syntax violated",
 	"scope broken, syntax violated",
 	"line scope broken, syntax violated",
--
 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 10:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-12 10:09 mdocml: Added enum mdoc_disp (similar to enum mdoc_list) 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).