pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkgfind Add -M flag to search for packages by...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/f3abdf199042
branches:  trunk
changeset: 489063:f3abdf199042
user:      peter <peter%pkgsrc.org@localhost>
date:      Tue Feb 15 21:24:36 2005 +0000

description:
Add -M flag to search for packages by maintainer.

Reviewed by wiz.

diffstat:

 pkgtools/pkgfind/Makefile        |   4 +-
 pkgtools/pkgfind/files/pkgfind.1 |  10 +++++--
 pkgtools/pkgfind/files/pkgfind.c |  50 ++++++++++++++++++++++-----------------
 3 files changed, 37 insertions(+), 27 deletions(-)

diffs (189 lines):

diff -r d4938a0b50b1 -r f3abdf199042 pkgtools/pkgfind/Makefile
--- a/pkgtools/pkgfind/Makefile Tue Feb 15 21:23:07 2005 +0000
+++ b/pkgtools/pkgfind/Makefile Tue Feb 15 21:24:36 2005 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.9 2005/01/31 14:58:31 peter Exp $
+# $NetBSD: Makefile,v 1.10 2005/02/15 21:24:36 peter Exp $
 
-DISTNAME=      pkgfind-20050127
+DISTNAME=      pkgfind-20050215
 CATEGORIES=    pkgtools
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r d4938a0b50b1 -r f3abdf199042 pkgtools/pkgfind/files/pkgfind.1
--- a/pkgtools/pkgfind/files/pkgfind.1  Tue Feb 15 21:23:07 2005 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.1  Tue Feb 15 21:24:36 2005 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkgfind.1,v 1.5 2005/01/07 16:57:21 wiz Exp $
+.\" $NetBSD: pkgfind.1,v 1.6 2005/02/15 21:24:36 peter Exp $
 .\"
 .\" Copyright (c) 2004 Peter Postma <peter%pointless.nl@localhost>
 .\" All rights reserved.
@@ -24,14 +24,14 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 7, 2005
+.Dd February 5, 2005
 .Dt PKGFIND 1
 .Sh NAME
 .Nm pkgfind
 .Nd find packages in pkgsrc
 .Sh SYNOPSIS
 .Nm
-.Op Fl Ccqx
+.Op Fl CcMqx
 .Ar keyword
 .Op Ar ...
 .Sh DESCRIPTION
@@ -57,6 +57,10 @@
 field, instead of looking at package names.
 .It Fl c
 Do case sensitive searches.
+.It Fl M
+Search in the
+.Dq MAINTAINER
+field, instead of looking at package names.
 .It Fl q
 Don't show the comment in the output, only the package name.
 .It Fl x
diff -r d4938a0b50b1 -r f3abdf199042 pkgtools/pkgfind/files/pkgfind.c
--- a/pkgtools/pkgfind/files/pkgfind.c  Tue Feb 15 21:23:07 2005 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.c  Tue Feb 15 21:24:36 2005 +0000
@@ -60,15 +60,16 @@
 
 static void            pkgfind(const char *, const char *);
 static void            showpkg(const char *, const char *, const char *);
-static int             getcomment(const char *, char **);
+static int             getstring(const char *, const char *, char **);
 static int             checkskip(const struct dirent *);
 static int             partialmatch(const char *, const char *);
 static int             exactmatch(const char *, const char *);
 static void            usage(void);
 
-static int             (*search)(const char *, const char *);
+static int             (*match)(const char *, const char *);
 
-static int             Cflag, cflag, qflag;
+static const char      *search;
+static int             cflag, qflag, xflag;
 
 int
 main(int argc, char *argv[])
@@ -78,24 +79,29 @@
 
        setprogname("pkgfind");
 
-       /* default searches have partial matches */
-       search = partialmatch;
+       /* default matches are partial matches */
+       match = partialmatch;
+       /* no special searches by default */
+       search = NULL;
 
-       Cflag = cflag = qflag = 0;
+       cflag = qflag = xflag = 0;
 
-       while ((ch = getopt(argc, argv, "Ccqx")) != -1) {
+       while ((ch = getopt(argc, argv, "CcMqx")) != -1) {
                switch (ch) {
                case 'C':       /* search in comments */
-                       Cflag = 1;
+                       search = "COMMENT";
                        break;
                case 'c':       /* case sensitive */
                        cflag = 1;
                        break;
+               case 'M':       /* search for maintainer */
+                       search = "MAINTAINER";
+                       break;
                case 'q':       /* quite, don't output comment */
                        qflag = 1;
                        break;
                case 'x':       /* exact matches */
-                       search = exactmatch;
+                       match = exactmatch;
                        break;
                default:
                        usage();
@@ -123,7 +129,7 @@
        struct dirent **cat, **list;
        int ncat, nlist, i, j;
        char tmp[PATH_MAX];
-       char *text, *comment = NULL;
+       char *text = NULL;
        struct stat sb;
 
        if ((ncat = scandir(path, &cat, checkskip, alphasort)) < 0)
@@ -149,16 +155,14 @@
                        }
                        if (stat(tmp, &sb) < 0 || !S_ISDIR(sb.st_mode))
                                continue;
-                       if (Cflag) {
+                       if (search != NULL) {
                                (void)strncat(tmp, "/Makefile", sizeof(tmp));
-                               if (getcomment(tmp, &comment) == 0 ||
-                                   comment == NULL)
+                               if (getstring(tmp, search, &text) == 0)
                                        continue;
-                               text = comment;
                        } else {
                                text = list[j]->d_name;
                        }
-                       if ((*search)(text, pkg))
+                       if ((*match)(text, pkg))
                                showpkg(path, cat[i]->d_name, list[j]->d_name);
                        free(list[j]);
                }
@@ -181,12 +185,12 @@
                        err(EXIT_FAILURE, "malloc");
                (void)snprintf(mk, len, "%s/%s/%s/Makefile", path, cat, pkg);
 
-               if (getcomment(mk, &comment) == 0) {
+               if (getstring(mk, "COMMENT", &comment) == 0) {
                        if ((mk = realloc(mk, len + 7)) == NULL)
                                err(EXIT_FAILURE, "malloc");
                        (void)snprintf(mk, len+7, "%s/%s/%s/Makefile.common",
                            path, cat, pkg);
-                       (void)getcomment(mk, &comment);
+                       (void)getstring(mk, "COMMENT", &comment);
                }
                free(mk);
        }
@@ -198,7 +202,7 @@
 }
 
 static int
-getcomment(const char *file, char **comment)
+getstring(const char *file, const char *string, char **nstring)
 {
        char line[120], *p;
        FILE *fp;
@@ -209,14 +213,16 @@
                if ((p = strchr(line, '\n')) == NULL)
                        continue;
                *p = '\0';
-               if (strncmp(line, "COMMENT", 7))
+               if (strncmp(line, string, strlen(string)) != 0)
                        continue;
-               p = line + 7;
+               p = line + strlen(string);
                if (*++p == '=')
                        p++;
                while (*p != '\0' && isspace((unsigned char)*p))
                        p++;
-               *comment = strdup(p);
+               if (*p == '\0')
+                       continue;
+               *nstring = strdup(p);
                (void)fclose(fp);
                return 1;
        }
@@ -268,6 +274,6 @@
 static void
 usage(void)
 {
-       (void)fprintf(stderr, "Usage: %s [-Ccqx] keyword [...]\n", getprogname());
+       (void)fprintf(stderr, "Usage: %s [-CcMqx] keyword [...]\n", getprogname());
        exit(EXIT_FAILURE);
 }



Home | Main Index | Thread Index | Old Index