summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/version
diff options
context:
space:
mode:
authorkrion <krion@FreeBSD.org>2005-07-27 07:55:12 +0000
committerkrion <krion@FreeBSD.org>2005-07-27 07:55:12 +0000
commite2bb2f5a2e412b3133d44a5158dba2dae50808ab (patch)
tree0d1cd9fc94a9b7eef7fd1d4781ddbcfbf15526c5 /usr.sbin/pkg_install/version
parent06ac0362e7378543f7e90859b84a9907eecb2359 (diff)
downloadFreeBSD-src-e2bb2f5a2e412b3133d44a5158dba2dae50808ab.zip
FreeBSD-src-e2bb2f5a2e412b3133d44a5158dba2dae50808ab.tar.gz
Add -o/-O options to pkg_version:
-o Show the origin recorded on package generation instead of the package name. -O Only list packages whose registered origin is origin. Based on PR: bin/78640 Submitted by: Marcus Grando <marcus at corp dot grupos.com.br>, flz
Diffstat (limited to 'usr.sbin/pkg_install/version')
-rw-r--r--usr.sbin/pkg_install/version/main.c14
-rw-r--r--usr.sbin/pkg_install/version/perform.c57
-rw-r--r--usr.sbin/pkg_install/version/pkg_version.111
-rw-r--r--usr.sbin/pkg_install/version/version.h2
4 files changed, 57 insertions, 27 deletions
diff --git a/usr.sbin/pkg_install/version/main.c b/usr.sbin/pkg_install/version/main.c
index 10c63a2..d56dddf 100644
--- a/usr.sbin/pkg_install/version/main.c
+++ b/usr.sbin/pkg_install/version/main.c
@@ -25,13 +25,15 @@ __FBSDID("$FreeBSD$");
#include "version.h"
#include <err.h>
-static char Options[] = "dIhl:L:qs:XtTv";
+static char Options[] = "dIhl:L:qs:XtTO:ov";
char *LimitChars = NULL;
char *PreventChars = NULL;
char *MatchName = NULL;
+char *LookUpOrigin = NULL;
Boolean RegexExtended = FALSE;
Boolean UseINDEXOnly = FALSE;
+Boolean ShowOrigin = FALSE;
static void usage __P((void));
@@ -75,6 +77,14 @@ main(int argc, char **argv)
MatchName = optarg;
break;
+ case 'O':
+ LookUpOrigin = optarg;
+ break;
+
+ case 'o':
+ ShowOrigin = TRUE;
+ break;
+
case 't':
errx(2, "Invalid -t usage.");
break;
@@ -105,7 +115,7 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n%s\n",
- "usage: pkg_version [-hIqv] [-l limchar] [-L limchar] [[-X] -s string] [index]",
+ "usage: pkg_version [-hIoqv] [-l limchar] [-L limchar] [[-X] -s string] [-O origin] [index]",
" pkg_version -t v1 v2",
" pkg_version -T name pattern");
exit(1);
diff --git a/usr.sbin/pkg_install/version/perform.c b/usr.sbin/pkg_install/version/perform.c
index 8d089c5..6659328 100644
--- a/usr.sbin/pkg_install/version/perform.c
+++ b/usr.sbin/pkg_install/version/perform.c
@@ -31,7 +31,7 @@ FILE *IndexFile;
struct index_head Index = SLIST_HEAD_INITIALIZER(Index);
static int pkg_do(char *);
-static void show_version(const char *, const char *, const char *);
+static void show_version(Package, const char *, const char *);
/*
* This is the traditional pkg_perform, except that the argument is _not_
@@ -68,26 +68,34 @@ pkg_perform(char **indexarg)
pat[1] = NULL;
MatchType = RegexExtended ? MATCH_EREGEX : MATCH_REGEX;
patterns = pat;
- }
- else {
+ } else {
MatchType = MATCH_ALL;
patterns = NULL;
- }
- pkgs = matchinstalled(MatchType, patterns, &err_cnt);
+ }
+
+ if (LookUpOrigin != NULL)
+ pkgs = matchbyorigin(LookUpOrigin, &err_cnt);
+ else
+ pkgs = matchinstalled(MatchType, patterns, &err_cnt);
if (err_cnt != 0)
errx(2, "Unable to find package database directory!");
if (pkgs == NULL) {
- switch (MatchType) {
- case MATCH_ALL:
- warnx("no packages installed");
- return (0);
- case MATCH_EREGEX:
- case MATCH_REGEX:
- warnx("no packages match pattern");
+ if (LookUpOrigin != NULL) {
+ warnx("no packages recorded with this origin");
return (1);
- default:
- break;
+ } else {
+ switch (MatchType) {
+ case MATCH_ALL:
+ warnx("no packages installed");
+ return (0);
+ case MATCH_EREGEX:
+ case MATCH_REGEX:
+ warnx("no packages match pattern");
+ return (1);
+ default:
+ break;
+ }
}
}
@@ -153,7 +161,7 @@ pkg_do(char *pkg)
if ((latest = vpipe("/usr/bin/make -V PKGNAME", tmp)) == NULL)
warnx("Failed to get PKGNAME from %s/Makefile!", tmp);
else
- show_version(plist.name, latest, "port");
+ show_version(plist, latest, "port");
}
}
if (latest == NULL) {
@@ -219,9 +227,9 @@ pkg_do(char *pkg)
}
}
if (latest == NULL)
- show_version(plist.name, NULL, plist.origin);
+ show_version(plist, NULL, NULL);
else
- show_version(plist.name, latest, "index");
+ show_version(plist, latest, "index");
}
if (latest != NULL)
free(latest);
@@ -238,15 +246,18 @@ pkg_do(char *pkg)
* You get when you try to match perl output in C ;-).
*/
void
-show_version(const char *installed, const char *latest, const char *source)
+show_version(Package plist, const char *latest, const char *source)
{
char *ch, tmp[PATH_MAX];
const char *ver;
int cmp = 0;
- if (!installed || strlen(installed) == 0)
+ if (!plist.name || strlen(plist.name) == 0)
return;
- strlcpy(tmp, installed, PATH_MAX);
+ if (ShowOrigin != FALSE)
+ strlcpy(tmp, plist.origin, PATH_MAX);
+ else
+ strlcpy(tmp, plist.name, PATH_MAX);
if (!Verbose) {
if ((ch = strrchr(tmp, '-')) != NULL)
ch[0] = '\0';
@@ -257,10 +268,10 @@ show_version(const char *installed, const char *latest, const char *source)
if (Verbose)
printf(" Comparison failed");
printf("\n");
- } else if (source != NULL && OUTPUT('?')) {
+ } else if (OUTPUT('?')) {
printf("%-34s ?", tmp);
if (Verbose)
- printf(" orphaned: %s", source);
+ printf(" orphaned: %s", plist.origin);
printf("\n");
}
} else if (strchr(latest,'|') != NULL) {
@@ -286,7 +297,7 @@ show_version(const char *installed, const char *latest, const char *source)
printf("\n");
}
} else {
- cmp = version_cmp(installed, latest);
+ cmp = version_cmp(plist.name, latest);
ver = strrchr(latest, '-');
ver = ver ? &ver[1] : latest;
if (cmp < 0 && OUTPUT('<')) {
diff --git a/usr.sbin/pkg_install/version/pkg_version.1 b/usr.sbin/pkg_install/version/pkg_version.1
index b9f7688..c48343a 100644
--- a/usr.sbin/pkg_install/version/pkg_version.1
+++ b/usr.sbin/pkg_install/version/pkg_version.1
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 24, 2005
+.Dd Jul 27, 2005
.Dt PKG_VERSION 1
.Os
.Sh NAME
@@ -33,13 +33,14 @@
.Nd summarize installed versions of packages
.Sh SYNOPSIS
.Nm
-.Op Fl hIqv
+.Op Fl hIoqv
.Op Fl l Ar limchar
.Op Fl L Ar limchar
.Oo
.Op Fl X
.Fl s Ar string
.Oc
+.Op Fl O Ar origin
.Op Ar index
.Nm
.Fl t Ar version1 version2
@@ -143,6 +144,12 @@ Note that because some of the status flag characters are also special
to the shell, it is best to quote
.Ar limchar
with single quotes.
+.It Fl o
+Show the origin recorded on package generation instead of the package
+name.
+.It Fl O
+Only list packages whose registered origin is
+.Ar origin .
.It Fl q
Enable quiet output.
Quiet output precludes printing the
diff --git a/usr.sbin/pkg_install/version/version.h b/usr.sbin/pkg_install/version/version.h
index c223dc7..c93d503 100644
--- a/usr.sbin/pkg_install/version/version.h
+++ b/usr.sbin/pkg_install/version/version.h
@@ -40,8 +40,10 @@ SLIST_HEAD(index_head, index_entry);
extern char *LimitChars;
extern char *PreventChars;
extern char *MatchName;
+extern char *LookUpOrigin;
extern Boolean RegexExtended;
extern Boolean UseINDEXOnly;
+extern Boolean ShowOrigin;
extern int version_match(char *, const char *);
OpenPOWER on IntegriCloud