|
|
2ff057 |
/** \ingroup rpmbuild
|
|
|
2ff057 |
* \file build/parseDescription.c
|
|
|
2ff057 |
* Parse %description section from spec file.
|
|
|
2ff057 |
*/
|
|
|
2ff057 |
|
|
|
2ff057 |
#include "system.h"
|
|
|
2ff057 |
|
|
|
2ff057 |
#include <rpm/header.h>
|
|
|
2ff057 |
#include <rpm/rpmlog.h>
|
|
|
2ff057 |
#include "build/rpmbuild_internal.h"
|
|
|
2ff057 |
#include "debug.h"
|
|
|
2ff057 |
|
|
|
2ff057 |
int parseDescription(rpmSpec spec)
|
|
|
2ff057 |
{
|
|
|
2ff057 |
int nextPart = PART_ERROR; /* assume error */
|
|
|
2ff057 |
StringBuf sb = NULL;
|
|
|
2ff057 |
int flag = PART_SUBNAME;
|
|
|
2ff057 |
Package pkg;
|
|
|
2ff057 |
int rc, argc;
|
|
|
2ff057 |
int arg;
|
|
|
2ff057 |
const char **argv = NULL;
|
|
|
2ff057 |
const char *name = NULL;
|
|
|
2ff057 |
const char *lang = RPMBUILD_DEFAULT_LANG;
|
|
|
2ff057 |
poptContext optCon = NULL;
|
|
|
2ff057 |
struct poptOption optionsTable[] = {
|
|
|
2ff057 |
{ NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
|
|
|
2ff057 |
{ NULL, 'l', POPT_ARG_STRING, &lang, 'l', NULL, NULL},
|
|
|
2ff057 |
{ 0, 0, 0, 0, 0, NULL, NULL}
|
|
|
2ff057 |
};
|
|
|
2ff057 |
|
|
|
2ff057 |
if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
|
|
|
2ff057 |
rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"),
|
|
|
2ff057 |
spec->lineNum, poptStrerror(rc));
|
|
|
2ff057 |
return PART_ERROR;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
|
|
|
2ff057 |
while ((arg = poptGetNextOpt(optCon)) > 0) {
|
|
|
2ff057 |
if (arg == 'n') {
|
|
|
2ff057 |
flag = PART_NAME;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
if (arg < -1) {
|
|
|
2ff057 |
rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
|
|
|
2ff057 |
spec->lineNum,
|
|
|
2ff057 |
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
|
|
2ff057 |
spec->line);
|
|
|
2ff057 |
goto exit;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
if (poptPeekArg(optCon)) {
|
|
|
2ff057 |
if (name == NULL)
|
|
|
2ff057 |
name = poptGetArg(optCon);
|
|
|
2ff057 |
if (poptPeekArg(optCon)) {
|
|
|
2ff057 |
rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
|
|
|
2ff057 |
spec->lineNum,
|
|
|
2ff057 |
spec->line);
|
|
|
2ff057 |
goto exit;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
if (lookupPackage(spec, name, flag, &pkg))
|
|
|
2ff057 |
goto exit;
|
|
|
2ff057 |
|
|
|
2ff057 |
sb = newStringBuf();
|
|
|
2ff057 |
|
|
|
2ff057 |
if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
|
|
|
2ff057 |
nextPart = PART_NONE;
|
|
|
2ff057 |
} else if (rc < 0) {
|
|
|
2ff057 |
nextPart = PART_ERROR;
|
|
|
2ff057 |
goto exit;
|
|
|
2ff057 |
} else {
|
|
|
2ff057 |
while (! (nextPart = isPart(spec->line))) {
|
|
|
2ff057 |
appendLineStringBuf(sb, spec->line);
|
|
|
2ff057 |
if ((rc =
|
|
|
2ff057 |
readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
|
|
|
2ff057 |
nextPart = PART_NONE;
|
|
|
2ff057 |
break;
|
|
|
2ff057 |
} else if (rc < 0) {
|
|
|
2ff057 |
nextPart = PART_ERROR;
|
|
|
2ff057 |
goto exit;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
}
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
stripTrailingBlanksStringBuf(sb);
|
|
|
2ff057 |
if (addLangTag(spec, pkg->header,
|
|
|
2ff057 |
RPMTAG_DESCRIPTION, getStringBuf(sb), lang)) {
|
|
|
2ff057 |
nextPart = PART_ERROR;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
exit:
|
|
|
2ff057 |
freeStringBuf(sb);
|
|
|
2ff057 |
free(argv);
|
|
|
2ff057 |
poptFreeContext(optCon);
|
|
|
2ff057 |
return nextPart;
|
|
|
2ff057 |
}
|