Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/pkg_install/admin Add "lsall" and "lsbest" commands...



details:   https://anonhg.NetBSD.org/src/rev/0f16df371d8b
branches:  trunk
changeset: 485928:0f16df371d8b
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Mon May 08 22:48:42 2000 +0000

description:
Add "lsall" and "lsbest" commands to pkg_admin, to find all/best
package matching a certain pattern. Examples:

            yui# cd /usr/pkgsrc/packages/i386ELF/All/
            yui# ls unzip*
            unzip-5.40.tgz  unzip-5.41.tgz
            yui# pkg_admin lsall 'unzip*'
            unzip-5.40.tgz
            unzip-5.41.tgz
            yui# pkg_admin lsall 'unzip>=5.40'
            unzip-5.40.tgz
            unzip-5.41.tgz
            yui# pkg_admin lsall 'unzip>=5.41'
            unzip-5.41.tgz
            yui# pkg_admin lsbest 'unzip>=5.40'
            unzip-5.41.tgz
            yui# pkg_admin lsall /usr/pkgsrc/packages/i386ELF/All/'{mit,unproven}-pthread*'
            /usr/pkgsrc/packages/i386ELF/All/mit-pthreads-1.60b6.tgz

This adds a shell/user-interface to pkg-patterns, which are a superset
of sh/csh patterns and can't be expanded by any shell.

diffstat:

 usr.sbin/pkg_install/admin/main.c      |  93 ++++++++++++++++++++++++++++++++-
 usr.sbin/pkg_install/admin/pkg_admin.1 |  33 +++++++++++-
 2 files changed, 120 insertions(+), 6 deletions(-)

diffs (185 lines):

diff -r a226ea1a14fe -r 0f16df371d8b usr.sbin/pkg_install/admin/main.c
--- a/usr.sbin/pkg_install/admin/main.c Mon May 08 22:41:38 2000 +0000
+++ b/usr.sbin/pkg_install/admin/main.c Mon May 08 22:48:42 2000 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: main.c,v 1.12 2000/03/19 17:24:28 hubertf Exp $        */
+/*     $NetBSD: main.c,v 1.13 2000/05/08 22:48:42 hubertf Exp $        */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.12 2000/03/19 17:24:28 hubertf Exp $");
+__RCSID("$NetBSD: main.c,v 1.13 2000/05/08 22:48:42 hubertf Exp $");
 #endif
 
 /*
@@ -332,6 +332,14 @@
        return 0;
 }
 
+static int
+lspattern_fn(const char *pkg, char *data)
+{
+       printf("%s/%s\n", data, pkg);
+       
+       return 0;
+}
+
 int 
 main(int argc, char *argv[])
 {
@@ -341,6 +349,7 @@
        if (strcasecmp(argv[1], "rebuild") == 0) {
 
                rebuild();
+               printf("Done.\n");
 
        } else if (strcasecmp(argv[1], "check") == 0) {
 
@@ -396,6 +405,84 @@
                } else {
                        checkall();
                }
+               printf("Done.\n");
+
+       } else if (strcasecmp(argv[1], "lsall") == 0) {
+               int saved_wd;
+
+               argv++;         /* argv[0] */
+               argv++;         /* "check" */
+
+               /* preserve cwd */
+               saved_wd=open(".", O_RDONLY);
+               if (saved_wd == -1)
+                       err(1, "Cannot save working dir");
+
+               while (*argv != NULL) {
+                       /* args specified */
+                       int     rc;
+                       char *basep, *dir;
+                       char *cwd;
+                       char base[FILENAME_MAX];
+
+                       dir = dirname_of(*argv);
+                       basep = basename_of(*argv);
+                       snprintf(base, sizeof(base), "%s.tgz", basep);
+
+                       fchdir(saved_wd);
+                       rc = chdir(dir);
+                       if (rc == -1)
+                               err(1, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR());
+
+                       cwd = getwd(NULL);
+                       if (findmatchingname(cwd, base, lspattern_fn, cwd) == -1)
+                               errx(1, "Error in findmatchingname(\"%s\", \"%s\", ...)",
+                                    cwd, base);
+                       free(cwd);
+                       
+                       argv++;
+               }
+
+               close(saved_wd);
+
+       } else if (strcasecmp(argv[1], "lsbest") == 0) {
+               int saved_wd;
+
+               argv++;         /* argv[0] */
+               argv++;         /* "check" */
+
+               /* preserve cwd */
+               saved_wd=open(".", O_RDONLY);
+               if (saved_wd == -1)
+                       err(1, "Cannot save working dir");
+
+               while (*argv != NULL) {
+                       /* args specified */
+                       int     rc;
+                       char *basep, *dir;
+                       char *cwd;
+                       char base[FILENAME_MAX];
+                       char *p;
+
+                       dir = dirname_of(*argv);
+                       basep = basename_of(*argv);
+                       snprintf(base, sizeof(base), "%s.tgz", basep);
+
+                       fchdir(saved_wd);
+                       rc = chdir(dir);
+                       if (rc == -1)
+                               err(1, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR());
+
+                       cwd = getwd(NULL);
+                       p = findbestmatchingname(cwd, base);
+                       if (p)
+                               printf("%s/%s\n", cwd, p);
+                       free(cwd);
+                       
+                       argv++;
+               }
+
+               close(saved_wd);
 
        } else if (strcasecmp(argv[1], "list") == 0 ||
            strcasecmp(argv[1], "dump") == 0) {
@@ -463,8 +550,6 @@
                usage();
        }
 
