diff --git a/parse.c b/parse.c index bf1eb9f..6bf6e3d 100644 --- a/parse.c +++ b/parse.c @@ -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; diff --git a/pkg.c b/pkg.c index 684a8c2..9366631 100644 --- a/pkg.c +++ b/pkg.c @@ -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); } /* diff --git a/pkg.h b/pkg.h index bdb0db9..ca080e9 100644 --- a/pkg.h +++ b/pkg.h @@ -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);