From 8ea6a3c8621287d11296b8300029f32a27743d9a Mon Sep 17 00:00:00 2001 From: nasr Date: Thu, 16 Apr 2026 17:10:02 +0200 Subject: feature(checkpoint): checkpoint cleaning up base library --- source/base/base_error.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 source/base/base_error.h (limited to 'source/base/base_error.h') diff --git a/source/base/base_error.h b/source/base/base_error.h new file mode 100644 index 0000000..e9f52b7 --- /dev/null +++ b/source/base/base_error.h @@ -0,0 +1,66 @@ +/* base library internal error checking system */ +#ifndef BASE_ERROR_H +#define BASE_ERROR_H + +#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 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)) { \ + 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 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