diff options
author | c | 2024-01-28 22:58:01 -0500 |
---|---|---|
committer | c | 2024-01-28 22:58:01 -0500 |
commit | 0b84414bdde53b367bc28563a6936513c4d3b50c (patch) | |
tree | e7f650d47d0295049d3f5e8fa9164080dacaee45 /src | |
parent | ca20ff4f4d0ac63856e538f9f4cef97197bf6465 (diff) |
Macro Hell.
Diffstat (limited to 'src')
-rw-r--r-- | src/include/util.h | 61 | ||||
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/util.c | 7 |
3 files changed, 65 insertions, 4 deletions
diff --git a/src/include/util.h b/src/include/util.h index 9f8a2b0..567916c 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -6,27 +6,80 @@ #include <string.h> #include <stdio.h> +/* Welcome to macro hell. */ + +#define HIDE(x) do {x} while (0) + #define MIN(a, b) (a < b ? a : b) #define MAX(a, b) (a > b ? a : b) -/* - TODO: Make these macros, to allow for better logging (printing __FILE__, - __func__, etc.) -*/ +/* Log some file info (mostly for use in other LOG_* macros.) */ +#define LOG_FINF HIDE( \ + fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__); \ +) + /* Log some debug information. */ void log_dbg(const char*, ...); +#define LOG_DBG(fmt, ...) HIDE( \ + fprintf(stderr, "\x1b[37m[\x1b[95;1m==\x1b[0m\x1b[37m]\x1b[0m\x1b[35m "); \ + LOG_FINF; \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ + fprintf(stderr, "\x1b[0m\n"); \ +) + /* c: */ void log_yay(const char*, ...); +#define LOG_YAY(fmt, ...) HIDE( \ + fprintf(stderr, "\x1b[37m[\x1b[92;1m==\x1b[0m\x1b[37m]\x1b[32m "); \ + LOG_FINF; \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ + fprintf(stderr, "\x1b[0m\n"); \ +) + /* Log some information. */ void log_inf(const char*, ...); +#define LOG_INF(fmt, ...) HIDE( \ + fprintf(stderr, "\x1b[37m[\x1b[94;1m==\x1b[0m\x1b[37m]\x1b[0m "); \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ + fprintf(stderr, "\x1b[0m\n"); \ +) + /* Log something with no formatting. */ void log_raw(const char*, ...); +#define LOG_RAW(fmt, ...) HIDE( \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ +) + /* Log a warning. */ void log_war(const char*, ...); +#define LOG_WAR(fmt, ...) HIDE( \ + fprintf(stderr, "\x1b[37m[\x1b[93;1m==\x1b[0m\x1b[37m]\x1b[93;1m WARNING:\x1b[0m\x1b[33m "); \ + LOG_FINF; \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ + fprintf(stderr, "\x1b[0m\n"); \ +) + /* Log an error. */ void log_err(const char*, ...); +#define LOG_ERR(fmt, ...) HIDE( \ + fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m ERROR:\x1b[0m\x1b[31m "); \ + LOG_FINF; \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ + fprintf(stderr, "\x1b[0m\n"); \ +) + +/* Warn of soon™-to-be-removed functions. */ +#define WFDEPRECATED LOG_WAR("Use of this function is deprecated.") + /* Die and leave message. */ void die(const char*, ...); +#define DIE(fmt, ...) HIDE( \ + fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m CAUSE OF DEATH:\x1b[0m\x1b[31m "); \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ + fprintf(stderr, "\x1b[0m\n"); \ + fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m Exiting...\x1b[0m\n"); \ + exit(1); \ +) /* If `calloc()` returns null, die. */ void* ecalloc(size_t, size_t); @@ -1,4 +1,5 @@ #include "include/main.h" +#include "include/util.h" /* FIXME: Segfaults ~30% of the time. No idea why. Thx future self <3. */ int main(int argc, char* argv[]) { @@ -1,6 +1,7 @@ #include "include/util.h" void log_dbg(const char* fmt, ...) { + WFDEPRECATED; va_list ap; fprintf(stdout, ""); @@ -14,6 +15,7 @@ void log_dbg(const char* fmt, ...) { } void log_yay(const char* fmt, ...) { + WFDEPRECATED; va_list ap; fprintf(stdout, "\x1b[37m[\x1b[92;1m==\x1b[0m\x1b[37m]\x1b[32m "); @@ -26,6 +28,7 @@ void log_yay(const char* fmt, ...) { } void log_inf(const char* fmt, ...) { + WFDEPRECATED; va_list ap; fprintf(stderr, "\x1b[37m[\x1b[94;1m==\x1b[0m\x1b[37m]\x1b[0m "); @@ -38,6 +41,7 @@ void log_inf(const char* fmt, ...) { } void log_raw(const char* fmt, ...) { + WFDEPRECATED; va_list ap; va_start(ap, fmt); @@ -46,6 +50,7 @@ void log_raw(const char* fmt, ...) { } void log_war(const char* fmt, ...) { + WFDEPRECATED; va_list ap; fprintf(stderr, "\x1b[37m[\x1b[93;1m==\x1b[0m\x1b[37m]\x1b[93;1m WARNING:\x1b[0m\x1b[33m "); @@ -58,6 +63,7 @@ void log_war(const char* fmt, ...) { } void log_err(const char* fmt, ...) { + WFDEPRECATED; va_list ap; fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m ERROR:\x1b[0m\x1b[31m "); @@ -70,6 +76,7 @@ void log_err(const char* fmt, ...) { } void die(const char* fmt, ...) { + WFDEPRECATED; va_list ap; fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m CAUSE OF DEATH:\x1b[0m\x1b[31m "); |