From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 993c5c33 for ; Wed, 19 Jul 2017 09:05:43 -0500 (EST) Date: Wed, 19 Jul 2017 09:05:43 -0500 (EST) Message-Id: <6560787923395425722.enqueue@fantadrom.bsd.lv> X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: mandoc: Prefer arch-dependent over arch-independent pages if the name X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Prefer arch-dependent over arch-independent pages if the name priority, the section number, and all names match. Changes little on installed systems except the ordering of apropos(1) results, because we install base and Xenocara manuals in different trees, but fixes lookup of pages like apm(4) vs. apm(4/amd64) in man.cgi(8). Issue discovered by martian67 on freenode and reported via tj@. Modified Files: -------------- mandoc: mansearch.c Revision Data ------------- Index: mansearch.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/mansearch.c,v retrieving revision 1.74 retrieving revision 1.75 diff -Lmansearch.c -Lmansearch.c -u -p -r1.74 -r1.75 --- mansearch.c +++ mansearch.c @@ -394,13 +394,29 @@ static int manpage_compare(const void *vp1, const void *vp2) { const struct manpage *mp1, *mp2; + const char *cp1, *cp2; + size_t sz1, sz2; int diff; mp1 = vp1; mp2 = vp2; - return (diff = mp2->bits - mp1->bits) ? diff : - (diff = mp1->sec - mp2->sec) ? diff : - strcasecmp(mp1->names, mp2->names); + if ((diff = mp2->bits - mp1->bits) || + (diff = mp1->sec - mp2->sec)) + return diff; + + /* Fall back to alphabetic ordering of names. */ + sz1 = strcspn(mp1->names, "("); + sz2 = strcspn(mp2->names, "("); + if (sz1 < sz2) + sz1 = sz2; + if ((diff = strncasecmp(mp1->names, mp2->names, sz1))) + return diff; + + /* For identical names and sections, prefer arch-dependent. */ + cp1 = strchr(mp1->names + sz1, '/'); + cp2 = strchr(mp2->names + sz2, '/'); + return cp1 != NULL && cp2 != NULL ? strcasecmp(cp1, cp2) : + cp1 != NULL ? -1 : cp2 != NULL ? 1 : 0; } static char * -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv