source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Sort pages in the pages table by file names.
Date: Fri, 29 Jul 2016 10:27:07 -0500 (EST)	[thread overview]
Message-ID: <4112701050681365096.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Sort pages in the pages table by file names.

Modified Files:
--------------
    mdocml:
        mandocdb.c

Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandocdb.c,v
retrieving revision 1.223
retrieving revision 1.224
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.223 -r1.224
--- mandocdb.c
+++ mandocdb.c
@@ -122,6 +122,7 @@ static	void	 mlink_add(struct mlink *, c
 static	void	 mlink_check(struct mpage *, struct mlink *);
 static	void	 mlink_free(struct mlink *);
 static	void	 mlinks_undupe(struct mpage *);
+int		 mpages_compare(const void *, const void *);
 static	void	 mpages_free(void);
 static	void	 mpages_merge(struct dba *, struct mparse *);
 static	void	 parse_cat(struct mpage *, int);
@@ -1084,22 +1085,30 @@ mlink_check(struct mpage *mpage, struct 
 static void
 mpages_merge(struct dba *dba, struct mparse *mp)
 {
-	struct mpage		*mpage, *mpage_dest;
+	struct mpage		**mplist, *mpage, *mpage_dest;
 	struct mlink		*mlink, *mlink_dest;
 	struct roff_man		*man;
 	char			*sodest;
 	char			*cp;
 	int			 fd;
-	unsigned int		 pslot;
+	unsigned int		 ip, npages, pslot;
 
+	npages = ohash_entries(&mpages);
+	mplist = mandoc_reallocarray(NULL, npages, sizeof(*mplist));
+	ip = 0;
 	mpage = ohash_first(&mpages, &pslot);
 	while (mpage != NULL) {
 		mlinks_undupe(mpage);
-		if ((mlink = mpage->mlinks) == NULL) {
-			mpage = ohash_next(&mpages, &pslot);
-			continue;
-		}
+		if (mpage->mlinks != NULL)
+			mplist[ip++] = mpage;
+		mpage = ohash_next(&mpages, &pslot);
+	}
+	npages = ip;
+	qsort(mplist, npages, sizeof(*mplist), mpages_compare);
 
+	for (ip = 0; ip < npages; ip++) {
+		mpage = mplist[ip];
+		mlink = mpage->mlinks;
 		name_mask = NAME_MASK;
 		mandoc_ohash_init(&names, 4, offsetof(struct str, key));
 		mandoc_ohash_init(&strings, 6, offsetof(struct str, key));
@@ -1207,8 +1216,18 @@ mpages_merge(struct dba *dba, struct mpa
 nextpage:
 		ohash_delete(&strings);
 		ohash_delete(&names);
-		mpage = ohash_next(&mpages, &pslot);
 	}
+	free(mplist);
+}
+
+int
+mpages_compare(const void *vp1, const void *vp2)
+{
+	const struct mpage	*mp1, *mp2;
+
+	mp1 = *(const struct mpage **)vp1;
+	mp2 = *(const struct mpage **)vp2;
+	return strcmp(mp1->mlinks->file, mp2->mlinks->file);
 }
 
 static void
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2016-07-29 15: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=4112701050681365096.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).