/** * @brief Add a new item to the end of the list. * * @param list the list to add to * @param data the new item to be added to the list * * @return the resultant list */ alpm_list_t SYMEXPORT *alpm_list_add(alpm_list_t *list, void *data) { alpm_list_t *ptr, *lp; ptr = malloc(sizeof(alpm_list_t)); if(ptr == NULL) { return list; } ptr->data = data; ptr->next = NULL; /* Special case: the input list is empty */ if(list == NULL) { ptr->prev = ptr; return ptr; } lp = alpm_list_last(list); lp->next = ptr; ptr->prev = lp; list->prev = ptr; return list; }
void show_results (void) { if (!results) { return; } alpm_list_fn_cmp fn_cmp = NULL; switch (config.sort) { case S_NAME: fn_cmp = (alpm_list_fn_cmp) results_cmp; break; case S_VOTE: fn_cmp = (alpm_list_fn_cmp) results_votes_cmp; break; case S_POP: fn_cmp = (alpm_list_fn_cmp) results_popularity_cmp; break; case S_IDATE: fn_cmp = (alpm_list_fn_cmp) results_installdate_cmp; break; case S_ISIZE: fn_cmp = (alpm_list_fn_cmp) results_isize_cmp; break; case S_REL: fn_cmp = (alpm_list_fn_cmp) results_relevance_cmp; break; } if (fn_cmp) { results = alpm_list_msort (results, alpm_list_count (results), fn_cmp); } const alpm_list_nav fn_nav = config.rsort ? alpm_list_previous : alpm_list_next; const alpm_list_t *i_first = config.rsort ? alpm_list_last (results) : results; for (const alpm_list_t *i = i_first; i; i = fn_nav (i)) { const results_t *r = i->data; if (r && r->type == R_ALPM_PKG) { print_package ("", r->ele, alpm_pkg_get_str); } else if (r && r->type == R_AUR_PKG) { print_package ("", r->ele, aur_get_str); } } alpm_list_free_inner (results, (alpm_list_fn_free) results_free); alpm_list_free (results); results = NULL; }
/** * @brief Create a new list in reverse order. * * @param list the list to copy * * @return a new list in reverse order */ alpm_list_t SYMEXPORT *alpm_list_reverse(alpm_list_t *list) { const alpm_list_t *lp; alpm_list_t *newlist = NULL, *backup; if(list == NULL) { return NULL; } lp = alpm_list_last(list); /* break our reverse circular list */ backup = list->prev; list->prev = NULL; while(lp) { newlist = alpm_list_add(newlist, lp->data); lp = lp->prev; } list->prev = backup; /* restore tail pointer */ return newlist; }
void show_results () { alpm_list_t *i_first; alpm_list_t *i; alpm_list_nav fn_nav=NULL;; alpm_list_fn_cmp fn_cmp=NULL; if (results!=NULL) { switch (config.sort) { case S_NAME: fn_cmp = (alpm_list_fn_cmp) results_cmp; break; case S_VOTE: fn_cmp = (alpm_list_fn_cmp) results_votes_cmp; break; case S_IDATE: fn_cmp = (alpm_list_fn_cmp) results_installdate_cmp; break; case S_ISIZE: fn_cmp = (alpm_list_fn_cmp) results_isize_cmp; break; } if (fn_cmp) results = alpm_list_msort (results, alpm_list_count (results), fn_cmp); if (config.rsort) { fn_nav = (alpm_list_nav) alpm_list_previous; i_first = alpm_list_last (results); } else { fn_nav = (alpm_list_nav) alpm_list_next; i_first = results; } for(i = i_first; i; i = fn_nav(i)) { results_t *r = i->data; if (r->type == R_ALPM_PKG) print_package ("", r->ele, alpm_pkg_get_str); else if (r->type == R_AUR_PKG) print_package ("", r->ele, aur_get_str); } alpm_list_free_inner (results, (alpm_list_fn_free) results_free); alpm_list_free (results); results = NULL; } }
/** * Computes resolvable dependencies for a given package and adds that package * and those resolvable dependencies to a list. * * @param handle the context handle * @param localpkgs is the list of local packages * @param pkg is the package to resolve * @param packages is a pointer to a list of packages which will be * searched first for any dependency packages needed to complete the * resolve, and to which will be added any [pkg] and all of its * dependencies not already on the list * @param remove is the set of packages which will be removed in this * transaction * @param data returns the dependency which could not be satisfied in the * event of an error * @return 0 on success, with [pkg] and all of its dependencies not already on * the [*packages] list added to that list, or -1 on failure due to an * unresolvable dependency, in which case the [*packages] list will be * unmodified by this function */ int _alpm_resolvedeps(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg, alpm_list_t *preferred, alpm_list_t **packages, alpm_list_t *remove, alpm_list_t **data) { int ret = 0; alpm_list_t *i, *j; alpm_list_t *targ; alpm_list_t *deps = NULL; alpm_list_t *packages_copy; if(_alpm_pkg_find(*packages, pkg->name) != NULL) { return 0; } /* Create a copy of the packages list, so that it can be restored on error */ packages_copy = alpm_list_copy(*packages); /* [pkg] has not already been resolved into the packages list, so put it on that list */ *packages = alpm_list_add(*packages, pkg); _alpm_log(handle, PM_LOG_DEBUG, "started resolving dependencies\n"); for(i = alpm_list_last(*packages); i; i = i->next) { pmpkg_t *tpkg = i->data; targ = alpm_list_add(NULL, tpkg); deps = alpm_checkdeps(handle, localpkgs, remove, targ, 0); alpm_list_free(targ); for(j = deps; j; j = j->next) { pmdepmissing_t *miss = j->data; pmdepend_t *missdep = miss->depend; /* check if one of the packages in the [*packages] list already satisfies * this dependency */ if(find_dep_satisfier(*packages, missdep)) { _alpm_depmiss_free(miss); continue; } /* check if one of the packages in the [preferred] list already satisfies * this dependency */ pmpkg_t *spkg = find_dep_satisfier(preferred, missdep); if(!spkg) { /* find a satisfier package in the given repositories */ spkg = resolvedep(handle, missdep, handle->dbs_sync, *packages, 0); } if(!spkg) { handle->pm_errno = PM_ERR_UNSATISFIED_DEPS; char *missdepstring = alpm_dep_compute_string(missdep); _alpm_log(handle, PM_LOG_WARNING, _("cannot resolve \"%s\", a dependency of \"%s\"\n"), missdepstring, tpkg->name); free(missdepstring); if(data) { *data = alpm_list_add(*data, miss); } ret = -1; } else { _alpm_log(handle, PM_LOG_DEBUG, "pulling dependency %s (needed by %s)\n", alpm_pkg_get_name(spkg), alpm_pkg_get_name(tpkg)); *packages = alpm_list_add(*packages, spkg); _alpm_depmiss_free(miss); } } alpm_list_free(deps); } if(ret != 0) { alpm_list_free(*packages); *packages = packages_copy; } else { alpm_list_free(packages_copy); } _alpm_log(handle, PM_LOG_DEBUG, "finished resolving dependencies\n"); return ret; }
/** * pacman_list_last: * @list: A #PacmanList. * * Finds the last entry in @list. * * Returns: An entry in a #PacmanList, or %NULL if @list is empty. */ PacmanList *pacman_list_last (const PacmanList *list) { return alpm_list_last (list); }