1 /** \file build/parseFiles.c
2 * Parse %files section from spec file.
9 /* These have to be global scope to make up for *stupid* compilers */
10 /*@observer@*/ /*@null@*/ static const char *name = NULL;
11 /*@observer@*/ /*@null@*/ static const char *file = NULL;
12 static struct poptOption optionsTable[] = {
13 { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
14 { NULL, 'f', POPT_ARG_STRING, &file, 'f', NULL, NULL},
15 { 0, 0, 0, 0, 0, NULL, NULL}
19 int parseFiles(Spec spec)
25 const char **argv = NULL;
26 int flag = PART_SUBNAME;
27 poptContext optCon = NULL;
31 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
32 rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%files: %s"),
33 spec->lineNum, poptStrerror(rc));
38 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
39 while ((arg = poptGetNextOpt(optCon)) > 0) {
46 rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s"),
48 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
54 if (poptPeekArg(optCon)) {
56 name = poptGetArg(optCon);
57 if (poptPeekArg(optCon)) {
58 rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s"),
66 if (lookupPackage(spec, name, flag, &pkg)) {
67 rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s"),
68 spec->lineNum, spec->line);
73 if (pkg->fileList != NULL) {
74 rpmError(RPMERR_BADSPEC, _("line %d: Second %%files list"),
81 /* XXX not necessary as readline has expanded already, but won't hurt. */
82 pkg->fileFile = rpmGetPath(file, NULL);
85 pkg->fileList = newStringBuf();
87 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
92 while (! (nextPart = isPart(spec->line))) {
93 appendStringBuf(pkg->fileList, spec->line);
94 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
108 poptFreeContext(optCon);