Make pkg_find() follow the PKG_CONFIG_PATH environmental variable, if available.

feature/tap-sh
Alyx 2012-01-15 19:03:54 -06:00 committed by William Pitcock
parent 3c8bac678d
commit d0639b3353
3 changed files with 39 additions and 5 deletions

View File

@ -367,13 +367,11 @@ parse_deplist(pkg_t *pkg, const char *depends)
* Parse a .pc file into a pkg_t object structure.
*/
pkg_t *
parse_file(const char *filename)
parse_file(const char *filename, FILE *f)
{
FILE *f;
pkg_t *pkg;
char readbuf[BUFSIZ];
f = fopen(filename, "r");
if (f == NULL)
return NULL;

38
pkg.c
View File

@ -27,10 +27,46 @@ pkg_t *
pkg_find(const char *name)
{
char locbuf[BUFSIZ];
char path[BUFSIZ];
char *env_path;
int count = 0, pcount = 0;
FILE *f;
snprintf(locbuf, sizeof locbuf, "/usr/lib/pkgconfig/%s.pc", name);
if (!(f = fopen(locbuf, "r")))
{
env_path = getenv("PKG_CONFIG_PATH");
if (env_path == NULL)
return NULL;
return parse_file(locbuf);
while (env_path[count] != '\0')
{
if (env_path[count] != ':')
{
path[pcount] = env_path[count];
pcount++;
}
if (env_path[count] == ':')
{
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name);
if (f = fopen(locbuf, "r"))
return parse_file(locbuf, f);
path[0] = '\0';
pcount = 0;
}
count++;
}
if (path[0] != '\0')
{
snprintf(locbuf, sizeof locbuf, "%s/%s.pc", path, name);
f = fopen(locbuf, "r");
}
}
return parse_file(locbuf, f);
}
/*

2
pkg.h
View File

@ -97,7 +97,7 @@ pkg_t *pkg_verify_dependency(pkg_dependency_t *pkgdep);
const char *pkg_get_comparator(pkg_dependency_t *pkgdep);
/* parse.c */
pkg_t *parse_file(const char *path);
pkg_t *parse_file(const char *path, FILE *f);
char *tuple_find(pkg_tuple_t *head, const char *key);
pkg_dependency_t *parse_deplist(pkg_t *pkg, const char *depends);
pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t *tail);