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

Generated at Thu Sep 6 11:32:28 2001 for rpm by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001