/** Find group members across a list of databases. * If a member exists in several databases, only the first database is used. * IgnorePkg is also handled. * @param dbs the list of alpm_db_t * * @pram name the name of the group * @return the list of alpm_pkg_t * (caller is responsible for alpm_list_free) */ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs, const char *name) { alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL; for(i = dbs; i; i = i->next) { alpm_db_t *db = i->data; alpm_group_t *grp = alpm_db_readgroup(db, name); if(!grp) continue; for(j = grp->packages; j; j = j->next) { alpm_pkg_t *pkg = j->data; if(_alpm_pkg_find(ignorelist, alpm_pkg_get_name(pkg))) { continue; } if(_alpm_pkg_should_ignore(db->handle, pkg)) { ignorelist = alpm_list_add(ignorelist, pkg); int install = 0; QUESTION(db->handle->trans, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, pkg, NULL, NULL, &install); if(!install) continue; } if(!_alpm_pkg_find(pkgs, alpm_pkg_get_name(pkg))) { pkgs = alpm_list_add(pkgs, pkg); } } } alpm_list_free(ignorelist); return pkgs; }
static int query_group(alpm_list_t *targets) { alpm_list_t *i, *j; char *grpname = NULL; int ret = 0; alpm_db_t *db_local = alpm_option_get_localdb(config->handle); if(targets == NULL) { for(j = alpm_db_get_groupcache(db_local); j; j = alpm_list_next(j)) { alpm_group_t *grp = alpm_list_getdata(j); const alpm_list_t *p; for(p = grp->packages; p; p = alpm_list_next(p)) { alpm_pkg_t *pkg = alpm_list_getdata(p); printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg)); } } } else { for(i = targets; i; i = alpm_list_next(i)) { alpm_group_t *grp; grpname = alpm_list_getdata(i); grp = alpm_db_readgroup(db_local, grpname); if(grp) { const alpm_list_t *p; for(p = grp->packages; p; p = alpm_list_next(p)) { if(!config->quiet) { printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p))); } else { printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(p))); } } } else { pm_fprintf(stderr, ALPM_LOG_ERROR, _("group '%s' was not found\n"), grpname); ret++; } } } return ret; }