pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkgfind Cleanup the C file (mostly nit-pickin...
details: https://anonhg.NetBSD.org/pkgsrc/rev/97ef9eb5f25d
branches: trunk
changeset: 482255:97ef9eb5f25d
user: peter <peter%pkgsrc.org@localhost>
date: Sat Oct 23 10:48:08 2004 +0000
description:
Cleanup the C file (mostly nit-picking) and improve the wording in the
man page. No functional changes.
Approved by wiz.
diffstat:
pkgtools/pkgfind/Makefile | 4 +-
pkgtools/pkgfind/files/pkgfind.1 | 19 ++++----
pkgtools/pkgfind/files/pkgfind.c | 87 +++++++++++++++++++--------------------
3 files changed, 55 insertions(+), 55 deletions(-)
diffs (218 lines):
diff -r 4cbb5f665312 -r 97ef9eb5f25d pkgtools/pkgfind/Makefile
--- a/pkgtools/pkgfind/Makefile Sat Oct 23 10:42:09 2004 +0000
+++ b/pkgtools/pkgfind/Makefile Sat Oct 23 10:48:08 2004 +0000
@@ -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 -r 4cbb5f665312 -r 97ef9eb5f25d pkgtools/pkgfind/files/pkgfind.1
--- a/pkgtools/pkgfind/files/pkgfind.1 Sat Oct 23 10:42:09 2004 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.1 Sat Oct 23 10:48:08 2004 +0000
@@ -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@localhost>
.\" All rights reserved.
@@ -49,17 +49,18 @@
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 -r 4cbb5f665312 -r 97ef9eb5f25d pkgtools/pkgfind/files/pkgfind.c
--- a/pkgtools/pkgfind/files/pkgfind.c Sat Oct 23 10:42:09 2004 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.c Sat Oct 23 10:48:08 2004 +0000
@@ -27,15 +27,11 @@
/*
* pancake%phreaker.net@localhost ** 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 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 @@
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 @@
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 @@
}
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 @@
{
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 @@
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 @@
}
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 @@
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)
{
Home |
Main Index |
Thread Index |
Old Index