pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkgfind Update to 20041020:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/a838e626e556
branches:  trunk
changeset: 482125:a838e626e556
user:      jmmv <jmmv%pkgsrc.org@localhost>
date:      Wed Oct 20 18:36:20 2004 +0000

description:
Update to 20041020:

* The following new flags have been added:
  -c - case sensitive search
  -x - exact match search
  -q - quite output
  -C - comment search

Patch provided by pancake at phreaker.net; closes PR pkg/26964.
Changes agreed by the original author of pkgfind, Peter Postma.

diffstat:

 pkgtools/pkgfind/Makefile        |    4 +-
 pkgtools/pkgfind/files/pkgfind.1 |   18 ++++++-
 pkgtools/pkgfind/files/pkgfind.c |  102 ++++++++++++++++++++++++++++++++------
 3 files changed, 103 insertions(+), 21 deletions(-)

diffs (234 lines):

diff -r 7bd63bcfe6a5 -r a838e626e556 pkgtools/pkgfind/Makefile
--- a/pkgtools/pkgfind/Makefile Wed Oct 20 18:12:05 2004 +0000
+++ b/pkgtools/pkgfind/Makefile Wed Oct 20 18:36:20 2004 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.2 2004/10/07 02:01:38 jlam Exp $
+# $NetBSD: Makefile,v 1.3 2004/10/20 18:36:20 jmmv Exp $
 
-DISTNAME=      pkgfind-20040622
+DISTNAME=      pkgfind-20041020
 CATEGORIES=    pkgtools
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 7bd63bcfe6a5 -r a838e626e556 pkgtools/pkgfind/files/pkgfind.1
--- a/pkgtools/pkgfind/files/pkgfind.1  Wed Oct 20 18:12:05 2004 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.1  Wed Oct 20 18:36:20 2004 +0000
@@ -23,19 +23,20 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd March 17, 2004
+.Dd October 20, 2004
 .Dt PKGFIND 1
 .Sh NAME
 .Nm pkgfind
 .Nd find packages in pkgsrc
 .Sh SYNOPSIS
 .Nm
+.Op Fl cqxC
 .Ar keyword
 .Op Ar ...
 .Sh DESCRIPTION
 .Nm
 can find packages in pkgsrc.
-It tries to find packages which matches the
+It tries to find packages which match the
 .Ar keyword
 in the package name.
 .Pp
@@ -46,6 +47,19 @@
 You may specify a different path by setting
 the environment variable
 .Pa PKGSRCDIR .
+.Pp
+The following options are supported:
+.Bl -tag -width XX
+.It Fl C
+Search in COMMENTs.
+.It Fl c
+Make case sensitive searchs
+.It Fl q
+Be quite in output.
+Only shows pkgnames.
+.It Fl x
+Exact word search.
+.El
 .Sh SEE ALSO
 http://www.pkgsrc.org/
 .Sh AUTHOR
diff -r 7bd63bcfe6a5 -r a838e626e556 pkgtools/pkgfind/files/pkgfind.c
--- a/pkgtools/pkgfind/files/pkgfind.c  Wed Oct 20 18:12:05 2004 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.c  Wed Oct 20 18:36:20 2004 +0000
@@ -25,6 +25,19 @@
  *
  */
 
+/*
+ * pancake%phreaker.net@localhost ** changes 2004/09/14
+ * 
+ * '-i' ignore case senseitive
+ * -x exact match
+ * -q quite (drop COMMENT on search)
+ * -C comments
+ *
+ * [TODO]
+ * -D DESCR
+ * -P PLIST
+ */
+
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -51,18 +64,46 @@
 static int             subcasestr(const char *, const char *);
 static void            usage(void);
 
