2 * \file build/parseDescription.c
3 * Parse %description section from spec file.
8 #include <rpm/header.h>
9 #include <rpm/rpmbuild.h>
10 #include <rpm/rpmlog.h>
15 int parseDescription(rpmSpec spec)
17 int nextPart = PART_ERROR; /* assume error */
19 int flag = PART_SUBNAME;
23 const char **argv = NULL;
24 const char *name = NULL;
25 const char *lang = RPMBUILD_DEFAULT_LANG;
26 poptContext optCon = NULL;
28 struct poptOption optionsTable[] = {
29 { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
30 { NULL, 'l', POPT_ARG_STRING, &lang, 'l', NULL, NULL},
31 { 0, 0, 0, 0, 0, NULL, NULL}
34 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
35 rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"),
36 spec->lineNum, poptStrerror(rc));
40 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
41 while ((arg = poptGetNextOpt(optCon)) > 0) {
48 rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
50 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
55 if (poptPeekArg(optCon)) {
57 name = poptGetArg(optCon);
58 if (poptPeekArg(optCon)) {
59 rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
66 if (lookupPackage(spec, name, flag, &pkg)) {
67 rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
68 spec->lineNum, spec->line);
76 if (headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) {
77 rpmlog(RPMLOG_ERR, _("line %d: Second description\n"),
83 t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
87 if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
90 nextPart = PART_ERROR;
93 while (! (nextPart = isPart(spec->line))) {
94 appendLineStringBuf(sb, spec->line);
97 readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
101 nextPart = PART_ERROR;
107 stripTrailingBlanksStringBuf(sb);
108 if (!(noLang && !rstreq(lang, RPMBUILD_DEFAULT_LANG))) {
109 (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION,
110 getStringBuf(sb), lang);
113 sb = freeStringBuf(sb);
117 optCon = poptFreeContext(optCon);