summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_install/info
diff options
context:
space:
mode:
authorhubertf <hubertf@NetBSD.org>1999-03-22 05:02:39 +0000
committerhubertf <hubertf@NetBSD.org>1999-03-22 05:02:39 +0000
commit04417da1663ee41a9933b1e6bdb0efa1f8896470 (patch)
tree4ee9164b79dff77224ff535089e2be208c0e207d /usr.sbin/pkg_install/info
parent6c70403fe8d4617944779e3d9dc3ffd2985dd131 (diff)
Replace static array of packages given to pkg_perform() with linear
list, using chopss' list functions (moved to lib/lpkg.c and lib/lib.h). Properly handle wildcards in arguments to "pkg_info", "pkg_delete" and "pkg_admin check". Some other minor cleanups.
Diffstat (limited to 'usr.sbin/pkg_install/info')
-rw-r--r--usr.sbin/pkg_install/info/main.c53
-rw-r--r--usr.sbin/pkg_install/info/perform.c17
-rw-r--r--usr.sbin/pkg_install/info/pkg_info.112
3 files changed, 55 insertions, 27 deletions
diff --git a/usr.sbin/pkg_install/info/main.c b/usr.sbin/pkg_install/info/main.c
index 3054121b640..702604451ad 100644
--- a/usr.sbin/pkg_install/info/main.c
+++ b/usr.sbin/pkg_install/info/main.c
@@ -1,11 +1,11 @@
-/* $NetBSD: main.c,v 1.15 1999/03/04 00:35:05 hubertf Exp $ */
+/* $NetBSD: main.c,v 1.16 1999/03/22 05:02:41 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.14 1997/10/08 07:47:26 charnier Exp";
#else
-__RCSID("$NetBSD: main.c,v 1.15 1999/03/04 00:35:05 hubertf Exp $");
+__RCSID("$NetBSD: main.c,v 1.16 1999/03/22 05:02:41 hubertf Exp $");
#endif
#endif
@@ -49,6 +49,7 @@ char PlayPen[FILENAME_MAX];
size_t PlayPenSize = sizeof(PlayPen);
char *CheckPkg = NULL;
size_t termwidth = 0;
+lpkg_head_t pkgs;
static void
usage(void)
@@ -60,13 +61,23 @@ usage(void)
exit(1);
}
+static int
+find_fn(const char *pkg, char *data)
+{
+ lpkg_t *lpp;
+
+ lpp=alloc_lpkg(pkg);
+ TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
+
+ return 0;
+}
+
int
main(int argc, char **argv)
{
- int ch;
- char **pkgs, **start;
+ int ch, rc;
+ lpkg_t *lpp;
- pkgs = start = argv;
while ((ch = getopt(argc, argv, Options)) != -1)
switch(ch) {
case 'a':
@@ -192,28 +203,36 @@ main(int argc, char **argv)
pkgdb_close();
}
+ TAILQ_INIT(&pkgs);
+
/* Get all the remaining package names, if any */
if (File2Pkg && !AllInstalled)
if (pkgdb_open(1)==-1) {
err(1, "cannot open pkgdb");
}
while (*argv) {
- /* pkgdb: if -F flag given, don't add pkgnames to *pkgs but
- * rather resolve the given filenames to pkgnames using
- * pkgdb_retrieve, then add them.
+ /* pkgdb: if -F flag given, don't add pkgnames to the "pkgs"
+ * queue but rather resolve the given filenames to pkgnames
+ * using pkgdb_retrieve, then add them.
*/
if (File2Pkg) {
char *s;
s = pkgdb_retrieve(*argv);
- if (s)
- *pkgs++ = s;
- else
- warnx("No matching pkg for %s.", *argv);
- /* should we bomb out here instead? - HF */
+ if (s) {
+ lpp=alloc_lpkg(s);
+ TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
+ } else
+ errx(1, "No matching pkg for %s.", *argv);
} else {
- *pkgs++ = *argv;
+ if (ispkgpattern(*argv)){
+ if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, find_fn, NULL) == 0)
+ errx(1, "No matching pkg for %s.", *argv);
+ } else {
+ lpp=alloc_lpkg(*argv);
+ TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
+ }
}
argv++;
}
@@ -222,9 +241,8 @@ main(int argc, char **argv)
pkgdb_close();
/* If no packages, yelp */
- if (pkgs == start && !AllInstalled && !CheckPkg)
+ if (TAILQ_FIRST(&pkgs)==NULL && !AllInstalled && !CheckPkg)
warnx("missing package name(s)"), usage();
- *pkgs = NULL;
if (isatty(STDOUT_FILENO)) {
const char *p;
@@ -237,6 +255,7 @@ main(int argc, char **argv)
termwidth = win.ws_col;
}
- exit(pkg_perform(start));
+ rc = pkg_perform(&pkgs);
+ exit(rc);
/* NOTREACHED */
}
diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c
index 072598a8a84..88e60807aed 100644
--- a/usr.sbin/pkg_install/info/perform.c
+++ b/usr.sbin/pkg_install/info/perform.c
@@ -1,11 +1,11 @@
-/* $NetBSD: perform.c,v 1.21 1999/03/04 00:35:05 hubertf Exp $ */
+/* $NetBSD: perform.c,v 1.22 1999/03/22 05:02:41 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#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.21 1999/03/04 00:35:05 hubertf Exp $");
+__RCSID("$NetBSD: perform.c,v 1.22 1999/03/22 05:02:41 hubertf Exp $");
#endif
#endif
@@ -237,12 +237,11 @@ cleanup(int sig)
}
int
-pkg_perform(char **pkgs)
+pkg_perform(lpkg_head_t *pkgs)
{
struct dirent *dp;
char *tmp;
DIR *dirp;
- int i;
int err_cnt = 0;
signal(SIGINT, cleanup);
@@ -291,9 +290,13 @@ pkg_perform(char **pkgs)
}
}
} else {
- for (i = 0; pkgs[i]; i++) {
- err_cnt += pkg_do(pkgs[i]);
- }
+ lpkg_t *lpp;
+
+ while ((lpp = TAILQ_FIRST(pkgs))) {
+ TAILQ_REMOVE(pkgs, lpp, lp_link);
+ err_cnt += pkg_do(lpp->lp_name);
+ free_lpkg(lpp);
+ }
}
return err_cnt;
}
diff --git a/usr.sbin/pkg_install/info/pkg_info.1 b/usr.sbin/pkg_install/info/pkg_info.1
index 8dc0498765d..5afa4affa74 100644
--- a/usr.sbin/pkg_install/info/pkg_info.1
+++ b/usr.sbin/pkg_install/info/pkg_info.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_info.1,v 1.15 1999/03/07 11:58:28 mycroft Exp $
+.\" $NetBSD: pkg_info.1,v 1.16 1999/03/22 05:02:41 hubertf Exp $
.\"
.\" FreeBSD install - a package for the installation and maintainance
.\" of non-core utilities.
@@ -47,8 +47,13 @@ command.
.Pp
The
.Ar pkg-name
-may be the name of an installed package, the pathname to a package
-distribution file, a filename belonging to an installed package (if -F
+may be the name of an installed package, a pattern matching several
+installed packages (see the
+.Fl e
+switch for a description of possible patterns), the pathname to a
+package distribution file, a filename belonging to an installed
+package (if
+.Fl F
is also given), or a URL to an ftp-available package.
.Pp
The following command-line options are supported:
@@ -203,6 +208,7 @@ of pkg_info
.Fl aF .
.Sh SEE ALSO
.Xr pkg_add 1 ,
+.Xr pkg_admin 1 ,
.Xr pkg_create 1 ,
.Xr pkg_delete 1 ,
.Xr mktemp 3 ,