+static int             quite = 0;
+static int             cases = 0;
+static int             exact = 0;
+static int             comme = 0;
+
 int
 main(int argc, char *argv[])
 {
        const char *path;
+       int ch;
 
-       if (argc < 2)
+       while ((ch = getopt(argc, argv, "xcqC")) != -1) {
+               switch (ch) {
+               case 'x':       /* exact match */
+                       exact = 1;
+                       break;
+               case 'c':       /* case sensitive */
+                       cases = 1;
+                       break;
+               case 'q':       /* quite */
+                       quite = 1;
+                       break;
+               case 'C':       /* comment search */
+                       comme = 1;
+                       break;
+               default:
+                       usage();
+                       /* NOTREACHED */
+               }
+       }
+       argc -= optind;
+       argv += optind;
+
+       if (argc < 1)
                usage();
 
        if ((path = getenv("PKGSRCDIR")) == NULL)
                path = PKGSRCDIR;
 
-       for (++argv; *argv != NULL; ++argv)
+       for (; *argv != NULL; ++argv)
                pkgfind(path, *argv);
 
        return 0;
@@ -74,6 +115,7 @@
        struct dirent **cat, **list;
        int ncat, nlist, i, j;
        char tmp[PATH_MAX];
+       char *comment = NULL;
        struct stat sb;
 
        if ((ncat = scandir(path, &cat, checkskip, alphasort)) < 0)
@@ -99,6 +141,16 @@
                        }
                        if (stat(tmp, &sb) < 0 || !S_ISDIR(sb.st_mode))
                                continue;
+
+                       if (comme) {
+                               strcat(tmp,"/Makefile");
+                               if (getcomment(tmp,&comment) != 0)
+                                       if (comment!=0)
+                                       if (subcasestr(comment, pkg))
+                                               showpkg(path, cat[i]->d_name,
+                                                   list[j]->d_name);
+                               continue;
+                       }
                        if (subcasestr(list[j]->d_name, pkg))
                                showpkg(path, cat[i]->d_name, list[j]->d_name);
                        free(list[j]);
@@ -112,26 +164,28 @@
 static void
 showpkg(const char *path, const char *cat, const char *pkg)
 {
-       char *mk, *comment;
+       char *mk, *comment = NULL;
 
-       (void)asprintf(&mk, "%s/%s/%s/Makefile", path, cat, pkg);
-       if (mk == NULL)
-               err(EXIT_FAILURE, "asprintf");
-
-       comment = NULL;
-       if (getcomment(mk, &comment) == 0) {
-               free(mk);
-               (void)asprintf(&mk, "%s/%s/%s/Makefile.common", path, cat, pkg);
+       if (!quite) {
+               (void)asprintf(&mk, "%s/%s/%s/Makefile", path, cat, pkg);
                if (mk == NULL)
                        err(EXIT_FAILURE, "asprintf");
-               (void)getcomment(mk, &comment);
+
+               if (getcomment(mk, &comment) == 0) {
+                       free(mk);
+                       (void)asprintf(&mk, "%s/%s/%s/Makefile.common",
+                           path, cat, pkg);
+                       if (mk == NULL)
+                               err(EXIT_FAILURE, "asprintf");
+                       (void)getcomment(mk, &comment);
+               }
+               free(mk);
        }
-       free(mk);
 
        if (comment != NULL)
                (void)printf("%s/%s: %s\n", cat, pkg, comment);
        else
-               (void)printf("%s/%s: no description\n", cat, pkg);
+               (void)printf("%s/%s\n", cat, pkg);
 }
 
 static int
@@ -177,13 +231,27 @@
 subcasestr(const char *s, const char *find)
 {
        size_t len, n;
+       int match = 0;
 
        len = strlen(find);
        n = strlen(s) - len;
 
+       if (exact) {
+               if (cases)
+                       match = (strcmp(find, s) == 0);
+               else
+                       match = (strcasecmp(find, s) == 0);
+               return match;
+       }
+
        do {
-               if (strncasecmp(s, find, len) == 0)
-                       return 1;
+               if (cases) {
+                       if (strncmp(s, find, len) == 0)
+                               return 1;
+               } else {
+                       if (strncasecmp(s, find, len) == 0)
+                               return 1;
+               }
        } while (*++s != '\0' && n-- > 0);
 
        return 0;
@@ -194,6 +262,6 @@
 {
        extern char *__progname;
 
-       (void)fprintf(stderr, "Usage: %s keyword [...]\n", __progname);
+       (void)fprintf(stderr, "Usage: %s [-cqxC] keyword [...]\n", __progname);
        exit(EXIT_FAILURE);
 }



Home | Main Index | Thread Index | Old Index