00001
00006 #include "system.h"
00007
00008 #include "rpmbuild.h"
00009 #include "debug.h"
00010
00011 extern int noLang;
00012
00013
00014 static const char *name = NULL;
00015 static const char *lang = NULL;
00016
00017 static struct poptOption optionsTable[] = {
00018 { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
00019 { NULL, 'l', POPT_ARG_STRING, &lang, 'l', NULL, NULL},
00020 { 0, 0, 0, 0, 0, NULL, NULL}
00021 };
00022
00023 int parseDescription(Spec spec)
00024 {
00025 int nextPart;
00026 StringBuf sb;
00027 int flag = PART_SUBNAME;
00028 Package pkg;
00029 int rc, argc;
00030 int arg;
00031 const char **argv = NULL;
00032 poptContext optCon = NULL;
00033 struct spectag *t = NULL;
00034
00035 name = NULL;
00036 lang = RPMBUILD_DEFAULT_LANG;
00037
00038 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
00039 rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%description: %s\n"),
00040 spec->lineNum, poptStrerror(rc));
00041 return RPMERR_BADSPEC;
00042 }
00043
00044 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
00045 while ((arg = poptGetNextOpt(optCon)) > 0) {
00046 if (arg == 'n') {
00047 flag = PART_NAME;
00048 }
00049 }
00050
00051 if (arg < -1) {
00052 rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s\n"),
00053 spec->lineNum,
00054 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00055 spec->line);
00056 FREE(argv);
00057 poptFreeContext(optCon);
00058 return RPMERR_BADSPEC;
00059 }
00060
00061 if (poptPeekArg(optCon)) {
00062 if (name == NULL)
00063 name = poptGetArg(optCon);
00064 if (poptPeekArg(optCon)) {
00065 rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s\n"),
00066 spec->lineNum,
00067 spec->line);
00068 FREE(argv);
00069 poptFreeContext(optCon);
00070 return RPMERR_BADSPEC;
00071 }
00072 }
00073
00074 if (lookupPackage(spec, name, flag, &pkg)) {
00075 rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s\n"),
00076 spec->lineNum, spec->line);
00077 FREE(argv);
00078 poptFreeContext(optCon);
00079 return RPMERR_BADSPEC;
00080 }
00081
00082
00083
00084
00085 #if 0
00086 if (headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) {
00087 rpmError(RPMERR_BADSPEC, _("line %d: Second description\n"),
00088 spec->lineNum);
00089 FREE(argv);
00090 poptFreeContext(optCon);
00091 return RPMERR_BADSPEC;
00092 }
00093 #endif
00094
00095 t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
00096
00097 sb = newStringBuf();
00098
00099 if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
00100 nextPart = PART_NONE;
00101 } else {
00102 if (rc) {
00103 return rc;
00104 }
00105 while (! (nextPart = isPart(spec->line))) {
00106 appendLineStringBuf(sb, spec->line);
00107 if (t) t->t_nlines++;
00108 if ((rc =
00109 readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
00110 nextPart = PART_NONE;
00111 break;
00112 }
00113 if (rc) {
00114 return rc;
00115 }
00116 }
00117 }
00118
00119 stripTrailingBlanksStringBuf(sb);
00120 if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) {
00121 headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION,
00122 getStringBuf(sb), lang);
00123 }
00124
00125 freeStringBuf(sb);
00126
00127 FREE(argv);
00128 poptFreeContext(optCon);
00129
00130 return nextPart;
00131 }