Main Page   Modules   Compound List   File List   Compound Members   File Members   Related Pages  

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

Generated at Mon May 21 08:53:38 2001 for rpm by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001