[Midnightbsd-cvs] src [9837] stable/0.9/usr.sbin/mport/mport.c: add support for -q and -o flags which allow compact versions of which for scripts
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat May 12 09:46:08 EDT 2018
Revision: 9837
http://svnweb.midnightbsd.org/src/?rev=9837
Author: laffer1
Date: 2018-05-12 09:46:07 -0400 (Sat, 12 May 2018)
Log Message:
-----------
add support for -q and -o flags which allow compact versions of which for scripts
Modified Paths:
--------------
stable/0.9/usr.sbin/mport/mport.c
Modified: stable/0.9/usr.sbin/mport/mport.c
===================================================================
--- stable/0.9/usr.sbin/mport/mport.c 2018-05-12 13:45:31 UTC (rev 9836)
+++ stable/0.9/usr.sbin/mport/mport.c 2018-05-12 13:46:07 UTC (rev 9837)
@@ -60,7 +60,7 @@
static int verify(mportInstance *);
static int lock(mportInstance *, const char *);
static int unlock(mportInstance *, const char *);
-static int which(mportInstance *mport, const char *filePath);
+static int which(mportInstance *, const char *, bool, bool);
int
main(int argc, char *argv[]) {
@@ -223,8 +223,26 @@
});
} else if (!strcmp(argv[1], "which")) {
dispatch_group_async(grp, q, ^{
- if (argc > 2) {
- which(mport, argv[2]);
+ __block int local_argc = argc;
+ __block char *const * local_argv = argv;
+ local_argv++;
+ if (local_argc > 2) {
+ int ch, qflag, oflag;
+ qflag = oflag = 0;
+ while ((ch = getopt(local_argc, local_argv, "qo")) != -1) {
+ switch (ch) {
+ case 'q':
+ qflag = 1;
+ break;
+ case 'o':
+ oflag = 1;
+ break;
+ }
+ }
+ local_argc -= optind;
+ local_argv += optind;
+
+ which(mport, *local_argv, qflag, oflag);
} else {
usage();
}
@@ -409,7 +427,7 @@
}
int
-which(mportInstance *mport, const char *filePath) {
+which(mportInstance *mport, const char *filePath, bool quiet, bool origin) {
mportPackageMeta *pack = NULL;
@@ -424,8 +442,15 @@
}
if (pack != NULL && pack->origin != NULL) {
- printf("%s was installed by package %s\n",
- filePath, pack->origin);
+ if (quiet && origin) {
+ printf("%s\n", pack->origin);
+ } else if (quiet) {
+ printf("%s-%s\n", pack->name, pack->version);
+ } else if (origin) {
+ printf("%s was installed by package %s\n", filePath, pack->origin);
+ } else {
+ printf("%s was installed by package %s-%s\n", filePath, pack->name, pack->version);
+ }
}
return (0);
More information about the Midnightbsd-cvs
mailing list