summaryrefslogtreecommitdiff
path: root/build/package.c
blob: 9184282a1eb01297532217b44533c725b59b4513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "spec.h"
#include "package.h"
#include "misc.h"
#include "rpmlib.h"
#include "files.h"

#include <malloc.h>

int lookupPackage(Spec spec, char *name, int flag, Package *pkg)
{
    char buf[BUFSIZ];
    char *n, *fullName;
    Package p;
    
    /* "main" package */
    if (! name) {
	if (pkg) {
	    *pkg = spec->packages;
	}
	return 0;
    }

    /* Construct package name */
    if (flag == PART_SUBNAME) {
	headerGetEntry(spec->packages->header, RPMTAG_NAME,
		       NULL, (void *) &n, NULL);
	sprintf(buf, "%s-%s", n, name);
	fullName = buf;
    } else {
	fullName = name;
    }

    p = spec->packages;
    while (p) {
	headerGetEntry(p->header, RPMTAG_NAME, NULL, (void *) &n, NULL);
	if (n && (! strcmp(fullName, n))) {
	    if (pkg) {
		*pkg = p;
	    }
	    return 0;
	}
	p = p->next;
    }

    if (pkg) {
	*pkg = NULL;
    }
    return 1;
}

Package newPackage(Spec spec)
{
    Package p;
    Package pp;

    p = malloc(sizeof(*p));

    p->header = headerNew();
    p->icon = NULL;
    p->autoReqProv = 1;
    
#if 0    
    p->reqProv = NULL;
    p->triggers = NULL;
    p->triggerScripts = NULL;
#endif
    
    p->fileFile = NULL;
    p->fileList = NULL;
    p->next = NULL;

    p->cpioList = NULL;
    p->cpioCount = 0;

    p->preInFile = NULL;
    p->postInFile = NULL;
    p->preUnFile = NULL;
    p->postUnFile = NULL;
    p->verifyFile = NULL;

    p->specialDoc = NULL;

    if (! spec->packages) {
	spec->packages = p;
    } else {
	/* Always add package to end of list */
	pp = spec->packages;
	while (pp->next) {
	    pp = pp->next;
	}
	pp->next = p;
    }

    return p;
}

void freePackages(Spec spec)
{
    Package p;

    while (spec->packages) {
	p = spec->packages;
	spec->packages = p->next;
	freePackage(p);
    }
}

void freePackage(Package p)
{
    if (! p) {
	return;
    }
    
    FREE(p->preInFile);
    FREE(p->postInFile);
    FREE(p->preUnFile);
    FREE(p->postUnFile);
    FREE(p->verifyFile);

    headerFree(p->header);
    freeStringBuf(p->fileList);
    FREE(p->fileFile);
    freeCpioList(p->cpioList, p->cpioCount);

    freeStringBuf(p->specialDoc);

    free(p);
}