fix: avoid segfault using --prefix until ewt fixes.

add --define "%foo %bar" option.
dump macros to same fd as --showrc uses.
add %GNUconfigure for full-blown package regeneration.
fix: RPM_ARCH/RPM_OS had wrong values.
fix: create ppc directories correctly.

CVS patchset: 2922
CVS date: 1999/03/28 00:47:40
This commit is contained in:
jbj 1999-03-28 00:47:40 +00:00
parent 6147ae7995
commit 9b94f186e6
12 changed files with 673 additions and 487 deletions

View File

@ -6,6 +6,12 @@
- more DU 4.0D fiddles (Shing-Gene Yung). - more DU 4.0D fiddles (Shing-Gene Yung).
- fix: segfault from unknown uid/gid -- use builder's uid/gid instead. - fix: segfault from unknown uid/gid -- use builder's uid/gid instead.
- autoReq/autoProv now per-package. - autoReq/autoProv now per-package.
- fix: avoid segfault using --prefix until ewt fixes.
- add --define "%foo %bar" option.
- dump macros to same fd as --showrc uses.
- add %GNUconfigure for full-blown package regeneration.
- fix: RPM_ARCH/RPM_OS had wrong values.
- fix: create ppc directories correctly.
2.91 -> 2.92 2.91 -> 2.92
- update with libtool-2.4f. - update with libtool-2.4f.

View File

@ -63,6 +63,7 @@ install-data-local:
*86) $(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/i386 ;;\ *86) $(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/i386 ;;\
alpha*) $(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/alpha ;;\ alpha*) $(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/alpha ;;\
sparc*) $(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/sparc ;;\ sparc*) $(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/sparc ;;\
powerpc*) $(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/ppc ;;\
esac esac
@$(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/@build_cpu@ @$(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/@build_cpu@
@$(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/noarch @$(mkinstalldirs) $(DESTDIR)/$(prefix)/src/redhat/RPMS/noarch

View File

@ -624,6 +624,7 @@ case "${build_cpu}" in
i386|i486|i586|i686|ix86) RPMCANONARCH=i386 ;; i386|i486|i586|i686|ix86) RPMCANONARCH=i386 ;;
alpha*) RPMCANONARCH=alpha ;; alpha*) RPMCANONARCH=alpha ;;
sparc*) RPMCANONARCH=sparc ;; sparc*) RPMCANONARCH=sparc ;;
powerpc*) RPMCANONARCH=ppc ;;
*) RPMCANONARCH=unknown ;; *) RPMCANONARCH=unknown ;;
esac esac
RPMCANONVENDOR="$build_vendor" RPMCANONVENDOR="$build_vendor"

View File

