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
|
/** \ingroup rpmbuild
* \file build/parseFiles.c
* Parse %files section from spec file.
*/
#include "system.h"
#include "rpmbuild.h"
/* These have to be global scope to make up for *stupid* compilers */
/*@observer@*/ /*@null@*/ static const char *name = NULL;
/*@observer@*/ /*@null@*/ static const char *file = NULL;
static struct poptOption optionsTable[] = {
{ NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
{ NULL, 'f', POPT_ARG_STRING, &file, 'f', NULL, NULL},
{ 0, 0, 0, 0, 0, NULL, NULL}
};
int parseFiles(Spec spec)
{
int nextPart;
Package pkg;
int rc, argc;
int arg;
const char **argv = NULL;
int flag = PART_SUBNAME;
poptContext optCon = NULL;
name = file = NULL;
if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%files: %s"),
spec->lineNum, poptStrerror(rc));
rc = RPMERR_BADSPEC;
goto exit;
}
optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
while ((arg = poptGetNextOpt(optCon)) > 0) {
if (arg == 'n') {
flag = PART_NAME;
}
}
if (arg < -1) {
rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s"),
spec->lineNum,
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
spec->line);
rc = RPMERR_BADSPEC;
goto exit;
}
if (poptPeekArg(optCon)) {
if (name == NULL)
name = poptGetArg(optCon);
if (poptPeekArg(optCon)) {
rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s"),
spec->lineNum,
spec->line);
rc = RPMERR_BADSPEC;
goto exit;
}
}
if (lookupPackage(spec, name, flag, &pkg)) {
rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s"),
spec->lineNum, spec->line);
rc = RPMERR_BADSPEC;
goto exit;
}
if (pkg->fileList != NULL) {
rpmError(RPMERR_BADSPEC, _("line %d: Second %%files list"),
spec->lineNum);
rc = RPMERR_BADSPEC;
goto exit;
}
if (file) {
/* XXX not necessary as readline has expanded already, but won't hurt. */
pkg->fileFile = rpmGetPath(file, NULL);
}
pkg->fileList = newStringBuf();
if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
nextPart = PART_NONE;
} else {
if (rc)
goto exit;
while (! (nextPart = isPart(spec->line))) {
appendStringBuf(pkg->fileList, spec->line);
if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
nextPart = PART_NONE;
break;
}
if (rc)
goto exit;
}
}
rc = nextPart;
exit:
if (argv)
FREE(argv);
if (optCon)
poptFreeContext(optCon);
return rc;
}
|