summaryrefslogtreecommitdiff
path: root/lib/libalpm/deps.c
diff options
context:
space:
mode:
authorNagy Gabor <ngaba@bibl.u-szeged.hu>2007-10-25 02:31:28 +0200
committerDan McGee <dan@archlinux.org>2007-10-25 07:10:08 -0500
commit0cff7c6bdf5461c3286edc940aabb88d63345381 (patch)
tree18f5a1febd6c25155c2680e77767b62634b50bf9 /lib/libalpm/deps.c
parent89ac8aa9c45486aa4f4b9599bb094f1d54ff1b66 (diff)
downloadpacman-0cff7c6bdf5461c3286edc940aabb88d63345381.tar.xz
Add alpm_dep_get_string method
Public alpm_dep_get_string function is introduced, which converts a pmdepend_t structure to printable string in %DEPENDS% format. This function is now used in pacman to print dependency error messages. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/deps.c')
-rw-r--r--lib/libalpm/deps.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 69c675cd..7f4fb0b5 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -838,4 +838,38 @@ const char SYMEXPORT *alpm_dep_get_version(pmdepend_t *dep)
return dep->version;
}
+/* the return-string must be freed! */
+char SYMEXPORT *alpm_dep_get_string(pmdepend_t *dep)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(dep != NULL, return(NULL));
+
+ char *ptr;
+ char *depstring = malloc(sizeof(pmdepend_t));
+ if(depstring == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepend_t));
+ return NULL;
+ }
+
+ strcpy(depstring, dep->name);
+ ptr = depstring + strlen(depstring);
+ switch(dep->mod) {
+ case PM_DEP_MOD_ANY:
+ break;
+ case PM_DEP_MOD_EQ:
+ sprintf(ptr, "=%s", dep->version);
+ break;
+ case PM_DEP_MOD_GE:
+ sprintf(ptr, ">=%s", dep->version);
+ break;
+ case PM_DEP_MOD_LE:
+ sprintf(ptr, "<=%s", dep->version);
+ break;
+ }
+
+ return(depstring);
+}
/* vim: set ts=2 sw=2 noet: */