00001
00006 #include "system.h"
00007
00008 #include <rpmio.h>
00009 #include <rpmiotypes.h>
00010 #include <rpmlog.h>
00011 #include "rpmbuild.h"
00012 #include "debug.h"
00013
00014
00015
00016
00017
00018 static const char *name = NULL;
00019
00020 static const char *file = NULL;
00021
00022 static struct poptOption optionsTable[] = {
00023 { NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
00024 { NULL, 'f', POPT_ARG_STRING, &file, 'f', NULL, NULL},
00025 { 0, 0, 0, 0, 0, NULL, NULL}
00026 };
00027
00028 int parseFiles(Spec spec)
00029 {
00030 rpmParseState nextPart;
00031 Package pkg;
00032 int rc, argc;
00033 int arg;
00034 const char ** argv = NULL;
00035 int flag = PART_SUBNAME;
00036 poptContext optCon = NULL;
00037
00038
00039 name = NULL;
00040 file = NULL;
00041
00042
00043 if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
00044 rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"),
00045 spec->lineNum, poptStrerror(rc));
00046 rc = RPMRC_FAIL;
00047 goto exit;
00048 }
00049
00050 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
00051 while ((arg = poptGetNextOpt(optCon)) > 0) {
00052 if (arg == 'n') {
00053 flag = PART_NAME;
00054 }
00055 }
00056
00057 if (arg < -1) {
00058 rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
00059 spec->lineNum,
00060 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00061 spec->line);
00062 rc = RPMRC_FAIL;
00063 goto exit;
00064 }
00065
00066 if (poptPeekArg(optCon)) {
00067
00068 if (name == NULL)
00069 name = poptGetArg(optCon);
00070
00071 if (poptPeekArg(optCon)) {
00072 rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
00073 spec->lineNum,
00074 spec->line);
00075 rc = RPMRC_FAIL;
00076 goto exit;
00077 }
00078 }
00079
00080 if (lookupPackage(spec, name, flag, &pkg) != RPMRC_OK) {
00081 rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
00082 spec->lineNum, spec->line);
00083 rc = RPMRC_FAIL;
00084 goto exit;
00085 }
00086
00087 if (pkg->fileList != NULL) {
00088 rpmlog(RPMLOG_ERR, _("line %d: Second %%files list\n"),
00089 spec->lineNum);
00090 rc = RPMRC_FAIL;
00091 goto exit;
00092 }
00093
00094 if (file) {
00095
00096 pkg->fileFile = rpmGetPath(file, NULL);
00097 }
00098
00099 pkg->fileList = rpmiobNew(0);
00100
00101 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
00102 nextPart = PART_NONE;
00103 } else {
00104 if (rc)
00105 goto exit;
00106 while ((nextPart = isPart(spec)) == PART_NONE) {
00107 pkg->fileList = rpmiobAppend(pkg->fileList, spec->line, 0);
00108 if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
00109 nextPart = PART_NONE;
00110 break;
00111 }
00112 if (rc)
00113 goto exit;
00114 }
00115 }
00116 rc = nextPart;
00117
00118 exit:
00119 argv = _free(argv);
00120 optCon = poptFreeContext(optCon);
00121
00122 return rc;
00123 }