- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

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