From: Elias Fleckenstein Date: Sun, 2 Jan 2022 10:53:21 +0000 (+0100) Subject: Turn common back into a normal directory (instead of a submodule) X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=56caeb540795fb92f3289bbc4744e94da0c20654;p=uwu-lang.git Turn common back into a normal directory (instead of a submodule) --- diff --git a/.gitmodules b/.gitmodules index ef80cf6..6f6110a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "common"] - path = common - url = git@github.com:EliasFleckenstein03/uwu-common [submodule "std"] path = std url = git@github.com:EliasFleckenstein03/uwu-std diff --git a/common b/common deleted file mode 160000 index a636a96..0000000 --- a/common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a636a960a0866a94719aff01774b9533743ee072 diff --git a/common/dir.h b/common/dir.h new file mode 100644 index 0000000..3e1ca41 --- /dev/null +++ b/common/dir.h @@ -0,0 +1,28 @@ +#ifndef _UWU_COMMON_DIR_H_ +#define _UWU_COMMON_DIR_H_ + +#include +#include +#include + +static char *wrap_name_func(const char *name, char *(*fn)(char *)) +{ + char *copy = strdup(name); + char *result = fn(copy); + char *result_copy = strdup(result); + + free(copy); + return result_copy; +} + +static inline char *basename_wrapper(const char *name) +{ + return wrap_name_func(name, &basename); +} + +static inline char *dirname_wrapper(const char *name) +{ + return wrap_name_func(name, &dirname); +} + +#endif diff --git a/common/dl.h b/common/dl.h new file mode 100644 index 0000000..04a2cd7 --- /dev/null +++ b/common/dl.h @@ -0,0 +1,14 @@ +#ifndef _UWU_COMMON_DL_H_ +#define _UWU_COMMON_DL_H_ + +#include +#include "err.h" + +inline static void check_dlerror() +{ + char *err = dlerror(); + if (err) + error("library error: %s\n", err); +} + +#endif diff --git a/common/err.h b/common/err.h new file mode 100644 index 0000000..9db3e23 --- /dev/null +++ b/common/err.h @@ -0,0 +1,27 @@ +#ifndef _UWU_COMMON_ERR_H_ +#define _UWU_COMMON_ERR_H_ + +#include +#include +#include + +static inline void error(const char *format, ...) +{ + va_list args; + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + exit(1); +} + +static inline void syserror(const char *call, FILE *file) +{ + perror(call); + + if (file) + fclose(file); + + exit(1); +} + +#endif diff --git a/common/file.h b/common/file.h new file mode 100644 index 0000000..5d875c9 --- /dev/null +++ b/common/file.h @@ -0,0 +1,19 @@ +#ifndef _UWU_COMMON_FILE_H_ +#define _UWU_COMMON_FILE_H_ + +#include +#include + +inline static bool file_exists(const char *filename) +{ + FILE *f = fopen(filename, "r"); + + if (f) { + fclose(f); + return true; + } + + return false; +} + +#endif diff --git a/common/str.h b/common/str.h new file mode 100644 index 0000000..e6ed70a --- /dev/null +++ b/common/str.h @@ -0,0 +1,17 @@ +#ifndef _UWU_COMMON_STR_H_ +#define _UWU_COMMON_STR_H_ + +#include +#include + +static inline char *asprintf_wrapper(const char *format, ...) +{ + va_list args; + va_start(args, format); + char *ptr; + vasprintf(&ptr, format, args); + va_end(args); + return ptr; +} + +#endif