@ -1,6 +1,7 @@
#include "system.h" #include "system.h"
#include <assert.h> #include <assert.h>
#include <stdarg.h>
#define isblank(_c) ((_c) == ' ' || (_c) == '\t') #define isblank(_c) ((_c) == ' ' || (_c) == '\t')
#define STREQ(_t, _f, _fn) ((_fn) == (sizeof(_t)-1) && !strncmp((_t), (_f), (_fn))) #define STREQ(_t, _f, _fn) ((_fn) == (sizeof(_t)-1) && !strncmp((_t), (_f), (_fn)))
@ -10,6 +11,7 @@
#define rpmError fprintf #define rpmError fprintf
#define RPMERR_BADSPEC stderr #define RPMERR_BADSPEC stderr
#define _(x) x #define _(x) x
#define xfree(_p) free((void *)_p)
#else #else
#include "rpmlib.h" #include "rpmlib.h"
#endif #endif
@ -89,29 +91,32 @@ sortMacroTable(MacroContext *mc)
} }
void void
dumpMacroTable(MacroContext *mc) dumpMacroTable(MacroContext *mc, FILE *f)
{ {
int i; int i;
int nempty = 0; int nempty = 0;
int nactive = 0; int nactive = 0;
if (f == NULL)
f = stderr;
fprintf(stderr, "========================\n"); fprintf(f, "========================\n");
for (i = 0; i < mc->firstFree; i++) { for (i = 0; i < mc->firstFree; i++) {
MacroEntry *me; MacroEntry *me;
if ((me = mc->macroTable[i]) == NULL) { if ((me = mc->macroTable[i]) == NULL) {
nempty++; nempty++;
continue; continue;
} }
fprintf(stderr, "%3d%c %s", me->level, fprintf(f, "%3d%c %s", me->level,
(me->used > 0 ? '=' : ':'), me->name); (me->used > 0 ? '=' : ':'), me->name);
if (me->opts) if (me->opts && *me->opts)
fprintf(stderr, "(%s)", me->opts); fprintf(f, "(%s)", me->opts);
if (me->body) if (me->body && *me->body)
fprintf(stderr, "\t%s", me->body); fprintf(f, "\t%s", me->body);
fprintf(stderr, "\n"); fprintf(f, "\n");
nactive++; nactive++;
} }
fprintf(stderr, _("======================== active %d empty %d\n"), fprintf(f, _("======================== active %d empty %d\n"),
nactive, nempty); nactive, nempty);
} }
@ -505,7 +510,7 @@ pushMacro(MacroEntry **mep, const char *n, const char *o, const char *b, int lev
me->prev = prev; me->prev = prev;
me->name = (prev ? prev->name : strdup(n)); me->name = (prev ? prev->name : strdup(n));
me->opts = (o ? strdup(o) : NULL); me->opts = (o ? strdup(o) : NULL);
me->body = (b ? strdup(b) : NULL); me->body = strdup(b ? b : "");
me->used = 0; me->used = 0;
me->level = level; me->level = level;
*mep = me; *mep = me;
@ -939,7 +944,7 @@ expandMacro(MacroBuf *mb)
} }
if (STREQ("dump", f, fn)) { if (STREQ("dump", f, fn)) {
dumpMacroTable(mb->mc); dumpMacroTable(mb->mc, NULL);
if (*se == '\n') if (*se == '\n')
se++; se++;
s = se; s = se;
@ -1029,10 +1034,12 @@ expandMacro(MacroBuf *mb)
} }
/* Recursively expand body of macro */ /* Recursively expand body of macro */
mb->s = me->body; if (me->body && *me->body) {
rc = expandMacro(mb); mb->s = me->body;
if (rc == 0) rc = expandMacro(mb);
me->used++; /* Mark macro as used */ if (rc == 0)
me->used++; /* Mark macro as used */
}
/* Free args for "%name " macros with opts */ /* Free args for "%name " macros with opts */
if (me->opts != NULL) if (me->opts != NULL)
@ -1050,6 +1057,7 @@ expandMacro(MacroBuf *mb)
} }
/* =============================================================== */ /* =============================================================== */
/* XXX this is used only in build/expression.c and will go away. */
const char * const char *
getMacroBody(MacroContext *mc, const char *name) getMacroBody(MacroContext *mc, const char *name)
{ {
@ -1059,6 +1067,7 @@ getMacroBody(MacroContext *mc, const char *name)
} }
/* =============================================================== */ /* =============================================================== */
int int
expandMacros(void *spec, MacroContext *mc, char *s, size_t slen) expandMacros(void *spec, MacroContext *mc, char *s, size_t slen)
{ {
@ -1123,6 +1132,17 @@ delMacro(MacroContext *mc, const char *name)
popMacro(mep); popMacro(mep);
} }
int
rpmDefineMacro(MacroContext *mc, const char *macro, int level)
{
MacroBuf macrobuf, *mb = &macrobuf;
/* XXX just enough to get by */
mb->mc = (mc ? mc : &globalMacroContext);
(void)doDefine(mb, macro, level, 0);
return 0;
}
void void
initMacros(MacroContext *mc, const char *macrofile) initMacros(MacroContext *mc, const char *macrofile)
{ {
@ -1143,7 +1163,6 @@ initMacros(MacroContext *mc, const char *macrofile)
for (mfile = m = strdup(macrofile); *mfile; mfile = me) { for (mfile = m = strdup(macrofile); *mfile; mfile = me) {
FILE *fp; FILE *fp;
char buf[BUFSIZ]; char buf[BUFSIZ];
MacroBuf macrobuf, *mb = &macrobuf;
if ((me = strchr(mfile, ':')) != NULL) if ((me = strchr(mfile, ':')) != NULL)
*me++ = '\0'; *me++ = '\0';
@ -1164,9 +1183,8 @@ initMacros(MacroContext *mc, const char *macrofile)
if (c != '%') if (c != '%')
continue; continue;
n++; n++; /* skip % */
mb->mc = mc; /* XXX just enough to get by */ (void)rpmDefineMacro(NULL, n, RMIL_MACROFILES);
(void)doDefine(mb, n, RMIL_MACROFILES, 0);
} }
fclose(fp); fclose(fp);
} }
@ -1194,7 +1212,6 @@ freeMacros(MacroContext *mc)
} }
/* =============================================================== */ /* =============================================================== */
int isCompressed(const char *file, int *compressed) int isCompressed(const char *file, int *compressed)
{ {
FD_t fd; FD_t fd;
@ -1237,6 +1254,93 @@ int isCompressed(const char *file, int *compressed)
return 0; return 0;
} }
/* =============================================================== */
/* Return concatenated and expanded macro list */
char *
rpmExpand(const char *arg, ...)
{
char buf[BUFSIZ], *p, *pe;
const char *s;
va_list ap;
if (arg == NULL)
return strdup("");
p = buf;
strcpy(p, arg);
pe = p + strlen(p);
*pe = '\0';
va_start(ap, arg);
while ((s = va_arg(ap, const char *)) != NULL) {
strcpy(pe, s);
pe += strlen(pe);
*pe = '\0';
}
va_end(ap);
expandMacros(NULL, &globalMacroContext, buf, sizeof(buf));
return strdup(buf);
}
int
rpmExpandNumeric(const char *arg)
{
const char *val;
int rc;
if (arg == NULL)
return 0;
val = rpmExpand(arg, NULL);
if (!(val && *val != '%'))
rc = 0;
else if (*val == 'Y' || *val == 'y')
rc = 1;
else if (*val == 'N' || *val == 'n')
rc = 0;
else {
char *end;
rc = strtol(val, &end, 0);
if (!(end && *end == '\0'))
rc = 0;
}
xfree(val);
return rc;
}
/* Return concatenated and expanded path with multiple /'s removed */
const char *
rpmGetPath(const char *path, ...)
{
char buf[BUFSIZ], *p, *pe;
const char *s;
va_list ap;
if (path == NULL)
return strdup("");
p = buf;
strcpy(p, path);
pe = p + strlen(p);
*pe = '\0';
va_start(ap, path);
while ((s = va_arg(ap, const char *)) != NULL) {
/* XXX FIXME: this fixes only some of the "...//..." problems */
if (pe > p && pe[-1] == '/')
while(*s && *s == '/') s++;
if (*s != '\0') {
strcpy(pe, s);
pe += strlen(pe);
*pe = '\0';
}
}
va_end(ap);
expandMacros(NULL, &globalMacroContext, buf, sizeof(buf));
return strdup(buf);
}
/* =============================================================== */ /* =============================================================== */
#ifdef DEBUG_MACROS #ifdef DEBUG_MACROS
@ -1253,7 +1357,7 @@ main(int argc, char *argv[])
int x; int x;
initMacros(&mc, macrofile); initMacros(&mc, macrofile);
dumpMacroTable(&mc); dumpMacroTable(&mc, NULL);
if ((fp = fopen(testfile, "r")) != NULL) { if ((fp = fopen(testfile, "r")) != NULL) {
while(fgets(buf, sizeof(buf), fp)) { while(fgets(buf, sizeof(buf), fp)) {

View File

@ -243,9 +243,6 @@ extern const struct headerSprintfExtension rpmHeaderFormats[];
#define RPMVAR_NUM 55 /* number of RPMVAR entries */ #define RPMVAR_NUM 55 /* number of RPMVAR entries */
#define xfree(_p) free((void *)_p) #define xfree(_p) free((void *)_p)
char *rpmExpand(const char *arg, ...);
const char *rpmGetPath(const char *path, ...);
int rpmExpandNumeric(const char *arg);
char * rpmGetVar(int var); char * rpmGetVar(int var);
int rpmGetBooleanVar(int var); int rpmGetBooleanVar(int var);

View File

@ -43,22 +43,27 @@ extern MacroContext globalMacroContext;
extern "C" { extern "C" {
#endif #endif
#define COMPRESSED_NOT 0 void dumpMacroTable __P((MacroContext *mc, FILE *f));
#define COMPRESSED_OTHER 1
#define COMPRESSED_BZIP2 2
int isCompressed(const char *file, int *compressed); /* XXX this is used only in build/expression.c and will go away. */
const char *getMacroBody __P((MacroContext *mc, const char *name));
void dumpMacroTable __P((MacroContext *mc)); int expandMacros __P((void *spec, MacroContext *mc, char *sbuf, size_t sbuflen));
void addMacro __P((MacroContext *mc, const char *n, const char *o, const char *b, int depth));
void delMacro __P((MacroContext *mc, const char *n));
int rpmDefineMacro __P((MacroContext *mc, const char *macro, int level));
void initMacros __P((MacroContext *mc, const char *macrofile)); void initMacros __P((MacroContext *mc, const char *macrofile));
void freeMacros __P((MacroContext *mc)); void freeMacros __P((MacroContext *mc));
void addMacro __P((MacroContext *mc, const char *n, const char *o, const char *b, int depth)); #define COMPRESSED_NOT 0
void delMacro __P((MacroContext *mc, const char *n)); #define COMPRESSED_OTHER 1
int expandMacros __P((void *spec, MacroContext *mc, char *sbuf, size_t sbuflen)); #define COMPRESSED_BZIP2 2
int isCompressed __P((const char *file, int *compressed));
const char *getMacroBody __P((MacroContext *mc, const char *name)); char * rpmExpand __P((const char *arg, ...));
const char *rpmGetPath __P((const char *path, ...));
int rpmExpandNumeric __P((const char *arg));
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -534,89 +534,6 @@ static void setDefaults(void) {
} }
/* Return concatenated and expanded macro list */
char * rpmExpand(const char *arg, ...)
{
char buf[BUFSIZ], *p, *pe;
const char *s;
va_list ap;
if (arg == NULL)
return strdup("");
p = buf;
strcpy(p, arg);
pe = p + strlen(p);
*pe = '\0';
va_start(ap, arg);
while ((s = va_arg(ap, const char *)) != NULL) {
strcpy(pe, s);
pe += strlen(pe);
*pe = '\0';
}
va_end(ap);
expandMacros(NULL, &globalMacroContext, buf, sizeof(buf));
return strdup(buf);
}
int rpmExpandNumeric(const char *arg)
{
const char *val;
int rc;
if (arg == NULL)
return 0;
val = rpmExpand(arg, NULL);
if (!(val && *val != '%'))
rc = 0;
else if (*val == 'Y' || *val == 'y')
rc = 1;
else if (*val == 'N' || *val == 'n')
rc = 0;
else {
char *end;
rc = strtol(val, &end, 0);
if (!(end && *end == '\0'))
rc = 0;
}
xfree(val);
return rc;
}
/* Return concatenated and expanded path with multiple /'s removed */
const char * rpmGetPath(const char *path, ...)
{
char buf[BUFSIZ], *p, *pe;
const char *s;
va_list ap;
if (path == NULL)
return strdup("");
p = buf;
strcpy(p, path);
pe = p + strlen(p);
*pe = '\0';
va_start(ap, path);
while ((s = va_arg(ap, const char *)) != NULL) {
/* XXX FIXME: this fixes only some of the "...//..." problems */
if (pe > p && pe[-1] == '/')
while(*s && *s == '/') s++;
if (*s != '\0') {
strcpy(pe, s);
pe += strlen(pe);
*pe = '\0';
}
}
va_end(ap);
expandMacros(NULL, &globalMacroContext, buf, sizeof(buf));
return strdup(buf);
}
int rpmReadRC(const char * rcfiles) int rpmReadRC(const char * rcfiles)
{ {
char *myrcfiles, *r, *re; char *myrcfiles, *r, *re;
@ -1323,7 +1240,7 @@ int rpmShowRC(FILE *f)
fprintf(f, "%-21s : %s\n", opt->name, s ? s : "(not set)"); fprintf(f, "%-21s : %s\n", opt->name, s ? s : "(not set)");
} }
dumpMacroTable(&globalMacroContext); dumpMacroTable(&globalMacroContext, f);
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
# $Id: macros.in,v 1.18 1999/03/27 21:40:56 jbj Exp $ # $Id: macros.in,v 1.19 1999/03/28 00:47:43 jbj Exp $
#============================================================================== #==============================================================================
# Macro naming conventions (preliminary): # Macro naming conventions (preliminary):
# #
@ -18,22 +18,30 @@
#============================================================================== #==============================================================================
# ---- path macros # ---- path macros
# XXX The use of which here is overly simple.
# #
%__bzip2 %(which bzip2) %__bzip2 %(which bzip2)
%__cat %(which cat) %__cat %(which cat)
%__chgrp %(which chgrp) %__chgrp %(which chgrp)
%__chmod %(which chmod) %__chmod %(which chmod)
%__chown %(which chown) %__chown %(which chown)
%__gzip %(which gzip) %__cpio %(which cpio)
%__install %(which install) %__gzip %(which gzip)
%__libtoolize %(which libtoolize) %__install %(which install)
%__make %(which make) %__make %(which make)
%__mkdir %(which mkdir) %__mkdir %(which mkdir)
%__patch %(which patch) %__patch %(which patch)
%__ranlib %(which ranlib) %__ranlib %(which ranlib)
%__rm %(which rm) %__rm %(which rm)
%__strip %(which strip) %__strip %(which strip)
%__tar %(which tar) %__tar %(which tar)
# XXX avoid weird failures from which if tools are not installed
%__libtoolize libtoolize
%__aclocal aclocal
%__autoheader autoheader
%__automake automake
%__autoconf autoconf
#============================================================================== #==============================================================================
# ---- Required rpmrc macros. # ---- Required rpmrc macros.
@ -111,8 +119,8 @@
RPM_SOURCE_DIR=\"%{_sourcedir}\"\ RPM_SOURCE_DIR=\"%{_sourcedir}\"\
RPM_BUILD_DIR=\"%{_builddir}\"\ RPM_BUILD_DIR=\"%{_builddir}\"\
RPM_OPT_FLAGS=\"%{optflags}\"\ RPM_OPT_FLAGS=\"%{optflags}\"\
RPM_ARCH=\"%{_target_cpu}\"\ RPM_ARCH=\"%{_arch}\"\
RPM_OS=\"%{_target_os}\"\ RPM_OS=\"%{_os}\"\
export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\ export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\
RPM_DOC_DIR=\"%{_docdir}\"\ RPM_DOC_DIR=\"%{_docdir}\"\
export RPM_DOC_DIR\ export RPM_DOC_DIR\
@ -163,3 +171,17 @@
%configure \ %configure \
%{?__libtoolize:[ -f configure.in ] && %{__libtoolize} --copy --force} \ %{?__libtoolize:[ -f configure.in ] && %{__libtoolize} --copy --force} \
CFLAGS="%{optflags}" ./configure %{_target_platform} --prefix=%{_prefix} CFLAGS="%{optflags}" ./configure %{_target_platform} --prefix=%{_prefix}
#------------------------------------------------------------------------------
# The GNUconfigure macro does the following:
# update config.guess and config.sub.
# regenerate all autoconf/automake files
# run configure with correct prefix, platform, and CFLAGS.
#
%GNUconfigure \
%{__libtoolize} --copy --force} \
%{__aclocal} \
%{__autoheader} \
%{__automake} \
%{__autoconf} \
CFLAGS="%{optflags}" ./configure %{_target_platform} --prefix=%{_prefix}

File diff suppressed because it is too large Load Diff

17
rpm.c
View File

@ -20,6 +20,8 @@
#define GETOPT_RELOCATE 1016 #define GETOPT_RELOCATE 1016
#define GETOPT_SHOWRC 1018 #define GETOPT_SHOWRC 1018
#define GETOPT_EXCLUDEPATH 1019 #define GETOPT_EXCLUDEPATH 1019
#define GETOPT_DEFINEMACRO 1020
#define GETOPT_PREFIX 1021 /* XXX hack to avoid prefix dump */
char * version = VERSION; char * version = VERSION;
@ -85,6 +87,7 @@ static struct poptOption optionsTable[] = {
{ "build", 'b', POPT_ARG_STRING, 0, 'b', NULL, NULL}, { "build", 'b', POPT_ARG_STRING, 0, 'b', NULL, NULL},
{ "checksig", 'K', 0, 0, 'K', NULL, NULL}, { "checksig", 'K', 0, 0, 'K', NULL, NULL},
{ "dbpath", '\0', POPT_ARG_STRING, 0, GETOPT_DBPATH, NULL, NULL}, { "dbpath", '\0', POPT_ARG_STRING, 0, GETOPT_DBPATH, NULL, NULL},
{ "define", '\0', POPT_ARG_STRING, 0, GETOPT_DEFINEMACRO, NULL, NULL},
{ "erase", 'e', 0, 0, 'e', NULL, NULL}, { "erase", 'e', 0, 0, 'e', NULL, NULL},
{ "excludedocs", '\0', 0, &excldocs, 0, NULL, NULL}, { "excludedocs", '\0', 0, &excldocs, 0, NULL, NULL},
{ "excludepath", '\0', POPT_ARG_STRING, 0, GETOPT_EXCLUDEPATH, NULL, NULL}, { "excludepath", '\0', POPT_ARG_STRING, 0, GETOPT_EXCLUDEPATH, NULL, NULL},
@ -115,7 +118,7 @@ static struct poptOption optionsTable[] = {
{ "oldpackage", '\0', 0, &oldPackage, 0, NULL, NULL}, { "oldpackage", '\0', 0, &oldPackage, 0, NULL, NULL},
{ "percent", '\0', 0, &showPercents, 0, NULL, NULL}, { "percent", '\0', 0, &showPercents, 0, NULL, NULL},
{ "pipe", '\0', POPT_ARG_STRING, &pipeOutput, 0, NULL, NULL}, { "pipe", '\0', POPT_ARG_STRING, &pipeOutput, 0, NULL, NULL},
{ "prefix", '\0', POPT_ARG_STRING, &prefix, 0, NULL, NULL}, { "prefix", '\0', POPT_ARG_STRING, &prefix, GETOPT_PREFIX, NULL, NULL},
{ "query", 'q', 0, NULL, 'q', NULL, NULL}, { "query", 'q', 0, NULL, 'q', NULL, NULL},
{ "querytags", '\0', 0, &queryTags, 0, NULL, NULL}, { "querytags", '\0', 0, &queryTags, 0, NULL, NULL},
{ "quiet", '\0', 0, &quiet, 0, NULL, NULL}, { "quiet", '\0', 0, &quiet, 0, NULL, NULL},
@ -819,10 +822,18 @@ int main(int argc, char ** argv) {
case GETOPT_DBPATH: case GETOPT_DBPATH:
if (optArg[0] != '/') if (optArg[0] != '/')
argerror(_("arguments to --dbpath must begin with a /")); argerror(_("arguments to --dbpath must begin with a /"));
addMacro(&globalMacroContext, "_dbpath", NULL, optArg, RMIL_CMDLINE); addMacro(&globalMacroContext,"_dbpath", NULL, optArg, RMIL_CMDLINE);
gotDbpath = 1; gotDbpath = 1;
break; break;
case GETOPT_DEFINEMACRO:
rpmDefineMacro(&globalMacroContext, optArg, RMIL_CMDLINE);
break;
case GETOPT_PREFIX: /* XXX FIXME */
argerror(_("--prefix is broke, use --relocate /oldpath=/newpath instead"));
break;
case GETOPT_TIMECHECK: case GETOPT_TIMECHECK:
tce = NULL; tce = NULL;
timeCheck = strtoul(optArg, &tce, 10); timeCheck = strtoul(optArg, &tce, 10);
@ -988,7 +999,7 @@ int main(int argc, char ** argv) {
"installation")); "installation"));
if (bigMode != MODE_INSTALL && ignoreSize) if (bigMode != MODE_INSTALL && ignoreSize)
argerror(_("--ignoreos may only be specified during package " argerror(_("--ignoresize may only be specified during package "
"installation")); "installation"));
if (allMatches && bigMode != MODE_UNINSTALL) if (allMatches && bigMode != MODE_UNINSTALL)

View File

@ -1,6 +1,7 @@
#include "system.h" #include "system.h"
#include <assert.h> #include <assert.h>
#include <stdarg.h>
#define isblank(_c) ((_c) == ' ' || (_c) == '\t') #define isblank(_c) ((_c) == ' ' || (_c) == '\t')
#define STREQ(_t, _f, _fn) ((_fn) == (sizeof(_t)-1) && !strncmp((_t), (_f), (_fn))) #define STREQ(_t, _f, _fn) ((_fn) == (sizeof(_t)-1) && !strncmp((_t), (_f), (_fn)))
@ -10,6 +11,7 @@
#define rpmError fprintf #define rpmError fprintf
#define RPMERR_BADSPEC stderr #define RPMERR_BADSPEC stderr
#define _(x) x #define _(x) x
#define xfree(_p) free((void *)_p)
#else #else
#include "rpmlib.h" #include "rpmlib.h"
#endif #endif
@ -89,29 +91,32 @@ sortMacroTable(MacroContext *mc)
} }
void void
dumpMacroTable(MacroContext *mc) dumpMacroTable(MacroContext *mc, FILE *f)
{ {
int i; int i;
int nempty = 0; int nempty = 0;
int nactive = 0; int nactive = 0;
if (f == NULL)
f = stderr;
fprintf(stderr, "========================\n"); fprintf(f, "========================\n");
for (i = 0; i < mc->firstFree; i++) { for (i = 0; i < mc->firstFree; i++) {
MacroEntry *me; MacroEntry *me;
if ((me = mc->macroTable[i]) == NULL) { if ((me = mc->macroTable[i]) == NULL) {
nempty++; nempty++;
continue; continue;
} }
fprintf(stderr, "%3d%c %s", me->level, fprintf(f, "%3d%c %s", me->level,
(me->used > 0 ? '=' : ':'), me->name); (me->used > 0 ? '=' : ':'), me->name);
if (me->opts) if (me->opts && *me->opts)
fprintf(stderr, "(%s)", me->opts); fprintf(f, "(%s)", me->opts);
if (me->body) if (me->body && *me->body)
fprintf(stderr, "\t%s", me->body); fprintf(f, "\t%s", me->body);
fprintf(stderr, "\n"); fprintf(f, "\n");
nactive++; nactive++;
} }
fprintf(stderr, _("======================== active %d empty %d\n"), fprintf(f, _("======================== active %d empty %d\n"),
nactive, nempty); nactive, nempty);
} }
@ -505,7 +510,7 @@ pushMacro(MacroEntry **mep, const char *n, const char *o, const char *b, int lev
me->prev = prev; me->prev = prev;
me->name = (prev ? prev->name : strdup(n)); me->name = (prev ? prev->name : strdup(n));
me->opts = (o ? strdup(o) : NULL); me->opts = (o ? strdup(o) : NULL);
me->body = (b ? strdup(b) : NULL); me->body = strdup(b ? b : "");
me->used = 0; me->used = 0;
me->level = level; me->level = level;
*mep = me; *mep = me;
@ -939,7 +944,7 @@ expandMacro(MacroBuf *mb)
} }
if (STREQ("dump", f, fn)) { if (STREQ("dump", f, fn)) {
dumpMacroTable(mb->mc); dumpMacroTable(mb->mc, NULL);
if (*se == '\n') if (*se == '\n')
se++; se++;
s = se; s = se;
@ -1029,10 +1034,12 @@ expandMacro(MacroBuf *mb)
} }
/* Recursively expand body of macro */ /* Recursively expand body of macro */
mb->s = me->body; if (me->body && *me->body) {
rc = expandMacro(mb); mb->s = me->body;
if (rc == 0) rc = expandMacro(mb);
me->used++; /* Mark macro as used */ if (rc == 0)
me->used++; /* Mark macro as used */
}
/* Free args for "%name " macros with opts */ /* Free args for "%name " macros with opts */
if (me->opts != NULL) if (me->opts != NULL)
@ -1050,6 +1057,7 @@ expandMacro(MacroBuf *mb)
} }
/* =============================================================== */ /* =============================================================== */
/* XXX this is used only in build/expression.c and will go away. */
const char * const char *
getMacroBody(MacroContext *mc, const char *name) getMacroBody(MacroContext *mc, const char *name)
{ {
@ -1059,6 +1067,7 @@ getMacroBody(MacroContext *mc, const char *name)
} }
/* =============================================================== */ /* =============================================================== */
int int
expandMacros(void *spec, MacroContext *mc, char *s, size_t slen) expandMacros(void *spec, MacroContext *mc, char *s, size_t slen)
{ {
@ -1123,6 +1132,17 @@ delMacro(MacroContext *mc, const char *name)
popMacro(mep); popMacro(mep);
} }
int
rpmDefineMacro(MacroContext *mc, const char *macro, int level)
{
MacroBuf macrobuf, *mb = &macrobuf;
/* XXX just enough to get by */
mb->mc = (mc ? mc : &globalMacroContext);
(void)doDefine(mb, macro, level, 0);
return 0;
}
void void
initMacros(MacroContext *mc, const char *macrofile) initMacros(MacroContext *mc, const char *macrofile)
{ {
@ -1143,7 +1163,6 @@ initMacros(MacroContext *mc, const char *macrofile)
for (mfile = m = strdup(macrofile); *mfile; mfile = me) { for (mfile = m = strdup(macrofile); *mfile; mfile = me) {
FILE *fp; FILE *fp;
char buf[BUFSIZ]; char buf[BUFSIZ];
MacroBuf macrobuf, *mb = &macrobuf;
if ((me = strchr(mfile, ':')) != NULL) if ((me = strchr(mfile, ':')) != NULL)
*me++ = '\0'; *me++ = '\0';
@ -1164,9 +1183,8 @@ initMacros(MacroContext *mc, const char *macrofile)
if (c != '%') if (c != '%')
continue; continue;
n++; n++; /* skip % */
mb->mc = mc; /* XXX just enough to get by */ (void)rpmDefineMacro(NULL, n, RMIL_MACROFILES);
(void)doDefine(mb, n, RMIL_MACROFILES, 0);
} }
fclose(fp); fclose(fp);
} }
@ -1194,7 +1212,6 @@ freeMacros(MacroContext *mc)
} }
/* =============================================================== */ /* =============================================================== */
int isCompressed(const char *file, int *compressed) int isCompressed(const char *file, int *compressed)
{ {
FD_t fd; FD_t fd;
@ -1237,6 +1254,93 @@ int isCompressed(const char *file, int *compressed)
return 0; return 0;
} }
/* =============================================================== */
/* Return concatenated and expanded macro list */
char *
rpmExpand(const char *arg, ...)
{
char buf[BUFSIZ], *p, *pe;
const char *s;
va_list ap;
if (arg == NULL)
return strdup("");
p = buf;
strcpy(p, arg);
pe = p + strlen(p);
*pe = '\0';
va_start(ap, arg);
while ((s = va_arg(ap, const char *)) != NULL) {
strcpy(pe, s);
pe += strlen(pe);
*pe = '\0';
}
va_end(ap);
expandMacros(NULL, &globalMacroContext, buf, sizeof(buf));
return strdup(buf);
}
int
rpmExpandNumeric(const char *arg)
{
const char *val;
int rc;
if (arg == NULL)
return 0;
val = rpmExpand(arg, NULL);
if (!(val && *val != '%'))
rc = 0;
else if (*val == 'Y' || *val == 'y')
rc = 1;
else if (*val == 'N' || *val == 'n')
rc = 0;
else {
char *end;
rc = strtol(val, &end, 0);
if (!(end && *end == '\0'))
rc = 0;
}
xfree(val);
return rc;
}
/* Return concatenated and expanded path with multiple /'s removed */
const char *
rpmGetPath(const char *path, ...)
{
char buf[BUFSIZ], *p, *pe;
const char *s;
va_list ap;
if (path == NULL)
return strdup("");
p = buf;
strcpy(p, path);
pe = p + strlen(p);
*pe = '\0';
va_start(ap, path);
while ((s = va_arg(ap, const char *)) != NULL) {
/* XXX FIXME: this fixes only some of the "...//..." problems */
if (pe > p && pe[-1] == '/')
while(*s && *s == '/') s++;
if (*s != '\0') {
strcpy(pe, s);
pe += strlen(pe);
*pe = '\0';
}
}
va_end(ap);
expandMacros(NULL, &globalMacroContext, buf, sizeof(buf));
return strdup(buf);
}
/* =============================================================== */ /* =============================================================== */
#ifdef DEBUG_MACROS #ifdef DEBUG_MACROS
@ -1253,7 +1357,7 @@ main(int argc, char *argv[])
int x; int x;
initMacros(&mc, macrofile); initMacros(&mc, macrofile);
dumpMacroTable(&mc); dumpMacroTable(&mc, NULL);
if ((fp = fopen(testfile, "r")) != NULL) { if ((fp = fopen(testfile, "r")) != NULL) {
while(fgets(buf, sizeof(buf), fp)) { while(fgets(buf, sizeof(buf), fp)) {

View File

@ -43,22 +43,27 @@ extern MacroContext globalMacroContext;
extern "C" { extern "C" {
#endif #endif
#define COMPRESSED_NOT 0 void dumpMacroTable __P((MacroContext *mc, FILE *f));
#define COMPRESSED_OTHER 1
#define COMPRESSED_BZIP2 2
int isCompressed(const char *file, int *compressed); /* XXX this is used only in build/expression.c and will go away. */
const char *getMacroBody __P((MacroContext *mc, const char *name));
void dumpMacroTable __P((MacroContext *mc)); int expandMacros __P((void *spec, MacroContext *mc, char *sbuf, size_t sbuflen));
void addMacro __P((MacroContext *mc, const char *n, const char *o, const char *b, int depth));
void delMacro __P((MacroContext *mc, const char *n));
int rpmDefineMacro __P((MacroContext *mc, const char *macro, int level));
void initMacros __P((MacroContext *mc, const char *macrofile)); void initMacros __P((MacroContext *mc, const char *macrofile));
void freeMacros __P((MacroContext *mc)); void freeMacros __P((MacroContext *mc));
void addMacro __P((MacroContext *mc, const char *n, const char *o, const char *b, int depth)); #define COMPRESSED_NOT 0
void delMacro __P((MacroContext *mc, const char *n)); #define COMPRESSED_OTHER 1
int expandMacros __P((void *spec, MacroContext *mc, char *sbuf, size_t sbuflen)); #define COMPRESSED_BZIP2 2
int isCompressed __P((const char *file, int *compressed));
const char *getMacroBody __P((MacroContext *mc, const char *name)); char * rpmExpand __P((const char *arg, ...));
const char *rpmGetPath __P((const char *path, ...));
int rpmExpandNumeric __P((const char *arg));
#ifdef __cplusplus #ifdef __cplusplus
} }