diff options
author | peter <peter@pkgsrc.org> | 2005-05-08 15:26:36 +0000 |
---|---|---|
committer | peter <peter@pkgsrc.org> | 2005-05-08 15:26:36 +0000 |
commit | 6802eccc9da74f0dfe80d551e69cc238394c08c0 (patch) | |
tree | 3e4a2f59a7eb33248ed630a24f892fb3d34e6e0d /pkgtools/pkgfind | |
parent | 055df63f5429a38a565b0c3a1b84f1ee0bf99c47 (diff) | |
download | pkgsrc-6802eccc9da74f0dfe80d551e69cc238394c08c0.tar.gz |
* Add -n flag to limit the amount of results.
* Fix for when /usr/pkgsrc is empty.
* Bump version to 20050508.
From pancake@phreaker.net, tweaks and manpage update by me.
Diffstat (limited to 'pkgtools/pkgfind')
-rw-r--r-- | pkgtools/pkgfind/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pkgfind/files/pkgfind.1 | 9 | ||||
-rw-r--r-- | pkgtools/pkgfind/files/pkgfind.c | 32 |
3 files changed, 30 insertions, 15 deletions
diff --git a/pkgtools/pkgfind/Makefile b/pkgtools/pkgfind/Makefile index 3d268df70e2..a30d506f448 100644 --- a/pkgtools/pkgfind/Makefile +++ b/pkgtools/pkgfind/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.11 2005/04/11 21:47:05 tv Exp $ +# $NetBSD: Makefile,v 1.12 2005/05/08 15:26:36 peter Exp $ -DISTNAME= pkgfind-20050215 +DISTNAME= pkgfind-20050508 CATEGORIES= pkgtools MASTER_SITES= # empty DISTFILES= # empty diff --git a/pkgtools/pkgfind/files/pkgfind.1 b/pkgtools/pkgfind/files/pkgfind.1 index 83fef377db7..f4ef919f1c7 100644 --- a/pkgtools/pkgfind/files/pkgfind.1 +++ b/pkgtools/pkgfind/files/pkgfind.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkgfind.1,v 1.6 2005/02/15 21:24:36 peter Exp $ +.\" $NetBSD: pkgfind.1,v 1.7 2005/05/08 15:26:36 peter Exp $ .\" .\" Copyright (c) 2004 Peter Postma <peter@pointless.nl> .\" All rights reserved. @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd February 5, 2005 +.Dd May 8, 2005 .Dt PKGFIND 1 .Sh NAME .Nm pkgfind @@ -32,6 +32,7 @@ .Sh SYNOPSIS .Nm .Op Fl CcMqx +.Op Fl n Ar number .Ar keyword .Op Ar ... .Sh DESCRIPTION @@ -57,6 +58,10 @@ Search in the field, instead of looking at package names. .It Fl c Do case sensitive searches. +.It Fl n Ar number +Stop searching after +.Ar number +packages are found. .It Fl M Search in the .Dq MAINTAINER diff --git a/pkgtools/pkgfind/files/pkgfind.c b/pkgtools/pkgfind/files/pkgfind.c index 5527be7311a..32f53059b22 100644 --- a/pkgtools/pkgfind/files/pkgfind.c +++ b/pkgtools/pkgfind/files/pkgfind.c @@ -58,7 +58,7 @@ static const char * const skip[] = { "licenses", "mk", "packages", NULL }; -static void pkgfind(const char *, const char *); +static void pkgfind(const char *, const char *, int); static void showpkg(const char *, const char *, const char *); static int getstring(const char *, const char *, char **); static int checkskip(const struct dirent *); @@ -69,13 +69,13 @@ static void usage(void); static int (*match)(const char *, const char *); static const char *search; -static int cflag, qflag, xflag; +static int cflag, qflag; int main(int argc, char *argv[]) { const char *path; - int ch; + int ch, count = 0; setprogname("pkgfind"); @@ -84,9 +84,9 @@ main(int argc, char *argv[]) /* no special searches by default */ search = NULL; - cflag = qflag = xflag = 0; + cflag = qflag = 0; - while ((ch = getopt(argc, argv, "CcMqx")) != -1) { + while ((ch = getopt(argc, argv, "Ccn:Mqx")) != -1) { switch (ch) { case 'C': /* search in comments */ search = "COMMENT"; @@ -94,6 +94,9 @@ main(int argc, char *argv[]) case 'c': /* case sensitive */ cflag = 1; break; + case 'n': + count = atoi(optarg); + break; case 'M': /* search for maintainer */ search = "MAINTAINER"; break; @@ -118,15 +121,15 @@ main(int argc, char *argv[]) path = PKGSRCDIR; for (; *argv != NULL; ++argv) - pkgfind(path, *argv); + pkgfind(path, *argv, count); return 0; } static void -pkgfind(const char *path, const char *pkg) +pkgfind(const char *path, const char *pkg, int count) { - struct dirent **cat, **list; + struct dirent **cat, **list = NULL; int ncat, nlist, i, j; char tmp[PATH_MAX]; char *text = NULL; @@ -162,8 +165,13 @@ pkgfind(const char *path, const char *pkg) } else { text = list[j]->d_name; } - if ((*match)(text, pkg)) + if ((*match)(text, pkg)) { showpkg(path, cat[i]->d_name, list[j]->d_name); + if (count != 0 && --count < 1) { + i = ncat; + break; + } + } free(list[j]); } free(cat[i]); @@ -178,7 +186,8 @@ showpkg(const char *path, const char *cat, const char *pkg) char *mk, *comment = NULL; size_t len; - len = strlen(path) + strlen(cat) + strlen(pkg) + strlen("Makefile") + 3 + 1; + len = strlen(path) + strlen(cat) + strlen(pkg) + + strlen("Makefile") + 3 + 1; if (!qflag) { if ((mk = malloc(len)) == NULL) @@ -274,6 +283,7 @@ exactmatch(const char *s, const char *find) static void usage(void) { - (void)fprintf(stderr, "Usage: %s [-CcMqx] keyword [...]\n", getprogname()); + (void)fprintf(stderr, "Usage: %s [-CcMqx] [-n number] keyword [...]\n", + getprogname()); exit(EXIT_FAILURE); } |