Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

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 extern int noLang;
00013 /*@=exportheadervar@*/
00014 
00015 /* These have to be global scope to make up for *stupid* compilers */
00016     /*@observer@*/ /*@null@*/ static const char *name = NULL;
00017     /*@observer@*/ /*@null@*/ static const char *lang = NULL;
00018 
00019     static struct poptOption optionsTable[] = {
00020         { NULL, 'n', POPT_ARG_STRING, &name, 'n',       NULL, NULL},
00021         { NULL, 'l', POPT_ARG_STRING, &lang, 'l',       NULL, NULL},
00022         { 0, 0, 0, 0, 0,        NULL, NULL}
00023     };
00024 
00025 int parseDescription(Spec spec)
00026 {
00027     int nextPart;
00028     StringBuf sb;
00029     int flag = PART_SUBNAME;
00030     Package pkg;
00031     int rc, argc;
00032     int arg;
00033     const char **argv = NULL;
00034     poptContext optCon = NULL;
00035     spectag t = NULL;
00036 
00037     name = NULL;
00038     lang = RPMBUILD_DEFAULT_LANG;
00039 
00040     if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
00041         rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%description: %s\n"),
00042                  spec->lineNum, poptStrerror(rc));
00043         return RPMERR_BADSPEC;
00044     }
00045 
00046     optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
00047     while ((arg = poptGetNextOpt(optCon)) > 0) {
00048         if (arg == 'n') {
00049             flag = PART_NAME;
00050         }
00051     }
00052 
00053     if (arg < -1) {
00054         rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s\n"),
00055                  spec->lineNum,
00056                  poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
00057                  spec->line);
00058         argv = _free(argv);
00059         optCon = poptFreeContext(optCon);
00060         return RPMERR_BADSPEC;
00061     }
00062 
00063     if (poptPeekArg(optCon)) {
00064         if (name == NULL)
00065             name = poptGetArg(optCon);
00066         if (poptPeekArg(optCon)) {
00067             rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s\n"),
00068                      spec->lineNum,
00069                      spec->line);
00070             argv = _free(argv);
00071             optCon = poptFreeContext(optCon);
00072             return RPMERR_BADSPEC;
00073         }
00074     }
00075 
00076     if (lookupPackage(spec, name, flag, &pkg)) {
00077         rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s\n"),
00078                  spec->lineNum, spec->line);
00079         argv = _free(argv);
00080         optCon = poptFreeContext(optCon);
00081         return RPMERR_BADSPEC;
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         argv = _free(argv);
00092         optCon = poptFreeContext(optCon);
00093         return RPMERR_BADSPEC;
00094     }
00095 #endif
00096 
00097     t = stashSt(spec, pkg->header, RPMTAG_DESCRIPTION, lang);
00098     
00099     sb = newStringBuf();
00100 
00101     if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
00102         nextPart = PART_NONE;
00103     } else {
00104         if (rc) {
00105             return rc;
00106         }
00107         while (! (nextPart = isPart(spec->line))) {
00108             appendLineStringBuf(sb, spec->line);
00109             if (t) t->t_nlines++;
00110             if ((rc =
00111                  readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
00112                 nextPart = PART_NONE;
00113                 break;
00114             }
00115             if (rc) {
00116                 return rc;
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     argv = _free(argv);
00130     optCon = poptFreeContext(optCon);
00131     
00132     return nextPart;
00133 }

Generated at Mon Sep 24 10:37:10 2001 for rpm by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001