-       printf("Done.\n");
-
        return 0;
 }
 
diff -r a226ea1a14fe -r 0f16df371d8b usr.sbin/pkg_install/admin/pkg_admin.1
--- a/usr.sbin/pkg_install/admin/pkg_admin.1    Mon May 08 22:41:38 2000 +0000
+++ b/usr.sbin/pkg_install/admin/pkg_admin.1    Mon May 08 22:48:42 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: pkg_admin.1,v 1.7 2000/02/22 01:24:26 hubertf Exp $
+.\"    $NetBSD: pkg_admin.1,v 1.8 2000/05/08 22:48:42 hubertf Exp $
 .\"
 .\" Copyright (c) 1999 Hubert Feyrer.  All rights reserved.
 .\"
@@ -29,7 +29,7 @@
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
 
-.Dd January 16th, 1999
+.Dd May 4th, 2000
 .Dt pkg_admin 1
 .Os
 .Sh NAME
@@ -81,6 +81,35 @@
 .Cm pkg_info -F .
 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 /dir/pkgpattern
+.It Cm lsbest /dir/pkgpattern
+List all/best package matching pattern in the given directory.
+Can be used to work around limitations of /bin/sh and other
+filename globbing mechanisms. This option implemente matching of
+pkg-wildcards against arbitrary files, useful mainly in the build
+system itself. See
+.Xr pkg_info 1
+for a description of the pattern.
+
+Example:
+.Bd -literal
+yui# cd /usr/pkgsrc/packages/i386ELF/All/
+yui# ls unzip*
+unzip-5.40.tgz  unzip-5.41.tgz
+yui# pkg_admin lsall 'unzip*'
+unzip-5.40.tgz
+unzip-5.41.tgz
+yui# pkg_admin lsall 'unzip>=5.40'
+unzip-5.40.tgz
+unzip-5.41.tgz
+yui# pkg_admin lsall 'unzip>=5.41'
+unzip-5.41.tgz
+yui# pkg_admin lsbest 'unzip>=5.40'
+unzip-5.41.tgz
+yui# pkg_admin lsall /usr/pkgsrc/packages/i386ELF/All/'{mit,unproven}-pthread*'
+/usr/pkgsrc/packages/i386ELF/All/mit-pthreads-1.60b6.tgz
+/usr/pkgsrc/packages/i386ELF/All/unproven-pthreads-0.15.tgz
+.Ed
 .El
 .Pp
 .Sh ENVIRONMENT



Home | Main Index | Thread Index | Old Index