1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-25 04:58:26 +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 #define DONE goto done
static void compact_pkg(struct pkg *new) static void compact_pkg(struct pkg *new, struct jrb *jrb)
{ {
struct pkg *old; struct pkg *old;
@ -102,7 +102,7 @@ static void compact_pkg(struct pkg *new)
return; return;
compact: compact:
new->id->jrb->val = new->more; jrb->val = new->more;
old->flags |= new->flags; old->flags |= new->flags;
/* @@@ we may leak a little */ /* @@@ we may leak a little */
free(new); free(new);
@ -114,6 +114,7 @@ static void gobble_buf(const char *name, const char *buf, size_t len)
const char *end = buf+len; const char *end = buf+len;
int lineno = 1; int lineno = 1;
struct pkg *pkg = NULL; /* current package */ struct pkg *pkg = NULL; /* current package */
struct jrb *jrb = NULL; /* RB tree node of current package */
struct ref **anchor = NULL; struct ref **anchor = NULL;
int i, failed_at = 0; int i, failed_at = 0;
@ -280,13 +281,14 @@ depends:
package: package:
if (pkg) if (pkg)
compact_pkg(pkg); compact_pkg(pkg, jrb);
WHITESPACE; WHITESPACE;
pkg = alloc_type(struct pkg); pkg = alloc_type(struct pkg);
pkg->id = ID(packages); jrb = ID(packages);
pkg->more = pkg->id->jrb->val; pkg->id = jrb->key;
pkg->id->jrb->val = pkg; pkg->more = jrb->val;
jrb->val = pkg;
pkg->version = NULL; pkg->version = NULL;
pkg->conflicts = pkg->depends = NULL; pkg->conflicts = pkg->depends = NULL;
pkg->filename = NULL; pkg->filename = NULL;
@ -298,7 +300,7 @@ version:
WHITESPACE; WHITESPACE;
if (pkg->version) if (pkg->version)
FAIL; FAIL;
pkg->version = ID(versions); pkg->version = ID(versions)->key;
goto eol; goto eol;
provides: provides:
@ -350,7 +352,7 @@ list_with_version:
WHITESPACE; WHITESPACE;
ref = alloc_type(struct ref); ref = alloc_type(struct ref);
ref->pkg = ID(packages); ref->pkg = ID(packages)->key;
/* /*
* Work around the Wireshark Anomaly * Work around the Wireshark Anomaly
@ -380,7 +382,7 @@ list_with_version:
FAIL; FAIL;
} }
WHITESPACE; WHITESPACE;
ref->version = ID(versions); ref->version = ID(versions)->key;
EXPECT(")"); EXPECT(")");
} }
ref->next = *anchor; ref->next = *anchor;
@ -396,7 +398,7 @@ list_with_version:
done: done:
if (pkg) if (pkg)
compact_pkg(pkg); compact_pkg(pkg, jrb);
return; return;
fail: 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; struct id *id;
@ -60,10 +60,9 @@ struct id *make_id(struct tree *tree, const char *s, size_t len)
id->s = s; id->s = s;
id->len = len; id->len = len;
id->jrb = jrb_find_or_insert(tree->root, id, NULL, tree->comp); id->jrb = jrb_find_or_insert(tree->root, id, NULL, tree->comp);
if (id->jrb->key != id) if (id->jrb->key == id)
return id->jrb->key;
free_id = NULL; 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); int comp_id(const void *a, const void *b);
struct tree *make_tree(int (*comp)(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); const struct jrb *find_id(const struct tree *tree, const char *s, size_t len);
#endif /* !ID_H */ #endif /* !ID_H */