source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: The termination condition of the iteration logic in
Date: Tue, 18 Oct 2016 17:27:55 -0500 (EST)	[thread overview]
Message-ID: <4662291817084134693.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
The termination condition of the iteration logic in page_bymacro() 
was overzealous.  Consequently, macro=substr and macro~regexp searches 
only returned all pages containing the first matching macro value,
rather than all pages containing any of the matching macro values.
Bug reported by tb@ - thanks!

Modified Files:
--------------
    mdocml:
        dbm.c

Revision Data
-------------
Index: dbm.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/dbm.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -Ldbm.c -Ldbm.c -u -p -r1.4 -r1.5
--- dbm.c
+++ dbm.c
@@ -346,41 +346,45 @@ page_byarch(const struct dbm_match *arg_
 }
 
 static struct dbm_res
-page_bymacro(int32_t im, const struct dbm_match *match)
+page_bymacro(int32_t arg_im, const struct dbm_match *arg_match)
 {
-	static const int32_t	*pp;
-	struct dbm_res		 res = {-1, 0};
-	const char		*cp;
-	int32_t			 iv;
+	static const struct dbm_match	*match;
+	static const int32_t		*pp;
+	static const char		*cp;
+	static int32_t			 im, iv;
+	struct dbm_res			 res = {-1, 0};
 
 	assert(im >= 0);
 	assert(im < MACRO_MAX);
 
 	/* Initialize for a new iteration. */
 
-	if (match != NULL) {
+	if (arg_match != NULL) {
 		iteration = ITER_MACRO;
+		match = arg_match;
+		im = arg_im;
 		cp = nvals[im] ? dbm_get(macros[im]->value) : NULL;
-		for (iv = 0; iv < nvals[im]; iv++) {
-			if (dbm_match(match, cp))
-				break;
-			cp = strchr(cp, '\0') + 1;
-		}
-		pp = iv == nvals[im] ? NULL : dbm_get(macros[im][iv].pages);
+		pp = NULL;
+		iv = -1;
 		return res;
 	}
 	if (iteration != ITER_MACRO)
 		return res;
 
-	/* No more matches. */
+	/* Find the next matching macro value. */
 
-	if (pp == NULL || *pp == 0) {
-		iteration = ITER_NONE;
-		pp = NULL;
-		return res;
+	while (pp == NULL || *pp == 0) {
+		if (++iv == nvals[im]) {
+			iteration = ITER_NONE;
+			return res;
+		}
+		if (iv)
+			cp = strchr(cp, '\0') + 1;
+		if (dbm_match(match, cp))
+			pp = dbm_get(macros[im][iv].pages);
 	}
 
-	/* Found a match. */
+	/* Found a matching page. */
 
 	res.page = (struct page *)dbm_get(*pp++) - pages;
 	return res;
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2016-10-18 22:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4662291817084134693.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).