From eb92bcb089a19dd456ce244732415660cf393a89 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 28 May 2019 22:30:07 +0100 Subject: pacman: refactor file match printing to their own functions Signed-off-by: Allan McRae --- src/pacman/files.c | 71 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/pacman/files.c b/src/pacman/files.c index fa4170bd..26f96a67 100644 --- a/src/pacman/files.c +++ b/src/pacman/files.c @@ -49,6 +49,15 @@ static void dump_pkg_machinereadable(alpm_db_t *db, alpm_pkg_t *pkg) } } +static void print_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, char *filename) +{ + const colstr_t *colstr = &config->colstr; + printf(_("%s is owned by %s%s/%s%s %s%s%s\n"), filename, + colstr->repo, alpm_db_get_name(db), colstr->title, + alpm_pkg_get_name(pkg), colstr->version, + alpm_pkg_get_version(pkg), colstr->nocolor); +} + static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) { int ret = 0; alpm_list_t *t; @@ -77,11 +86,7 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) { if(config->op_f_machinereadable) { print_line_machinereadable(repo, pkg, filename); } else if(!config->quiet) { - const colstr_t *colstr = &config->colstr; - printf(_("%s is owned by %s%s/%s%s %s%s%s\n"), filename, - colstr->repo, alpm_db_get_name(repo), colstr->title, - alpm_pkg_get_name(pkg), colstr->version, - alpm_pkg_get_version(pkg), colstr->nocolor); + print_owned_by(repo, pkg, filename); } else { printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg)); } @@ -99,11 +104,39 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) { return 0; } +static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg) +{ + alpm_db_t *db_local = alpm_get_localdb(config->handle); + const colstr_t *colstr = &config->colstr; + + if(config->op_f_machinereadable) { + alpm_list_t *ml; + for(ml = match; ml; ml = alpm_list_next(ml)) { + char *filename = ml->data; + print_line_machinereadable(repo, pkg, filename); + } + } else if(config->quiet) { + printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg)); + } else { + alpm_list_t *ml; + printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(repo), + colstr->title, alpm_pkg_get_name(pkg), + colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor); + + print_groups(pkg); + print_installed(db_local, pkg); + printf("\n"); + + for(ml = match; ml; ml = alpm_list_next(ml)) { + char *filename = ml->data; + printf(" %s\n", filename); + } + } +} + static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) { int ret = 0; - alpm_db_t *db_local = alpm_get_localdb(config->handle); alpm_list_t *t; - const colstr_t *colstr = &config->colstr; for(t = targets; t; t = alpm_list_next(t)) { char *targ = t->data; @@ -148,29 +181,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) { } if(match != NULL) { - if(config->op_f_machinereadable) { - alpm_list_t *ml; - for(ml = match; ml; ml = alpm_list_next(ml)) { - char *filename = ml->data; - print_line_machinereadable(repo, pkg, filename); - } - } else if(config->quiet) { - printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg)); - } else { - alpm_list_t *ml; - printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(repo), - colstr->title, alpm_pkg_get_name(pkg), - colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor); - - print_groups(pkg); - print_installed(db_local, pkg); - printf("\n"); - - for(ml = match; ml; ml = alpm_list_next(ml)) { - c = ml->data; - printf(" %s\n", c); - } - } + print_match(match, repo, pkg); alpm_list_free(match); } } -- cgit v1.2.3-24-g4f1b