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

Generated at Thu Apr 19 15:29:41 2001 for rpm by doxygen1.2.6-20010408 written by Dimitri van Heesch, © 1997-2001