summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2007-07-20 22:22:52 +0000
committerjoerg <joerg@pkgsrc.org>2007-07-20 22:22:52 +0000
commit5fc8c04e5a12f57e78ff219939f14470a0cb6b1f (patch)
tree9c7f11e24952f3888bc9f061ea5b0183ccc2a158
parente00c79e3eb0ed18f4e52a8036eb271a64295b207 (diff)
downloadpkgsrc-5fc8c04e5a12f57e78ff219939f14470a0cb6b1f.tar.gz
Split pattern related functions from lib/str.c off into lib/opattern.c.
Rename pmatch to pkg_match and add new function pkg_order that implements the order logic used by pkg_add internally. Change the interface of findmatchingname's callback to take the pattern used for the matching as first argument. The new pkg_order function takes it and it doesn't hurt in other cases. Adjust callers and corresponding callbacks accordingly. Remove an unused matchfn typedef in dewey.c. Bump to 20070720. OK jlam@
-rw-r--r--pkgtools/pkg_install/files/add/perform.c8
-rw-r--r--pkgtools/pkg_install/files/admin/main.c18
-rw-r--r--pkgtools/pkg_install/files/audit-packages/audit-packages.c10
-rw-r--r--pkgtools/pkg_install/files/delete/perform.c8
-rw-r--r--pkgtools/pkg_install/files/info/perform.c6
-rw-r--r--pkgtools/pkg_install/files/lib/Makefile.in6
-rw-r--r--pkgtools/pkg_install/files/lib/dewey.c3
-rw-r--r--pkgtools/pkg_install/files/lib/ftpio.c16
-rw-r--r--pkgtools/pkg_install/files/lib/lib.h13
-rw-r--r--pkgtools/pkg_install/files/lib/opattern.c165
-rw-r--r--pkgtools/pkg_install/files/lib/str.c116
-rw-r--r--pkgtools/pkg_install/files/lib/version.h4
12 files changed, 221 insertions, 152 deletions
diff --git a/pkgtools/pkg_install/files/add/perform.c b/pkgtools/pkg_install/files/add/perform.c
index db734df1a34..cf1afcb2988 100644
--- a/pkgtools/pkg_install/files/add/perform.c
+++ b/pkgtools/pkg_install/files/add/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.47 2007/04/20 14:25:13 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.48 2007/07/20 22:22:52 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -14,7 +14,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.47 2007/04/20 14:25:13 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.48 2007/07/20 22:22:52 joerg Exp $");
#endif
#endif
@@ -583,7 +583,7 @@ pkg_do(const char *pkg, lpkg_head_t *pkgs)
/*
* step into pkg2chk, read it's +CONTENTS file and see if
- * all @pkgdep lines agree with PkgName (using pmatch())
+ * all @pkgdep lines agree with PkgName (using pkg_match())
*/
snprintf(depC, sizeof(depC), "%s/%s/%s", dbdir, pkg2chk, CONTENTS_FNAME);
depf = fopen(depC , "r");
@@ -630,7 +630,7 @@ pkg_do(const char *pkg, lpkg_head_t *pkgs)
}
if (strcmp(base_new, base_exist) == 0) {
/* Same pkg, so do the interesting compare */
- if (pmatch(depp->name, PkgName)) {
+ if (pkg_match(depp->name, PkgName)) {
if (Verbose)
printf("@pkgdep check: %s is ok for %s (in %s pkg)\n",
PkgName, depp->name, pkg2chk);
diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c
index 696070f64cf..2ff36960e25 100644
--- a/pkgtools/pkg_install/files/admin/main.c
+++ b/pkgtools/pkg_install/files/admin/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.20 2006/04/04 06:25:59 wiz Exp $ */
+/* $NetBSD: main.c,v 1.21 2007/07/20 22:22:52 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.20 2006/04/04 06:25:59 wiz Exp $");
+__RCSID("$NetBSD: main.c,v 1.21 2007/07/20 22:22:52 joerg Exp $");
#endif
/*
@@ -83,7 +83,7 @@ int pkgcnt;
static int quiet;
-static int checkpattern_fn(const char *, void *);
+static int checkpattern_fn(const char *, const char *, void *);
static void set_unset_variable(char **, Boolean);
/* print usage message and exit */
@@ -414,7 +414,7 @@ checkall(void)
}
static int
-checkpattern_fn(const char *pkg, void *vp)
+checkpattern_fn(const char *pattern, const char *pkg, void *vp)
{
int rc;
@@ -433,7 +433,7 @@ checkpattern_fn(const char *pkg, void *vp)
}
static int
-lspattern_fn(const char *pkg, void *vp)
+lspattern_fn(const char *pattern, const char *pkg, void *vp)
{
char *data = vp;
printf("%s/%s\n", data, pkg);
@@ -441,7 +441,7 @@ lspattern_fn(const char *pkg, void *vp)
}
static int
-lsbasepattern_fn(const char *pkg, void *vp)
+lsbasepattern_fn(const char *pattern, const char *pkg, void *vp)
{
printf("%s\n", pkg);
return 0;
@@ -523,7 +523,7 @@ main(int argc, char *argv[])
pattern = argv[0];
pkg = argv[1];
- if (pmatch(pattern, pkg)){
+ if (pkg_match(pattern, pkg)){
return 0;
} else {
return 1;
@@ -757,7 +757,7 @@ struct varval {
};
static int
-set_installed_info_var(const char *name, void *ud)
+set_installed_info_var(const char *pattern, const char *name, void *ud)
{
char filename[BUFSIZ];
struct varval *varval;
@@ -823,7 +823,7 @@ set_unset_variable(char **argv, Boolean unset)
ret++;
}
} else if (isdir(*argv) || islinktodir(*argv))
- set_installed_info_var(*argv, &varval);
+ set_installed_info_var(NULL, *argv, &varval);
else {
/* try 'pkg-[0-9]*' */
char try[MaxPathSize];
diff --git a/pkgtools/pkg_install/files/audit-packages/audit-packages.c b/pkgtools/pkg_install/files/audit-packages/audit-packages.c
index 1058191ae75..b021d638184 100644
--- a/pkgtools/pkg_install/files/audit-packages/audit-packages.c
+++ b/pkgtools/pkg_install/files/audit-packages/audit-packages.c
@@ -1,4 +1,4 @@
-/* $NetBSD: audit-packages.c,v 1.1 2007/07/14 20:17:08 adrianp Exp $ */
+/* $NetBSD: audit-packages.c,v 1.2 2007/07/20 22:22:52 joerg Exp $ */
/*
* Copyright (c) 2007 Adrian Portelli <adrianp@NetBSD.org>.
@@ -105,7 +105,7 @@ Boolean eol = FALSE; /* don't check eol */
int main(int, char **);
void *safe_calloc(size_t, size_t);
char *ap_fixpkgname(char *);
-static int foundpkg(const char *, void *);
+static int foundpkg(const char *, const char *, void *);
static int checkforpkg(char *);
void usage(void);
int dvl(void);
@@ -460,12 +460,12 @@ main(int argc, char **argv)
/*
* if we're checking for just one package (i.e.
* check_one) regardless if it's installed or not
- * (i.e. -n and -p) then use pmatch
+ * (i.e. -n and -p) then use pkg_match
* to see if we have a hit using pattern
* matching.
*/
- if ((pmatch(pv_entry[0], one_package)) == 1) {
+ if ((pkg_match(pv_entry[0], one_package)) == 1) {
/* flag to indicate we have found something */
vuln_found = TRUE;
@@ -645,7 +645,7 @@ get_confvalues(void)
/* called by checkforpkg to see if a package exists */
static int
-foundpkg(const char *found, void *vp)
+foundpkg(const char *pattern, const char *found, void *vp)
{
char *data = vp;
char *buf;
diff --git a/pkgtools/pkg_install/files/delete/perform.c b/pkgtools/pkg_install/files/delete/perform.c
index 878217bd290..89eb7f7a350 100644
--- a/pkgtools/pkg_install/files/delete/perform.c
+++ b/pkgtools/pkg_install/files/delete/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.16 2005/05/30 13:23:31 wiz Exp $ */
+/* $NetBSD: perform.c,v 1.17 2007/07/20 22:22:52 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.16 2005/05/30 13:23:31 wiz Exp $");
+__RCSID("$NetBSD: perform.c,v 1.17 2007/07/20 22:22:52 joerg Exp $");
#endif
#endif
@@ -83,7 +83,7 @@ static int require_find_recursive_down(lpkg_t *, package_t *);
static int require_find(char *, rec_find_t);
static int require_delete(char *, int);
static void require_print(void);
-static int undepend(const char *, void *);
+static int undepend(const char *, const char *, void *);
static char LogDir[MaxPathSize];
static char linebuf[MaxPathSize];
@@ -118,7 +118,7 @@ cleanup(int sig)
* findmatchingname(), deppkgname is expanded from a (possible) pattern.
*/
static int
-undepend(const char *deppkgname, void *vp)
+undepend(const char *pattern, const char *deppkgname, void *vp)
{
char *pkg2delname = vp;
char fname[MaxPathSize], ftmp[MaxPathSize];
diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c
index e1823079c74..06917a52706 100644
--- a/pkgtools/pkg_install/files/info/perform.c
+++ b/pkgtools/pkg_install/files/info/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.30 2007/03/11 22:05:03 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.31 2007/07/20 22:22:52 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -14,7 +14,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.30 2007/03/11 22:05:03 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.31 2007/07/20 22:22:52 joerg Exp $");
#endif
#endif
@@ -334,7 +334,7 @@ bail:
* Function to be called for pkgs found
*/
static int
-foundpkg(const char *found, void *vp)
+foundpkg(const char *pattern, const char *found, void *vp)
{
char *data = vp;
char buf[MaxPathSize+1];
diff --git a/pkgtools/pkg_install/files/lib/Makefile.in b/pkgtools/pkg_install/files/lib/Makefile.in
index 2185dad3a1e..ab0462e0f4e 100644
--- a/pkgtools/pkg_install/files/lib/Makefile.in
+++ b/pkgtools/pkg_install/files/lib/Makefile.in
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.in,v 1.14 2007/07/16 09:57:59 joerg Exp $
+# $NetBSD: Makefile.in,v 1.15 2007/07/20 22:22:53 joerg Exp $
srcdir= @srcdir@
@@ -24,8 +24,8 @@ INSTALL= @INSTALL@
LIB= libinstall.a
-OBJS= automatic.o dewey.o fexec.o file.o ftpio.o global.o lpkg.o path.o pen.o \
- pexec.o pkgdb.o plist.o str.o var.o version.o
+OBJS= automatic.o dewey.o fexec.o file.o ftpio.o global.o lpkg.o opattern.o \
+ path.o pen.o pexec.o pkgdb.o plist.o str.o var.o version.o
all: $(LIB)
diff --git a/pkgtools/pkg_install/files/lib/dewey.c b/pkgtools/pkg_install/files/lib/dewey.c
index f476b92042b..87ebbafcc82 100644
--- a/pkgtools/pkg_install/files/lib/dewey.c
+++ b/pkgtools/pkg_install/files/lib/dewey.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dewey.c,v 1.5 2006/04/04 06:30:10 wiz Exp $ */
+/* $NetBSD: dewey.c,v 1.6 2007/07/20 22:22:53 joerg Exp $ */
/*
* Copyright © 2002 Alistair G. Crooks. All rights reserved.
@@ -44,7 +44,6 @@
#include "dewey.h"
#define PKG_PATTERN_MAX 1024
-typedef int (*matchfn) (const char *, void *);
/* do not modify these values, or things will NOT work */
enum {
diff --git a/pkgtools/pkg_install/files/lib/ftpio.c b/pkgtools/pkg_install/files/lib/ftpio.c
index 00a746a0f29..28a81c254fb 100644
--- a/pkgtools/pkg_install/files/lib/ftpio.c
+++ b/pkgtools/pkg_install/files/lib/ftpio.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ftpio.c,v 1.22 2007/07/14 22:57:15 joerg Exp $ */
+/* $NetBSD: ftpio.c,v 1.23 2007/07/20 22:22:53 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: ftpio.c,v 1.22 2007/07/14 22:57:15 joerg Exp $");
+__RCSID("$NetBSD: ftpio.c,v 1.23 2007/07/20 22:22:53 joerg Exp $");
#endif
/*-
@@ -686,7 +686,7 @@ ftp_expand_URL(const char *base, char *pattern)
/* replace possible version(wildcard) given with "-*".
* we can't use the pkg wildcards here as dewey compare
* and alternates won't be handled by ftp(1); sort
- * out later, using pmatch() */
+ * out later, using pkg_match() */
if (retry_tbz) {
retry_with_tbz:
(void) snprintf(buf, sizeof(buf), "nlist %.*s*.tbz %s\n",
@@ -742,11 +742,11 @@ retry_with_tbz:
strip_txz(s_filename, NULL, filename);
strip_txz(s_pattern, NULL, pattern);
- if (pmatch(s_pattern, s_filename)) {
+ if (pkg_match(s_pattern, s_filename)) {
matches++;
/* compare findbestmatchingname() */
- findbestmatchingname_fn(filename, best);
+ findbestmatchingname_fn(pattern, filename, best);
}
}
(void) fclose(f);
@@ -828,10 +828,10 @@ http_expand_URL(const char *base, char *pattern)
offset += len;
strip_txz(s_filename, NULL, filename);
- if (pmatch(s_pattern, s_filename)) {
+ if (pkg_match(s_pattern, s_filename)) {
/* compare findbestmatchingname() */
- findbestmatchingname_fn(filename,
- best);
+ findbestmatchingname_fn(pattern,
+ filename, best);
}
}
}
diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h
index ba491004ca3..9fa87c4dc1d 100644
--- a/pkgtools/pkg_install/files/lib/lib.h
+++ b/pkgtools/pkg_install/files/lib/lib.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.25 2007/07/16 09:57:59 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.26 2007/07/20 22:22:53 joerg Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -284,7 +284,7 @@ typedef struct _lpkg_head_t lpkg_head_t;
/* Type of function to be handed to findmatchingname; return value of this
* is currently ignored */
-typedef int (*matchfn) (const char *, void *);
+typedef int (*matchfn) (const char *, const char *, void *);
/* This structure describes a pipe to a child process */
typedef struct {
@@ -335,16 +335,17 @@ void str_lowercase(unsigned char *);
const char *basename_of(const char *);
const char *dirname_of(const char *);
const char *suffix_of(const char *);
-int pmatch(const char *, const char *);
+int pkg_match(const char *, const char *);
+int pkg_order(const char *, const char *, const char *);
int findmatchingname(const char *, const char *, matchfn, void *); /* doesn't really belong to "strings" */
char *findbestmatchingname(const char *, const char *); /* neither */
int ispkgpattern(const char *);
void strip_txz(char *, char *, const char *);
/* callback functions for findmatchingname */
-int findbestmatchingname_fn(const char *, void *); /* neither */
-int note_whats_installed(const char *, void *);
-int add_to_list_fn(const char *, void *);
+int findbestmatchingname_fn(const char *, const char *, void *); /* neither */
+int note_whats_installed(const char *, const char *, void *);
+int add_to_list_fn(const char *, const char *, void *);
/* File */
diff --git a/pkgtools/pkg_install/files/lib/opattern.c b/pkgtools/pkg_install/files/lib/opattern.c
new file mode 100644
index 00000000000..bcbb46c5eb9
--- /dev/null
+++ b/pkgtools/pkg_install/files/lib/opattern.c
@@ -0,0 +1,165 @@
+/* $NetBSD: opattern.c,v 1.1 2007/07/20 22:22:53 joerg Exp $ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <nbcompat.h>
+#if HAVE_SYS_CDEFS_H
+#include <sys/cdefs.h>
+#endif
+#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: opattern.c,v 1.1 2007/07/20 22:22:53 joerg Exp $");
+#endif
+#endif
+
+/*
+ * FreeBSD install - a package for the installation and maintainance
+ * of non-core utilities.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Jordan K. Hubbard
+ * 18 July 1993
+ *
+ * Miscellaneous string utilities.
+ *
+ */
+
+#if HAVE_ASSERT_H
+#include <assert.h>
+#endif
+#if HAVE_ERR_H
+#include <err.h>
+#endif
+#if HAVE_FNMATCH_H
+#include <fnmatch.h>
+#endif
+#include "lib.h"
+#include "dewey.h"
+
+/* pull in definitions and macros for resizing arrays as we go */
+#include "defs.h"
+
+/*
+ * Perform alternate match on "pkg" against "pattern",
+ * calling pkg_match (recursively) to resolve any other patterns.
+ * Return 1 on match, 0 otherwise
+ */
+static int
+alternate_match(const char *pattern, const char *pkg)
+{
+ char *sep;
+ char buf[MaxPathSize];
+ char *last;
+ char *alt;
+ char *cp;
+ int cnt;
+ int found;
+
+ if ((sep = strchr(pattern, '{')) == (char *) NULL) {
+ errx(EXIT_FAILURE, "alternate_match(): '{' expected in `%s'", pattern);
+ }
+ (void) strncpy(buf, pattern, (size_t) (sep - pattern));
+ alt = &buf[sep - pattern];
+ last = (char *) NULL;
+ for (cnt = 0, cp = sep; *cp && last == (char *) NULL; cp++) {
+ if (*cp == '{') {
+ cnt++;
+ } else if (*cp == '}' && --cnt == 0 && last == (char *) NULL) {
+ last = cp + 1;
+ }
+ }
+ if (cnt != 0) {
+ errx(EXIT_FAILURE, "Malformed alternate `%s'", pattern);
+ }
+ for (found = 0, cp = sep + 1; *sep != '}'; cp = sep + 1) {
+ for (cnt = 0, sep = cp; cnt > 0 || (cnt == 0 && *sep != '}' && *sep != ','); sep++) {
+ if (*sep == '{') {
+ cnt++;
+ } else if (*sep == '}') {
+ cnt--;
+ }
+ }
+ (void) snprintf(alt, sizeof(buf) - (alt - buf), "%.*s%s", (int) (sep - cp), cp, last);
+ if (pkg_match(buf, pkg) == 1) {
+ found = 1;
+ }
+ }
+ return found;
+}
+
+/*
+ * Perform glob match on "pkg" against "pattern".
+ * Return 1 on match, 0 otherwise
+ */
+static int
+glob_match(const char *pattern, const char *pkg)
+{
+ return fnmatch(pattern, pkg, FNM_PERIOD) == 0;
+}
+
+/*
+ * Perform simple match on "pkg" against "pattern".
+ * Return 1 on match, 0 otherwise
+ */
+static int
+simple_match(const char *pattern, const char *pkg)
+{
+ return strcmp(pattern, pkg) == 0;
+}
+
+/*
+ * Match pkg against pattern, return 1 if matching, 0 else
+ */
+int
+pkg_match(const char *pattern, const char *pkg)
+{
+ if (strchr(pattern, '{') != (char *) NULL) {
+ /* emulate csh-type alternates */
+ return alternate_match(pattern, pkg);
+ }
+ if (strpbrk(pattern, "<>") != (char *) NULL) {
+ int ret;
+
+ /* perform relational dewey match on version number */
+ ret = dewey_match(pattern, pkg);
+ if (ret < 0)
+ errx(EXIT_FAILURE, "dewey_match returned error");
+ return ret;
+ }
+ if (strpbrk(pattern, "*?[]") != (char *) NULL) {
+ /* glob match */
+ return glob_match(pattern, pkg);
+ }
+
+ /* no alternate, dewey or glob match -> simple compare */
+ return simple_match(pattern, pkg);
+}
+
+int
+pkg_order(const char *pattern, const char *first_pkg, const char *second_pkg)
+{
+ const char *first_version = strrchr(first_pkg, '/');
+ const char *second_version = strrchr(second_pkg, '/');
+
+ if (first_version == NULL || !pkg_match(pattern, first_pkg))
+ return pkg_match(pattern, second_pkg) ? 2 : 0;
+
+ if (second_version == NULL || !pkg_match(pattern, second_pkg))
+ return pkg_match(pattern, first_pkg) ? 1 : 0;
+
+ if (dewey_cmp(first_version, DEWEY_GT, second_version))
+ return 1;
+ else
+ return 2;
+}
diff --git a/pkgtools/pkg_install/files/lib/str.c b/pkgtools/pkg_install/files/lib/str.c
index 1a0ac8338d8..d057d8bbf89 100644
--- a/pkgtools/pkg_install/files/lib/str.c
+++ b/pkgtools/pkg_install/files/lib/str.c
@@ -1,4 +1,4 @@
-/* $NetBSD: str.c,v 1.18 2006/04/05 18:17:08 wiz Exp $ */
+/* $NetBSD: str.c,v 1.19 2007/07/20 22:22:53 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.18 2006/04/05 18:17:08 wiz Exp $");
+__RCSID("$NetBSD: str.c,v 1.19 2007/07/20 22:22:53 joerg Exp $");
#endif
#endif
@@ -118,102 +118,6 @@ str_lowercase(unsigned char *s)
}
/*
- * Perform alternate match on "pkg" against "pattern",
- * calling pmatch (recursively) to resolve any other patterns.
- * Return 1 on match, 0 otherwise
- */
-static int
-alternate_match(const char *pattern, const char *pkg)
-{
- char *sep;
- char buf[MaxPathSize];
- char *last;
- char *alt;
- char *cp;
- int cnt;
- int found;
-
- if ((sep = strchr(pattern, '{')) == (char *) NULL) {
- errx(EXIT_FAILURE, "alternate_match(): '{' expected in `%s'", pattern);
- }
- (void) strncpy(buf, pattern, (size_t) (sep - pattern));
- alt = &buf[sep - pattern];
- last = (char *) NULL;
- for (cnt = 0, cp = sep; *cp && last == (char *) NULL; cp++) {
- if (*cp == '{') {
- cnt++;
- } else if (*cp == '}' && --cnt == 0 && last == (char *) NULL) {
- last = cp + 1;
- }
- }
- if (cnt != 0) {
- errx(EXIT_FAILURE, "Malformed alternate `%s'", pattern);
- }
- for (found = 0, cp = sep + 1; *sep != '}'; cp = sep + 1) {
- for (cnt = 0, sep = cp; cnt > 0 || (cnt == 0 && *sep != '}' && *sep != ','); sep++) {
- if (*sep == '{') {
- cnt++;
- } else if (*sep == '}') {
- cnt--;
- }
- }
- (void) snprintf(alt, sizeof(buf) - (alt - buf), "%.*s%s", (int) (sep - cp), cp, last);
- if (pmatch(buf, pkg) == 1) {
- found = 1;
- }
- }
- return found;
-}
-
-/*
- * Perform glob match on "pkg" against "pattern".
- * Return 1 on match, 0 otherwise
- */
-static int
-glob_match(const char *pattern, const char *pkg)
-{
- return fnmatch(pattern, pkg, FNM_PERIOD) == 0;
-}
-
-/*
- * Perform simple match on "pkg" against "pattern".
- * Return 1 on match, 0 otherwise
- */
-static int
-simple_match(const char *pattern, const char *pkg)
-{
- return strcmp(pattern, pkg) == 0;
-}
-
-/*
- * Match pkg against pattern, return 1 if matching, 0 else
- */
-int
-pmatch(const char *pattern, const char *pkg)
-{
- if (strchr(pattern, '{') != (char *) NULL) {
- /* emulate csh-type alternates */
- return alternate_match(pattern, pkg);
- }
- if (strpbrk(pattern, "<>") != (char *) NULL) {
- int ret;
-
- /* perform relational dewey match on version number */
- ret = dewey_match(pattern, pkg);
- if (ret < 0)
- errx(EXIT_FAILURE, "dewey_match returned error");
- return ret;
- }
- if (strpbrk(pattern, "*?[]") != (char *) NULL) {
- /* glob match */
- return glob_match(pattern, pkg);
- }
-
- /* no alternate, dewey or glob match -> simple compare */
- return simple_match(pattern, pkg);
-}
-
-/*
* Search dir for pattern, calling match(pkg_found, data) for every match.
* Returns -1 on error, 1 if found, 0 otherwise.
*/
@@ -255,10 +159,10 @@ findmatchingname(const char *dir, const char *pattern, matchfn match, void *data
/* we need to match pattern and suffix separately, in case
* each is a different pattern class (e.g. dewey and
* character class (.t[bg]z)) */
- if (pmatch(tmp_pattern, tmp_file)
- && (pat_sfx[0] == '\0' || pmatch(pat_sfx, file_sfx))) {
+ if (pkg_match(tmp_pattern, tmp_file)
+ && (pat_sfx[0] == '\0' || pkg_match(pat_sfx, file_sfx))) {
if (match) {
- match(dp->d_name, data);
+ match(pattern, dp->d_name, data);
/* return value ignored for now */
}
found = 1;
@@ -283,7 +187,7 @@ ispkgpattern(const char *pkg)
* Also called for FTP matching
*/
int
-findbestmatchingname_fn(const char *found, void *vp)
+findbestmatchingname_fn(const char *pattern, const char *found, void *vp)
{
char *best = vp;
char *found_version, *best_version;
@@ -326,8 +230,8 @@ findbestmatchingname_fn(const char *found, void *vp)
/* if best_version==NULL only if best==NULL
* (or best[0]='\0') */
if (best != NULL) {
- if (best[0] == '\0'
- || dewey_cmp(found_version, DEWEY_GT, best_version)) {
+ if (best[0] == '\0' ||
+ pkg_order(pattern, found_no_sfx, best) == 1) {
/* found pkg(version) is bigger than current "best"
* version - remember! */
strcpy(best, found);
@@ -403,7 +307,7 @@ strip_txz(char *buf, char *sfx, const char *fname)
* note found version in "note".
*/
int
-note_whats_installed(const char *found, void *vp)
+note_whats_installed(const char *pattern, const char *found, void *vp)
{
char *note = vp;
@@ -415,7 +319,7 @@ note_whats_installed(const char *found, void *vp)
* alloc lpkg for pkg and add it to list.
*/
int
-add_to_list_fn(const char *pkg, void *vp)
+add_to_list_fn(const char *pattern, const char *pkg, void *vp)
{
lpkg_head_t *pkgs = vp;
lpkg_t *lpp;
diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h
index 739737b4d37..1ad20452506 100644
--- a/pkgtools/pkg_install/files/lib/version.h
+++ b/pkgtools/pkg_install/files/lib/version.h
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.67 2007/07/14 22:57:15 joerg Exp $ */
+/* $NetBSD: version.h,v 1.68 2007/07/20 22:22:53 joerg Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@@ -33,6 +33,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
-#define PKGTOOLS_VERSION "20070715"
+#define PKGTOOLS_VERSION "20070720"
#endif /* _INST_LIB_VERSION_H_ */