[pacman-dev] [PATCH v3 4/8] Show optdep install status in package info

Benedikt Morbach benedikt.morbach at googlemail.com
Mon Aug 1 14:31:48 EDT 2011


Signed-off-by: Benedikt Morbach <benedikt.morbach at googlemail.com>
---
 src/pacman/package.c |    5 +----
 src/pacman/util.c    |   18 ++++++++++++++----
 src/pacman/util.h    |    1 +
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/pacman/package.c b/src/pacman/package.c
index 7b1442e..790b20c 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -88,10 +88,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
 	}
 
 	/* turn optdepends list into a text list */
-	for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) {
-		alpm_optdepend_t *optdep = alpm_list_getdata(i);
-		optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
-	}
+	optstrings = optdep_string_list(alpm_pkg_get_optdepends(pkg), 1);
 
 	if(extra || from == PKG_FROM_LOCALDB) {
 		/* compute this here so we don't get a pause in the middle of output */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 37059d1..f633241 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1011,9 +1011,10 @@ static int opt_cmp(const void *o1, const void *o2)
 /** Creates a newly-allocated list of optdepend strings from a list of optdepends.
  * The list must be freed!
  * @param optlist an alpm_list_t of optdepends to turn into a strings
+ * @param include_installed if false, installed packages are excluded from the list.
  * @return an alpm_list_t of optdepend formatted strings with description
  */
-alpm_list_t *optdep_string_list(const alpm_list_t *optlist)
+alpm_list_t *optdep_string_list(const alpm_list_t *optlist, int include_installed)
 {
 	alpm_list_t *optstrings = NULL;
 	alpm_optdepend_t *optdep;
@@ -1026,9 +1027,18 @@ alpm_list_t *optdep_string_list(const alpm_list_t *optlist)
 		optdep = alpm_list_getdata(optlist);
 		if(alpm_db_get_pkg(db_local, optdep->depend->name) == NULL) {
 			optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep));
+		} else if(include_installed) {
+			const char * const installed = _(" [installed]");
+			char *str, *tmp;
+			tmp = alpm_optdep_compute_string(optdep);
+			if((str = realloc(tmp, strlen(tmp) + strlen(installed) + 1)) != NULL) {
+				strcpy(str + strlen(str), installed);
+				optstrings = alpm_list_add(optstrings, str);
+			} else {
+				free(tmp);
+			}
 		}
 	}
-
 	return optstrings;
 }
 
@@ -1040,7 +1050,7 @@ void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
 	new = alpm_pkg_get_optdepends(newpkg);
 	optdeps = alpm_list_diff(new, old, opt_cmp);
 
-	optstrings = optdep_string_list(optdeps);
+	optstrings = optdep_string_list(optdeps, 0);
 
 	if(optstrings) {
 		printf(_("New optional dependencies for %s\n"), alpm_pkg_get_name(newpkg));
@@ -1055,7 +1065,7 @@ void display_optdepends(alpm_pkg_t *pkg)
 {
 	alpm_list_t *optstrings;
 
-	optstrings = optdep_string_list(alpm_pkg_get_optdepends(pkg));
+	optstrings = optdep_string_list(alpm_pkg_get_optdepends(pkg), 0);
 
 	if(optstrings) {
 		printf(_("Optional dependencies for %s\n"), alpm_pkg_get_name(pkg));
diff --git a/src/pacman/util.h b/src/pacman/util.h
index ee3dbd1..ff1cec3 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -62,6 +62,7 @@ void display_targets(const alpm_list_t *pkgs, int install);
 int str_cmp(const void *s1, const void *s2);
 void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg);
 void display_optdepends(alpm_pkg_t *pkg);
+alpm_list_t *optdep_string_list(const alpm_list_t *optdeps, int include_installed);
 void print_packages(const alpm_list_t *packages);
 void select_display(const alpm_list_t *pkglist);
 int select_question(int count);
-- 
1.7.6



More information about the pacman-dev mailing list