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>
This commit is contained in:
parent
6dcd4b5383
commit
819a0c2986
2 changed files with 28 additions and 12 deletions
|
@ -235,8 +235,11 @@ Transaction Options (apply to '-S', '-R' and '-U')
|
||||||
|
|
||||||
*\--print-format* <format>::
|
*\--print-format* <format>::
|
||||||
Specify a printf-like format to control the output of the '\--print'
|
Specify a printf-like format to control the output of the '\--print'
|
||||||
operation. The possible attributes are: "%a" for arch, "%n" for pkgname,
|
operation. The possible attributes are: "%a" for arch, "%d" for
|
||||||
"%v" for pkgver, "%l" for location, "%r" for repository, and "%s" for size.
|
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'.
|
Implies '\--print'.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,13 @@ enum {
|
||||||
CELL_FREE = (1 << 3)
|
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 trans_init(int flags, int check_valid)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -1156,18 +1163,22 @@ void print_packages(const alpm_list_t *packages)
|
||||||
free(temp);
|
free(temp);
|
||||||
temp = string;
|
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 */
|
/* %n : pkgname */
|
||||||
if(strstr(temp, "%n")) {
|
VAL_FROM_FORMAT_STR(temp, "%n", alpm_pkg_get_name)
|
||||||
string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));
|
/* %p : packager */
|
||||||
free(temp);
|
VAL_FROM_FORMAT_STR(temp, "%p", alpm_pkg_get_packager)
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %v : pkgver */
|
/* %v : pkgver */
|
||||||
if(strstr(temp, "%v")) {
|
VAL_FROM_FORMAT_STR(temp, "%v", alpm_pkg_get_version)
|
||||||
string = strreplace(temp, "%v", alpm_pkg_get_version(pkg));
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %l : location */
|
/* %l : location */
|
||||||
if(strstr(temp, "%l")) {
|
if(strstr(temp, "%l")) {
|
||||||
char *pkgloc = pkg_get_location(pkg);
|
char *pkgloc = pkg_get_location(pkg);
|
||||||
|
@ -1195,6 +1206,8 @@ void print_packages(const alpm_list_t *packages)
|
||||||
free(size);
|
free(size);
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
|
/* %u : url */
|
||||||
|
VAL_FROM_FORMAT_STR(temp, "%u", alpm_pkg_get_url)
|
||||||
printf("%s\n", string);
|
printf("%s\n", string);
|
||||||
free(string);
|
free(string);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue