build/parseFiles.c

Go to the documentation of this file.
00001 
00006 #include "system.h"
00007 
00008 #include "rpmbuild.h"
00009 #include "debug.h"
00010 
00011 /*@access StringBuf @*/         /* compared with NULL */
00012 /*@access poptContext @*/       /* compared with NULL */
00013 
00014 /* These have to be global scope to make up for *stupid* compilers */
00015 /*@unchecked@*/
00016     /*@observer@*/ /*@null@*/ static const char *name = NULL;
00017 /*@unchecked@*/
00018     /*@observer@*/ /*@null@*/ static const char *file = NULL;
00019 /*@unchecked@*/
00020     static struct poptOption optionsTable[] = {
00021         { NULL, 'n', POPT_ARG_STRING, &name, 'n',       NULL, NULL},
00022         { NULL, 'f', POPT_ARG_STRING, &file, 'f',       NULL, NULL},
00023         { 0, 0, 0, 0, 0,        NULL, NULL}
00024     };
00025 
00026 int parseFiles(Spec spec)
00027 {
00028     int nextPart;
00029     Package pkg;
00030     int rc, argc;
00031     int arg;
00032     const char ** argv = NULL;
00033     int flag = PART_SUBNAME;
00034     poptContext optCon = NULL;
00035 
00036     /*@-mods@*/
00037     name = NULL;
00038     file = NULL;
00039     /*@=mods@*/
00040 
00041     if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
00042         rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%files: %s\n"),
00043                  spec->lineNum, poptStrerror(rc));
00044         rc = RPMERR_BADSPEC;
00045         goto exit;
00046     }
00047 
00048     optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
00049     while ((arg = poptGetNextOpt(optCon)) > 0) {
00050         if (arg == 'n') {
00051             flag = PART_NAME;
00052         }
00053     }
00054 
00055     if (arg < -1) {
00056         rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s\n"),
00057                  spec->lineNum,
00058                  poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
00059                  spec->line);
00060         rc = RPMERR_BADSPEC;
00061         goto exit;
00062     }
00063 
00064     if (poptPeekArg(optCon)) {
00065         /*@-mods@*/
00066         if (name == NULL)
00067             name = poptGetArg(optCon);
00068         /*@=mods@*/
00069         if (poptPeekArg(optCon)) {
00070             rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s\n"),
00071                      spec->lineNum,
00072                      spec->line);
00073             rc = RPMERR_BADSPEC;
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         rc = RPMERR_BADSPEC;
00082         goto exit;
00083     }
00084 
00085     if (pkg->fileList != NULL) {
00086         rpmError(RPMERR_BADSPEC, _("line %d: Second %%files list\n"),
00087                  spec->lineNum);
00088         rc = RPMERR_BADSPEC;
00089         goto exit;
00090     }
00091 
00092     if (file)  {
00093     /* XXX not necessary as readline has expanded already, but won't hurt.  */
00094         pkg->fileFile = rpmGetPath(file, NULL);
00095     }
00096 
00097     pkg->fileList = newStringBuf();
00098     
00099     if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
00100         nextPart = PART_NONE;
00101     } else {
00102         if (rc)
00103             goto exit;
00104         while (! (nextPart = isPart(spec->line))) {
00105             appendStringBuf(pkg->fileList, spec->line);
00106             if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
00107                 nextPart = PART_NONE;
00108                 break;
00109             }
00110             if (rc)
00111                 goto exit;
00112         }
00113     }
00114     rc = nextPart;
00115 
00116 exit:
00117     argv = _free(argv);
00118     optCon = poptFreeContext(optCon);
00119         
00120     return rc;
00121 }

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