2 * \file build/parseFiles.c
3 * Parse %files section from spec file.
8 #include <rpm/rpmlog.h>
9 #include <rpm/rpmfileutil.h>
10 #include "build/rpmbuild_internal.h"
13 int parseFiles(rpmSpec spec)
15 int nextPart, res = PART_ERROR;
19 const char ** argv = NULL;
20 const char *name = NULL;
21 int flag = PART_SUBNAME;
22 poptContext optCon = NULL;
23 struct poptOption optionsTable[] = {
24 { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
25 { NULL, 'f', POPT_ARG_STRING, NULL, 'f', NULL, NULL},
26 { 0, 0, 0, 0, 0, NULL, NULL}
29 /* XXX unmask %license while parsing %files */
30 rpmPushMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC);
32 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
33 rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"),
34 spec->lineNum, poptStrerror(rc));
38 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
39 while ((arg = poptGetNextOpt(optCon)) > 0) {
46 rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
48 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
53 if (poptPeekArg(optCon)) {
55 name = poptGetArg(optCon);
56 if (poptPeekArg(optCon)) {
57 rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
64 if (lookupPackage(spec, name, flag, &pkg))
68 * This should be an error, but its surprisingly commonly abused for the
69 * effect of multiple -f arguments in versions that dont support it.
70 * Warn but preserve behavior, except for leaking memory.
72 if (pkg->fileList != NULL) {
73 rpmlog(RPMLOG_WARNING, _("line %d: multiple %%files for package '%s'\n"),
74 spec->lineNum, rpmstrPoolStr(pkg->pool, pkg->name));
75 pkg->fileList = argvFree(pkg->fileList);
78 for (arg=1; arg<argc; arg++) {
79 if (rstreq(argv[arg], "-f") && argv[arg+1]) {
80 char *file = rpmGetPath(argv[arg+1], NULL);
81 argvAdd(&(pkg->fileFile), file);
86 pkg->fileList = argvNew();
88 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
93 while (! (nextPart = isPart(spec->line))) {
94 argvAdd(&(pkg->fileList), spec->line);
95 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
106 rpmPopMacro(NULL, "license");
108 poptFreeContext(optCon);