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