ckiss

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

commit 52c1bcd4a4e41d4387a983a68ed57c0ae50efcbe
parent f97bad4c374472cb26f673755a74a0c33c4d3eb7
Author: aabacchus <ben@bvnf.space>
Date:   Sun, 23 Apr 2023 22:16:58 +0100

split utils.c prototypes into utils.h

Diffstat:
Msrc/Makefile | 14+++++++-------
Msrc/array.c | 1+
Msrc/checksum.c | 1+
Msrc/ckiss.h | 36------------------------------------
Msrc/list.c | 1+
Msrc/main.c | 1+
Msrc/pkg.c | 1+
Msrc/search.c | 1+
Msrc/utils.c | 1+
Asrc/utils.h | 44++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 58 insertions(+), 43 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -27,11 +27,11 @@ clean: .PHONY: clean test all -utils.o: ckiss.h array.h +utils.o: ckiss.h array.h utils.h test.o: ckiss.h -list.o: ckiss.h -search.o: ckiss.h array.h -array.o: ckiss.h array.h -checksum.o: ckiss.h pkg.h -pkg.o: ckiss.h pkg.h -main.o: ckiss.h +list.o: ckiss.h utils.h +search.o: ckiss.h array.h utils.h +array.o: ckiss.h array.h utils.h +checksum.o: ckiss.h pkg.h utils.h +pkg.o: ckiss.h pkg.h utils.h +main.o: ckiss.h utils.h diff --git a/src/array.c b/src/array.c @@ -3,6 +3,7 @@ #include "ckiss.h" #include "array.h" +#include "utils.h" size_t arr_len(array_t arr) { diff --git a/src/checksum.c b/src/checksum.c @@ -6,6 +6,7 @@ #include "ckiss.h" #include "pkg.h" +#include "utils.h" /* reads f and returns the checksum */ static char * diff --git a/src/ckiss.h b/src/ckiss.h @@ -37,44 +37,8 @@ struct env { }; /* include these now in case they need struct env */ -#include "array.h" #include "pkg.h" -/* called "mylog" to avoid collision with math.h log function. */ -void mylog(const char *s); -void mylog2(const char *name, const char *s); -void mylog_v(char *format, ...); -void warn(const char *s); -void warn2(const char *name, const char *s); -noreturn void die(const char *s); -noreturn void die2(const char *name, const char *s); -noreturn void die_perror(const char *s); - -/* returns a string containing the concatenation of all args. Args must be - * terminated with a NULL. Returned string must be freed by caller.*/ -char *concat(char *s, ...); - -/* Goes through the path array looking for a file in each directory with the - * given name. Returns the first one. The returned string must be freed by the - * caller. If limit is true, only return the first result found in path, - * otherwise return an array of all results found in path. If isglob is true, - * treat name as a glob. test_flags is OR'd with the file's mode (from stat(3)) - * to check if it matches a criterion (eg. executable, directory). */ -array_t find_in_path(char *name, array_t path, mode_t test_flags, bool limit, bool isglob); - -/* Checks for the first cmd which may be found in path. Returns the index of the - * cmd (0, 1, 2, ...). Arg list must be terminated with a NULL */ -int available_cmd(array_t path, char *cmd, ...); - -/* setup internal colours used by the logging functions. */ -void setup_colors(struct env *e); - -/* parses environment variables to initialise a struct env. */ -struct env *setup_env(void); - -/* correctly frees a struct env. */ -void destroy_env(struct env *e); - /* returns the checksum of the file specified by s, if needed and if the cache * is present (must download first) */ char *source_generate_checksum(struct source *s); diff --git a/src/list.c b/src/list.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> #include "ckiss.h" +#include "utils.h" void pkg_print(char *pkg, struct env *e) { diff --git a/src/main.c b/src/main.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include "ckiss.h" +#include "utils.h" noreturn void usage(int r) { diff --git a/src/pkg.c b/src/pkg.c @@ -6,6 +6,7 @@ #include "ckiss.h" #include "pkg.h" +#include "utils.h" /* returns the location of the cache file for the source for pkg, or NULL if not * needed (eg git sources or local files in repo) */ diff --git a/src/search.c b/src/search.c @@ -3,6 +3,7 @@ #include "ckiss.h" #include "array.h" +#include "utils.h" int search(int argc, char **argv, struct env *e) { diff --git a/src/utils.c b/src/utils.c @@ -9,6 +9,7 @@ #include "array.h" #include "ckiss.h" +#include "utils.h" static char *c1 = "", *c2 = "", *c3 = ""; diff --git a/src/utils.h b/src/utils.h @@ -0,0 +1,44 @@ +#ifndef _CKISS_UTILS_H +#define _CKISS_UTILS_H + +#include <stdbool.h> +#include <stdnoreturn.h> + +#include "array.h" + +/* called "mylog" to avoid collision with math.h log function. */ +void mylog(const char *s); +void mylog2(const char *name, const char *s); +void mylog_v(char *format, ...); +void warn(const char *s); +void warn2(const char *name, const char *s); +noreturn void die(const char *s); +noreturn void die2(const char *name, const char *s); +noreturn void die_perror(const char *s); + +/* returns a string containing the concatenation of all args. Args must be + * terminated with a NULL. Returned string must be freed by caller.*/ +char *concat(char *s, ...); + +/* Goes through the path array looking for a file in each directory with the + * given name. Returns the first one. The returned string must be freed by the + * caller. If limit is true, only return the first result found in path, + * otherwise return an array of all results found in path. If isglob is true, + * treat name as a glob. test_flags is OR'd with the file's mode (from stat(3)) + * to check if it matches a criterion (eg. executable, directory). */ +array_t find_in_path(char *name, array_t path, mode_t test_flags, bool limit, bool isglob); + +/* Checks for the first cmd which may be found in path. Returns the index of the + * cmd (0, 1, 2, ...). Arg list must be terminated with a NULL */ +int available_cmd(array_t path, char *cmd, ...); + +/* setup internal colours used by the logging functions. */ +void setup_colors(struct env *e); + +/* parses environment variables to initialise a struct env. */ +struct env *setup_env(void); + +/* correctly frees a struct env. */ +void destroy_env(struct env *e); + +#endif