* shuffle variable names in findbestmatchingname_fn() around

a bit, to make them more descriptive
 * in findbestmatchingname_fn, fix a bug where a null pointer wasn't
   caught (I wonder why we didn't actually hit that case...)
 * Bugfix in findbestmatchingname_fn: when comparing, strip off any
   trailing ".tgz", as this will give wrong results. "1.9.8.tgz" was
   found to be greater than "1.9.8.1".
This commit is contained in:
hubertf 2000-06-18 01:29:30 +00:00
parent 7aed2e5cfb
commit e5b91ee82e
1 changed files with 35 additions and 9 deletions

View File

@ -1,11 +1,11 @@
/* $NetBSD: str.c,v 1.21 2000/02/07 11:26:26 abs Exp $ */
/* $NetBSD: str.c,v 1.22 2000/06/18 01:29:30 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp";
#else
__RCSID("$NetBSD: str.c,v 1.21 2000/02/07 11:26:26 abs Exp $");
__RCSID("$NetBSD: str.c,v 1.22 2000/06/18 01:29:30 hubertf Exp $");
#endif
#endif
@ -330,16 +330,42 @@ ispkgpattern(const char *pkg)
* Also called for FTP matching
*/
int
findbestmatchingname_fn(const char *pkg, char *data)
findbestmatchingname_fn(const char *found, char *best)
{
char *s1, *s2;
char *found_version, *best_version;
char *found_tgz, *best_tgz;
char found_no_tgz[255];
char best_no_tgz[255];
s1 = strrchr(pkg, '-') + 1;
s2 = strrchr(data, '-') + 1;
if (data[0] == '\0' || deweycmp(s1, GT, s2)) {
strcpy(data, pkg);
found_version = strrchr(found, '-') + 1;
found_tgz = strstr(found, ".tgz");
if (found_tgz) {
/* strip off any ".tgz" */
strncpy(found_no_tgz, found_version, found_tgz-found_version);
found_no_tgz[found_tgz-found_version] = '\0';
found_version = found_no_tgz;
}
best_version=NULL;
if (best && best[0] != '\0') {
best_version = strrchr(best, '-') + 1;
best_tgz = strstr(best, ".tgz");
if (best_tgz) {
/* strip off any ".tgz" */
strncpy(best_no_tgz, best_version, best_tgz-best_version);
best_no_tgz[best_tgz-best_version] = '\0';
best_version = best_no_tgz;
}
}
found_version, best_version); fflush(stdout);
if (best == NULL || best[0] == '\0' || deweycmp(found_version, GT, best_version)) {
/* found pkg(version) is bigger than current "best"
* version - remember! */
strcpy(best, found);
}
return 0;
}