10 #include "stringbuf.h"
11 #include "popt/popt.h"
13 /* These have to be global scope to make up for *stupid* compilers */
16 static struct poptOption optionsTable[] = {
17 { NULL, 'n', POPT_ARG_STRING, &name, 'n' },
18 { NULL, 'f', POPT_ARG_STRING, &file, 'f' },
22 int parseFiles(Spec spec)
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",
36 spec->lineNum, poptStrerror(rc));
37 return RPMERR_BADSPEC;
40 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
41 while ((arg = poptGetNextOpt(optCon)) > 0) {
48 rpmError(RPMERR_BADSPEC, "line %d: Bad option %s: %s",
50 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
53 poptFreeContext(optCon);
54 return RPMERR_BADSPEC;
57 if (poptPeekArg(optCon)) {
59 name = poptGetArg(optCon);
61 if (poptPeekArg(optCon)) {
62 rpmError(RPMERR_BADSPEC, "line %d: Too many names: %s",
66 poptFreeContext(optCon);
67 return RPMERR_BADSPEC;
71 if (lookupPackage(spec, name, flag, &pkg)) {
72 rpmError(RPMERR_BADSPEC, "line %d: Package does not exist: %s",
73 spec->lineNum, spec->line);
75 poptFreeContext(optCon);
76 return RPMERR_BADSPEC;
80 rpmError(RPMERR_BADSPEC, "line %d: Second %%files list",
83 poptFreeContext(optCon);
84 return RPMERR_BADSPEC;
88 pkg->fileFile = strdup(file);
90 pkg->fileList = newStringBuf();
92 if (readLine(spec, STRIP_NOTHING) > 0) {
95 while (! (nextPart = isPart(spec->line))) {
96 appendStringBuf(pkg->fileList, spec->line);
97 if (readLine(spec, STRIP_NOTHING) > 0) {
105 poptFreeContext(optCon);