summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorjmmv <jmmv>2004-10-20 18:36:20 +0000
committerjmmv <jmmv>2004-10-20 18:36:20 +0000
commit243e81e2d41302c18a9076484bcd7f6968554694 (patch)
treee53be0aa60dae3f366283858a04ad5d09436e20f /pkgtools
parentd28a84137967df35c9051f120272250735d31e75 (diff)
downloadpkgsrc-243e81e2d41302c18a9076484bcd7f6968554694.tar.gz
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 (limited to 'pkgtools')
-rw-r--r--pkgtools/pkgfind/Makefile4
-rw-r--r--pkgtools/pkgfind/files/pkgfind.118
-rw-r--r--pkgtools/pkgfind/files/pkgfind.c102
3 files changed, 103 insertions, 21 deletions
diff --git a/pkgtools/pkgfind/Makefile b/pkgtools/pkgfind/Makefile
index abfed65cf7d..766493fa656 100644
--- a/pkgtools/pkgfind/Makefile
+++ b/pkgtools/pkgfind/Makefile
@@ -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 --git a/pkgtools/pkgfind/files/pkgfind.1 b/pkgtools/pkgfind/files/pkgfind.1
index fb6dce82a77..1e5846a7428 100644
--- a/pkgtools/pkgfind/files/pkgfind.1
+++ b/pkgtools/pkgfind/files/pkgfind.1
@@ -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 @@ by default.
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 --git a/pkgtools/pkgfind/files/pkgfind.c b/pkgtools/pkgfind/files/pkgfind.c
index cb68e6f4638..fb81531d765 100644
--- a/pkgtools/pkgfind/files/pkgfind.c
+++ b/pkgtools/pkgfind/files/pkgfind.c
@@ -25,6 +25,19 @@
*
*/
+/*
+ * pancake@phreaker.net ** 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 checkskip(const struct dirent *);
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 @@ pkgfind(const char *path, const char *pkg)
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 @@ pkgfind(const char *path, const char *pkg)
}
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 @@ pkgfind(const char *path, const char *pkg)
static void
showpkg(const char *path, const char *cat, const char *pkg)
{
- char *mk, *comment;
-
- (void)asprintf(&mk, "%s/%s/%s/Makefile", path, cat, pkg);
- if (mk == NULL)
- err(EXIT_FAILURE, "asprintf");
+ char *mk, *comment = NULL;
- 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 @@ static int
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 @@ usage(void)
{
extern char *__progname;
- (void)fprintf(stderr, "Usage: %s keyword [...]\n", __progname);
+ (void)fprintf(stderr, "Usage: %s [-cqxC] keyword [...]\n", __progname);
exit(EXIT_FAILURE);
}