On Thu, Jul 21, 2011 at 1:39 PM, Benedikt Morbach <[email protected]> wrote: > --- > src/pacman/util.c | 41 ++++++++++++++++++++++++++++------------- > src/pacman/util.h | 1 + > 2 files changed, 29 insertions(+), 13 deletions(-) > > diff --git a/src/pacman/util.c b/src/pacman/util.c > index 14dcf94..d3a5648 100644 > --- a/src/pacman/util.c > +++ b/src/pacman/util.c > @@ -990,17 +990,13 @@ int opt_cmp(const void *o1, const void *o2) > > void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg) > { > - alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL; > + alpm_list_t *old, *new, *optdeps, *optstrings; > > old = alpm_pkg_get_optdepends(oldpkg); > new = alpm_pkg_get_optdepends(newpkg); > optdeps = alpm_list_diff(new,old,opt_cmp); > > - /* turn optdepends list into a text list */ > - for(i = optdeps; i; i = alpm_list_next(i)) { > - alpm_optdepend_t *optdep = (alpm_optdepend_t > *)alpm_list_getdata(i); > - optstrings = alpm_list_add(optstrings, > alpm_optdep_compute_string(optdep)); > - } > + optstrings = optdep_string_list(optdeps); > > if(optstrings) { > printf(_("New optional dependencies for %s\n"), > alpm_pkg_get_name(newpkg)); > @@ -1013,15 +1009,10 @@ void display_new_optdepends(alpm_pkg_t *oldpkg, > alpm_pkg_t *newpkg) > > void display_optdepends(alpm_pkg_t *pkg) > { > - alpm_list_t *i, *optdeps, *optstrings = NULL; > + alpm_list_t *optdeps, *optstrings; > > optdeps = alpm_pkg_get_optdepends(pkg); > - > - /* turn optdepends list into a text list */ > - for(i = optdeps; i; i = alpm_list_next(i)) { > - alpm_optdepend_t *optdep = (alpm_optdepend_t > *)alpm_list_getdata(i); > - optstrings = alpm_list_add(optstrings, > alpm_optdep_compute_string(optdep)); > - } > + optstrings = optdep_string_list(optdeps); > > if(optstrings) { > printf(_("Optional dependencies for %s\n"), > alpm_pkg_get_name(pkg)); > @@ -1031,6 +1022,30 @@ void display_optdepends(alpm_pkg_t *pkg) > FREELIST(optstrings); > } > > +/* Creates a human readable list from a alpm_list_t of optdepends > + * include_installed is false, installed packages are excluded from the list > + * the returned list has to be freed! > + */ > + No blank line between comment and function signature, please. You're also missing something here- I see no 'include_installed" bits at all. Please also use punctuation (e.g. periods at end of sentences), and even better yet would be making this Doxygen-style and using @param and such. > +alpm_list_t *optdep_string_list(const alpm_list_t *optlist) > +{ > + alpm_list_t *optstrings = NULL; > + alpm_optdepend_t *optdep; > + alpm_db_t *db_local; > + > + db_local = alpm_option_get_localdb(config->handle); > + > + /* turn optdepends list into a text list */ > + for( ; optlist; optlist = alpm_list_next(optlist)) { > + optdep = (alpm_optdepend_t *)alpm_list_getdata(optlist); No cast needed. > + if(alpm_db_get_pkg(db_local, optdep->depend->name) == NULL) { > + optstrings = alpm_list_add(optstrings, > alpm_optdep_compute_string(optdep)); > + } > + } > + > + return optstrings; > +} > + > static void display_repo_list(const char *dbname, alpm_list_t *list) > { > const char *prefix= " "; > diff --git a/src/pacman/util.h b/src/pacman/util.h > index ee3dbd1..ed7c01f 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); This is unnecessary. I'd rather the function be static in util.c and defined before any users as it is used nowhere else.
> void print_packages(const alpm_list_t *packages); > void select_display(const alpm_list_t *pkglist); > int select_question(int count); > -- > 1.7.6
