1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-24 23:45:20 +02:00

qpkg: towards "struct id" without jrb reference - change ID creation

- id.h, id.c (make_id): return a "struct jrb *", so that we have access to
  key and value
- gobble.c (ID, gobble_buf): adapt to above change
- gobble.c (compact_pkg, gobble_buf): keep the RB node reference instead
  of awkwardly regenerating it via pkg->id->jrb
This commit is contained in:
Werner Almesberger 2010-11-21 03:07:48 -03:00
parent 7058115a64
commit 44e4434b4c
3 changed files with 17 additions and 16 deletions

View File

@ -92,7 +92,7 @@
#define DONE goto done
static void compact_pkg(struct pkg *new)
static void compact_pkg(struct pkg *new, struct jrb *jrb)
{
struct pkg *old;
@ -102,7 +102,7 @@ static void compact_pkg(struct pkg *new)
return;
compact:
new->id->jrb->val = new->more;
jrb->val = new->more;
old->flags |= new->flags;
/* @@@ we may leak a little */
free(new);
@ -114,6 +114,7 @@ static void gobble_buf(const char *name, const char *buf, size_t len)
const char *end = buf+len;
int lineno = 1;
struct pkg *pkg = NULL; /* current package */
struct jrb *jrb = NULL; /* RB tree node of current package */
struct ref **anchor = NULL;
int i, failed_at = 0;
@ -280,13 +281,14 @@ depends:
package:
if (pkg)
compact_pkg(pkg);
compact_pkg(pkg, jrb);
WHITESPACE;
pkg = alloc_type(struct pkg);
pkg->id = ID(packages);
pkg->more = pkg->id->jrb->val;
pkg->id->jrb->val = pkg;
jrb = ID(packages);
pkg->id = jrb->key;
pkg->more = jrb->val;
jrb->val = pkg;
pkg->version = NULL;
pkg->conflicts = pkg->depends = NULL;
pkg->filename = NULL;
@ -298,7 +300,7 @@ version:
WHITESPACE;
if (pkg->version)
FAIL;
pkg->version = ID(versions);
pkg->version = ID(versions)->key;
goto eol;
provides:
@ -350,7 +352,7 @@ list_with_version:
WHITESPACE;
ref = alloc_type(struct ref);
ref->pkg = ID(packages);
ref->pkg = ID(packages)->key;
/*
* Work around the Wireshark Anomaly
@ -380,7 +382,7 @@ list_with_version:
FAIL;
}
WHITESPACE;
ref->version = ID(versions);
ref->version = ID(versions)->key;
EXPECT(")");
}
ref->next = *anchor;
@ -396,7 +398,7 @@ list_with_version:
done:
if (pkg)
compact_pkg(pkg);
compact_pkg(pkg, jrb);
return;
fail:

View File

@ -50,7 +50,7 @@ struct tree *make_tree(int (*comp)(const void *a, const void *b))
}
struct id *make_id(struct tree *tree, const char *s, size_t len)
struct jrb *make_id(struct tree *tree, const char *s, size_t len)
{
struct id *id;
@ -60,10 +60,9 @@ struct id *make_id(struct tree *tree, const char *s, size_t len)
id->s = s;
id->len = len;
id->jrb = jrb_find_or_insert(tree->root, id, NULL, tree->comp);
if (id->jrb->key != id)
return id->jrb->key;
if (id->jrb->key == id)
free_id = NULL;
return id;
return id->jrb;
}

View File

@ -62,7 +62,7 @@ struct id {
int comp_id(const void *a, const void *b);
struct tree *make_tree(int (*comp)(const void *a, const void *b));
struct id *make_id(struct tree *tree, const char *s, size_t len);
struct jrb *make_id(struct tree *tree, const char *s, size_t len);
const struct jrb *find_id(const struct tree *tree, const char *s, size_t len);
#endif /* !ID_H */