1 /** \ingroup rpmbuild
2 * \file build/parsePolicies.c
3 * Parse %policies section from spec file.
4 */
5
6 #include "system.h"
7
8 #include <rpm/header.h>
9 #include <rpm/rpmbuild.h>
10 #include <rpm/rpmlog.h>
11 #include <rpm/rpmfileutil.h>
12 #include "build/rpmbuild_internal.h"
13 #include "debug.h"
14
parsePolicies(rpmSpec spec)15 int parsePolicies(rpmSpec spec)
16 {
17 int res = PART_ERROR;
18 Package pkg;
19 int rc, argc;
20 int arg;
21 const char **argv = NULL;
22 char *name = NULL;
23 int flag = PART_SUBNAME;
24 poptContext optCon = NULL;
25
26 struct poptOption optionsTable[] = {
27 {NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
28 {0, 0, 0, 0, 0, NULL, NULL}
29 };
30
31 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
32 rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%policies: %s\n"),
33 spec->lineNum, poptStrerror(rc));
34 goto exit;
35 }
36
37 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
38 while ((arg = poptGetNextOpt(optCon)) > 0) {
39 if (arg == 'n') {
40 flag = PART_NAME;
41 }
42 }
43
44 if (arg < -1) {
45 rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
46 spec->lineNum,
47 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line);
48 goto exit;
49 }
50
51 if (poptPeekArg(optCon)) {
52 if (name == NULL)
53 name = xstrdup(poptGetArg(optCon));
54 if (poptPeekArg(optCon)) {
55 rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
56 spec->lineNum, spec->line);
57 goto exit;
58 }
59 }
60
61 if (lookupPackage(spec, name, flag, &pkg))
62 goto exit;
63
64 res = parseLines(spec, (STRIP_TRAILINGSPACE | STRIP_COMMENTS),
65 &(pkg->policyList), NULL);
66
67 exit:
68 free(argv);
69 free(name);
70 poptFreeContext(optCon);
71
72 return res;
73 }
74