diff --git a/qpkg/Makefile b/qpkg/Makefile index 62afe7b..0f28a26 100644 --- a/qpkg/Makefile +++ b/qpkg/Makefile @@ -12,7 +12,7 @@ SHELL = /bin/bash -OBJS_qpkg = fixup.o gobble.o id.o prereq.o qpkg.o jrb.o +OBJS_qpkg = fixup.o gobble.o id.o pkg.o prereq.o qpkg.o jrb.o OBJS_rbtest = rbtest.o jrb.o OBJS = $(OBJS_qpkg) $(OBJS_rbtest) diff --git a/qpkg/fixup.c b/qpkg/fixup.c index 55e3d76..a9f481b 100644 --- a/qpkg/fixup.c +++ b/qpkg/fixup.c @@ -12,8 +12,10 @@ #include + #include "jrb.h" +#include "pkg.h" #include "qpkg.h" #include "fixup.h" diff --git a/qpkg/gobble.c b/qpkg/gobble.c index eb8bedd..307f80b 100644 --- a/qpkg/gobble.c +++ b/qpkg/gobble.c @@ -21,6 +21,7 @@ #include "util.h" #include "id.h" +#include "pkg.h" #include "qpkg.h" #include "gobble.h" @@ -123,8 +124,7 @@ static void finish_pkg(struct pkg *new, struct jrb *jrb) compact: jrb->val = new->more; old->flags |= new->flags; - /* @@@ we may leak a little */ - free(new); + free_pkg(new); } @@ -302,17 +302,8 @@ package: finish_pkg(pkg, jrb); WHITESPACE; - pkg = alloc_type(struct pkg); jrb = ID(packages); - pkg->id = jrb->key; - pkg->more = jrb->val; - jrb->val = pkg; - pkg->version = NULL; - pkg->arch = NULL; - pkg->conflicts = pkg->depends = NULL; - pkg->filename = NULL; - pkg->flags = 0; - pkg->mark = 0; + pkg = new_pkg(jrb); goto eol; version: diff --git a/qpkg/pkg.c b/qpkg/pkg.c new file mode 100644 index 0000000..8fe4511 --- /dev/null +++ b/qpkg/pkg.c @@ -0,0 +1,59 @@ +/* + * pkg.c - Package structure and operations + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include + +#include "util.h" +#include "jrb.h" +#include "pkg.h" + + + +struct pkg *new_pkg(struct jrb *jrb) +{ + struct pkg *pkg; + + pkg = alloc_type(struct pkg); + + pkg->id = jrb->key; + pkg->more = jrb->val; + jrb->val = pkg; + pkg->version = NULL; + pkg->arch = NULL; + pkg->conflicts = pkg->depends = NULL; + pkg->filename = NULL; + pkg->flags = 0; + pkg->mark = 0; + + return pkg; +} + + +static void free_refs(struct ref *refs) +{ + struct ref *next; + + while (refs) { + next = refs->next; + free(refs); + refs = next; + } +} + + +void free_pkg(struct pkg *pkg) +{ + free_refs(pkg->conflicts); + free_refs(pkg->depends); + free(pkg); +} diff --git a/qpkg/pkg.h b/qpkg/pkg.h new file mode 100644 index 0000000..d00f19c --- /dev/null +++ b/qpkg/pkg.h @@ -0,0 +1,60 @@ +/* + * pkg.h - Package structure and operations + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef PKG_H +#define PKG_H + +#include "jrb.h" + +#include "id.h" + + +enum flags { + /* parse-time flags */ + QPKG_INSTALLED = 1 << 0, /* installed on target */ + + /* run-time flags */ + QPKG_ADDING = 1 << 10, /* resolving dependencies */ +}; + +enum relop { + rel_eq, + rel_ge, + rel_lt, +}; + +struct pkg; + +struct ref { + struct id *pkg; + struct id *version; + enum relop relop; /* undefined if version == NULL */ + struct ref *next; +}; + +struct pkg { + struct id *id; + struct id *version; + const char *arch; + struct ref *conflicts; + struct ref *depends; + const char *filename; + int flags; /* see enum flags */ + struct pkg *more; + int mark; +}; + + +struct pkg *new_pkg(struct jrb *jrb); +void free_pkg(struct pkg *pkg); + +#endif /* !PKG_H */ diff --git a/qpkg/prereq.c b/qpkg/prereq.c index a99518b..22e7f40 100644 --- a/qpkg/prereq.c +++ b/qpkg/prereq.c @@ -18,6 +18,7 @@ #include "util.h" #include "id.h" +#include "pkg.h" #include "qpkg.h" #include "prereq.h" diff --git a/qpkg/qpkg.c b/qpkg/qpkg.c index ce428de..e0a8027 100644 --- a/qpkg/qpkg.c +++ b/qpkg/qpkg.c @@ -21,6 +21,7 @@ #include "prereq.h" #include "gobble.h" #include "fixup.h" +#include "pkg.h" #include "qpkg.h" diff --git a/qpkg/qpkg.h b/qpkg/qpkg.h index d0a1593..dd05ea2 100644 --- a/qpkg/qpkg.h +++ b/qpkg/qpkg.h @@ -16,42 +16,6 @@ #include "id.h" -enum flags { - /* parse-time flags */ - QPKG_INSTALLED = 1 << 0, /* installed on target */ - - /* run-time flags */ - QPKG_ADDING = 1 << 10, /* resolving dependencies */ -}; - -enum relop { - rel_eq, - rel_ge, - rel_lt, -}; - -struct pkg; - -struct ref { - struct id *pkg; - struct id *version; - enum relop relop; /* undefined if version == NULL */ - struct ref *next; -}; - -struct pkg { - struct id *id; - struct id *version; - const char *arch; - struct ref *conflicts; - struct ref *depends; - const char *filename; - int flags; /* see enum flags */ - struct pkg *more; - int mark; -}; - - struct tree *packages; struct tree *versions;