diff options
author | peter <peter@pkgsrc.org> | 2004-10-23 10:48:08 +0000 |
---|---|---|
committer | peter <peter@pkgsrc.org> | 2004-10-23 10:48:08 +0000 |
commit | 0cdb56f50413943c9388cafcf1cabea0e256f81f (patch) | |
tree | 55c4dd1577d09ab5676da57041e4e024aa104634 /pkgtools | |
parent | 32ffd426133037db161a45fe137c85e351c0bbd1 (diff) | |
download | pkgsrc-0cdb56f50413943c9388cafcf1cabea0e256f81f.tar.gz |
Cleanup the C file (mostly nit-picking) and improve the wording in the
man page. No functional changes.
Approved by wiz.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkgfind/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pkgfind/files/pkgfind.1 | 19 | ||||
-rw-r--r-- | pkgtools/pkgfind/files/pkgfind.c | 87 |
3 files changed, 55 insertions, 55 deletions
diff --git a/pkgtools/pkgfind/Makefile b/pkgtools/pkgfind/Makefile index 766493fa656..dfd287b9934 100644 --- a/pkgtools/pkgfind/Makefile +++ b/pkgtools/pkgfind/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.3 2004/10/20 18:36:20 jmmv Exp $ +# $NetBSD: Makefile,v 1.4 2004/10/23 10:48:08 peter Exp $ -DISTNAME= pkgfind-20041020 +DISTNAME= pkgfind-20041023 CATEGORIES= pkgtools MASTER_SITES= # empty DISTFILES= # empty diff --git a/pkgtools/pkgfind/files/pkgfind.1 b/pkgtools/pkgfind/files/pkgfind.1 index 06b07312c0e..e3cf8b46403 100644 --- a/pkgtools/pkgfind/files/pkgfind.1 +++ b/pkgtools/pkgfind/files/pkgfind.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkgfind.1,v 1.3 2004/10/20 23:56:18 wiz Exp $ +.\" $NetBSD: pkgfind.1,v 1.4 2004/10/23 10:48:08 peter Exp $ .\" .\" Copyright (c) 2004 Peter Postma <peter@pointless.nl> .\" All rights reserved. @@ -49,17 +49,18 @@ You may specify a different path by setting the environment variable .Pa PKGSRCDIR . .Pp -The following options are supported: -.Bl -tag -width XX +The following options may be used: +.Bl -tag -width Ds .It Fl C -Search in COMMENTs. -.It Fl c -Make case sensitive searches. +Search in the +.Dq COMMENT +field, instead of looking at package names. +.It Fl C +Do case sensitive searches. .It Fl q -Be quiet in output. -Only shows pkgnames. +Don't show the comment in the output, only the package name. .It Fl x -Exact word search. +Do exact word searches. .El .Sh SEE ALSO http://www.pkgsrc.org/ diff --git a/pkgtools/pkgfind/files/pkgfind.c b/pkgtools/pkgfind/files/pkgfind.c index e63ee57e8f4..06013d4b4be 100644 --- a/pkgtools/pkgfind/files/pkgfind.c +++ b/pkgtools/pkgfind/files/pkgfind.c @@ -27,15 +27,11 @@ /* * pancake@phreaker.net ** changes 2004/09/14 - * - * -i ignore case - * -x exact match - * -q quiet (drop COMMENT on search) - * -C comments * - * [TODO] - * -D DESCR - * -P PLIST + * -C search in comments + * -c case sensitive + * -q quiet, don't output comment + * -x exact matches */ #include <sys/types.h> @@ -61,13 +57,13 @@ static void pkgfind(const char *, const char *); static void showpkg(const char *, const char *, const char *); static int getcomment(const char *, char **); static int checkskip(const struct dirent *); -static int subcasestr(const char *, const char *); +static int partialmatch(const char *, const char *); +static int exactmatch(const char *, const char *); static void usage(void); -static int quiet = 0; -static int cases = 0; -static int exact = 0; -static int comme = 0; +static int (*search)(const char *, const char *); + +static int Cflag, cflag, qflag, xflag; int main(int argc, char *argv[]) @@ -75,19 +71,24 @@ main(int argc, char *argv[]) const char *path; int ch; + /* default searches have partial matches */ + search = partialmatch; + + Cflag = cflag = qflag = xflag = 0; + while ((ch = getopt(argc, argv, "Ccqx")) != -1) { switch (ch) { - case 'C': /* comment search */ - comme = 1; + case 'C': /* search in comments */ + Cflag = 1; break; case 'c': /* case sensitive */ - cases = 1; + cflag = 1; break; - case 'q': /* quiet */ - quiet = 1; + case 'q': /* quite, don't output comment */ + qflag = 1; break; - case 'x': /* exact match */ - exact = 1; + case 'x': /* exact matches */ + search = exactmatch; break; default: usage(); @@ -115,7 +116,7 @@ pkgfind(const char *path, const char *pkg) struct dirent **cat, **list; int ncat, nlist, i, j; char tmp[PATH_MAX]; - char *comment = NULL; + char *text, *comment = NULL; struct stat sb; if ((ncat = scandir(path, &cat, checkskip, alphasort)) < 0) @@ -141,17 +142,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 (Cflag) { + (void)strncat(tmp, "/Makefile", sizeof(tmp)); + if (getcomment(tmp, &comment) == 0 || + comment == NULL) + continue; + text = comment; + } else { + text = list[j]->d_name; } - if (subcasestr(list[j]->d_name, pkg)) + if ((*search)(text, pkg)) showpkg(path, cat[i]->d_name, list[j]->d_name); free(list[j]); } @@ -166,7 +166,7 @@ showpkg(const char *path, const char *cat, const char *pkg) { char *mk, *comment = NULL; - if (!quiet) { + if (!qflag) { (void)asprintf(&mk, "%s/%s/%s/Makefile", path, cat, pkg); if (mk == NULL) err(EXIT_FAILURE, "asprintf"); @@ -192,7 +192,6 @@ static int getcomment(const char *file, char **comment) { char line[120], *p; - size_t len; FILE *fp; if ((fp = fopen(file, "r")) == NULL) @@ -228,24 +227,15 @@ checkskip(const struct dirent *dp) } static int -subcasestr(const char *s, const char *find) +partialmatch(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 (cases) { + if (cflag) { if (strncmp(s, find, len) == 0) return 1; } else { @@ -257,6 +247,15 @@ subcasestr(const char *s, const char *find) return 0; } +static int +exactmatch(const char *s, const char *find) +{ + if (cflag) + return (strcmp(s, find) == 0); + else + return (strcasecmp(s, find) == 0); +} + static void usage(void) { |