pkg_t *satisfying_pkg =
pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
pkg_installed_and_constraint_satisfied,
- dependence_to_satisfy, 1, NULL);
+ dependence_to_satisfy, 1);
/* Being that I can't test constraing in pkg_hash, I will test it here */
if (satisfying_pkg != NULL) {
if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
pkg_t *satisfying_pkg =
pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
pkg_constraint_satisfied,
- dependence_to_satisfy, 1, NULL);
+ dependence_to_satisfy, 1);
/* Being that I can't test constraing in pkg_hash, I will test it here too */
if (satisfying_pkg != NULL) {
if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
{
int count;
char ** resized;
- char *depend_str = pkg_depend_str(pkg, ref_ndx);
count = 0;
while(the_lost && the_lost[count]) count++;
count++; /* need one to hold the null */
resized = xrealloc(the_lost, sizeof(char *) * (count + 1));
- resized[count - 1] = xstrdup(depend_str);
+ resized[count - 1] = pkg_depend_str(pkg, ref_ndx);
resized[count] = NULL;
return resized;
for(i = 0; i < pkg->pre_depends_count; i++){
parseDepends(depends, hash, pkg->pre_depends_str[i]);
+ free(pkg->pre_depends_str[i]);
depends->type = PREDEPEND;
depends++;
}
+ if (pkg->pre_depends_str)
+ free(pkg->pre_depends_str);
for(i = 0; i < pkg->depends_count; i++){
parseDepends(depends, hash, pkg->depends_str[i]);
+ free(pkg->depends_str[i]);
depends++;
}
+ if (pkg->depends_str)
+ free(pkg->depends_str);
for(i = 0; i < pkg->recommends_count; i++){
parseDepends(depends, hash, pkg->recommends_str[i]);
+ free(pkg->recommends_str[i]);
depends->type = RECOMMEND;
depends++;
}
+ if(pkg->recommends_str)
+ free(pkg->recommends_str);
for(i = 0; i < pkg->suggests_count; i++){
parseDepends(depends, hash, pkg->suggests_str[i]);
+ free(pkg->suggests_str[i]);
depends->type = SUGGEST;
depends++;
}
+ if(pkg->suggests_str)
+ free(pkg->suggests_str);
+}
+
+const char*
+constraint_to_str(enum version_constraint c)
+{
+ switch (c) {
+ case NONE:
+ return "";
+ case EARLIER:
+ return "< ";
+ case EARLIER_EQUAL:
+ return "<= ";
+ case EQUAL:
+ return "= ";
+ case LATER_EQUAL:
+ return ">= ";
+ case LATER:
+ return "> ";
+ }
+
+ return "";
}
/*
- * pkg_depend_string: returns the depends string specified by index.
- * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
- * [0,npredepends) -> returns pre_depends_str[index]
- * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
- * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
- * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
+ * Returns a printable string for pkg's dependency at the specified index. The
+ * resultant string must be passed to free() by the caller.
*/
-char *pkg_depend_str(pkg_t *pkg, int index)
+char *
+pkg_depend_str(pkg_t *pkg, int index)
{
- if (index < pkg->pre_depends_count) {
- return pkg->pre_depends_str[index];
- }
- index -= pkg->pre_depends_count;
+ int i, len;
+ char *str;
+ compound_depend_t *cdep;
+ depend_t *dep;
- if (index < pkg->depends_count) {
- return pkg->depends_str[index];
- }
- index -= pkg->depends_count;
+ len = 0;
+ cdep = &pkg->depends[index];
- if (index < pkg->recommends_count) {
- return pkg->recommends_str[index];
- }
- index -= pkg->recommends_count;
+ /* calculate string length */
+ for (i=0; i<cdep->possibility_count; i++) {
+ dep = cdep->possibilities[i];
- if (index < pkg->suggests_count) {
- return pkg->suggests_str[index];
- }
+ if (i != 0)
+ len += 3; /* space, pipe, space */
+
+ len += strlen(dep->pkg->name);
+
+ if (dep->version) {
+ len += 2; /* space, left parenthesis */
+ len += 3; /* constraint string (<=, >=, etc), space */
+ len += strlen(dep->version);
+ len += 1; /* right parenthesis */
+ }
+ }
+
+ str = xmalloc(len + 1); /* +1 for the NULL terminator */
+ str[0] = '\0';
+
+ for (i=0; i<cdep->possibility_count; i++) {
+ dep = cdep->possibilities[i];
+
+ if (i != 0)
+ strncat(str, " | ", len);
+
+ strncat(str, dep->pkg->name, len);
+
+ if (dep->version) {
+ strncat(str, " (", len);
+ strncat(str, constraint_to_str(dep->constraint), len);
+ strncat(str, dep->version, len);
+ strncat(str, ")", len);
+ }
+ }
- fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
- return NULL;
+ return str;
}
/*