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