2 * \file build/parseDescription.c
3 * Parse %description section from spec file.
8 #include <rpm/header.h>
9 #include <rpm/rpmlog.h>
10 #include "build/rpmbuild_internal.h"
13 int parseDescription(rpmSpec spec)
15 int nextPart = PART_ERROR; /* assume error */
17 int flag = PART_SUBNAME;
21 const char **argv = NULL;
22 const char *name = NULL;
23 const char *lang = RPMBUILD_DEFAULT_LANG;
24 poptContext optCon = NULL;
25 struct poptOption optionsTable[] = {
26 { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
27 { NULL, 'l', POPT_ARG_STRING, &lang, 'l', NULL, NULL},
28 { 0, 0, 0, 0, 0, NULL, NULL}
31 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
32 rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"),
33 spec->lineNum, poptStrerror(rc));
37 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
38 while ((arg = poptGetNextOpt(optCon)) > 0) {
45 rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
47 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
52 if (poptPeekArg(optCon)) {
54 name = poptGetArg(optCon);
55 if (poptPeekArg(optCon)) {
56 rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
63 if (lookupPackage(spec, name, flag, &pkg)) {
64 rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
65 spec->lineNum, spec->line);
73 if (headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) {
74 rpmlog(RPMLOG_ERR, _("line %d: Second description\n"),
82 if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
85 nextPart = PART_ERROR;
88 while (! (nextPart = isPart(spec->line))) {
89 appendLineStringBuf(sb, spec->line);
91 readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
95 nextPart = PART_ERROR;
101 stripTrailingBlanksStringBuf(sb);
102 if (!((spec->flags & RPMSPEC_NOLANG) && !rstreq(lang, RPMBUILD_DEFAULT_LANG))) {
103 (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION,
104 getStringBuf(sb), lang);
111 poptFreeContext(optCon);