# build/parseDescription.c

Go to the documentation of this file.

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