summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/info
diff options
context:
space:
mode:
authoreik <eik@FreeBSD.org>2004-06-29 18:54:47 +0000
committereik <eik@FreeBSD.org>2004-06-29 18:54:47 +0000
commit7923356ae6b0c5daf724f0e5c8844ffec1bb4871 (patch)
tree96259c70ed86c0b116099b99afb26ba9fecc746e /usr.sbin/pkg_install/info
parent649576111eab9cebc8bcde1eb574a9f3644fe2a6 (diff)
downloadFreeBSD-src-7923356ae6b0c5daf724f0e5c8844ffec1bb4871.zip
FreeBSD-src-7923356ae6b0c5daf724f0e5c8844ffec1bb4871.tar.gz
- match package version numbers with relational operators
- use glob patterns when matching packages by origin - csh-style {...} choices in glob matching - pkg_info: new flag -E (list matching package names only) - pkg_version: new flag -T (test if a given name matches a pattern) - new flag -X (interpret pattern as an extended regular expression) PR: 56961
Diffstat (limited to 'usr.sbin/pkg_install/info')
-rw-r--r--usr.sbin/pkg_install/info/info.h2
-rw-r--r--usr.sbin/pkg_install/info/main.c14
-rw-r--r--usr.sbin/pkg_install/info/perform.c30
-rw-r--r--usr.sbin/pkg_install/info/pkg_info.124
4 files changed, 64 insertions, 6 deletions
diff --git a/usr.sbin/pkg_install/info/info.h b/usr.sbin/pkg_install/info/info.h
index 21563ca..926ce2e 100644
--- a/usr.sbin/pkg_install/info/info.h
+++ b/usr.sbin/pkg_install/info/info.h
@@ -50,6 +50,8 @@
#define SHOW_CKSUM 0x04000
#define SHOW_FMTREV 0x08000
#define SHOW_PTREV 0x10000
+#define SHOW_DEPEND 0x20000
+#define SHOW_PKGNAME 0x40000
struct which_entry {
TAILQ_ENTRY(which_entry) next;
diff --git a/usr.sbin/pkg_install/info/main.c b/usr.sbin/pkg_install/info/main.c
index c4860ea..3c2fb44 100644
--- a/usr.sbin/pkg_install/info/main.c
+++ b/usr.sbin/pkg_install/info/main.c
@@ -26,7 +26,7 @@ __FBSDID("$FreeBSD$");
#include "info.h"
#include <err.h>
-static char Options[] = "abcdDe:fgGhiIkl:LmoO:pPqQrRst:vVW:x";
+static char Options[] = "abcdDe:EfgGhiIkl:LmoO:pPqQrRst:vVW:xX";
int Flags = 0;
match_t MatchType = MATCH_GLOB;
@@ -75,6 +75,10 @@ main(int argc, char **argv)
SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE;
break;
+ case 'E':
+ Flags |= SHOW_PKGNAME;
+ break;
+
case 'I':
Flags |= SHOW_INDEX;
break;
@@ -170,6 +174,10 @@ main(int argc, char **argv)
MatchType = MATCH_REGEX;
break;
+ case 'X':
+ MatchType = MATCH_EREGEX;
+ break;
+
case 'e':
CheckPkg = optarg;
break;
@@ -220,7 +228,7 @@ main(int argc, char **argv)
* Don't try to apply heuristics if arguments are regexs or if
* the argument refers to an existing file.
*/
- if (MatchType != MATCH_REGEX && !isfile(*argv))
+ if (MatchType != MATCH_REGEX && MatchType != MATCH_EREGEX && !isfile(*argv))
while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
*pkgs_split++ = '\0';
/*
@@ -250,7 +258,7 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
- "usage: pkg_info [-bcdDfgGiIkLmopPqQrRsvVx] [-e package] [-l prefix]",
+ "usage: pkg_info [-bcdDEfgGiIjLmopPqQrRsvVxX] [-e package] [-l prefix]",
" [-t template] -a | pkg-name ...",
" pkg_info [-qQ] -W filename",
" pkg_info [-qQ] -O origin",
diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c
index f45f7c7..5511f41 100644
--- a/usr.sbin/pkg_install/info/perform.c
+++ b/usr.sbin/pkg_install/info/perform.c
@@ -31,6 +31,7 @@ static int find_pkg(struct which_head *);
static int cmp_path(const char *, const char *, const char *);
static char *abspath(const char *);
static int find_pkgs_by_origin(const char *);
+static int matched_packages(char **pkgs);
int
pkg_perform(char **pkgs)
@@ -42,7 +43,9 @@ pkg_perform(char **pkgs)
signal(SIGINT, cleanup);
/* Overriding action? */
- if (CheckPkg) {
+ if (Flags & SHOW_PKGNAME) {
+ return matched_packages(pkgs);
+ } else if (CheckPkg) {
return isinstalledpkg(CheckPkg) == TRUE ? 0 : 1;
/* Not reached */
} else if (!TAILQ_EMPTY(whead)) {
@@ -67,6 +70,7 @@ pkg_perform(char **pkgs)
return 0;
/* Not reached */
case MATCH_REGEX:
+ case MATCH_EREGEX:
warnx("no packages match pattern(s)");
return 1;
/* Not reached */
@@ -451,3 +455,27 @@ find_pkgs_by_origin(const char *origin)
return 0;
}
+
+/*
+ * List only the matching package names.
+ * Mainly intended for scripts.
+ */
+static int
+matched_packages(char **pkgs)
+{
+ char **matched;
+ int i, errcode;
+
+ matched = matchinstalled(MatchType == MATCH_GLOB ? MATCH_NGLOB : MatchType, pkgs, &errcode);
+
+ if (errcode != 0 || matched == NULL)
+ return 1;
+
+ for (i = 0; matched[i]; i++)
+ if (!Quiet)
+ printf("%s\n", matched[i]);
+ else if (QUIET)
+ printf("%s%s\n", InfoPrefix, matched[i]);
+
+ return 0;
+}
diff --git a/usr.sbin/pkg_install/info/pkg_info.1 b/usr.sbin/pkg_install/info/pkg_info.1
index 9500486..7dfe453 100644
--- a/usr.sbin/pkg_install/info/pkg_info.1
+++ b/usr.sbin/pkg_install/info/pkg_info.1
@@ -25,7 +25,7 @@
.Nd a utility for displaying information on software packages
.Sh SYNOPSIS
.Nm
-.Op Fl bcdDfgGiIkLmopPqQrRsvVx
+.Op Fl bcdDEfgGiIkLmopPqQrRsvVxX
.Op Fl e Ar package
.Op Fl l Ar prefix
.Op Fl t Ar template
@@ -54,6 +54,15 @@ The following command line options are supported:
The named packages are described. A package name may either be the name of
an installed package, the pathname to a package distribution file or a
URL to an FTP available package.
+Package version numbers can also be matched in a relational manner using the
+.Pa \*[Ge], \*[Le], \*[Gt]
+and
+.Pa \*[Lt]
+operators. For example,
+.Pa pkg_info 'portupgrade\*[Ge]20030723'
+will match versions 20030723 and later of the
+.Pa portupgrade
+package.
.It Fl a
Show all currently installed packages.
.It Fl b
@@ -140,12 +149,22 @@ expressions could be provided, in that case
.Nm
displays information about all packages that match at least one
regular expression from the list.
+.It Fl X
+Like
+.Fl x ,
+but treats the
+.Ar pkg-name
+as an extended regular expression.
.It Fl e Ar pkg-name
If the package identified by
.Ar pkg-name
is currently installed, return 0, otherwise return 1. This option
allows you to easily test for the presence of another (perhaps
prerequisite) package from a script.
+.It Fl E
+Show only matching package names. This option takes
+precedence over all other package formatting options.
+If any packages match, return 0, otherwise return 1.
.It Fl l Ar str
Prefix each information category header (see
.Fl q )
@@ -236,6 +255,7 @@ Default location of the installed package database.
.Sh AUTHORS
.An Jordan Hubbard
.Sh CONTRIBUTORS
-.An John Kohl Aq jtk@rational.com
+.An John Kohl Aq jtk@rational.com ,
+.An Oliver Eikemeier Aq eik@FreeBSD.org
.Sh BUGS
Sure to be some.
OpenPOWER on IntegriCloud