diff options
author | Jelle van der Waa <jelle@vdwaa.nl> | 2022-03-26 16:54:20 +0100 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2022-07-21 19:09:59 +1000 |
commit | 819a0c29867e3a13abddaa4680defb3399f772ef (patch) | |
tree | e9e861ac14a492a703091715f96a6f47bff50e48 /src | |
parent | 6dcd4b53830e1a472d655a3721f23a78eecacba1 (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>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/util.c | 33 |
1 files changed, 23 insertions, 10 deletions
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); } |