From 078e21a1feb811f9ef7797ce3ee5d2e8ffcccfce Mon Sep 17 00:00:00 2001 From: nasr Date: Fri, 17 Apr 2026 17:49:10 +0200 Subject: feature(main): during my work on other projects I improved the base library a bit. this is a drag and drop of that in the project. the next steps exit out of implementing lineair regression and attempting to calcualte what the value would be of a key in the btree... Signed-off-by: nasr feature(main): during my work on other projects I improved the base library a bit. this is a drag and drop of that in the project. the next steps exit out of implementing lineair regression and attempting to calcualte what the value would be of a key in the btree... Signed-off-by: nasr --- source/base/base_error.h | 89 +++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 35 deletions(-) (limited to 'source/base/base_error.h') diff --git a/source/base/base_error.h b/source/base/base_error.h index b2bb4c0..e9f52b7 100644 --- a/source/base/base_error.h +++ b/source/base/base_error.h @@ -1,47 +1,66 @@ -/* base library internal logging system */ +/* base library internal error checking system */ #ifndef BASE_ERROR_H #define BASE_ERROR_H -#define error_at(msg) \ - do \ - { \ - os_write(STDERR_FD, RED "[ERROR] ", LEN(RED "[ERROR] ")); \ - write_string(STDERR_FD, __FILE__); \ - write_string(STDERR_FD, ":"); \ - write_int(__LINE__); \ - write_string(STDERR_FD, " in "); \ - write_string(STDERR_FD, __func__); \ - write_string(STDERR_FD, ": "); \ - write_string(STDERR_FD, (msg)); \ - os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \ +#define error_at(msg) \ + do { \ + write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ ": " Reset); \ + write_string(STDERR_FD, (msg)); \ + write_string(STDERR_FD, "\n"); \ } while (0) -#define fatal(msg) \ - do \ - { \ - error_at(msg); \ - _exit(1); \ +#define warn(msg) \ + do { \ + write_string(STDERR_FD, Yellow "[WARN] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ ": " Reset); \ + write_string(STDERR_FD, (msg)); \ + write_string(STDERR_FD, "\n"); \ } while (0) -#define assert_msg(expr, msg) \ - do \ - { \ - if (!(expr)) \ - { \ - fatal(msg); \ - } \ +#define assert_msg(expr, msg) \ + do { \ + if (!(expr)) { \ + write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ ": " Reset); \ + write_string(STDERR_FD, (msg)); \ + write_string(STDERR_FD, "\n"); \ + _exit(1); \ + } \ } while (0) -#define warn(msg) \ - do \ - { \ - os_write(STDERR_FD, YELLOW "[WARN] ", LEN(YELLOW "[WARN] ")); \ - write_string(STDERR_FD, __FILE__); \ - write_string(STDERR_FD, ":"); \ - write_int(__LINE__); \ - write_string(STDERR_FD, ": "); \ - write_string(STDERR_FD, (msg)); \ - os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \ +#define show \ + do { \ + write_string(STDOUT_FD, __FILE__ ":"); \ + write_int(STDOUT_FD, __LINE__); \ + write_string(STDOUT_FD, ":" __func__ "\n"); \ + } while (0) + +#define test(expr) \ + do { \ + if ((expr) != 0) { \ + write_string(STDERR_FD, "[FAILED] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ "\n"); \ + _exit(1); \ + } \ + } while (0) + +#define verify(expr) \ + do { \ + if ((expr) != 0) { \ + write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ "\n" Reset); \ + _exit(1); \ + } else { \ + write_string(STDERR_FD, Green "[OK] " __FILE__ ":"); \ + write_int(STDERR_FD, __LINE__); \ + write_string(STDERR_FD, ":" __func__ "\n" Reset); \ + } \ } while (0) #endif /* BASE_ERROR_H */ -- cgit v1.3