summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormorganamilo <morganamilo@gmail.com>2019-05-28 23:30:07 +0200
committerAllan McRae <allan@archlinux.org>2019-06-06 02:29:39 +0200
commiteb92bcb089a19dd456ce244732415660cf393a89 (patch)
treec9a32cde6bc874e878280be2ad3e7ee00615ff3c /src
parent27e80ca7f61d0eb9861d36c24520a3e081bcb2ec (diff)
downloadpacman-eb92bcb089a19dd456ce244732415660cf393a89.tar.gz
pacman-eb92bcb089a19dd456ce244732415660cf393a89.tar.xz
pacman: refactor file match printing to their own functions
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/files.c71
1 files changed, 41 insertions, 30 deletions
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);
}
}