pkg: clean up pkg_find() by adding pkg_try_specific_path(). (issue #16)
parent
2aaa1ce0df
commit
4b193018a4
84
pkg.c
84
pkg.c
|
@ -211,13 +211,33 @@ pkg_free(pkg_t *pkg)
|
||||||
free(pkg);
|
free(pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline pkg_t *
|
||||||
|
pkg_try_specific_path(const char *path, const char *name, unsigned int flags)
|
||||||
|
{
|
||||||
|
pkg_t *pkg = NULL;
|
||||||
|
FILE *f;
|
||||||
|
char locbuf[PKG_CONFIG_PATH_SZ];
|
||||||
|
char uninst_locbuf[PKG_CONFIG_PATH_SZ];
|
||||||
|
|
||||||
|
snprintf(locbuf, sizeof locbuf, "%s/%s" PKG_CONFIG_EXT, path, name);
|
||||||
|
snprintf(uninst_locbuf, sizeof uninst_locbuf, "%s/%s-uninstalled" PKG_CONFIG_EXT, path, name);
|
||||||
|
|
||||||
|
if (!(flags & PKGF_NO_UNINSTALLED) && (f = fopen(uninst_locbuf, "r")) != NULL)
|
||||||
|
{
|
||||||
|
pkg = pkg_new_from_file(uninst_locbuf, f);
|
||||||
|
pkg->uninstalled = true;
|
||||||
|
}
|
||||||
|
else if ((f = fopen(locbuf, "r")) != NULL)
|
||||||
|
pkg = pkg_new_from_file(locbuf, f);
|
||||||
|
|
||||||
|
return pkg;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
pkg_t *
|
pkg_t *
|
||||||
pkg_find_in_registry_key(HKEY hkey, const char *name, unsigned int flags)
|
pkg_find_in_registry_key(HKEY hkey, const char *name, unsigned int flags)
|
||||||
{
|
{
|
||||||
pkg_t *pkg = NULL;
|
pkg_t *pkg = NULL;
|
||||||
char locbuf[PKG_CONFIG_PATH_SZ];
|
|
||||||
char uninst_locbuf[PKG_CONFIG_PATH_SZ];
|
|
||||||
|
|
||||||
HKEY key;
|
HKEY key;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -238,28 +258,9 @@ pkg_find_in_registry_key(HKEY hkey, const char *name, unsigned int flags)
|
||||||
if (RegQueryValueEx(key, buf, NULL, &type, pathbuf, &pathbuflen)
|
if (RegQueryValueEx(key, buf, NULL, &type, pathbuf, &pathbuflen)
|
||||||
== ERROR_SUCCESS && type == REG_SZ)
|
== ERROR_SUCCESS && type == REG_SZ)
|
||||||
{
|
{
|
||||||
FILE *f;
|
pkg = pkg_try_specific_path(pathbuf, name, flags);
|
||||||
/* XXX: support REG_EXPAND_SZ? */
|
if (pkg != NULL)
|
||||||
|
|
||||||
snprintf(locbuf, sizeof locbuf, "%s/%s" PKG_CONFIG_EXT,
|
|
||||||
pathbuf, name);
|
|
||||||
snprintf(uninst_locbuf, sizeof uninst_locbuf,
|
|
||||||
"%s/%s-uninstalled" PKG_CONFIG_EXT, pathbuf, name);
|
|
||||||
|
|
||||||
if (!(flags & PKGF_NO_UNINSTALLED)
|
|
||||||
&& (f = fopen(uninst_locbuf, "r")) != NULL)
|
|
||||||
{
|
|
||||||
pkg = pkg_new_from_file(locbuf, f);
|
|
||||||
pkg->uninstalled = true;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if ((f = fopen(locbuf, "r")) != NULL)
|
|
||||||
{
|
|
||||||
pkg = pkg_new_from_file(locbuf, f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bufsize = sizeof buf;
|
bufsize = sizeof buf;
|
||||||
|
@ -273,8 +274,6 @@ pkg_find_in_registry_key(HKEY hkey, const char *name, unsigned int flags)
|
||||||
pkg_t *
|
pkg_t *
|
||||||
pkg_find(const char *name, unsigned int flags)
|
pkg_find(const char *name, unsigned int flags)
|
||||||
{
|
{
|
||||||
char locbuf[PKG_CONFIG_PATH_SZ];
|
|
||||||
char uninst_locbuf[PKG_CONFIG_PATH_SZ];
|
|
||||||
char **path = NULL;
|
char **path = NULL;
|
||||||
size_t count = 0, iter = 0;
|
size_t count = 0, iter = 0;
|
||||||
const char *env_path;
|
const char *env_path;
|
||||||
|
@ -296,22 +295,9 @@ pkg_find(const char *name, unsigned int flags)
|
||||||
|
|
||||||
for (iter = 0; iter < count; iter++)
|
for (iter = 0; iter < count; iter++)
|
||||||
{
|
{
|
||||||
snprintf(locbuf, sizeof locbuf, "%s/%s" PKG_CONFIG_EXT, path[iter], name);
|
pkg = pkg_try_specific_path(path[iter], name, flags);
|
||||||
snprintf(uninst_locbuf, sizeof uninst_locbuf, "%s/%s-uninstalled" PKG_CONFIG_EXT, path[iter], name);
|
if (pkg != NULL)
|
||||||
|
|
||||||
if (!(flags & PKGF_NO_UNINSTALLED) && (f = fopen(uninst_locbuf, "r")) != NULL)
|
|
||||||
{
|
|
||||||
pkg = pkg_new_from_file(locbuf, f);
|
|
||||||
pkg->uninstalled = true;
|
|
||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
if ((f = fopen(locbuf, "r")) != NULL)
|
|
||||||
{
|
|
||||||
pkg = pkg_new_from_file(locbuf, f);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,28 +311,14 @@ pkg_find(const char *name, unsigned int flags)
|
||||||
|
|
||||||
for (iter = 0; iter < count; iter++)
|
for (iter = 0; iter < count; iter++)
|
||||||
{
|
{
|
||||||
snprintf(locbuf, sizeof locbuf, "%s/%s" PKG_CONFIG_EXT, path[iter], name);
|
pkg = pkg_try_specific_path(path[iter], name, flags);
|
||||||
snprintf(uninst_locbuf, sizeof uninst_locbuf, "%s/%s-uninstalled" PKG_CONFIG_EXT, path[iter], name);
|
if (pkg != NULL)
|
||||||
|
|
||||||
if (!(flags & PKGF_NO_UNINSTALLED) && (f = fopen(uninst_locbuf, "r")) != NULL)
|
|
||||||
{
|
|
||||||
pkg_t *pkg = pkg_new_from_file(locbuf, f);
|
|
||||||
pkg->uninstalled = true;
|
|
||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
if ((f = fopen(locbuf, "r")) != NULL)
|
|
||||||
{
|
|
||||||
pkg = pkg_new_from_file(locbuf, f);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* support getting PKG_CONFIG_PATH from registry */
|
/* support getting PKG_CONFIG_PATH from registry */
|
||||||
|
|
||||||
pkg = pkg_find_in_registry_key(HKEY_CURRENT_USER, name, flags);
|
pkg = pkg_find_in_registry_key(HKEY_CURRENT_USER, name, flags);
|
||||||
if (!pkg)
|
if (!pkg)
|
||||||
pkg = pkg_find_in_registry_key(HKEY_LOCAL_MACHINE, name, flags);
|
pkg = pkg_find_in_registry_key(HKEY_LOCAL_MACHINE, name, flags);
|
||||||
|
|
Loading…
Reference in New Issue