• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

build/parseDescription.c

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

Generated on Mon Nov 29 2010 05:18:41 for rpm by  doxygen 1.7.2