2 * \file build/parseFiles.c
3 * Parse %files section from spec file.
11 /*@access StringBuf @*/ /* compared with NULL */
13 /* These have to be global scope to make up for *stupid* compilers */
14 /*@observer@*/ /*@null@*/ static const char *name = NULL;
15 /*@observer@*/ /*@null@*/ static const char *file = NULL;
16 static struct poptOption optionsTable[] = {
17 { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
18 { NULL, 'f', POPT_ARG_STRING, &file, 'f', NULL, NULL},
19 { 0, 0, 0, 0, 0, NULL, NULL}
22 int parseFiles(Spec spec)
28 const char **argv = NULL;
29 int flag = PART_SUBNAME;
30 poptContext optCon = NULL;
34 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
35 rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%files: %s\n"),
36 spec->lineNum, poptStrerror(rc));
41 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
42 while ((arg = poptGetNextOpt(optCon)) > 0) {
49 rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s\n"),
51 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
57 if (poptPeekArg(optCon)) {
59 name = poptGetArg(optCon);
60 if (poptPeekArg(optCon)) {
61 rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s\n"),
69 if (lookupPackage(spec, name, flag, &pkg)) {
70 rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s\n"),
71 spec->lineNum, spec->line);
76 if (pkg->fileList != NULL) {
77 rpmError(RPMERR_BADSPEC, _("line %d: Second %%files list\n"),
84 /* XXX not necessary as readline has expanded already, but won't hurt. */
85 pkg->fileFile = rpmGetPath(file, NULL);
88 pkg->fileList = newStringBuf();
90 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
95 while (! (nextPart = isPart(spec->line))) {
96 appendStringBuf(pkg->fileList, spec->line);
97 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
110 poptFreeContext(optCon);