source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Add support for `gsize' eqn token (introduced in second-edition
@ 2011-07-22 14:55 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-07-22 14:55 UTC (permalink / raw)
  To: source

Log Message:
-----------
Add support for `gsize' eqn token (introduced in second-edition troff).

Modified Files:
--------------
    mdocml:
        eqn.7
        eqn.c
        libroff.h
        mandoc.h
        read.c

Revision Data
-------------
Index: eqn.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -Leqn.c -Leqn.c -u -p -r1.28 -r1.29
--- eqn.c
+++ eqn.c
@@ -126,14 +126,17 @@ enum	eqnpartt {
 	EQN_DEFINE = 0,
 	EQN_SET,
 	EQN_UNDEF,
+	EQN_GSIZE,
 	EQN__MAX
 };
 
 static	enum eqn_rest	 eqn_box(struct eqn_node *, struct eqn_box *);
-static	struct eqn_box	*eqn_box_alloc(struct eqn_box *);
+static	struct eqn_box	*eqn_box_alloc(struct eqn_node *, 
+				struct eqn_box *);
 static	void		 eqn_box_free(struct eqn_box *);
 static	struct eqn_def	*eqn_def_find(struct eqn_node *, 
 				const char *, size_t);
+static	int		 eqn_do_gsize(struct eqn_node *);
 static	int		 eqn_do_define(struct eqn_node *);
 static	int		 eqn_do_set(struct eqn_node *);
 static	int		 eqn_do_undef(struct eqn_node *);
