2 * \file build/parseFiles.c
3 * Parse %files section from spec file.
8 #include <rpm/rpmbuild.h>
9 #include <rpm/rpmlog.h>
10 #include <rpm/rpmfileutil.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 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
30 rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"),
31 spec->lineNum, poptStrerror(rc));
35 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
36 while ((arg = poptGetNextOpt(optCon)) > 0) {
43 rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
45 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
50 if (poptPeekArg(optCon)) {
52 name = poptGetArg(optCon);
53 if (poptPeekArg(optCon)) {
54 rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
61 if (lookupPackage(spec, name, flag, &pkg)) {
62 rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
63 spec->lineNum, spec->line);
67 for (arg=1; arg<argc; arg++) {
68 if (rstreq(argv[arg], "-f") && argv[arg+1]) {
69 char *file = rpmGetPath(argv[arg+1], NULL);
70 if (!pkg->fileFile) pkg->fileFile = newStringBuf();
71 appendLineStringBuf(pkg->fileFile, file);
76 pkg->fileList = newStringBuf();
78 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
83 while (! (nextPart = isPart(spec->line))) {
84 appendStringBuf(pkg->fileList, spec->line);
85 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
97 optCon = poptFreeContext(optCon);