#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "deps.h"
#include "alpm_list.h"
#include "util.h"
#include "log.h"
#include "error.h"
#include "package.h"
#include "db.h"
#include "cache.h"
#include "handle.h"
static pmgraph_t *_alpm_graph_new(void)
{
pmgraph_t *graph = NULL;
MALLOC(graph, sizeof(pmgraph_t), RET_ERR(PM_ERR_MEMORY, NULL));
if(graph) {
graph->state = 0;
graph->data = NULL;
graph->parent = NULL;
graph->children = NULL;
graph->childptr = NULL;
}
return(graph);
}
static void _alpm_graph_free(void *data)
{
pmgraph_t *graph = data;
alpm_list_free(graph->children);
free(graph);
}
pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepmod_t depmod,
const char *depname, const char *depversion)
{
pmdepmissing_t *miss;
ALPM_LOG_FUNC;
MALLOC(miss, sizeof(pmdepmissing_t), RET_ERR(PM_ERR_MEMORY, NULL));
strncpy(miss->target, target, PKG_NAME_LEN);
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);
}
static alpm_list_t *_alpm_graph_init(alpm_list_t *targets)
{
alpm_list_t *i, *j, *k;
alpm_list_t *vertices = NULL;
for(i = targets; i; i = i->next) {
pmgraph_t *vertex = _alpm_graph_new();
vertex->data = (void *)i->data;
vertices = alpm_list_add(vertices, vertex);
}
for(i = vertices; i; i = i->next) {
pmgraph_t *vertex_i = i->data;
pmpkg_t *p_i = vertex_i->data;
TODO
for(j = vertices; j; j = j->next) {
pmgraph_t *vertex_j = j->data;
pmpkg_t *p_j = vertex_j->data;
int child = 0;
for(k = alpm_pkg_get_depends(p_i); k && !child; k = k->next) {
pmdepend_t *depend = k->data;
child = alpm_depcmp(p_j, depend);
}
if(child) {
vertex_i->children =
alpm_list_add(vertex_i->children, vertex_j);
}
}
vertex_i->childptr = vertex_i->children;
}
return(vertices);
}
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
{
alpm_list_t *newtargs = NULL;
alpm_list_t *vertices = NULL;
alpm_list_t *vptr;
pmgraph_t *vertex;
ALPM_LOG_FUNC;
if(targets == NULL) {
return(NULL);
}
_alpm_log(PM_LOG_DEBUG, "started sorting dependencies\n");
vertices = _alpm_graph_init(targets);
vptr = vertices;
vertex = vertices->data;
|