[pacman-dev] [PATCH 1/6] Split optdep into alpm_depend_t and description
Benedikt Morbach
benedikt.morbach at googlemail.com
Thu Jul 21 14:39:22 EDT 2011
This is done as a preparation to better handle optdepends.
This commit should not change pacman's behaviour, as it simply adds new
functions and data structures and doesn't yet hook them up anywhere.
---
lib/libalpm/alpm.h | 12 +++++++++
lib/libalpm/deps.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/libalpm/deps.h | 3 ++
3 files changed, 85 insertions(+), 0 deletions(-)
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 6e1e4bc..21f65a1 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -130,6 +130,12 @@ typedef struct _alpm_depend_t {
alpm_depmod_t mod;
} alpm_depend_t;
+/** Optional dependency */
+typedef struct _alpm_optdepend_t {
+ alpm_depend_t *depend;
+ char *description;
+} alpm_optdepend_t;
+
/** Missing dependency */
typedef struct _alpm_depmissing_t {
char *target;
@@ -1021,6 +1027,12 @@ alpm_list_t *alpm_checkconflicts(alpm_handle_t *handle, alpm_list_t *pkglist);
*/
char *alpm_dep_compute_string(const alpm_depend_t *dep);
+/** Returns a newly allocated string representing the optional dependency information.
+ * @param dep a optional dependency info structure
+ * @return a formatted string, e.g. "sqlite: for Database support"
+ */
+char *alpm_optdep_compute_string(const alpm_optdepend_t *optdep);
+
/** @} */
/** @} */
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index c3681b3..2f4f53a 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -44,6 +44,13 @@ void _alpm_dep_free(alpm_depend_t *dep)
FREE(dep);
}
+void _alpm_optdep_free(alpm_optdepend_t *optdep)
+{
+ _alpm_dep_free(optdep->depend);
+ FREE(optdep->description);
+ FREE(optdep);
+}
+
static alpm_depmissing_t *depmiss_new(const char *target, alpm_depend_t *dep,
const char *causingpkg)
{
@@ -466,6 +473,44 @@ alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
return newdep;
}
+alpm_optdepend_t *_alpm_splitoptdep(const char *optstring)
+{
+ alpm_optdepend_t *optdep;
+ char *depstring;
+ const char *descstring;
+
+ ASSERT(optstring != NULL, return NULL);
+
+ CALLOC(optdep, 1, sizeof(alpm_optdepend_t), return NULL);
+
+ if ((descstring = strstr(optstring, ":")) == NULL) {
+ descstring = optstring + strlen(optstring);
+ }
+
+ STRNDUP(depstring, optstring, descstring - optstring, return NULL);
+ optdep->depend = _alpm_splitdep(depstring);
+ FREE(depstring);
+
+ if (*descstring == '\0') {
+ optdep->description = NULL;
+ } else {
+ STRDUP(optdep->description, descstring + 1, return NULL);
+ }
+
+ return optdep;
+}
+
+alpm_optdepend_t *_alpm_optdep_dup(const alpm_optdepend_t *optdep)
+{
+ alpm_optdepend_t *newdep;
+ CALLOC(newdep, 1, sizeof(alpm_optdepend_t), return NULL);
+
+ newdep->depend = _alpm_dep_dup(optdep->depend);
+ STRDUP(newdep->description, optdep->description, return NULL);
+
+ return newdep;
+}
+
/* These parameters are messy. We check if this package, given a list of
* targets and a db is safe to remove. We do NOT remove it if it is in the
* target list, or if if the package was explictly installed and
@@ -820,4 +865,29 @@ char SYMEXPORT *alpm_dep_compute_string(const alpm_depend_t *dep)
return str;
}
+
+/** Reverse of splitoptdep; make a optdep string from a alpm_optdepend_t struct.
+ * The string must be freed!
+ * @param optdep the optdepend to turn into a string
+ * @return a string-formatted optional dependency with description
+ */
+char SYMEXPORT *alpm_optdep_compute_string(const alpm_optdepend_t *optdep)
+{
+ char *str, *depstring;
+ size_t len;
+
+ ASSERT(optdep != NULL, return NULL);
+
+ depstring = alpm_dep_compute_string(optdep->depend);
+
+ if(optdep->description != NULL) {
+ len = strlen(depstring) + strlen(optdep->description) + 2;
+ MALLOC(str, len, return NULL);
+ snprintf(str, len, "%s:%s", depstring, optdep->description);
+ FREE(depstring);
+ return str;
+ } else {
+ return depstring;
+ }
+}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
index 6ef4cbb..acdd25a 100644
--- a/lib/libalpm/deps.h
+++ b/lib/libalpm/deps.h
@@ -28,7 +28,9 @@
#include "alpm.h"
void _alpm_dep_free(alpm_depend_t *dep);
+void _alpm_optdep_free(alpm_optdepend_t *optdep);
alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep);
+alpm_optdepend_t *_alpm_optdep_dup(const alpm_optdepend_t *optdep);
void _alpm_depmiss_free(alpm_depmissing_t *miss);
alpm_list_t *_alpm_sortbydeps(alpm_handle_t *handle, alpm_list_t *targets, int reverse);
void _alpm_recursedeps(alpm_db_t *db, alpm_list_t *targs, int include_explicit);
@@ -36,6 +38,7 @@ int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs, alpm_pkg_t
alpm_list_t *preferred, alpm_list_t **packages, alpm_list_t *remove,
alpm_list_t **data);
alpm_depend_t *_alpm_splitdep(const char *depstring);
+alpm_optdepend_t *_alpm_splitoptdep(const char *optstring);
int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep);
#endif /* _ALPM_DEPS_H */
--
1.7.6
More information about the pacman-dev
mailing list