source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Make `undef' not expand its argument before undefining it.
@ 2011-07-21 11:57 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-07-21 11:57 UTC (permalink / raw)
  To: source

Log Message:
-----------
Make `undef' not expand its argument before undefining it.  Document
this and have the same behaviour apply to `set' and `define'.

Modified Files:
--------------
    mdocml:
        eqn.7
        eqn.c

Revision Data
-------------
Index: eqn.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -Leqn.c -Leqn.c -u -p -r1.13 -r1.14
--- eqn.c
+++ eqn.c
@@ -48,15 +48,17 @@ static	void		 eqn_box_free(struct eqn_bo
 static	struct eqn_def	*eqn_def_find(struct eqn_node *, 
 				const char *, size_t);
 static	int		 eqn_do_define(struct eqn_node *);
-static	int		 eqn_do_ign2(struct eqn_node *);
+static	int		 eqn_do_set(struct eqn_node *);
 static	int		 eqn_do_undef(struct eqn_node *);
 static	const char	*eqn_nexttok(struct eqn_node *, size_t *);
-static	const char	*eqn_next(struct eqn_node *, char, size_t *);
+static	const char	*eqn_nextrawtok(struct eqn_node *, size_t *);
+static	const char	*eqn_next(struct eqn_node *, 
+				char, size_t *, int);
 static	int		 eqn_box(struct eqn_node *, struct eqn_box *);
 
 static	const struct eqnpart eqnparts[EQN__MAX] = {
 	{ "define", 6, eqn_do_define }, /* EQN_DEFINE */
-	{ "set", 3, eqn_do_ign2 }, /* EQN_SET */
+	{ "set", 3, eqn_do_set }, /* EQN_SET */
 	{ "undef", 5, eqn_do_undef }, /* EQN_UNDEF */
 };
 
@@ -206,14 +208,21 @@ eqn_box_free(struct eqn_box *bp)
 }
 
 static const char *
+eqn_nextrawtok(struct eqn_node *ep, size_t *sz)
+{
+
+	return(eqn_next(ep, '"', sz, 0));
+}
+
+static const char *
 eqn_nexttok(struct eqn_node *ep, size_t *sz)
 {
 
-	return(eqn_next(ep, '"', sz));
+	return(eqn_next(ep, '"', sz, 1));
 }
 
 static const char *
-eqn_next(struct eqn_node *ep, char quote, size_t *sz)
+eqn_next(struct eqn_node *ep, char quote, size_t *sz, int repl)
 {
 	char		*start, *next;
 	int		 q, diff, lim;
@@ -265,7 +274,7 @@ again:
 
 	/* Quotes aren't expanded for values. */
 
-	if (q)
+	if (q || ! repl)
 		return(start);
 
 	if (NULL != (def = eqn_def_find(ep, start, *sz))) {
@@ -289,13 +298,13 @@ again:
 }
 
 static int
-eqn_do_ign2(struct eqn_node *ep)
+eqn_do_set(struct eqn_node *ep)
 {
 	const char	*start;
 
-	if (NULL == (start = eqn_nexttok(ep, NULL)))
+	if (NULL == (start = eqn_nextrawtok(ep, NULL)))
 		EQN_MSG(MANDOCERR_EQNARGS, ep);
-	else if (NULL == (start = eqn_nexttok(ep, NULL)))
+	else if (NULL == (start = eqn_nextrawtok(ep, NULL)))
 		EQN_MSG(MANDOCERR_EQNARGS, ep);
 	else
 		return(1);
@@ -311,7 +320,7 @@ eqn_do_define(struct eqn_node *ep)
 	struct eqn_def	*def;
 	int		 i;
 
-	if (NULL == (start = eqn_nexttok(ep, &sz))) {
+	if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
 		EQN_MSG(MANDOCERR_EQNARGS, ep);
 		return(0);
 	}
@@ -344,7 +353,7 @@ eqn_do_define(struct eqn_node *ep)
 		def = &ep->defs[i];
 	}
 
-	start = eqn_next(ep, ep->data[(int)ep->cur], &sz);
+	start = eqn_next(ep, ep->data[(int)ep->cur], &sz, 0);
 
 	if (NULL == start) {
 		EQN_MSG(MANDOCERR_EQNARGS, ep);
@@ -355,9 +364,6 @@ eqn_do_define(struct eqn_node *ep)
 	def->val = mandoc_realloc(def->val, sz + 1);
 	memcpy(def->val, start, sz);
 	def->val[(int)sz] = '\0';
-
-	/*fprintf(stderr, "Defining: [%s], [%s]\n", 
-			def->key, def->val);*/
 	return(1);
 }
 
@@ -368,7 +374,7 @@ eqn_do_undef(struct eqn_node *ep)
 	struct eqn_def	*def;
 	size_t		 sz;
 
-	if (NULL == (start = eqn_nexttok(ep, &sz))) {
+	if (NULL == (start = eqn_nextrawtok(ep, &sz))) {
 		EQN_MSG(MANDOCERR_EQNARGS, ep);
 		return(0);
 	} else if (NULL != (def = eqn_def_find(ep, start, sz)))
Index: eqn.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/eqn.7,v
retrieving revision 1.6
retrieving revision 1.7
diff -Leqn.7 -Leqn.7 -u -p -r1.6 -r1.7
--- eqn.7
+++ eqn.7
@@ -100,6 +100,7 @@ Note that a quoted
 causes errors in some
 .Nm
 implementations and should not be considered portable.
+It is not expanded for replacements.
 Definitions may refer to other definitions; these are evaluated
 recursively when text replacement occurs and not when the definition is
 created.
@@ -115,6 +116,15 @@ Self-referencing definitions will raise 
 .It Cm set
 Set an equation mode.
 Both arguments are thrown away.
+Its syntax is as follows:
+.Pp
+.D1 set Ar key val
+.Pp
+The
+.Ar key
+and
+.Ar val
+are not expanded for replacements.
 .It Cm undef
 Unset a previously-defined key.
 Its syntax is as follows:
@@ -124,6 +134,9 @@ Its syntax is as follows:
 Once invoked, the definition for
 .Ar key
 is discarded.
+The
+.Ar key
+is not expanded for replacements.
 .El
 .Sh COMPATIBILITY
 This section documents the compatibility of mandoc
--
 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-21 11:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-21 11:57 mdocml: Make `undef' not expand its argument before undefining it 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).