From f0a088596ec7da11c44a83dd42d34935532b83e5 Mon Sep 17 00:00:00 2001 From: jbj Date: Wed, 31 Mar 1999 16:57:01 +0000 Subject: [PATCH] expand twiddles in macrofiles list. CVS patchset: 2931 CVS date: 1999/03/31 16:57:01 --- CHANGES | 1 + lib/macro.c | 25 +++++++++++++++++++------ po/rpm.pot | 6 +++--- rpmio/macro.c | 25 +++++++++++++++++++------ 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index 83be84312..fc6ea83ff 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ - fix: create ppc directories correctly. - (re-)enable fixowner/fixgroup macros. - fix: specfile BuildRoot was masking rpmrc macro. + - expand twiddles in macrofiles list. 2.91 -> 2.92 - update with libtool-2.4f. diff --git a/lib/macro.c b/lib/macro.c index 7f522fbeb..d545d0dab 100644 --- a/lib/macro.c +++ b/lib/macro.c @@ -1144,7 +1144,7 @@ rpmDefineMacro(MacroContext *mc, const char *macro, int level) } void -initMacros(MacroContext *mc, const char *macrofile) +initMacros(MacroContext *mc, const char *macrofiles) { char *m, *mfile, *me; static int first = 1; @@ -1157,10 +1157,10 @@ initMacros(MacroContext *mc, const char *macrofile) first = 0; } - if (macrofile == NULL) + if (macrofiles == NULL) return; - for (mfile = m = strdup(macrofile); *mfile; mfile = me) { + for (mfile = m = strdup(macrofiles); *mfile; mfile = me) { FILE *fp; char buf[BUFSIZ]; @@ -1169,7 +1169,20 @@ initMacros(MacroContext *mc, const char *macrofile) else me = mfile + strlen(mfile); - if ((fp=fopen(mfile, "r")) == NULL) + /* Expand ~/ to $HOME */ + buf[0] = '\0'; + if (mfile[0] == '~' && mfile[1] == '/') { + char *home; + if ((home = getenv("HOME")) != NULL) { + mfile += 2; + strncpy(buf, home, sizeof(buf)); + strncat(buf, "/", sizeof(buf) - strlen(buf)); + } + } + strncat(buf, mfile, sizeof(buf) - strlen(buf)); + buf[sizeof(buf)-1] = '\0'; + + if ((fp=fopen(buf, "r")) == NULL) continue; /* XXX Assume new fangled macro expansion */ @@ -1346,7 +1359,7 @@ rpmGetPath(const char *path, ...) #ifdef DEBUG_MACROS MacroContext mc = { NULL, 0, 0}; -char *macrofile = "./paths:./environment:./macros"; +char *macrofiles = "./paths:./environment:./macros"; char *testfile = "./test"; int @@ -1356,7 +1369,7 @@ main(int argc, char *argv[]) FILE *fp; int x; - initMacros(&mc, macrofile); + initMacros(&mc, macrofiles); dumpMacroTable(&mc, NULL); if ((fp = fopen(testfile, "r")) != NULL) { diff --git a/po/rpm.pot b/po/rpm.pot index 617ec20c7..5c9ce7371 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 1999-03-31 08:13-0500\n" +"POT-Creation-Date: 1999-03-31 11:39-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2597,12 +2597,12 @@ msgstr "" msgid "Target buffer overflow" msgstr "" -#: ../lib/macro.c:1225 ../lib/macro.c:1233 +#: ../lib/macro.c:1239 ../lib/macro.c:1247 #, c-format msgid "File %s: %s" msgstr "" -#: ../lib/macro.c:1236 +#: ../lib/macro.c:1250 #, c-format msgid "File %s is smaller than %d bytes" msgstr "" diff --git a/rpmio/macro.c b/rpmio/macro.c index 7f522fbeb..d545d0dab 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1144,7 +1144,7 @@ rpmDefineMacro(MacroContext *mc, const char *macro, int level) } void -initMacros(MacroContext *mc, const char *macrofile) +initMacros(MacroContext *mc, const char *macrofiles) { char *m, *mfile, *me; static int first = 1; @@ -1157,10 +1157,10 @@ initMacros(MacroContext *mc, const char *macrofile) first = 0; } - if (macrofile == NULL) + if (macrofiles == NULL) return; - for (mfile = m = strdup(macrofile); *mfile; mfile = me) { + for (mfile = m = strdup(macrofiles); *mfile; mfile = me) { FILE *fp; char buf[BUFSIZ]; @@ -1169,7 +1169,20 @@ initMacros(MacroContext *mc, const char *macrofile) else me = mfile + strlen(mfile); - if ((fp=fopen(mfile, "r")) == NULL) + /* Expand ~/ to $HOME */ + buf[0] = '\0'; + if (mfile[0] == '~' && mfile[1] == '/') { + char *home; + if ((home = getenv("HOME")) != NULL) { + mfile += 2; + strncpy(buf, home, sizeof(buf)); + strncat(buf, "/", sizeof(buf) - strlen(buf)); + } + } + strncat(buf, mfile, sizeof(buf) - strlen(buf)); + buf[sizeof(buf)-1] = '\0'; + + if ((fp=fopen(buf, "r")) == NULL) continue; /* XXX Assume new fangled macro expansion */ @@ -1346,7 +1359,7 @@ rpmGetPath(const char *path, ...) #ifdef DEBUG_MACROS MacroContext mc = { NULL, 0, 0}; -char *macrofile = "./paths:./environment:./macros"; +char *macrofiles = "./paths:./environment:./macros"; char *testfile = "./test"; int @@ -1356,7 +1369,7 @@ main(int argc, char *argv[]) FILE *fp; int x; - initMacros(&mc, macrofile); + initMacros(&mc, macrofiles); dumpMacroTable(&mc, NULL); if ((fp = fopen(testfile, "r")) != NULL) {