Further simplify rpmInitMacros()

- Use argvSplit() for splitting the macro path to components instead of
  manual pointer-parsery.
- If URL's are to be supported or accepted at all (previous code attempted
  to skip them), ':' is a very poor delimiter character.
This commit is contained in:
Panu Matilainen 2008-04-19 16:42:56 +03:00
parent e336146a9e
commit 9ae911eefe
1 changed files with 14 additions and 27 deletions

View File

@ -1511,45 +1511,32 @@ exit:
void void
rpmInitMacros(rpmMacroContext mc, const char * macrofiles) rpmInitMacros(rpmMacroContext mc, const char * macrofiles)
{ {
char *mfiles, *m, *me; ARGV_t pattern, globs = NULL;
if (macrofiles == NULL) if (macrofiles == NULL)
return; return;
mfiles = xstrdup(macrofiles); argvSplit(&globs, macrofiles, ":");
for (m = mfiles; m && *m != '\0'; m = me) { for (pattern = globs; *pattern; pattern++) {
ARGV_t av = NULL; ARGV_t path, files = NULL;
int ac = 0;
int i;
for (me = m; (me = strchr(me, ':')) != NULL; me++) {
/* Skip over URI's. */
if (!(me[1] == '/' && me[2] == '/'))
break;
}
if (me && *me == ':')
*me++ = '\0';
else
me = m + strlen(m);
/* Glob expand the macro file path element, expanding ~ to $HOME. */ /* Glob expand the macro file path element, expanding ~ to $HOME. */
i = rpmGlob(m, &ac, &av); if (rpmGlob(*pattern, NULL, &files) != 0) {
if (i != 0)
continue; continue;
}
/* Read macros from each file. */ /* Read macros from each file. */
for (i = 0; i < ac; i++) { for (path = files; *path; path++) {
if (rpmFileHasSuffix(av[i], ".rpmnew") || if (rpmFileHasSuffix(*path, ".rpmnew") ||
rpmFileHasSuffix(av[i], ".rpmsave") || rpmFileHasSuffix(*path, ".rpmsave") ||
rpmFileHasSuffix(av[i], ".rpmorig")) { rpmFileHasSuffix(*path, ".rpmorig")) {
continue; continue;
} }
(void) rpmLoadMacroFile(mc, av[i]); (void) rpmLoadMacroFile(mc, *path);
} }
argvFree(av); argvFree(files);
} }
mfiles = _free(mfiles); argvFree(globs);
/* Reload cmdline macros */ /* Reload cmdline macros */
rpmLoadMacros(rpmCLIMacroContext, RMIL_CMDLINE); rpmLoadMacros(rpmCLIMacroContext, RMIL_CMDLINE);