On Wed, Nov 23, 2011 at 1:51 PM, Benedikt Morbach <benedikt.morbach@googlemail.com> wrote:
--- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -517,6 +517,12 @@ char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info, const char *filena f = alpm_list_add(f, _alpm_splitdep(line)); \ } while(1) /* note the while(1) and not (0) */
+#define READ_AND_SPLITOPTDEP(f) do { \ + if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error; \ + if(_alpm_strip_newline(line) == 0) break; \ + f = alpm_list_add(f, _alpm_splitoptdep(line)); \ +} while(1) /* note the while(1) and not (0) */
This DEFINE is equal to the one bellow. Wouldn't it be possible to separete it in some header file and use from there?
--- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -504,6 +504,12 @@ cleanup: f = alpm_list_add(f, _alpm_splitdep(line)); \ } while(1) /* note the while(1) and not (0) */
+#define READ_AND_SPLITOPTDEP(f) do { \ + if(_alpm_archive_fgets(archive, &buf) != ARCHIVE_OK) goto error; \ + if(_alpm_strip_newline(buf.line) == 0) break; \ + f = alpm_list_add(f, _alpm_splitoptdep(line)); \ +} while(1) /* note the while(1) and not (0) */ +
diff --git a/src/pacman/util.c b/src/pacman/util.c index c0dcb9f..2363e6f 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1139,32 +1139,81 @@ void print_packages(const alpm_list_t *packages) void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg) { - alpm_list_t *old = alpm_pkg_get_optdepends(oldpkg); - alpm_list_t *new = alpm_pkg_get_optdepends(newpkg); - alpm_list_t *optdeps = alpm_list_diff(new,old,str_cmp); - if(optdeps) { + alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL; + + 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 = i->data; + optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep)); + }
This las for also looks quite equal to the one in display_optdepends. I think they could be merged somehow (maybe another DEFINE or a function)
void display_optdepends(alpm_pkg_t *pkg) { - alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg); - if(optdeps) { + alpm_list_t *i, *optdeps, *optstrings = NULL; + + 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 = i->data; + optstrings = alpm_list_add(optstrings, alpm_optdep_compute_string(optdep)); + }
-- A: Because it obfuscates the reading. Q: Why is top posting so bad? ------------------------------------------- Denis A. Altoe Falqueto Linux user #524555 -------------------------------------------