#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "util.h"
#include "log.h"
#include "error.h"
#include "list.h"
#include "package.h"
#include "db.h"
#include "cache.h"
#include "provide.h"
#include "deps.h"
#include "versioncmp.h"
#include "handle.h"
extern pmhandle_t *handle;
pmdepmissing_t *_alpm_depmiss_new(const char *target, unsigned char type, unsigned char depmod,
const char *depname, const char *depversion)
{
pmdepmissing_t *miss;
miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t));
if(miss == NULL) {
_alpm_log(PM_LOG_ERROR, "malloc failure: could not allocate %d bytes", sizeof(pmdepmissing_t));
RET_ERR(PM_ERR_MEMORY, NULL);
}
STRNCPY(miss->target, target, PKG_NAME_LEN);
miss->type = type;
miss->depend.mod = depmod;
STRNCPY(miss->depend.name, depname, PKG_NAME_LEN);
if(depversion) {
STRNCPY(miss->depend.version, depversion, PKG_VERSION_LEN);
} else {
miss->depend.version[0] = 0;
}
return(miss);
}
int _alpm_depmiss_isin(pmdepmissing_t *needle, PMList *haystack)
{
PMList *i;
for(i = haystack; i; i = i->next) {
pmdepmissing_t *miss = i->data;
if(!memcmp(needle, miss, sizeof(pmdepmissing_t))
&& !memcmp(&needle->depend, &miss->depend, sizeof(pmdepend_t))) {
return(1);
}
}
return(0);
}
PMList *_alpm_sortbydeps(PMList *targets, int mode)
{
PMList *newtargs = NULL;
PMList *i, *j, *k;
int change = 1;
int numscans = 0;
int numtargs = 0;
if(targets == NULL) {
return(NULL);
}
for(i = targets; i; i = i->next) {
newtargs = _alpm_list_add(newtargs, i->data);
numtargs++;
}
while(change) {
PMList *tmptargs = NULL;
change = 0;
if(numscans > numtargs) {
_alpm_log(PM_LOG_WARNING, "possible dependency cycle detected");
continue;
}
numscans++;
for(i = newtargs; i; i = i->next) {
pmpkg_t *p = (pmpkg_t*)i->data;
for(j = p->depends; j; j = j->next) {
pmdepend_t dep;
pmpkg_t *q = NULL;
if(_alpm_splitdep(j->data, &dep)) {
continue;
}
for(k = i->next; k; k = k->next) {
q = (pmpkg_t *)k->data;
if(!strcmp(dep.name, q->name)) {
if(!_alpm_pkg_isin(q->name, tmptargs)) {
change = 1;
tmptargs = _alpm_list_add(tmptargs, q);
}
break;
}
}
}
if(!_alpm_pkg_isin(p->name, tmptargs)) {
tmptargs = _alpm_list_add(tmptargs, p);
}
}
FREELISTPTR(newtargs);
newtargs = tmptargs;
}
if(mode == PM_TRANS_TYPE_REMOVE) {
|