2000-08-28 03:18:25 +08:00
|
|
|
/** \ingroup rpmbuild
|
|
|
|
* \file build/parseFiles.c
|
2000-01-25 04:02:32 +08:00
|
|
|
* Parse %files section from spec file.
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#include "rpmbuild.h"
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1998-07-31 06:09:42 +08:00
|
|
|
|
1998-03-05 00:51:06 +08:00
|
|
|
/* These have to be global scope to make up for *stupid* compilers */
|
1999-10-28 07:18:10 +08:00
|
|
|
/*@observer@*/ /*@null@*/ static const char *name = NULL;
|
|
|
|
/*@observer@*/ /*@null@*/ static const char *file = NULL;
|
1998-03-05 00:51:06 +08:00
|
|
|
static struct poptOption optionsTable[] = {
|
1998-11-20 03:10:23 +08:00
|
|
|
{ NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
|
|
|
|
{ NULL, 'f', POPT_ARG_STRING, &file, 'f', NULL, NULL},
|
|
|
|
{ 0, 0, 0, 0, 0, NULL, NULL}
|
1998-03-05 00:51:06 +08:00
|
|
|
};
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
int parseFiles(Spec spec)
|
|
|
|
{
|
|
|
|
int nextPart;
|
|
|
|
Package pkg;
|
|
|
|
int rc, argc;
|
1998-04-03 02:31:12 +08:00
|
|
|
int arg;
|
1999-10-28 07:18:10 +08:00
|
|
|
const char **argv = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
int flag = PART_SUBNAME;
|
|
|
|
poptContext optCon = NULL;
|
1998-03-05 00:51:06 +08:00
|
|
|
|
|
|
|
name = file = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Error parsing %%files: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, poptStrerror(rc));
|
2000-02-22 11:09:53 +08:00
|
|
|
rc = RPMERR_BADSPEC;
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
|
|
|
|
while ((arg = poptGetNextOpt(optCon)) > 0) {
|
|
|
|
if (arg == 'n') {
|
|
|
|
flag = PART_NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg < -1) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Bad option %s: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum,
|
|
|
|
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
|
|
|
spec->line);
|
2000-02-22 11:09:53 +08:00
|
|
|
rc = RPMERR_BADSPEC;
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (poptPeekArg(optCon)) {
|
1999-10-28 07:18:10 +08:00
|
|
|
if (name == NULL)
|
1998-01-13 05:31:29 +08:00
|
|
|
name = poptGetArg(optCon);
|
|
|
|
if (poptPeekArg(optCon)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum,
|
|
|
|
spec->line);
|
2000-02-22 11:09:53 +08:00
|
|
|
rc = RPMERR_BADSPEC;
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lookupPackage(spec, name, flag, &pkg)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, spec->line);
|
2000-02-22 11:09:53 +08:00
|
|
|
rc = RPMERR_BADSPEC;
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
1998-11-17 05:40:28 +08:00
|
|
|
if (pkg->fileList != NULL) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: Second %%files list"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum);
|
2000-02-22 11:09:53 +08:00
|
|
|
rc = RPMERR_BADSPEC;
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2000-02-22 11:09:53 +08:00
|
|
|
if (file) {
|
|
|
|
/* XXX not necessary as readline has expanded already, but won't hurt. */
|
|
|
|
pkg->fileFile = rpmGetPath(file, NULL);
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
2000-02-22 11:09:53 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
pkg->fileList = newStringBuf();
|
|
|
|
|
1998-05-21 01:05:26 +08:00
|
|
|
if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
nextPart = PART_NONE;
|
|
|
|
} else {
|
2000-02-22 11:09:53 +08:00
|
|
|
if (rc)
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
while (! (nextPart = isPart(spec->line))) {
|
1998-01-14 11:32:44 +08:00
|
|
|
appendStringBuf(pkg->fileList, spec->line);
|
1998-05-21 01:05:26 +08:00
|
|
|
if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
nextPart = PART_NONE;
|
|
|
|
break;
|
|
|
|
}
|
2000-02-22 11:09:53 +08:00
|
|
|
if (rc)
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-22 11:09:53 +08:00
|
|
|
rc = nextPart;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-02-22 11:09:53 +08:00
|
|
|
exit:
|
|
|
|
if (argv)
|
|
|
|
FREE(argv);
|
|
|
|
if (optCon)
|
|
|
|
poptFreeContext(optCon);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-02-22 11:09:53 +08:00
|
|
|
return rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|