From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id E4273138336 for ; Sun, 14 Jul 2019 13:09:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DDF21E089D; Sun, 14 Jul 2019 13:09:46 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 93132E089D for ; Sun, 14 Jul 2019 13:09:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 78385347162 for ; Sun, 14 Jul 2019 13:09:45 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 23A096DB for ; Sun, 14 Jul 2019 13:09:44 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1563104609.46f6f4a1c29eb1bcd66af043b13d6952ad3a5e0a.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: man/, / X-VCS-Repository: proj/portage-utils X-VCS-Files: man/qsearch.1 qsearch.c X-VCS-Directories: man/ / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 46f6f4a1c29eb1bcd66af043b13d6952ad3a5e0a X-VCS-Branch: master Date: Sun, 14 Jul 2019 13:09:44 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: e9a93ca6-a4ed-4ccf-aacb-dd167196f115 X-Archives-Hash: f85fab32a615e7aa9655bb4d15107a7a commit: 46f6f4a1c29eb1bcd66af043b13d6952ad3a5e0a Author: Fabian Groffen gentoo org> AuthorDate: Sun Jul 14 11:43:29 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sun Jul 14 11:43:29 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=46f6f4a1 qsearch: add -F argument, also make -v act like for other applets Signed-off-by: Fabian Groffen gentoo.org> man/qsearch.1 | 3 +++ qsearch.c | 59 ++++++++++++++++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/man/qsearch.1 b/man/qsearch.1 index f6b9baf..e805f82 100644 --- a/man/qsearch.1 +++ b/man/qsearch.1 @@ -29,6 +29,9 @@ Show homepage info instead of description. \fB\-R\fR, \fB\-\-repo\fR Show repository the ebuild originates from. .TP +\fB\-F\fR \fI\fR, \fB\-\-format\fR \fI\fR +Print matched atom using given format string. +.TP \fB\-\-root\fR \fI\fR Set the ROOT env var. .TP diff --git a/qsearch.c b/qsearch.c index db220c7..8245383 100644 --- a/qsearch.c +++ b/qsearch.c @@ -25,7 +25,7 @@ #include "xarray.h" #include "xregex.h" -#define QSEARCH_FLAGS "asSNHR" COMMON_FLAGS +#define QSEARCH_FLAGS "asSNHRF:" COMMON_FLAGS static struct option const qsearch_long_opts[] = { {"all", no_argument, NULL, 'a'}, {"search", no_argument, NULL, 's'}, @@ -33,6 +33,7 @@ static struct option const qsearch_long_opts[] = { {"name-only", no_argument, NULL, 'N'}, {"homepage", no_argument, NULL, 'H'}, {"repo", no_argument, NULL, 'R'}, + {"format", a_argument, NULL, 'F'}, COMMON_LONG_OPTS }; static const char * const qsearch_opts_help[] = { @@ -42,6 +43,7 @@ static const char * const qsearch_opts_help[] = { "Only show package name", "Show homepage info instead of description", "Show repository the ebuild originates from", + "Print matched atom using given format string", COMMON_OPTS_HELP }; #define qsearch_usage(ret) usage(ret, QSEARCH_FLAGS, qsearch_long_opts, qsearch_opts_help, NULL, lookup_applet_idx("qsearch")) @@ -50,10 +52,11 @@ struct qsearch_state { bool show_homepage:1; bool show_name:1; bool show_desc:1; - bool show_repo:1; bool search_desc:1; bool search_name:1; + bool need_full_atom:1; regex_t search_expr; + const char *fmt; }; static int @@ -99,16 +102,10 @@ qsearch_cb(tree_pkg_ctx *pkg_ctx, void *priv) match = true; if (match) { - const char *qfmt; - if (state->show_repo) { - atom = tree_get_atom(pkg_ctx, 1); - qfmt = "%[CATEGORY]%[PN]%[REPO]"; - } else { - qfmt = "%[CATEGORY]%[PN]"; - } + atom = tree_get_atom(pkg_ctx, state->need_full_atom); printf("%s%s%s\n", - atom_format(qfmt, atom), - (state->show_name ? "" : " "), + atom_format(state->fmt, atom), + (state->show_name ? "" : ": "), (state->show_name ? "" : desc ? desc : "")); } @@ -131,23 +128,25 @@ int qsearch_main(int argc, char **argv) const char *overlay; size_t n; struct qsearch_state state = { - .show_homepage = false, - .show_name = false, - .show_desc = false, - .show_repo = false, - .search_desc = false, - .search_name = false, + .show_homepage = false, + .show_name = false, + .show_desc = false, + .search_desc = false, + .search_name = false, + .need_full_atom = false, + .fmt = NULL, }; while ((i = GETOPT_LONG(QSEARCH, qsearch, "")) != -1) { switch (i) { COMMON_GETOPTS_CASES(qsearch) - case 'a': search_me = ".*"; break; - case 's': state.search_name = true; break; - case 'S': state.search_desc = true; break; - case 'N': state.show_name = true; break; - case 'H': state.show_homepage = true; break; - case 'R': state.show_repo = true; break; + case 'a': search_me = ".*"; break; + case 's': state.search_name = true; break; + case 'S': state.search_desc = true; break; + case 'N': state.show_name = true; break; + case 'H': state.show_homepage = true; break; + case 'F': state.fmt = optarg; /* fall through */ + case 'R': state.need_full_atom = true; break; } } @@ -165,6 +164,20 @@ int qsearch_main(int argc, char **argv) } xregcomp(&state.search_expr, search_me, REG_EXTENDED | REG_ICASE); + /* set default format */ + if (state.fmt == NULL) { + if (state.need_full_atom) + if (verbose) + state.fmt = "%[CATEGORY]%[PF]%[REPO]"; + else + state.fmt = "%[CATEGORY]%[PN]%[REPO]"; + else + if (verbose) + state.fmt = "%[CATEGORY]%[PF]"; + else + state.fmt = "%[CATEGORY]%[PN]"; + } + /* use sorted order here so the duplicate reduction works reliably */ array_for_each(overlays, n, overlay) { tree_ctx *t = tree_open(portroot, overlay);