ckiss

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 67531573d8c64054c52c1b8b819cd5bb553c0288
parent 8e06b61f64711c984465c443cb68b527f13706e5
Author: aabacchus <ben@bvnf.space>
Date:   Sun, 23 Apr 2023 16:26:05 +0100

move find_pkg, pkg_open_file into pkg.c

Diffstat:
Msrc/ckiss.h | 6------
Msrc/pkg.c | 27++++++++++++++++++++++++++-
Msrc/pkg.h | 6++++++
Msrc/utils.c | 25-------------------------
4 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/ckiss.h b/src/ckiss.h @@ -66,12 +66,6 @@ array_t find_in_path(char *name, array_t path, mode_t test_flags, bool limit, bo * cmd (0, 1, 2, ...). Arg list must be terminated with a NULL */ int available_cmd(array_t path, char *cmd, ...); -/* Wrapper around find_in_path. Name is an exact name, not a glob. Return the - * first package in $KISS_PATH:$sys_db, or NULL. */ -char *find_pkg(char *name, struct env *e); - -FILE *pkg_open_file(char *pkg_path, char *file, char *mode); - /* setup internal colours used by the logging functions. */ void setup_colors(struct env *e); diff --git a/src/pkg.c b/src/pkg.c @@ -56,7 +56,7 @@ pkg_source_type(char *remote, char *pkg_path) { struct pkg * pkg_parse_sources(char *pkg, struct env *e) { struct source **s = NULL; - char *pkg_path = find_pkg(pkg, e); + char *pkg_path = find_pkg_path(pkg, e); if (pkg_path == NULL) die2(pkg, "not found"); @@ -135,3 +135,28 @@ pkg_free(struct pkg *p) { free(p->pkg_path); free(p); } + +char * +find_pkg_path(char *name, struct env *e) { + array_t full_path = arr_copy(e->kiss_path); + arr_append(&full_path, e->sys_db, -1, true); + + array_t s = find_in_path(name, full_path, S_IFDIR, true, false); + char *pkg = NULL; + if (s != NULL) + pkg = s[0]; + + free(s); + arr_free(full_path); + return pkg; +} + +FILE * +pkg_open_file(char *pkg_path, char *file, char *mode) { + char *s = concat(pkg_path, "/", file, NULL); + FILE *f = fopen(s, mode); + if (f == NULL) + return NULL; + free(s); + return f; +} diff --git a/src/pkg.h b/src/pkg.h @@ -30,4 +30,10 @@ struct pkg *pkg_parse_sources(char *pkg, struct env *e); void pkg_free(struct pkg *p); +/* Wrapper around find_in_path. Name is an exact name, not a glob. Return the + * first package in $KISS_PATH:$sys_db, or NULL. */ +char *find_pkg_path(char *name, struct env *e); + +FILE *pkg_open_file(char *pkg_path, char *file, char *mode); + #endif diff --git a/src/utils.c b/src/utils.c @@ -170,31 +170,6 @@ available_cmd(array_t path, char *cmd, ...) { return -1; } -char * -find_pkg(char *name, struct env *e) { - array_t full_path = arr_copy(e->kiss_path); - arr_append(&full_path, e->sys_db, -1, true); - - array_t s = find_in_path(name, full_path, S_IFDIR, true, false); - char *pkg = NULL; - if (s != NULL) - pkg = s[0]; - - free(s); - arr_free(full_path); - return pkg; -} - -FILE * -pkg_open_file(char *pkg_path, char *file, char *mode) { - char *s = concat(pkg_path, "/", file, NULL); - FILE *f = fopen(s, mode); - if (f == NULL) - return NULL; - free(s); - return f; -} - void setup_colors(struct env *e) { if (!isatty(1) || e->color == 0) {