Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Complete implementation of -T option; now works in 'filter mode'
Chris Rees committed 14 years ago
commit 8910e3367cb45859e22834a98f302c0a3620c1fa
parent b184089
2 files changed +27 -2
modified pkg/pkg-version.1
@@ -77,7 +77,14 @@ Display only the packages which origin matches
.It Fl t Ar <version1> Ar <version2>
< To be added >
.It Fl T Ar <pkgname> Ar <pattern>
-
< To be added >
+
Compare
+
.Ar <pkgname>
+
against shell glob
+
.Ar <pattern> and set exit code accordingly.
+
.Fl T
+
can also be used in `filter mode':
+
When one of the arguments is `-', standard input is used, and lines
+
with matching package names/patterns are echoed to standard output.
.El
.Sh WARNING
.Sh ENVRIOMENT
modified pkg/version.c
@@ -130,6 +130,7 @@ exec_version(int argc, char **argv)
	SLIST_HEAD(, index_entry) indexhead;
	struct utsname u;
	int rel_major_ver;
+
	int retval;
	char *line = NULL;
	size_t linecap = 0;
	ssize_t linelen;
@@ -280,7 +281,24 @@ exec_version(int argc, char **argv)
		return (EX_USAGE);
	
	} else if (opt == VERSION_TESTPATTERN) {
-
		return fnmatch(argv[1], argv[0], 0);
+
		if (strcmp(argv[0], "-") == 0) {
+
			ch = 0; /* pattern from stdin */
+
		} else if (strcmp(argv[1], "-") == 0) {
+
			ch = 1; /* pkgname from stdin */
+
		} else return fnmatch(argv[1], argv[0], 0);
+
		
+
		retval = FNM_NOMATCH;
+
		
+
		while ((linelen = getline(&line, &linecap, stdin)) > 0) {
+
			line[linelen - 1] = '\0'; /* Strip trailing newline */
+
			if ((ch == 0 && (fnmatch(argv[1], line, 0) == 0))
+
				|| (ch == 1 && (fnmatch(line, argv[0], 0) == 0))) {
+
				retval = EPKG_OK;
+
				printf("%.*s\n", (int)linelen, line);
+
			}
+
		}
+
		
+
		return (retval);
		
	} else  {
		if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)