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));
34 return RPMERR_BADSPEC;
37 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
38 while ((arg = poptGetNextOpt(optCon)) > 0) {
45 rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s"),
47 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
50 poptFreeContext(optCon);
51 return RPMERR_BADSPEC;
54 if (poptPeekArg(optCon)) {
56 name = poptGetArg(optCon);
57 if (poptPeekArg(optCon)) {
58 rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s"),
62 poptFreeContext(optCon);
63 return RPMERR_BADSPEC;
67 if (lookupPackage(spec, name, flag, &pkg)) {
68 rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s"),
69 spec->lineNum, spec->line);
71 poptFreeContext(optCon);
72 return RPMERR_BADSPEC;
75 if (pkg->fileList != NULL) {
76 rpmError(RPMERR_BADSPEC, _("line %d: Second %%files list"),
79 poptFreeContext(optCon);
80 return RPMERR_BADSPEC;
84 pkg->fileFile = xstrdup(file);
86 pkg->fileList = newStringBuf();
88 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
94 while (! (nextPart = isPart(spec->line))) {
95 appendStringBuf(pkg->fileList, spec->line);
96 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
107 poptFreeContext(optCon);