Signed-off-by: Benedikt Morbach <[email protected]>
---
 src/pacman/package.c |    7 ++-----
 src/pacman/util.c    |   20 +++++++++++++++-----
 src/pacman/util.h    |    1 +
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/pacman/package.c b/src/pacman/package.c
index 4f8a180..7e17f0c 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -58,11 +58,8 @@ static void deplist_display(const char *title,
 static void optdeplist_display(const char *title,
                alpm_list_t *optdeps)
 {
-       alpm_list_t *i, *text = NULL;
-       for(i = optdeps; i; i = alpm_list_next(i)) {
-               alpm_optdepend_t *optdep = alpm_list_getdata(i);
-               text = alpm_list_add(text, alpm_optdep_compute_string(optdep));
-       }
+       alpm_list_t *text = NULL;
+       text = optdep_string_list(optdeps, 1);
        list_display_linebreak(title, text);
        FREELIST(text);
 }
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 27121d3..1c534e3 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1033,9 +1033,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;
@@ -1046,11 +1047,20 @@ alpm_list_t *optdep_string_list(const alpm_list_t 
*optlist)
        /* turn optdepends list into a text list */
        for( ; optlist; optlist = alpm_list_next(optlist)) {
                optdep = alpm_list_getdata(optlist);
-               if(alpm_db_get_pkg(db_local, optdep->depend->name) == NULL) {
+               if(include_installed && alpm_db_get_pkg(db_local, 
optdep->depend->name)) {
+                       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);
+                       }
+               } else {
                        optstrings = alpm_list_add(optstrings, 
alpm_optdep_compute_string(optdep));
                }
        }
-
        return optstrings;
 }
 
@@ -1062,7 +1072,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));
@@ -1077,7 +1087,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 6a26b08..01d2211 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -63,6 +63,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.1


Reply via email to