From d92392129691bddc6cb6ce6fbefd6969fd02d315 Mon Sep 17 00:00:00 2001 From: jbj Date: Wed, 2 Dec 1998 17:59:32 +0000 Subject: [PATCH] change --rcfile to permit colon separated file list. compile in defaults from rpmrc/macros. CVS patchset: 2573 CVS date: 1998/12/02 17:59:32 --- CHANGES | 2 + lib/rpmlib.h | 2 +- lib/rpmmacro.h | 1 + lib/rpmrc.c | 155 +++++++++++++++++++++++++++++++++---------------------- po/rpm.pot | 46 ++++++++--------- rpmio/rpmmacro.h | 1 + 6 files changed, 122 insertions(+), 85 deletions(-) diff --git a/CHANGES b/CHANGES index 64d072d..53c142b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ 2.5.6 -> 2.90 + - change --rcfile to permit colon separated file list. + - compile in defaults from rpmrc/macros. - finish hiding rpmdb index record data ("matches"). - implement abstract fd type almost everywhere. - update and rename Czech (Pavel Makovec ) diff --git a/lib/rpmlib.h b/lib/rpmlib.h index fd000f4..a3239cb 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -253,7 +253,7 @@ extern const struct headerSprintfExtension rpmHeaderFormats[]; char * rpmGetVar(int var); int rpmGetBooleanVar(int var); -void rpmSetVar(int var, char *val); +void rpmSetVar(int var, const char *val); /** rpmrc.c **/ diff --git a/lib/rpmmacro.h b/lib/rpmmacro.h index ba01ed6..be0a3ca 100644 --- a/lib/rpmmacro.h +++ b/lib/rpmmacro.h @@ -21,6 +21,7 @@ extern MacroContext globalMacroContext; /* * Markers for types of macros added throughout rpm. */ +#define RMIL_DEFAULT -11 #define RMIL_MACROFILES -9 #define RMIL_RPMRC -7 #define RMIL_TARBALL -5 diff --git a/lib/rpmrc.c b/lib/rpmrc.c index a92523d..389dd25 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -11,9 +11,10 @@ #include "misc.h" -static const char *usrlibrpmrc = LIBRPMRC_FILENAME; -static const char *etcrpmrc = "/etc/rpmrc"; +static const char *defrcfiles = LIBRPMRC_FILENAME ":/etc/rpmrc:~/.rpmrc"; +#if UNUSED static const char *macrofiles = MACROFILES; +#endif struct MacroContext globalMacroContext; @@ -156,9 +157,12 @@ static struct canonEntry *lookupInCanonTable(char *name, static const char *lookupInDefaultTable(const char *name, struct defaultEntry *table, int tableLen); + +static void setVarDefault(int var, const char *macroname, const char *val, const char *body); +static void setPathDefault(int var, const char *macroname, const char *subdir); static void setDefaults(void); -static void setPathDefault(int var, char * macroname, char * subdir); -static void rebuildCompatTables(int type, char * name); + +static void rebuildCompatTables(int type, char *name); /* compatiblity tables */ static int machCompatCacheAdd(char * name, const char * fn, int linenum, @@ -469,14 +473,24 @@ int rpmReadConfigFiles(const char * file, const char * target) return 0; } -static void setPathDefault(int var, char *macroname, char *subdir) { +static void setVarDefault(int var, const char *macroname, const char *val, const char *body) +{ + if (rpmGetVar(var)) return; + rpmSetVar(var, val); + if (body == NULL) + body = val; + addMacro(&globalMacroContext, macroname, NULL, body, RMIL_DEFAULT); +} + +static void setPathDefault(int var, const char *macroname, const char *subdir) +{ char * topdir; char * fn; if (rpmGetVar(var)) return; topdir = rpmGetVar(RPMVAR_TOPDIR); - if (!topdir) topdir = rpmGetVar(RPMVAR_TMPPATH); + if (topdir == NULL) topdir = rpmGetVar(RPMVAR_TMPPATH); fn = alloca(strlen(topdir) + strlen(subdir) + 2); strcpy(fn, topdir); @@ -488,7 +502,7 @@ static void setPathDefault(int var, char *macroname, char *subdir) { if (macroname != NULL) { #define _TOPDIRMACRO "%{_topdir}/" - char *body = alloca(sizeof(_TOPDIRMACRO) + strlen(subdir) + 2); + char *body = alloca(sizeof(_TOPDIRMACRO) + strlen(subdir) + 1); strcpy(body, _TOPDIRMACRO); strcat(body, subdir); addMacro(&globalMacroContext, macroname, NULL, body, RMIL_RPMRC); @@ -498,21 +512,36 @@ static void setPathDefault(int var, char *macroname, char *subdir) { static void setDefaults(void) { - /* Read in all macro files (and also set maximum recursion depth) */ - initMacros(&globalMacroContext, macrofiles); + addMacro(&globalMacroContext, "_usr", NULL, "/usr", RMIL_DEFAULT); + addMacro(&globalMacroContext, "_var", NULL, "/var", RMIL_DEFAULT); + + setVarDefault(RPMVAR_MACROFILES, "_macrofiles", + "/usr/lib/rpm/macros", "%{_usr}/lib/rpm/macros"); + setVarDefault(RPMVAR_TOPDIR, "_topdir", + "/usr/src/redhat", "%{_usr}/src/redhat"); + setVarDefault(RPMVAR_TMPPATH, "_tmppath", + "/var/tmp", "%{_var}/tmp"); + setVarDefault(RPMVAR_DBPATH, "_dbpath", + "/var/lib/rpm", "%{_var}/lib/rpm"); + setVarDefault(RPMVAR_DEFAULTDOCDIR, "_defaultdocdir", + "/usr/doc", "%{_usr}/doc"); + + setVarDefault(RPMVAR_OPTFLAGS, "optflags", "-O2", NULL); + setVarDefault(RPMVAR_SIGTYPE, "sigtype", "none", NULL); + setVarDefault(RPMVAR_BUILDSHELL, "buildshell", "/bin/sh", NULL); + + setPathDefault(RPMVAR_BUILDDIR, "_builddir", "BUILD"); + setPathDefault(RPMVAR_RPMDIR, "_rpmdir", "RPMS"); + setPathDefault(RPMVAR_SRPMDIR, "_srcrpmdir", "SRPMS"); + setPathDefault(RPMVAR_SOURCEDIR, "_sourcedir", "SOURCES"); + setPathDefault(RPMVAR_SPECDIR, "_specdir", "SPECS"); - rpmSetVar(RPMVAR_OPTFLAGS, "-O2"); - rpmSetVar(RPMVAR_SIGTYPE, "none"); - rpmSetVar(RPMVAR_DEFAULTDOCDIR, "/usr/doc"); - rpmSetVar(RPMVAR_TOPDIR, "/usr/src/redhat"); - rpmSetVar(RPMVAR_BUILDSHELL, "/bin/sh"); } -int rpmReadRC(const char * file) { - FD_t fd; - const char * fn; - char * home; - int rc = 0; +int rpmReadRC(const char * rcfiles) +{ + char *myrcfiles, *r, *re; + int rc; static int first = 1; if (first) { @@ -520,56 +549,60 @@ int rpmReadRC(const char * file) { first = 0; } - fd = fdOpen(usrlibrpmrc, O_RDONLY, 0); - if (fdFileno(fd) >= 0) { - rc = doReadRC(fd, usrlibrpmrc); - fdClose(fd); - if (rc) return rc; - } else { - rpmError(RPMERR_RPMRC, _("Unable to open %s for reading: %s."), - usrlibrpmrc, strerror(errno)); - return 1; - } + if (rcfiles == NULL) + rcfiles = defrcfiles; - fn = (file != NULL ? file : etcrpmrc); - fd = fdOpen(fn, O_RDONLY, 0); - if (fdFileno(fd) >= 0) { - rc = doReadRC(fd, fn); - fdClose(fd); - if (rc) return rc; - } else if (file != NULL) { - rpmError(RPMERR_RPMRC, _("Unable to open %s for reading: %s."), file, - strerror(errno)); - return 1; - } + /* Read each file in rcfiles. */ + rc = 0; + for (r = myrcfiles = strdup(rcfiles); *r != '\0'; r = re) { + char fn[FILENAME_MAX+1]; + FD_t fd; - if (file == NULL) { - home = getenv("HOME"); - if (home != NULL) { - char *fn = alloca(strlen(home) + 8); - strcpy(fn, home); - strcat(fn, "/.rpmrc"); - fd = fdOpen(fn, O_RDONLY, 0); - if (fdFileno(fd) >= 0) { - rc |= doReadRC(fd, fn); - fdClose(fd); - if (rc) return rc; + /* Get pointer to rest of files */ + if ((re = strchr(r, ':')) != NULL) + *re++ = '\0'; + else + re = r + strlen(r); + + /* Expand ~/ to $HOME/ */ + fn[0] = '\0'; + if (r[0] == '~' && r[1] == '/') { + char *home = getenv("HOME"); + if (home == NULL) { + rpmError(RPMERR_RPMRC, _("Cannot expand %s"), r); + rc = 1; + break; } + strcpy(fn, home); + r++; } + strcat(fn, r); + + /* Read another rcfile */ + fd = fdOpen(fn, O_RDONLY, 0); + if (fdFileno(fd) < 0) { + /* XXX Only /usr/lib/rpm/rpmrc must exist in default rcfiles list */ + if (rcfiles == defrcfiles && myrcfiles != r) + continue; + rpmError(RPMERR_RPMRC, _("Unable to open %s for reading: %s."), + fn, strerror(errno)); + rc = 1; + break; + } + rc = doReadRC(fd, fn); + fdClose(fd); + if (rc) break; } + if (myrcfiles) free(myrcfiles); + if (rc) + return rc; rpmSetMachine(NULL, NULL); /* XXX WTFO? Why bother? */ - setPathDefault(RPMVAR_BUILDDIR, "_builddir", "BUILD"); - setPathDefault(RPMVAR_RPMDIR, "_rpmdir", "RPMS"); - setPathDefault(RPMVAR_SRPMDIR, "_srcrpmdir", "SRPMS"); - setPathDefault(RPMVAR_SOURCEDIR, "_sourcedir", "SOURCES"); - setPathDefault(RPMVAR_SPECDIR, "_specdir", "SPECS"); - - if ((fn = rpmGetVar(RPMVAR_MACROFILES)) != NULL) - initMacros(&globalMacroContext, fn); + if ((r = rpmGetVar(RPMVAR_MACROFILES)) != NULL) + initMacros(&globalMacroContext, r); - return 0; + return rc; } static int doReadRC(FD_t fd, const char * filename) { @@ -937,7 +970,7 @@ int rpmGetBooleanVar(int var) { return 0; } -void rpmSetVar(int var, char *val) { +void rpmSetVar(int var, const char *val) { freeRpmVar(&values[var]); values[var].arch = NULL; diff --git a/po/rpm.pot b/po/rpm.pot index a05ab2f..c20159b 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 1998-12-01 18:23-0500\n" +"POT-Creation-Date: 1998-12-02 12:50-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2978,92 +2978,92 @@ msgstr "" msgid "read failed: %s (%d)" msgstr "" -#: ../lib/rpmrc.c:212 +#: ../lib/rpmrc.c:216 #, c-format msgid "missing second ':' at %s:%d" msgstr "" -#: ../lib/rpmrc.c:215 +#: ../lib/rpmrc.c:219 #, c-format msgid "missing architecture name at %s:%d" msgstr "" -#: ../lib/rpmrc.c:363 +#: ../lib/rpmrc.c:367 #, c-format msgid "Incomplete data line at %s:%d" msgstr "" -#: ../lib/rpmrc.c:367 +#: ../lib/rpmrc.c:371 #, c-format msgid "Too many args in data line at %s:%d" msgstr "" -#: ../lib/rpmrc.c:374 +#: ../lib/rpmrc.c:378 #, c-format msgid "Bad arch/os number: %s (%s:%d)" msgstr "" -#: ../lib/rpmrc.c:408 +#: ../lib/rpmrc.c:412 #, c-format msgid "Incomplete default line at %s:%d" msgstr "" -#: ../lib/rpmrc.c:413 +#: ../lib/rpmrc.c:417 #, c-format msgid "Too many args in default line at %s:%d" msgstr "" -#: ../lib/rpmrc.c:529 ../lib/rpmrc.c:541 +#: ../lib/rpmrc.c:572 +#, c-format +msgid "Cannot expand %s" +msgstr "" + +#: ../lib/rpmrc.c:587 #, c-format msgid "Unable to open %s for reading: %s." msgstr "" -#: ../lib/rpmrc.c:588 +#: ../lib/rpmrc.c:621 #, c-format msgid "Failed to read %s: %s." msgstr "" -#: ../lib/rpmrc.c:619 +#: ../lib/rpmrc.c:652 #, c-format msgid "missing ':' at %s:%d" msgstr "" -#: ../lib/rpmrc.c:635 ../lib/rpmrc.c:730 +#: ../lib/rpmrc.c:668 ../lib/rpmrc.c:716 #, c-format msgid "missing argument for %s at %s:%d" msgstr "" -#: ../lib/rpmrc.c:665 -#, c-format -msgid "no macroname for setenv %s:%d" -msgstr "" - -#: ../lib/rpmrc.c:696 +#: ../lib/rpmrc.c:682 #, c-format msgid "expansion failed at %s:d \"%s\"" msgstr "" -#: ../lib/rpmrc.c:702 +#: ../lib/rpmrc.c:688 #, c-format msgid "cannot open %s at %s:%d" msgstr "" -#: ../lib/rpmrc.c:720 +#: ../lib/rpmrc.c:706 #, c-format msgid "missing architecture for %s at %s:%d" msgstr "" -#: ../lib/rpmrc.c:787 +#: ../lib/rpmrc.c:773 #, c-format msgid "bad option '%s' at %s:%d" msgstr "" -#: ../lib/rpmrc.c:1152 +#: ../lib/rpmrc.c:1131 #, c-format msgid "Unknown system: %s\n" msgstr "" -#: ../lib/rpmrc.c:1153 +#: ../lib/rpmrc.c:1132 msgid "Please contact rpm-list@redhat.com\n" msgstr "" diff --git a/rpmio/rpmmacro.h b/rpmio/rpmmacro.h index ba01ed6..be0a3ca 100644 --- a/rpmio/rpmmacro.h +++ b/rpmio/rpmmacro.h @@ -21,6 +21,7 @@ extern MacroContext globalMacroContext; /* * Markers for types of macros added throughout rpm. */ +#define RMIL_DEFAULT -11 #define RMIL_MACROFILES -9 #define RMIL_RPMRC -7 #define RMIL_TARBALL -5 -- 2.7.4