rpm
5.2.1
|
00001 00006 #include "system.h" 00007 00008 #include <rpmio.h> 00009 #include <rpmiotypes.h> 00010 #include <rpmlog.h> 00011 #include "rpmbuild.h" 00012 #include "debug.h" 00013 00014 /*@-exportheadervar@*/ 00015 /*@unchecked@*/ 00016 extern int noLang; 00017 /*@=exportheadervar@*/ 00018 00019 /* These have to be global scope to make up for *stupid* compilers */ 00020 /*@unchecked@*/ 00021 /*@observer@*/ /*@null@*/ static const char *name = NULL; 00022 /*@unchecked@*/ 00023 /*@observer@*/ /*@null@*/ static const char *lang = NULL; 00024 00025 /*@unchecked@*/ 00026 static struct poptOption optionsTable[] = { 00027 { NULL, 'n', POPT_ARG_STRING, &name, 0, NULL, NULL}, 00028 { NULL, 'l', POPT_ARG_STRING, &lang, 0, NULL, NULL}, 00029 { 0, 0, 0, 0, 0, NULL, NULL} 00030 }; 00031 00032 int parseDescription(Spec spec) 00033 /*@globals name, lang @*/ 00034 /*@modifies name, lang @*/ 00035 { 00036 rpmParseState nextPart = (rpmParseState) RPMRC_FAIL; /* assume error */ 00037 rpmiob iob; 00038 int flag = PART_SUBNAME; 00039 Package pkg; 00040 int rc, argc; 00041 int arg; 00042 const char **argv = NULL; 00043 poptContext optCon = NULL; 00044 spectag t = NULL; 00045 00046 { char * se = strchr(spec->line, '#'); 00047 if (se) { 00048 *se = '\0'; 00049 while (--se >= spec->line && strchr(" \t\n\r", *se) != NULL) 00050 *se = '\0'; 00051 } 00052 } 00053 00054 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) { 00055 rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%description: %s\n"), 00056 spec->lineNum, poptStrerror(rc)); 00057 return RPMRC_FAIL; 00058 } 00059 00060 name = NULL; 00061 lang = RPMBUILD_DEFAULT_LANG; 00062 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); 00063 while ((arg = poptGetNextOpt(optCon)) > 0) 00064 {;} 00065 if (name != NULL) 00066 flag = PART_NAME; 00067 00068 if (arg < -1) { 00069 rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"), 00070 spec->lineNum, 00071 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 00072 spec->line); 00073 goto exit; 00074 } 00075 00076 if (poptPeekArg(optCon)) { 00077 if (name == NULL) 00078 name = poptGetArg(optCon); 00079 if (poptPeekArg(optCon)) { 00080 rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"), 00081 spec->lineNum, spec->line); 00082 goto exit; 00083 } 00084 } 00085 00086 if (lookupPackage(spec, name, flag, &pkg) != RPMRC_OK) { 00087 rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"), 00088 spec->lineNum, spec->line); 00089 goto exit; 00090 } 00091 00092 /* Lose the inheirited %description (if present). */ 00093 { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 00094 int xx; 00095 he->tag = RPMTAG_DESCRIPTION; 00096 xx = headerGet(pkg->header, he, 0); 00097 he->p.ptr = _free(he->p.ptr); 00098 if (xx && he->t == RPM_STRING_TYPE) 00099 xx = headerDel(pkg->header, he, 0); 00100 } 00101 00102 t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang); 00103 00104 iob = rpmiobNew(0); 00105 00106 if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) { 00107 nextPart = PART_NONE; 00108 } else { 00109 if (rc) { 00110 nextPart = (rpmParseState) RPMRC_FAIL; 00111 goto exit; 00112 } 00113 while ((nextPart = isPart(spec)) == PART_NONE) { 00114 iob = rpmiobAppend(iob, spec->line, 1); 00115 if (t) t->t_nlines++; 00116 if ((rc = 00117 readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) { 00118 nextPart = PART_NONE; 00119 break; 00120 } 00121 if (rc) { 00122 nextPart = (rpmParseState) RPMRC_FAIL; 00123 goto exit; 00124 } 00125 } 00126 } 00127 00128 iob = rpmiobRTrim(iob); 00129 if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) { 00130 (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION, 00131 rpmiobStr(iob), lang); 00132 } 00133 00134 iob = rpmiobFree(iob); 00135 00136 exit: 00137 argv = _free(argv); 00138 optCon = poptFreeContext(optCon); 00139 return nextPart; 00140 }