summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-07-29 15:26:37 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-07-29 15:26:37 +0000
commit5dc72ca0a75eecdb2c5b15b71cee27ac4e0e3b71 (patch)
treeffecd68019b2807a3deef180413f2e3a25259d6e
parentfa24ad4613aa34ca49a0ab74cbf742c4d021a7fb (diff)
downloadmandoc-5dc72ca0a75eecdb2c5b15b71cee27ac4e0e3b71.tar.gz
Sort pages in the pages table by file names.
-rw-r--r--mandocdb.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 7914e0f5..c525537e 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -122,6 +122,7 @@ static void mlink_add(struct mlink *, const struct stat *);
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 mlink *mlink)
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 mparse *mp)
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