1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-15 06:29:22 +02:00

qpkg: rearrange things in prereq.c to free the stack paradigm for other uses

- prereq.c (stack, epoch, push, pop, resolve, prereq): renamed to
  "installs"
- prereq.c (n_stack, stack_max, push, pop, resolve, prereq): changed
  "stack" to "install"
- prereq.c (push): renamed "push" to "append_install"
- prereq.c (pop): renamed "pop" to "backtrack"
This commit is contained in:
Werner Almesberger 2010-11-21 08:12:14 -03:00
parent 89223833f1
commit d0a1a9e82f

View File

@ -30,10 +30,10 @@ struct list {
static struct pkg **best = NULL;
static struct pkg **stack = NULL;
static struct pkg **installs = NULL;
static int n_best; /* undefined if best == NULL */
static int n_stack = 0;
static int stack_max = 0;
static int n_install = 0;
static int install_max = 0;
static int epoch(const char **s, const struct id *id)
@ -98,40 +98,40 @@ static void done(void)
{
int size;
if (best && n_best <= n_stack)
if (best && n_best <= n_install)
return;
free(best);
size = sizeof(*stack)*(n_stack+1);
size = sizeof(*installs)*(n_install+1);
best = alloc_size(size);
memcpy(best, stack, sizeof(*stack)*n_stack);
n_best = n_stack;
memcpy(best, installs, sizeof(*installs)*n_install);
n_best = n_install;
best[n_best] = NULL;
}
static void push(struct pkg *pkg)
static void append_install(struct pkg *pkg)
{
//fprintf(stderr, "push %.*s\n", ID2PF(pkg->id));
if (n_stack == stack_max) {
stack_max = (stack_max+1)*2;
stack = realloc(stack, sizeof(*stack)*stack_max);
if (!stack) {
if (n_install == install_max) {
install_max = (install_max+1)*2;
installs = realloc(installs, sizeof(*installs)*install_max);
if (!installs) {
perror("realloc");
exit(1);
}
}
stack[n_stack++] = pkg;
installs[n_install++] = pkg;
assert(!pkg->mark && !(pkg->flags & QPKG_INSTALLED));
pkg->mark = 1;
}
static void pop(void)
static void backtrack(void)
{
assert(n_stack);
n_stack--;
stack[n_stack]->mark = 0;
assert(n_install);
n_install--;
installs[n_install]->mark = 0;
}
@ -186,7 +186,7 @@ static int level = 0;
next_dep = next_dep->next;
}
for (pkg = dep->pkg->jrb->val; pkg; pkg = pkg->more) {
if (best && n_stack == n_best)
if (best && n_install == n_best)
return;
#if 0
fprintf(stderr, "%*s", level, "");
@ -207,14 +207,14 @@ fprintf(stderr, "\n");
if (conflicts(pkg, conf))
continue;
level++;
push(pkg);
append_install(pkg);
more_deps.refs = pkg->depends;
more_deps.next = next_dep;
more_conf.refs = pkg->conflicts;
more_conf.next = conf;
resolve(&more_deps, dep->next, &more_conf);
next_dep = more_deps.next;
pop();
backtrack();
level--;
}
}
@ -229,13 +229,13 @@ struct pkg **prereq(struct pkg *pkg)
#if 0
/* make sure we don't return NULL if all dependencies are met */
if (!stack) {
stack = alloc_type(struct pkg *);
stack_max = 1;
if (!installs) {
installs = alloc_type(struct pkg *);
install_max = 1;
}
#endif
/* @@@ make list of pre-existing conflicts */
resolve(&deps, NULL, NULL);
free(stack);
free(installs);
return best;
}