2 * \file build/parseDescription.c
3 * Parse %description section from spec file.
11 extern int noLang; /* XXX FIXME: pass as arg */
13 /* These have to be global scope to make up for *stupid* compilers */
14 /*@observer@*/ /*@null@*/ static const char *name = NULL;
15 /*@observer@*/ /*@null@*/ static const char *lang = NULL;
17 static struct poptOption optionsTable[] = {
18 { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
19 { NULL, 'l', POPT_ARG_STRING, &lang, 'l', NULL, NULL},
20 { 0, 0, 0, 0, 0, NULL, NULL}
23 int parseDescription(Spec spec)
27 int flag = PART_SUBNAME;
31 const char **argv = NULL;
32 poptContext optCon = NULL;
33 struct spectag *t = NULL;
36 lang = RPMBUILD_DEFAULT_LANG;
38 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
39 rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%description: %s\n"),
40 spec->lineNum, poptStrerror(rc));
41 return RPMERR_BADSPEC;
44 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
45 while ((arg = poptGetNextOpt(optCon)) > 0) {
52 rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s\n"),
54 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
57 poptFreeContext(optCon);
58 return RPMERR_BADSPEC;
61 if (poptPeekArg(optCon)) {
63 name = poptGetArg(optCon);
64 if (poptPeekArg(optCon)) {
65 rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s\n"),
69 poptFreeContext(optCon);
70 return RPMERR_BADSPEC;
74 if (lookupPackage(spec, name, flag, &pkg)) {
75 rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s\n"),
76 spec->lineNum, spec->line);
78 poptFreeContext(optCon);
79 return RPMERR_BADSPEC;
86 if (headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) {
87 rpmError(RPMERR_BADSPEC, _("line %d: Second description\n"),
90 poptFreeContext(optCon);
91 return RPMERR_BADSPEC;
95 t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
99 if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
100 nextPart = PART_NONE;
105 while (! (nextPart = isPart(spec->line))) {
106 appendLineStringBuf(sb, spec->line);
107 if (t) t->t_nlines++;
109 readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
110 nextPart = PART_NONE;
119 stripTrailingBlanksStringBuf(sb);
120 if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) {
121 headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION,
122 getStringBuf(sb), lang);
128 poptFreeContext(optCon);