@@ -149,6 +152,7 @@ static	const struct eqnpart eqnparts[EQN
 	{ { "define", 6 }, eqn_do_define }, /* EQN_DEFINE */
 	{ { "set", 3 }, eqn_do_set }, /* EQN_SET */
 	{ { "undef", 5 }, eqn_do_undef }, /* EQN_UNDEF */
+	{ { "gsize", 5 }, eqn_do_gsize }, /* EQN_UNDEF */
 };
 
 static	const struct eqnstr eqnmarks[EQNMARK__MAX] = {
@@ -298,6 +302,7 @@ eqn_alloc(int pos, int line, struct mpar
 	p->parse = parse;
 	p->eqn.ln = line;
 	p->eqn.pos = pos;
+	p->gsize = EQN_DEFSIZE;
 
 	return(p);
 }
@@ -330,7 +335,7 @@ eqn_eqn(struct eqn_node *ep, struct eqn_
 	struct eqn_box	*bp;
 	enum eqn_rest	 c;
 
-	bp = eqn_box_alloc(last);
+	bp = eqn_box_alloc(ep, last);
 	bp->type = EQN_SUBEXPR;
 
 	while (EQN_OK == (c = eqn_box(ep, bp)))
@@ -347,7 +352,7 @@ eqn_list(struct eqn_node *ep, struct eqn
 	size_t		 sz;
 	enum eqn_rest	 c;
 
-	bp = eqn_box_alloc(last);
+	bp = eqn_box_alloc(ep, last);
 	bp->type = EQN_LIST;
 
 	if (NULL == (start = eqn_nexttok(ep, &sz))) {
@@ -516,7 +521,7 @@ eqn_box(struct eqn_node *ep, struct eqn_
 		last->last->size = size;
 	}
 
-	bp = eqn_box_alloc(last);
+	bp = eqn_box_alloc(ep, last);
 	bp->type = EQN_TEXT;
 	for (i = 0; i < (int)EQNSYM__MAX; i++)
 		if (EQNSTREQ(&eqnsyms[i].str, start, sz)) {
@@ -548,13 +553,13 @@ eqn_free(struct eqn_node *p)
 }
 
 static struct eqn_box *
-eqn_box_alloc(struct eqn_box *parent)
+eqn_box_alloc(struct eqn_node *ep, struct eqn_box *parent)
 {
 	struct eqn_box	*bp;
 
 	bp = mandoc_calloc(1, sizeof(struct eqn_box));
 	bp->parent = parent;
-	bp->size = EQN_DEFSIZE;
+	bp->size = ep->gsize;
 
 	if (NULL == parent->first)
 		parent->first = bp;
@@ -695,9 +700,9 @@ eqn_do_set(struct eqn_node *ep)
 	const char	*start;
 
 	if (NULL == (start = eqn_nextrawtok(ep, NULL)))
-		EQN_MSG(MANDOCERR_EQNARGS, ep);
+		EQN_MSG(MANDOCERR_EQNEOF, ep);
 	else if (NULL == (start = eqn_nextrawtok(ep, NULL)))
-		EQN_MSG(MANDOCERR_EQNARGS, ep);
+		EQN_MSG(MANDOCERR_EQNEOF, ep);
 	else
 		return(1);
 
@@ -713,7 +718,7 @@ eqn_do_define(struct eqn_node *ep)
 	int		 i;
 
 	if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
-		EQN_MSG(MANDOCERR_EQNARGS, ep);
+		EQN_MSG(MANDOCERR_EQNEOF, ep);
 		return(0);
 	}
 
@@ -748,7 +753,7 @@ eqn_do_define(struct eqn_node *ep)
 	start = eqn_next(ep, ep->data[(int)ep->cur], &sz, 0);
 
 	if (NULL == start) {
-		EQN_MSG(MANDOCERR_EQNARGS, ep);
+		EQN_MSG(MANDOCERR_EQNEOF, ep);
 		return(0);
 	}
 
@@ -760,6 +765,21 @@ eqn_do_define(struct eqn_node *ep)
 }
 
 static int
+eqn_do_gsize(struct eqn_node *ep)
+{
+	const char	*start;
+	size_t		 sz;
+
+	if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
+		EQN_MSG(MANDOCERR_EQNEOF, ep);
+		return(0);
+	} 
+
+	ep->gsize = mandoc_strntoi(start, sz, 10);
+	return(1);
+}
+
+static int
 eqn_do_undef(struct eqn_node *ep)
 {
 	const char	*start;
@@ -767,7 +787,7 @@ eqn_do_undef(struct eqn_node *ep)
 	size_t		 sz;
 
 	if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
-		EQN_MSG(MANDOCERR_EQNARGS, ep);
+		EQN_MSG(MANDOCERR_EQNEOF, ep);
 		return(0);
 	} else if (NULL != (def = eqn_def_find(ep, start, sz)))
 		def->keysz = 0;
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.90
retrieving revision 1.91
diff -Lmandoc.h -Lmandoc.h -u -p -r1.90 -r1.91
--- mandoc.h
+++ mandoc.h
@@ -110,7 +110,6 @@ enum	mandocerr {
 	MANDOCERR_ERROR, /* ===== start of errors ===== */
 
 	/* related to equations */
-	MANDOCERR_EQNARGS, /* bad equation macro arguments */
 	MANDOCERR_EQNNEST, /* too many nested equation defines */
 	MANDOCERR_EQNNSCOPE, /* unexpected equation scope closure*/
 	MANDOCERR_EQNSCOPE, /* equation scope open on exit */
Index: libroff.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libroff.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -Llibroff.h -Llibroff.h -u -p -r1.24 -r1.25
--- libroff.h
+++ libroff.h
@@ -49,6 +49,7 @@ struct	eqn_node {
 	size_t		  rew;
 	size_t		  cur;
 	size_t		  sz;
+	int		  gsize;
 	struct eqn	  eqn;
 	struct mparse	 *parse;
 	struct eqn_node  *next;
Index: eqn.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn.7,v
retrieving revision 1.16
retrieving revision 1.17
diff -Leqn.7 -Leqn.7 -u -p -r1.16 -r1.17
--- eqn.7
+++ eqn.7
@@ -66,6 +66,7 @@ eqn     : box | eqn box
 box     : text
         | "{" eqn "}"
         | "define" text text
+        | "gsize" text
         | "set" text text
         | "undef" text
         | box pos box
@@ -141,6 +142,15 @@ foo bar 'baz'
 .Ed
 .Pp
 Self-referencing definitions will raise an error.
+.It Cm gsize
+Set the default size of subsequent output.
+Its syntax is as follows:
+.Pp
+.D1 define Ar size
+.Pp
+The
+.Ar size
+value should be an integer.
 .It Cm set
 Set an equation mode.
 Both arguments are thrown away.
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -Lread.c -Lread.c -u -p -r1.21 -r1.22
--- read.c
+++ read.c
@@ -152,7 +152,6 @@ static	const char * const	mandocerrs[MAN
 	"generic error",
 
 	/* related to equations */
-	"bad equation macro syntax",
 	"too many nested equation defines",
 	"unexpected equation scope closure",
 	"equation scope open on exit",
--
 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:[~2011-07-22 14:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-22 14:55 mdocml: Add support for `gsize' eqn token (introduced in second-edition 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).