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         /*@globals name, lang @*/
00031         /*@modifies name, lang @*/
00032 {
00033     int nextPart = RPMERR_BADSPEC;      /* assume error */
00034     StringBuf sb;
00035     int flag = PART_SUBNAME;
00036     Package pkg;
00037     int rc, argc;
00038     int arg;
00039     const char **argv = NULL;
00040     poptContext optCon = NULL;
00041     spectag t = NULL;
00042 
00043     name = NULL;
00044     lang = RPMBUILD_DEFAULT_LANG;
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         goto exit;
00065     }
00066 
00067     if (poptPeekArg(optCon)) {
00068         if (name == NULL)
00069             name = poptGetArg(optCon);
00070         if (poptPeekArg(optCon)) {
00071             rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s\n"),
00072                      spec->lineNum,
00073                      spec->line);
00074             goto exit;
00075         }
00076     }
00077 
00078     if (lookupPackage(spec, name, flag, &pkg)) {
00079         rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s\n"),
00080                  spec->lineNum, spec->line);
00081         goto exit;
00082     }
00083 
00084 
00085     /******************/
00086 
00087 #if 0    
00088     if (headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) {
00089         rpmError(RPMERR_BADSPEC, _("line %d: Second description\n"),
00090                 spec->lineNum);
00091         goto exit;
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             nextPart = RPMERR_BADSPEC;
00104             goto exit;
00105         }
00106         while (! (nextPart = isPart(spec->line))) {
00107             appendLineStringBuf(sb, spec->line);
00108             if (t) t->t_nlines++;
00109             if ((rc =
00110                 readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
00111                 nextPart = PART_NONE;
00112                 break;
00113             }
00114             if (rc) {
00115                 nextPart = RPMERR_BADSPEC;
00116                 goto exit;
00117             }
00118         }
00119     }
00120     
00121     stripTrailingBlanksStringBuf(sb);
00122     if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) {
00123         (void) headerAddI18NString(pkg->header, RPMTAG_DESCRIPTION,
00124                         getStringBuf(sb), lang);
00125     }
00126     
00127     sb = freeStringBuf(sb);
00128      
00129 exit:
00130     argv = _free(argv);
00131     optCon = poptFreeContext(optCon);
00132     return nextPart;
00133 }

Generated on Fri Oct 12 08:44:53 2007 for rpm by  doxygen 1.5.2