diff options
| author | hubertf <hubertf@NetBSD.org> | 1999-03-22 05:02:39 +0000 |
|---|---|---|
| committer | hubertf <hubertf@NetBSD.org> | 1999-03-22 05:02:39 +0000 |
| commit | 04417da1663ee41a9933b1e6bdb0efa1f8896470 (patch) | |
| tree | 4ee9164b79dff77224ff535089e2be208c0e207d /usr.sbin/pkg_install/add | |
| parent | 6c70403fe8d4617944779e3d9dc3ffd2985dd131 (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/add')
| -rw-r--r-- | usr.sbin/pkg_install/add/main.c | 49 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 16 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/pkg_add.1 | 3 |
3 files changed, 34 insertions, 34 deletions
diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c index 6cd6213654a..7d2a3f4c637 100644 --- a/usr.sbin/pkg_install/add/main.c +++ b/usr.sbin/pkg_install/add/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.8 1999/01/19 17:01:57 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.9 1999/03/22 05:02:39 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #if 0 static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.8 1999/01/19 17:01:57 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.9 1999/03/22 05:02:39 hubertf Exp $"); #endif #endif @@ -49,10 +49,6 @@ char *Directory = NULL; char FirstPen[FILENAME_MAX]; add_mode_t AddMode = NORMAL; -#define MAX_PKGS 20 -char pkgnames[MAX_PKGS][MAXPATHLEN]; -char *pkgs[MAX_PKGS]; - static void usage(void) { @@ -66,10 +62,11 @@ int main(int argc, char **argv) { int ch, error; - char **start; + lpkg_head_t pkgs; + lpkg_t *lpp; char *cp; + char pkgname[MAXPATHLEN]; - start = argv; while ((ch = getopt(argc, argv, Options)) != -1) { switch(ch) { case 'v': @@ -119,40 +116,38 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if (argc > MAX_PKGS) { - warnx("too many packages (max %d)", MAX_PKGS); - return(1); - } - + TAILQ_INIT(&pkgs); + if (AddMode != SLAVE) { - for (ch = 0; ch < MAX_PKGS; pkgs[ch++] = NULL) ; - /* Get all the remaining package names, if any */ for (ch = 0; *argv; ch++, argv++) { if (!strcmp(*argv, "-")) /* stdin? */ - pkgs[ch] = "-"; + lpp = alloc_lpkg("-"); else if (isURL(*argv)) /* preserve URLs */ - pkgs[ch] = strcpy(pkgnames[ch], *argv); + lpp = alloc_lpkg(*argv); else { /* expand all pathnames to fullnames */ char *s; - if (fexists(*argv)) /* refers to a file directly */ - pkgs[ch] = realpath(*argv, pkgnames[ch]); - else if (ispkgpattern(*argv) + if (fexists(*argv)) { /* refers to a file directly */ + lpp = alloc_lpkg(realpath(*argv, pkgname)); + } else if (ispkgpattern(*argv) && (s=findbestmatchingname(dirname_of(*argv), - basename_of(*argv))) > 0) { + basename_of(*argv))) != NULL) { if (Verbose) printf("Using %s for %s\n",s, *argv); - - pkgs[ch] = realpath(s, pkgnames[ch]); + + lpp = alloc_lpkg(realpath(s, pkgname)); } else { /* look for the file(pattern) in the expected places */ - if (!(cp = fileFindByPath(NULL, *argv))) + if (!(cp = fileFindByPath(NULL, *argv))) { + lpp = NULL; warnx("can't find package '%s'", *argv); - else - pkgs[ch] = strcpy(pkgnames[ch], cp); + } else + lpp = alloc_lpkg(cp); } } + if (lpp) + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); } } /* If no packages, yelp */ @@ -161,7 +156,7 @@ main(int argc, char **argv) else if (ch > 1 && AddMode == MASTER) warnx("only one package name may be specified with master mode"), usage(); - if ((error = pkg_perform(pkgs)) != 0) { + if ((error = pkg_perform(&pkgs)) != 0) { if (Verbose) warnx("%d package addition(s) failed", error); return error; diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index c17a0a171ee..76040e7e33c 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.28 1998/11/07 23:16:50 hubertf Exp $ */ +/* $NetBSD: perform.c,v 1.29 1999/03/22 05:02:40 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.28 1998/11/07 23:16:50 hubertf Exp $"); +__RCSID("$NetBSD: perform.c,v 1.29 1999/03/22 05:02:40 hubertf Exp $"); #endif #endif @@ -602,9 +602,10 @@ cleanup(int signo) } int -pkg_perform(char **pkgs) +pkg_perform(lpkg_head_t *pkgs) { - int i, err_cnt = 0; + int err_cnt = 0; + lpkg_t *lpp; signal(SIGINT, cleanup); signal(SIGHUP, cleanup); @@ -612,8 +613,11 @@ pkg_perform(char **pkgs) if (AddMode == SLAVE) err_cnt = pkg_do(NULL); else { - for (i = 0; pkgs[i]; i++) - err_cnt += pkg_do(pkgs[i]); + while ((lpp = TAILQ_FIRST(pkgs))) { + err_cnt += pkg_do(lpp->lp_name); + TAILQ_REMOVE(pkgs, lpp, lp_link); + free_lpkg(lpp); + } } return err_cnt; } diff --git a/usr.sbin/pkg_install/add/pkg_add.1 b/usr.sbin/pkg_install/add/pkg_add.1 index 8d7a1874b4b..63956ef7990 100644 --- a/usr.sbin/pkg_install/add/pkg_add.1 +++ b/usr.sbin/pkg_install/add/pkg_add.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_add.1,v 1.12 1999/03/07 11:58:27 mycroft Exp $ +.\" $NetBSD: pkg_add.1,v 1.13 1999/03/22 05:02:40 hubertf Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -364,6 +364,7 @@ period. Where to register packages instead of .Pa /var/db/pkg . .Sh SEE ALSO +.Xr pkg_admin 1 , .Xr pkg_create 1 , .Xr pkg_delete 1 , .Xr pkg_info 1 , |
