10 #include "stringbuf.h"
11 #include "popt/popt.h"
13 int parseFiles(Spec spec)
20 char arg, **argv = NULL;
21 int flag = PART_SUBNAME;
22 poptContext optCon = NULL;
23 struct poptOption optionsTable[] = {
24 { NULL, 'n', POPT_ARG_STRING, &name, 'n' },
25 { NULL, 'f', POPT_ARG_STRING, &file, 'f' },
29 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
30 rpmError(RPMERR_BADSPEC, "line %d: Error parsing %%files: %s",
31 spec->lineNum, poptStrerror(rc));
32 return RPMERR_BADSPEC;
35 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
36 while ((arg = poptGetNextOpt(optCon)) > 0) {
43 rpmError(RPMERR_BADSPEC, "line %d: Bad option %s: %s",
45 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
48 poptFreeContext(optCon);
49 return RPMERR_BADSPEC;
52 if (poptPeekArg(optCon)) {
54 name = poptGetArg(optCon);
56 if (poptPeekArg(optCon)) {
57 rpmError(RPMERR_BADSPEC, "line %d: Too many names: %s",
61 poptFreeContext(optCon);
62 return RPMERR_BADSPEC;
66 if (lookupPackage(spec, name, flag, &pkg)) {
67 rpmError(RPMERR_BADSPEC, "line %d: Package does not exist: %s",
68 spec->lineNum, spec->line);
70 poptFreeContext(optCon);
71 return RPMERR_BADSPEC;
75 rpmError(RPMERR_BADSPEC, "line %d: Second %%files list",
78 poptFreeContext(optCon);
79 return RPMERR_BADSPEC;
83 pkg->fileFile = strdup(file);
85 pkg->fileList = newStringBuf();
87 if (readLine(spec, STRIP_NOTHING) > 0) {
90 while (! (nextPart = isPart(spec->line))) {
91 appendLineStringBuf(pkg->fileList, spec->line);
92 if (readLine(spec, STRIP_NOTHING) > 0) {
100 poptFreeContext(optCon);