diff options
author | xtraeme <xtraeme@pkgsrc.org> | 2004-06-22 20:01:01 +0000 |
---|---|---|
committer | xtraeme <xtraeme@pkgsrc.org> | 2004-06-22 20:01:01 +0000 |
commit | 17e9870aafb32e0054ae9d38f5e81cd71cc0fa32 (patch) | |
tree | 21511a67d1f2966746ec94a206762e7acfd33d73 /pkgtools | |
parent | 971b16937d2eb1dd19f0e4e0b9999c9b90875ed0 (diff) | |
download | pkgsrc-17e9870aafb32e0054ae9d38f5e81cd71cc0fa32.tar.gz |
Initial import of pkgfind-20040622 from pkgsrc-wip, written by
Peter Postma.
pkgfind can find packages in pkgsrc. It tries to find packages which
matches a keyword in the package name.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkgfind/DESCR | 2 | ||||
-rw-r--r-- | pkgtools/pkgfind/Makefile | 39 | ||||
-rw-r--r-- | pkgtools/pkgfind/PLIST | 4 | ||||
-rw-r--r-- | pkgtools/pkgfind/files/pkgfind.1 | 52 | ||||
-rw-r--r-- | pkgtools/pkgfind/files/pkgfind.c | 199 |
5 files changed, 296 insertions, 0 deletions
diff --git a/pkgtools/pkgfind/DESCR b/pkgtools/pkgfind/DESCR new file mode 100644 index 00000000000..cd6f2b79852 --- /dev/null +++ b/pkgtools/pkgfind/DESCR @@ -0,0 +1,2 @@ +pkgfind can find packages in pkgsrc. It tries to find packages which +matches a keyword in the package name. diff --git a/pkgtools/pkgfind/Makefile b/pkgtools/pkgfind/Makefile new file mode 100644 index 00000000000..53633829e88 --- /dev/null +++ b/pkgtools/pkgfind/Makefile @@ -0,0 +1,39 @@ +# $NetBSD: Makefile,v 1.1.1.1 2004/06/22 20:01:01 xtraeme Exp $ + +DISTNAME= pkgfind-20040622 +CATEGORIES= pkgtools +MASTER_SITES= # empty +DISTFILES= # empty + +MAINTAINER= peter@pointless.nl +COMMENT= Find packages by package name in pkgsrc + +PKG_INSTALLATION_TYPES= overwrite pkgviews + +NO_BUILDLINK= yes +NO_CONFIGURE= yes +NO_CHECKSUM= yes + +INSTALLATION_DIRS= bin man/cat1 man/man1 + +NROFF= nroff -mandoc + +do-extract: + @${CP} -Rp ${FILESDIR} ${WRKSRC} + +do-build: + ${CC} ${CFLAGS} -o ${WRKSRC}/pkgfind ${WRKSRC}/pkgfind.c + ${NROFF} ${WRKSRC}/pkgfind.1 > ${WRKSRC}/pkgfind.cat1 + +do-install: + ${INSTALL_PROGRAM} ${WRKSRC}/pkgfind ${PREFIX}/bin/pkgfind + ${INSTALL_MAN} ${WRKSRC}/pkgfind.1 ${PREFIX}/man/man1/pkgfind.1 + ${INSTALL_MAN} ${WRKSRC}/pkgfind.cat1 ${PREFIX}/man/cat1/pkgfind.0 + +SUBST_CLASSES= path +SUBST_STAGE.path= post-patch +SUBST_FILES.path= pkgfind.c pkgfind.1 +SUBST_SED.path= -e "s,/usr/pkgsrc,${_PKGSRCDIR},g" +SUBST_MESSAGE.path= "Adjusting pkgsrc directory." + +.include "../../mk/bsd.pkg.mk" diff --git a/pkgtools/pkgfind/PLIST b/pkgtools/pkgfind/PLIST new file mode 100644 index 00000000000..28c935bf742 --- /dev/null +++ b/pkgtools/pkgfind/PLIST @@ -0,0 +1,4 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2004/06/22 20:01:01 xtraeme Exp $ +bin/pkgfind +man/cat1/pkgfind.0 +man/man1/pkgfind.1 diff --git a/pkgtools/pkgfind/files/pkgfind.1 b/pkgtools/pkgfind/files/pkgfind.1 new file mode 100644 index 00000000000..fb6dce82a77 --- /dev/null +++ b/pkgtools/pkgfind/files/pkgfind.1 @@ -0,0 +1,52 @@ +.\" +.\" Copyright (c) 2004 Peter Postma <peter@pointless.nl> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd March 17, 2004 +.Dt PKGFIND 1 +.Sh NAME +.Nm pkgfind +.Nd find packages in pkgsrc +.Sh SYNOPSIS +.Nm +.Ar keyword +.Op Ar ... +.Sh DESCRIPTION +.Nm +can find packages in pkgsrc. +It tries to find packages which matches the +.Ar keyword +in the package name. +.Pp +.Nm +searches in +.Pa /usr/pkgsrc +by default. +You may specify a different path by setting +the environment variable +.Pa PKGSRCDIR . +.Sh SEE ALSO +http://www.pkgsrc.org/ +.Sh AUTHOR +.An Peter Postma Aq peter@pointless.nl diff --git a/pkgtools/pkgfind/files/pkgfind.c b/pkgtools/pkgfind/files/pkgfind.c new file mode 100644 index 00000000000..cb68e6f4638 --- /dev/null +++ b/pkgtools/pkgfind/files/pkgfind.c @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2004 Peter Postma <peter@pointless.nl> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/stat.h> + +#include <ctype.h> +#include <err.h> +#include <dirent.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define PKGSRCDIR "/usr/pkgsrc" + +static const char * const skip[] = { + ".", "..", "CVS", "bootstrap", "doc", "distfiles", + "licenses", "mk", "packages", NULL +}; + +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 void usage(void); + +int +main(int argc, char *argv[]) +{ + const char *path; + + if (argc < 2) + usage(); + + if ((path = getenv("PKGSRCDIR")) == NULL) + path = PKGSRCDIR; + + for (++argv; *argv != NULL; ++argv) + pkgfind(path, *argv); + + return 0; +} + +static void +pkgfind(const char *path, const char *pkg) +{ + struct dirent **cat, **list; + int ncat, nlist, i, j; + char tmp[PATH_MAX]; + struct stat sb; + + if ((ncat = scandir(path, &cat, checkskip, alphasort)) < 0) + err(EXIT_FAILURE, "%s", path); + + for (i = 0; i < ncat; i++) { + if (snprintf(tmp, sizeof(tmp), "%s/%s", path, cat[i]->d_name) + >= sizeof(tmp)) { + warnx("filename too long"); + continue; + } + if (stat(tmp, &sb) < 0 || !S_ISDIR(sb.st_mode)) + continue; + if ((nlist = scandir(tmp, &list, checkskip, alphasort)) < 0) { + warn("%s", tmp); + continue; + } + for (j = 0; j < nlist; j++) { + if (snprintf(tmp, sizeof(tmp), "%s/%s/%s", path, + cat[i]->d_name, list[j]->d_name) >= sizeof(tmp)) { + warnx("filename too long"); + continue; + } + if (stat(tmp, &sb) < 0 || !S_ISDIR(sb.st_mode)) + continue; + if (subcasestr(list[j]->d_name, pkg)) + showpkg(path, cat[i]->d_name, list[j]->d_name); + free(list[j]); + } + free(cat[i]); + } + free(list); + free(cat); +} + +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"); + + comment = NULL; + 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); + + if (comment != NULL) + (void)printf("%s/%s: %s\n", cat, pkg, comment); + else + (void)printf("%s/%s: no description\n", cat, pkg); +} + +static int +getcomment(const char *file, char **comment) +{ + char line[120], *p; + size_t len; + FILE *fp; + + if ((fp = fopen(file, "r")) == NULL) + return 0; + while (fgets(line, sizeof(line), fp) != NULL) { + if ((p = strchr(line, '\n')) == NULL) + continue; + *p = '\0'; + if (strncmp(line, "COMMENT", 7)) + continue; + p = line + 7; + if (*++p == '=') + p++; + while (*p != '\0' && isspace((unsigned char)*p)) + p++; + *comment = strdup(p); + (void)fclose(fp); + return 1; + } + (void)fclose(fp); + return 0; +} + +static int +checkskip(const struct dirent *dp) +{ + const char * const *p; + + for (p = skip; *p != NULL; p++) + if (strcmp(dp->d_name, *p) == 0) + return 0; + return 1; +} + +static int +subcasestr(const char *s, const char *find) +{ + size_t len, n; + + len = strlen(find); + n = strlen(s) - len; + + do { + if (strncasecmp(s, find, len) == 0) + return 1; + } while (*++s != '\0' && n-- > 0); + + return 0; +} + +static void +usage(void) +{ + extern char *__progname; + + (void)fprintf(stderr, "Usage: %s keyword [...]\n", __progname); + exit(EXIT_FAILURE); +} |