Add PRINT_FORMAT_LIST define to remove repetitive code
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
e7d7433b4b
commit
717e5e9157
1 changed files with 21 additions and 73 deletions
|
@ -68,6 +68,17 @@ enum {
|
||||||
temp = string; \
|
temp = string; \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
|
#define PRINT_FORMAT_LIST(temp, format, func, extract) \
|
||||||
|
if(strstr(temp, format)) { \
|
||||||
|
alpm_list_t *lst = func(pkg); \
|
||||||
|
char *cl = concat_list(lst, (formatfn)extract); \
|
||||||
|
string = strreplace(temp, format, cl); \
|
||||||
|
free(cl); \
|
||||||
|
free(temp); \
|
||||||
|
temp = string; \
|
||||||
|
} \
|
||||||
|
|
||||||
|
|
||||||
int trans_init(int flags, int check_valid)
|
int trans_init(int flags, int check_valid)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -1255,86 +1266,23 @@ void print_packages(const alpm_list_t *packages)
|
||||||
/* %u : url */
|
/* %u : url */
|
||||||
PRINT_FORMAT_STRING(temp, "%u", alpm_pkg_get_url)
|
PRINT_FORMAT_STRING(temp, "%u", alpm_pkg_get_url)
|
||||||
/* %C : checkdepends */
|
/* %C : checkdepends */
|
||||||
if(strstr(temp, "%C")) {
|
PRINT_FORMAT_LIST(temp, "%C", alpm_pkg_get_checkdepends, alpm_dep_compute_string)
|
||||||
alpm_list_t *lst = alpm_pkg_get_checkdepends(pkg);
|
|
||||||
char *depends = concat_list(lst, (formatfn)alpm_dep_compute_string);
|
|
||||||
string = strreplace(temp, "%C", depends);
|
|
||||||
free(depends);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %D : depends */
|
/* %D : depends */
|
||||||
if(strstr(temp, "%D")) {
|
PRINT_FORMAT_LIST(temp, "%D", alpm_pkg_get_depends, alpm_dep_compute_string)
|
||||||
alpm_list_t *lst = alpm_pkg_get_depends(pkg);
|
|
||||||
char *depends = concat_list(lst, (formatfn)alpm_dep_compute_string);
|
|
||||||
string = strreplace(temp, "%D", depends);
|
|
||||||
free(depends);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %G : groups */
|
/* %G : groups */
|
||||||
if(strstr(temp, "%G")) {
|
PRINT_FORMAT_LIST(temp, "%G", alpm_pkg_get_groups, NULL)
|
||||||
alpm_list_t *lst = alpm_pkg_get_groups(pkg);
|
|
||||||
char *depends = concat_list(lst, NULL);
|
|
||||||
string = strreplace(temp, "%G", depends);
|
|
||||||
free(depends);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %H : conflicts */
|
/* %H : conflicts */
|
||||||
if(strstr(temp, "%H")) {
|
PRINT_FORMAT_LIST(temp, "%H", alpm_pkg_get_conflicts, alpm_dep_compute_string)
|
||||||
alpm_list_t *lst = alpm_pkg_get_conflicts(pkg);
|
|
||||||
char *depends = concat_list(lst, (formatfn)alpm_dep_compute_string);
|
|
||||||
string = strreplace(temp, "%H", depends);
|
|
||||||
free(depends);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %M : makedepends */
|
/* %M : makedepends */
|
||||||
if(strstr(temp, "%M")) {
|
PRINT_FORMAT_LIST(temp, "%M", alpm_pkg_get_makedepends, alpm_dep_compute_string)
|
||||||
alpm_list_t *lst = alpm_pkg_get_makedepends(pkg);
|
/* %O : optdepends */
|
||||||
char *depends = concat_list(lst, (formatfn)alpm_dep_compute_string);
|
PRINT_FORMAT_LIST(temp, "%O", alpm_pkg_get_optdepends, alpm_dep_compute_string)
|
||||||
string = strreplace(temp, "%M", depends);
|
|
||||||
free(depends);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %O : optional */
|
|
||||||
if(strstr(temp, "%O")) {
|
|
||||||
alpm_list_t *lst = alpm_pkg_get_optdepends(pkg);
|
|
||||||
char *depends = concat_list(lst, (formatfn)alpm_dep_compute_string);
|
|
||||||
string = strreplace(temp, "%O", depends);
|
|
||||||
free(depends);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %P : provides */
|
/* %P : provides */
|
||||||
if(strstr(temp, "%P")) {
|
PRINT_FORMAT_LIST(temp, "%P", alpm_pkg_get_provides, alpm_dep_compute_string)
|
||||||
alpm_list_t *lst = alpm_pkg_get_provides(pkg);
|
|
||||||
char *depends = concat_list(lst, (formatfn)alpm_dep_compute_string);
|
|
||||||
string = strreplace(temp, "%P", depends);
|
|
||||||
free(depends);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %R : replaces */
|
/* %R : replaces */
|
||||||
if(strstr(temp, "%R")) {
|
PRINT_FORMAT_LIST(temp, "%R", alpm_pkg_get_replaces, alpm_dep_compute_string)
|
||||||
alpm_list_t *lst = alpm_pkg_get_replaces(pkg);
|
|
||||||
char *depends = concat_list(lst, (formatfn)alpm_dep_compute_string);
|
|
||||||
string = strreplace(temp, "%R", depends);
|
|
||||||
free(depends);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
/* %L : license */
|
/* %L : license */
|
||||||
if(strstr(temp, "%L")) {
|
PRINT_FORMAT_LIST(temp, "%L", alpm_pkg_get_licenses, NULL)
|
||||||
alpm_list_t *lst = alpm_pkg_get_licenses(pkg);
|
|
||||||
char *licenses = concat_list(lst, NULL);
|
|
||||||
string = strreplace(temp, "%L", licenses);
|
|
||||||
free(licenses);
|
|
||||||
free(temp);
|
|
||||||
temp = string;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s\n", string);
|
printf("%s\n", string);
|
||||||
free(string);
|
free(string);
|
||||||
|
|
Loading…
Add table
Reference in a new issue