diff --git a/usr.sbin/pkg_install/admin/main.c b/usr.sbin/pkg_install/admin/main.c index 280a639b4ad6..80219640db9b 100644 --- a/usr.sbin/pkg_install/admin/main.c +++ b/usr.sbin/pkg_install/admin/main.c @@ -1,8 +1,8 @@ -/* $NetBSD: main.c,v 1.39 2003/09/08 22:11:12 jlam Exp $ */ +/* $NetBSD: main.c,v 1.40 2003/09/13 05:48:50 jlam Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: main.c,v 1.39 2003/09/08 22:11:12 jlam Exp $"); +__RCSID("$NetBSD: main.c,v 1.40 2003/09/13 05:48:50 jlam Exp $"); #endif /* @@ -49,7 +49,7 @@ __RCSID("$NetBSD: main.c,v 1.39 2003/09/08 22:11:12 jlam Exp $"); #define DEFAULT_SFX ".t[bg]z" /* default suffix for ls{all,best} */ -static const char Options[] = "K:s:V"; +static const char Options[] = "bd:K:s:V"; void usage(void); @@ -364,7 +364,13 @@ lspattern_fn(const char *pkg, void *vp) { char *data = vp; printf("%s/%s\n", data, pkg); - + return 0; +} + +static int +lsbasepattern_fn(const char *pkg, void *vp) +{ + printf("%s\n", pkg); return 0; } @@ -372,8 +378,11 @@ int main(int argc, char *argv[]) { int ch; + char lsdir[FILENAME_MAX]; + char *lsdirp = NULL; char sfx[FILENAME_MAX]; Boolean use_default_sfx = TRUE; + Boolean show_basename_only = FALSE; setprogname(argv[0]); @@ -382,6 +391,15 @@ main(int argc, char *argv[]) while ((ch = getopt(argc, argv, Options)) != -1) switch (ch) { + case 'b': + show_basename_only = TRUE; + break; + + case 'd': + (void) strlcpy(lsdir, optarg, sizeof(lsdir)); + lsdirp = lsdir; + break; + case 'K': _pkgdb_setPKGDB_DIR(optarg); break; @@ -501,7 +519,7 @@ main(int argc, char *argv[]) char cwd[MAXPATHLEN]; char base[FILENAME_MAX]; - dir = dirname_of(*argv); + dir = lsdirp ? lsdirp : dirname_of(*argv); basep = basename_of(*argv); snprintf(base, sizeof(base), "%s%s", basep, sfx); @@ -512,7 +530,12 @@ main(int argc, char *argv[]) if (getcwd(cwd, sizeof(cwd)) == NULL) err(EXIT_FAILURE, "getcwd"); - if (findmatchingname(cwd, base, lspattern_fn, cwd) == -1) + + if (show_basename_only) + rc = findmatchingname(cwd, base, lsbasepattern_fn, cwd); + else + rc = findmatchingname(cwd, base, lspattern_fn, cwd); + if (rc == -1) errx(EXIT_FAILURE, "Error in findmatchingname(\"%s\", \"%s\", ...)", cwd, base); @@ -539,7 +562,7 @@ main(int argc, char *argv[]) char base[FILENAME_MAX]; char *p; - dir = dirname_of(*argv); + dir = lsdirp ? lsdirp : dirname_of(*argv); basep = basename_of(*argv); snprintf(base, sizeof(base), "%s%s", basep, sfx); @@ -552,7 +575,10 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "getcwd"); p = findbestmatchingname(cwd, base); if (p) { - printf("%s/%s\n", cwd, p); + if (show_basename_only) + printf("%s\n", p); + else + printf("%s/%s\n", cwd, p); free(p); } @@ -631,7 +657,7 @@ main(int argc, char *argv[]) void usage(void) { - printf("usage: pkg_admin [-V] [-s sfx] command args ...\n" + printf("usage: pkg_admin [-b] [-d lsdir] [-V] [-s sfx] command args ...\n" "Where 'commands' and 'args' are:\n" " rebuild - rebuild pkgdb from +CONTENTS files\n" " check [pkg ...] - check md5 checksum of installed files\n" diff --git a/usr.sbin/pkg_install/admin/pkg_admin.1 b/usr.sbin/pkg_install/admin/pkg_admin.1 index 969031ea2e17..b3715fd94e00 100644 --- a/usr.sbin/pkg_install/admin/pkg_admin.1 +++ b/usr.sbin/pkg_install/admin/pkg_admin.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_admin.1,v 1.24 2003/09/08 08:57:42 wiz Exp $ +.\" $NetBSD: pkg_admin.1,v 1.25 2003/09/13 05:48:50 jlam Exp $ .\" .\" Copyright (c) 1999-2002 Hubert Feyrer. All rights reserved. .\" @@ -51,6 +51,18 @@ Packages System. .Sh OPTIONS The following command-line options are supported: .Bl -tag -width indent +.It Fl b +Print only the basenames when matching package names for +.Cm lsall +and +.Cm lsbest . +.It Fl d Ar lsdir +Set +.Ar lsdir +as the path to the directory in which to find matching package names for +.Cm lsall +and +.Cm lsbest . .It Fl K Ar pkg_dbdir Set .Ar pkg_dbdir @@ -104,12 +116,17 @@ Columns are printed for the keyfield used in the pkgdb - the filename -, and the data field - the package the file belongs to. .It Cm lsall Ar /dir/pkgpattern .It Cm lsbest Ar /dir/pkgpattern -List all/best package matching pattern in the given directory. +List all/best package matching pattern in the given directory +.Pa /dir . +If the +.Fl d +flag is given, then that directory path overrides +.Pa /dir . Can be used to work around limitations of /bin/sh and other filename globbing mechanisms. This option implements matching of -pkg-wildcards against arbitrary files, useful mainly in the build -system itself. +pkg-wildcards against arbitrary files and directories, useful mainly in +the build system itself. See .Xr pkg_info 1 for a description of the pattern. diff --git a/usr.sbin/pkg_install/lib/version.h b/usr.sbin/pkg_install/lib/version.h index 30584651ea18..cd9ca1a49dca 100644 --- a/usr.sbin/pkg_install/lib/version.h +++ b/usr.sbin/pkg_install/lib/version.h @@ -1,4 +1,4 @@ -/* $NetBSD: version.h,v 1.30 2003/09/08 07:13:29 jlam Exp $ */ +/* $NetBSD: version.h,v 1.31 2003/09/13 05:48:51 jlam 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 "20030907" +#define PKGTOOLS_VERSION "20030912" #endif /* _INST_LIB_VERSION_H_ */