pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkgfind * Add -n flag to limit the amount of ...
details: https://anonhg.NetBSD.org/pkgsrc/rev/b72625d49916
branches: trunk
changeset: 493527:b72625d49916
user: peter <peter%pkgsrc.org@localhost>
date: Sun May 08 15:26:36 2005 +0000
description:
* Add -n flag to limit the amount of results.
* Fix for when /usr/pkgsrc is empty.
* Bump version to 20050508.
>From pancake%phreaker.net@localhost, tweaks and manpage update by me.
diffstat:
pkgtools/pkgfind/Makefile | 4 ++--
pkgtools/pkgfind/files/pkgfind.1 | 9 +++++++--
pkgtools/pkgfind/files/pkgfind.c | 32 +++++++++++++++++++++-----------
3 files changed, 30 insertions(+), 15 deletions(-)
diffs (152 lines):
diff -r 4b30e2a77a86 -r b72625d49916 pkgtools/pkgfind/Makefile
--- a/pkgtools/pkgfind/Makefile Sun May 08 15:14:28 2005 +0000
+++ b/pkgtools/pkgfind/Makefile Sun May 08 15:26:36 2005 +0000
@@ -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 -r 4b30e2a77a86 -r b72625d49916 pkgtools/pkgfind/files/pkgfind.1
--- a/pkgtools/pkgfind/files/pkgfind.1 Sun May 08 15:14:28 2005 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.1 Sun May 08 15:26:36 2005 +0000
@@ -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@localhost>
.\" 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 @@
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 -r 4b30e2a77a86 -r b72625d49916 pkgtools/pkgfind/files/pkgfind.c
--- a/pkgtools/pkgfind/files/pkgfind.c Sun May 08 15:14:28 2005 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.c Sun May 08 15:26:36 2005 +0000
@@ -58,7 +58,7 @@
"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 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 @@
/* 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 @@
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 @@
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 @@
} 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 @@
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 @@
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);
}
Home |
Main Index |
Thread Index |
Old Index