aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle van der Waa <jelle@vdwaa.nl>2022-03-26 16:54:20 +0100
committerAllan McRae <allan@archlinux.org>2022-07-21 19:09:59 +1000
commit819a0c29867e3a13abddaa4680defb3399f772ef (patch)
treee9e861ac14a492a703091715f96a6f47bff50e48
parent6dcd4b53830e1a472d655a3721f23a78eecacba1 (diff)
util.c: extend --print-format with expac options
Extend --print-format with all expac format strings which can be easily added without conversions and through a simple C macro. Signed-off-by: Jelle van der Waa <jelle@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--doc/pacman.8.asciidoc7
-rw-r--r--src/pacman/util.c33
2 files changed, 28 insertions, 12 deletions
diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc
index 785844ce..49e392cb 100644
--- a/doc/pacman.8.asciidoc
+++ b/doc/pacman.8.asciidoc
@@ -235,8 +235,11 @@ Transaction Options (apply to '-S', '-R' and '-U')
*\--print-format* <format>::
Specify a printf-like format to control the output of the '\--print'
- operation. The possible attributes are: "%a" for arch, "%n" for pkgname,
- "%v" for pkgver, "%l" for location, "%r" for repository, and "%s" for size.
+ operation. The possible attributes are: "%a" for arch, "%d" for
+ description, "%e" for pkgbase, "%f" for filename, "%g" for base64
+ encoded PGP signature, "%h" for sha256sum, "%n" for pkgname, "%p" for
+ packager, "%v" for pkgver, "%l" for location, "%r" for repository, and
+ "%s" for size.
Implies '\--print'.
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 53833d6f..3b92e678 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -61,6 +61,13 @@ enum {
CELL_FREE = (1 << 3)
};
+#define VAL_FROM_FORMAT_STR(temp, format, func) \
+ if(strstr(temp, format)) { \
+ string = strreplace(temp, format, func(pkg)); \
+ free(temp); \
+ temp = string; \
+ } \
+
int trans_init(int flags, int check_valid)
{
int ret;
@@ -1156,18 +1163,22 @@ void print_packages(const alpm_list_t *packages)
free(temp);
temp = string;
}
+ /* %d : description */
+ VAL_FROM_FORMAT_STR(temp, "%d", alpm_pkg_get_desc)
+ /* %e : pkgbase */
+ VAL_FROM_FORMAT_STR(temp, "%e", alpm_pkg_get_base)
+ /* %f : filename */
+ VAL_FROM_FORMAT_STR(temp, "%f", alpm_pkg_get_filename)
+ /* %g : base64 encoded PGP signature */
+ VAL_FROM_FORMAT_STR(temp, "%g", alpm_pkg_get_base64_sig)
+ /* %h : sha25sum */
+ VAL_FROM_FORMAT_STR(temp, "%h", alpm_pkg_get_sha256sum)
/* %n : pkgname */
- if(strstr(temp, "%n")) {
- string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));
- free(temp);
- temp = string;
- }
+ VAL_FROM_FORMAT_STR(temp, "%n", alpm_pkg_get_name)
+ /* %p : packager */
+ VAL_FROM_FORMAT_STR(temp, "%p", alpm_pkg_get_packager)
/* %v : pkgver */
- if(strstr(temp, "%v")) {
- string = strreplace(temp, "%v", alpm_pkg_get_version(pkg));
- free(temp);
- temp = string;
- }
+ VAL_FROM_FORMAT_STR(temp, "%v", alpm_pkg_get_version)
/* %l : location */
if(strstr(temp, "%l")) {
char *pkgloc = pkg_get_location(pkg);
@@ -1195,6 +1206,8 @@ void print_packages(const alpm_list_t *packages)
free(size);
free(temp);
}
+ /* %u : url */
+ VAL_FROM_FORMAT_STR(temp, "%u", alpm_pkg_get_url)
printf("%s\n", string);
free(string);
}