1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

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>
This commit is contained in:
Nagy Gabor 2007-10-25 02:31:28 +02:00 committed by Dan McGee
parent 89ac8aa9c4
commit 0cff7c6bdf
5 changed files with 44 additions and 31 deletions

View File

@ -379,6 +379,7 @@ pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss);
pmdepmod_t alpm_dep_get_mod(pmdepend_t *dep);
const char *alpm_dep_get_name(pmdepend_t *dep);
const char *alpm_dep_get_version(pmdepend_t *dep);
char *alpm_dep_get_string(pmdepend_t *dep);
/*
* File conflicts

View File

@ -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: */

View File

@ -137,26 +137,14 @@ int pacman_add(alpm_list_t *targets)
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
pmdepend_t *dep = alpm_miss_get_dep(miss);
char *depstring = alpm_dep_get_string(dep);
/* TODO indicate if the error was a virtual package or not:
* :: %s: requires %s, provided by %s
*/
printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
alpm_dep_get_name(dep));
switch(alpm_dep_get_mod(dep)) {
case PM_DEP_MOD_ANY:
break;
case PM_DEP_MOD_EQ:
printf("=%s", alpm_dep_get_version(dep));
break;
case PM_DEP_MOD_GE:
printf(">=%s", alpm_dep_get_version(dep));
break;
case PM_DEP_MOD_LE:
printf("<=%s", alpm_dep_get_version(dep));
break;
}
printf("\n");
depstring);
free(depstring);
}
break;
case PM_ERR_CONFLICTING_DEPS:

View File

@ -129,8 +129,10 @@ int pacman_remove(alpm_list_t *targets)
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
pmdepend_t *dep = alpm_miss_get_dep(miss);
char *depstring = alpm_dep_get_string(dep);
printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
alpm_dep_get_name(dep));
depstring);
free(depstring);
}
alpm_list_free(data);
break;

View File

@ -559,22 +559,10 @@ int sync_trans(alpm_list_t *targets, int sync_only)
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
pmdepend_t *dep = alpm_miss_get_dep(miss);
char *depstring = alpm_dep_get_string(dep);
printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
alpm_dep_get_name(dep));
switch(alpm_dep_get_mod(dep)) {
case PM_DEP_MOD_ANY:
break;
case PM_DEP_MOD_EQ:
printf("=%s", alpm_dep_get_version(dep));
break;
case PM_DEP_MOD_GE:
printf(">=%s", alpm_dep_get_version(dep));
break;
case PM_DEP_MOD_LE:
printf("<=%s", alpm_dep_get_version(dep));
break;
}
printf("\n");
depstring);
free(depstring);
}
break;
case PM_ERR_CONFLICTING_DEPS: