Date:2010-11-22 20:19:32 (8 years 11 months ago)
Author:Werner Almesberger
Commit:bbf9c42bc8ab2b71f1d7933d2f967dbc05ac0524
Message:qpkg: move "struct pkg" and its allocation from gobble.c and qpkg.h to pkg.[hc]

- Makefile (OBJS_qpkg): added pkg.o
- gobble.c (gobble_buf): moved "struct pkg" allocation to function new_pkg
in pkg.c
- qpkg.h: moved "struct pkg" and subordinate structures to pkg.h
- pkg.h, pkg.c (new_pkg, free_pkg): provide package structure definition,
allocation, and deallocation
- fixup.c, gobble.c, prereq.c, qpkg.c: include "pkg.h"
- gobble.c (finish_pkg): use free_pkg instead of just "free" to avoid
leaking memory
Files: qpkg/Makefile (1 diff)
qpkg/fixup.c (1 diff)
qpkg/gobble.c (3 diffs)
qpkg/pkg.c (1 diff)
qpkg/pkg.h (1 diff)
qpkg/prereq.c (1 diff)
qpkg/qpkg.c (1 diff)
qpkg/qpkg.h (1 diff)

Change Details

qpkg/Makefile
1212
1313SHELL = /bin/bash
1414
15OBJS_qpkg = fixup.o gobble.o id.o prereq.o qpkg.o jrb.o
15OBJS_qpkg = fixup.o gobble.o id.o pkg.o prereq.o qpkg.o jrb.o
1616OBJS_rbtest = rbtest.o jrb.o
1717OBJS = $(OBJS_qpkg) $(OBJS_rbtest)
1818
qpkg/fixup.c
1212
1313
1414#include <stdio.h>
15
1516#include "jrb.h"
1617
18#include "pkg.h"
1719#include "qpkg.h"
1820#include "fixup.h"
1921
qpkg/gobble.c
2121
2222#include "util.h"
2323#include "id.h"
24#include "pkg.h"
2425#include "qpkg.h"
2526#include "gobble.h"
2627
...... 
123124compact:
124125    jrb->val = new->more;
125126    old->flags |= new->flags;
126    /* @@@ we may leak a little */
127    free(new);
127    free_pkg(new);
128128}
129129
130130
...... 
302302        finish_pkg(pkg, jrb);
303303
304304    WHITESPACE;
305    pkg = alloc_type(struct pkg);
306305    jrb = ID(packages);
307    pkg->id = jrb->key;
308    pkg->more = jrb->val;
309    jrb->val = pkg;
310    pkg->version = NULL;
311    pkg->arch = NULL;
312    pkg->conflicts = pkg->depends = NULL;
313    pkg->filename = NULL;
314    pkg->flags = 0;
315    pkg->mark = 0;
306    pkg = new_pkg(jrb);
316307    goto eol;
317308
318309version:
qpkg/pkg.c
1/*
2 * pkg.c - Package structure and operations
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdlib.h>
15
16#include "util.h"
17#include "jrb.h"
18#include "pkg.h"
19
20
21
22struct pkg *new_pkg(struct jrb *jrb)
23{
24    struct pkg *pkg;
25
26    pkg = alloc_type(struct pkg);
27
28    pkg->id = jrb->key;
29    pkg->more = jrb->val;
30    jrb->val = pkg;
31    pkg->version = NULL;
32    pkg->arch = NULL;
33    pkg->conflicts = pkg->depends = NULL;
34    pkg->filename = NULL;
35    pkg->flags = 0;
36    pkg->mark = 0;
37
38    return pkg;
39}
40
41
42static void free_refs(struct ref *refs)
43{
44    struct ref *next;
45
46    while (refs) {
47        next = refs->next;
48        free(refs);
49        refs = next;
50    }
51}
52
53
54void free_pkg(struct pkg *pkg)
55{
56    free_refs(pkg->conflicts);
57    free_refs(pkg->depends);
58    free(pkg);
59}
qpkg/pkg.h
1/*
2 * pkg.h - Package structure and operations
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#ifndef PKG_H
14#define PKG_H
15
16#include "jrb.h"
17
18#include "id.h"
19
20
21enum flags {
22    /* parse-time flags */
23    QPKG_INSTALLED = 1 << 0, /* installed on target */
24
25    /* run-time flags */
26    QPKG_ADDING = 1 << 10, /* resolving dependencies */
27};
28
29enum relop {
30    rel_eq,
31    rel_ge,
32    rel_lt,
33};
34
35struct pkg;
36
37struct ref {
38    struct id *pkg;
39    struct id *version;
40    enum relop relop; /* undefined if version == NULL */
41    struct ref *next;
42};
43
44struct pkg {
45    struct id *id;
46    struct id *version;
47    const char *arch;
48    struct ref *conflicts;
49    struct ref *depends;
50    const char *filename;
51    int flags; /* see enum flags */
52    struct pkg *more;
53    int mark;
54};
55
56
57struct pkg *new_pkg(struct jrb *jrb);
58void free_pkg(struct pkg *pkg);
59
60#endif /* !PKG_H */
qpkg/prereq.c
1818
1919#include "util.h"
2020#include "id.h"
21#include "pkg.h"
2122#include "qpkg.h"
2223#include "prereq.h"
2324
qpkg/qpkg.c
2121#include "prereq.h"
2222#include "gobble.h"
2323#include "fixup.h"
24#include "pkg.h"
2425#include "qpkg.h"
2526
2627
qpkg/qpkg.h
1616#include "id.h"
1717
1818
19enum flags {
20    /* parse-time flags */
21    QPKG_INSTALLED = 1 << 0, /* installed on target */
22
23    /* run-time flags */
24    QPKG_ADDING = 1 << 10, /* resolving dependencies */
25};
26
27enum relop {
28    rel_eq,
29    rel_ge,
30    rel_lt,
31};
32
33struct pkg;
34
35struct ref {
36    struct id *pkg;
37    struct id *version;
38    enum relop relop; /* undefined if version == NULL */
39    struct ref *next;
40};
41
42struct pkg {
43    struct id *id;
44    struct id *version;
45    const char *arch;
46    struct ref *conflicts;
47    struct ref *depends;
48    const char *filename;
49    int flags; /* see enum flags */
50    struct pkg *more;
51    int mark;
52};
53
54
5519struct tree *packages;
5620struct tree *versions;
5721

Archive Download the corresponding diff file

Branches:
master



interactive