From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage-utils:master commit in: man/, /
Date: Sun, 19 Jan 2020 09:49:44 +0000 (UTC) [thread overview]
Message-ID: <1579427330.16215c71c61da9cb44868d58b4c3ce0529c5d4ac.grobian@gentoo> (raw)
commit: 16215c71c61da9cb44868d58b4c3ce0529c5d4ac
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 19 09:48:50 2020 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jan 19 09:48:50 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=16215c71
qatom: add -l option to match an atom against the tree
returns the latest available version of the atom requested, or nothing
when not found
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
man/qatom.1 | 5 ++++-
qatom.c | 33 +++++++++++++++++++++++++++------
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/man/qatom.1 b/man/qatom.1
index 6254912..4f6ccf2 100644
--- a/man/qatom.1
+++ b/man/qatom.1
@@ -1,5 +1,5 @@
.\" generated by mkman.py, please do NOT edit!
-.TH qatom "1" "Nov 2019" "Gentoo Foundation" "qatom"
+.TH qatom "1" "Jan 2020" "Gentoo Foundation" "qatom"
.SH NAME
qatom \- split atom strings
.SH SYNOPSIS
@@ -70,6 +70,9 @@ Compare two atoms.
\fB\-p\fR, \fB\-\-print\fR
Print reconstructed atom.
.TP
+\fB\-l\fR, \fB\-\-lookup\fR
+Lookup atom in tree.
+.TP
\fB\-\-root\fR \fI<arg>\fR
Set the ROOT env var.
.TP
diff --git a/qatom.c b/qatom.c
index 23d10d8..59f7392 100644
--- a/qatom.c
+++ b/qatom.c
@@ -8,36 +8,37 @@
*/
#include "main.h"
-
-#include <stdlib.h>
-#include <stdbool.h>
+#include "applets.h"
#include "atom.h"
-#include "applets.h"
+#include "tree.h"
#define QATOM_FORMAT "%{CATEGORY} %{PN} %{PV} %[PR] %[SLOT] %[pfx] %[sfx]"
-#define QATOM_FLAGS "F:cp" COMMON_FLAGS
+#define QATOM_FLAGS "F:cpl" COMMON_FLAGS
static struct option const qatom_long_opts[] = {
{"format", a_argument, NULL, 'F'},
{"compare", no_argument, NULL, 'c'},
{"print", no_argument, NULL, 'p'},
+ {"lookup", no_argument, NULL, 'l'},
COMMON_LONG_OPTS
};
static const char * const qatom_opts_help[] = {
"Custom output format (default: " QATOM_FORMAT ")",
"Compare two atoms",
"Print reconstructed atom",
+ "Lookup atom in tree",
COMMON_OPTS_HELP
};
#define qatom_usage(ret) usage(ret, QATOM_FLAGS, qatom_long_opts, qatom_opts_help, NULL, lookup_applet_idx("qatom"))
int qatom_main(int argc, char **argv)
{
- enum qatom_atom { _EXPLODE=0, _COMPARE, _PRINT } action = _EXPLODE;
+ enum qatom_atom { _EXPLODE=0, _COMPARE, _PRINT, _LOOKUP } action = _EXPLODE;
const char *format = QATOM_FORMAT;
depend_atom *atom;
depend_atom *atomc;
+ tree_ctx *tree = NULL;
int i;
while ((i = GETOPT_LONG(QATOM, qatom, "")) != -1) {
@@ -45,6 +46,7 @@ int qatom_main(int argc, char **argv)
case 'F': format = optarg; break;
case 'c': action = _COMPARE; break;
case 'p': action = _PRINT; break;
+ case 'l': action = _LOOKUP; break;
COMMON_GETOPTS_CASES(qatom)
}
}
@@ -55,6 +57,12 @@ int qatom_main(int argc, char **argv)
if (action == _COMPARE && (argc - optind) % 2)
err("compare needs even number of arguments");
+ if (action == _LOOKUP) {
+ tree = tree_open(portroot, main_overlay);
+ if (tree == NULL)
+ err("failed to open tree");
+ }
+
for (i = optind; i < argc; i++) {
atom = atom_explode(argv[i]);
if (atom == NULL) {
@@ -101,10 +109,23 @@ int qatom_main(int argc, char **argv)
case _PRINT:
printf("%s\n", atom_to_string(atom));
break;
+ case _LOOKUP:
+ {
+ tree_pkg_ctx *pkg = tree_match_atom(tree, atom);
+ if (pkg != NULL) {
+ atomc = tree_get_atom(pkg, true);
+ if (!quiet)
+ printf("%s: ", atom_to_string(atom));
+ printf("%s\n", atom_format(format, atomc));
+ }
+ }
}
atom_implode(atom);
}
+ if (action == _LOOKUP)
+ tree_close(tree);
+
return EXIT_SUCCESS;
}
next reply other threads:[~2020-01-19 9:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-19 9:49 Fabian Groffen [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-12-15 9:36 [gentoo-commits] proj/portage-utils:master commit in: man/, / Fabian Groffen
2022-05-26 14:36 Fabian Groffen
2021-02-17 20:23 Fabian Groffen
2020-05-16 13:06 Fabian Groffen
2019-07-14 18:51 Fabian Groffen
2019-07-14 13:09 Fabian Groffen
2019-06-21 18:24 Fabian Groffen
2019-05-03 8:50 Fabian Groffen
2019-05-02 18:02 Fabian Groffen
2019-04-28 8:52 Fabian Groffen
2019-02-28 19:28 Fabian Groffen
2016-03-28 4:53 Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1579427330.16215c71c61da9cb44868d58b4c3ce0529c5d4ac.grobian@gentoo \
--to=grobian@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox