aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/qcheck.15
-rw-r--r--man/qfile.15
-rw-r--r--qfile.c49
3 files changed, 32 insertions, 27 deletions
diff --git a/man/qcheck.1 b/man/qcheck.1
index 9e4d8732..f48fa63d 100644
--- a/man/qcheck.1
+++ b/man/qcheck.1
@@ -1,5 +1,5 @@
.\" generated by mkman.py, please do NOT edit!
-.TH qcheck "1" "May 2019" "Gentoo Foundation" "qcheck"
+.TH qcheck "1" "Jul 2019" "Gentoo Foundation" "qcheck"
.SH NAME
qcheck \- verify integrity of installed packages
.SH SYNOPSIS
@@ -9,6 +9,9 @@ qcheck \- verify integrity of installed packages
.SH OPTIONS
.TP
+\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR
+Custom output format (default: %[CATEGORY]%[PN]).
+.TP
\fB\-s\fR \fI<arg>\fR, \fB\-\-skip\fR \fI<arg>\fR
Ignore files matching the regular expression <arg>.
.TP
diff --git a/man/qfile.1 b/man/qfile.1
index 6dedef26..33dfbee1 100644
--- a/man/qfile.1
+++ b/man/qfile.1
@@ -1,5 +1,5 @@
.\" generated by mkman.py, please do NOT edit!
-.TH qfile "1" "May 2019" "Gentoo Foundation" "qfile"
+.TH qfile "1" "Jul 2019" "Gentoo Foundation" "qfile"
.SH NAME
qfile \- list all pkgs owning files
.SH SYNOPSIS
@@ -35,6 +35,9 @@ After version \fB0.74\fR of portage-utils, the \fB-b\fR option was
renamed to \fB-d\fR.
.SH OPTIONS
.TP
+\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR
+Print matched atom using given format string.
+.TP
\fB\-S\fR, \fB\-\-slots\fR
Display installed packages with slots.
.TP
diff --git a/qfile.c b/qfile.c
index 1a6b4707..bc5c9ac6 100644
--- a/qfile.c
+++ b/qfile.c
@@ -20,8 +20,9 @@
#include "rmspace.h"
#include "tree.h"
-#define QFILE_FLAGS "doRx:S" COMMON_FLAGS
+#define QFILE_FLAGS "F:doRx:S" COMMON_FLAGS
static struct option const qfile_long_opts[] = {
+ {"format", a_argument, NULL, 'F'},
{"slots", no_argument, NULL, 'S'},
{"root-prefix", no_argument, NULL, 'R'},
{"dir", no_argument, NULL, 'd'},
@@ -30,6 +31,7 @@ static struct option const qfile_long_opts[] = {
COMMON_LONG_OPTS
};
static const char * const qfile_opts_help[] = {
+ "Print matched atom using given format string",
"Display installed packages with slots",
"Assume arguments are already prefixed by $ROOT",
"Also match directories for single component arguments",
@@ -64,16 +66,13 @@ struct qfile_opt_state {
char *exclude_pkg;
char *exclude_slot;
depend_atom *exclude_atom;
- bool slotted;
bool basename;
bool orphans;
bool assume_root_prefix;
+ const char *format;
+ bool need_full_atom;
};
-/*
- * We assume the people calling us have chdir(/var/db/pkg) and so
- * we use relative paths throughout here.
- */
static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
{
struct qfile_opt_state *state = priv;
@@ -215,24 +214,9 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
continue;
if (non_orphans == NULL) {
- const char *fmt;
-
- atom = tree_get_atom(pkg_ctx, true);
+ atom = tree_get_atom(pkg_ctx, state->need_full_atom);
- if (state->slotted) {
- if (verbose) {
- fmt = "%[CATEGORY]%[PF]%[SLOT]";
- } else {
- fmt = "%[CATEGORY]%[PN]%[SLOT]";
- }
- } else {
- if (verbose) {
- fmt = "%[CATEGORY]%[PF]";
- } else {
- fmt = "%[CATEGORY]%[PN]";
- }
- }
- printf("%s", atom_format(fmt, atom));
+ printf("%s", atom_format(state->format, atom));
if (quiet)
puts("");
else
@@ -402,10 +386,11 @@ int qfile_main(int argc, char **argv)
{
struct qfile_opt_state state = {
.buflen = _Q_PATH_MAX,
- .slotted = false,
+ .need_full_atom = false,
.basename = false,
.orphans = false,
.assume_root_prefix = false,
+ .format = NULL,
};
int i, nb_of_queries, found = 0;
char *p;
@@ -413,7 +398,8 @@ int qfile_main(int argc, char **argv)
while ((i = GETOPT_LONG(QFILE, qfile, "")) != -1) {
switch (i) {
COMMON_GETOPTS_CASES(qfile)
- case 'S': state.slotted = true; break;
+ case 'F': state.format = optarg; /* fall through */
+ case 'S': state.need_full_atom = true; break;
case 'd': state.basename = true; break;
case 'o': state.orphans = true; break;
case 'R': state.assume_root_prefix = true; break;
@@ -436,6 +422,19 @@ int qfile_main(int argc, char **argv)
argc -= optind;
argv += optind;
+ if (state.format == NULL) {
+ if (state.need_full_atom)
+ if (verbose)
+ state.format = "%[CATEGORY]%[PF]%[SLOT]";
+ else
+ state.format = "%[CATEGORY]%[PN]%[SLOT]";
+ else
+ if (verbose)
+ state.format = "%[CATEGORY]%[PF]";
+ else
+ state.format = "%[CATEGORY]%[PN]";
+ }
+
state.buf = xmalloc(state.buflen);
if (state.assume_root_prefix) {
/* Get a copy of $ROOT, with no trailing slash