diff options
Diffstat (limited to 'source/base/base_error.h')
| -rw-r--r-- | source/base/base_error.h | 89 |
1 files changed, 54 insertions, 35 deletions
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 @@ | |||
| 1 | /* base library internal logging system */ | 1 | /* base library internal error checking system */ |
| 2 | #ifndef BASE_ERROR_H | 2 | #ifndef BASE_ERROR_H |
| 3 | #define BASE_ERROR_H | 3 | #define BASE_ERROR_H |
| 4 | 4 | ||
| 5 | #define error_at(msg) \ | 5 | #define error_at(msg) \ |
| 6 | do \ | 6 | do { \ |
| 7 | { \ | 7 | write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ |
| 8 | os_write(STDERR_FD, RED "[ERROR] ", LEN(RED "[ERROR] ")); \ | 8 | write_int(STDERR_FD, __LINE__); \ |
| 9 | write_string(STDERR_FD, __FILE__); \ | 9 | write_string(STDERR_FD, ":" __func__ ": " Reset); \ |
| 10 | write_string(STDERR_FD, ":"); \ | 10 | write_string(STDERR_FD, (msg)); \ |
| 11 | write_int(__LINE__); \ | 11 | write_string(STDERR_FD, "\n"); \ |
| 12 | write_string(STDERR_FD, " in "); \ | ||
| 13 | write_string(STDERR_FD, __func__); \ | ||
| 14 | write_string(STDERR_FD, ": "); \ | ||
| 15 | write_string(STDERR_FD, (msg)); \ | ||
| 16 | os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \ | ||
| 17 | } while (0) | 12 | } while (0) |
| 18 | 13 | ||
| 19 | #define fatal(msg) \ | 14 | #define warn(msg) \ |
| 20 | do \ | 15 | do { \ |
| 21 | { \ | 16 | write_string(STDERR_FD, Yellow "[WARN] " __FILE__ ":"); \ |
| 22 | error_at(msg); \ | 17 | write_int(STDERR_FD, __LINE__); \ |
| 23 | _exit(1); \ | 18 | write_string(STDERR_FD, ":" __func__ ": " Reset); \ |
| 19 | write_string(STDERR_FD, (msg)); \ | ||
| 20 | write_string(STDERR_FD, "\n"); \ | ||
| 24 | } while (0) | 21 | } while (0) |
| 25 | 22 | ||
| 26 | #define assert_msg(expr, msg) \ | 23 | #define assert_msg(expr, msg) \ |
| 27 | do \ | 24 | do { \ |
| 28 | { \ | 25 | if (!(expr)) { \ |
| 29 | if (!(expr)) \ | 26 | write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ |
| 30 | { \ | 27 | write_int(STDERR_FD, __LINE__); \ |
| 31 | fatal(msg); \ | 28 | write_string(STDERR_FD, ":" __func__ ": " Reset); \ |
| 32 | } \ | 29 | write_string(STDERR_FD, (msg)); \ |
| 30 | write_string(STDERR_FD, "\n"); \ | ||
| 31 | _exit(1); \ | ||
| 32 | } \ | ||
| 33 | } while (0) | 33 | } while (0) |
| 34 | 34 | ||
| 35 | #define warn(msg) \ | 35 | #define show \ |
| 36 | do \ | 36 | do { \ |
| 37 | { \ | 37 | write_string(STDOUT_FD, __FILE__ ":"); \ |
| 38 | os_write(STDERR_FD, YELLOW "[WARN] ", LEN(YELLOW "[WARN] ")); \ | 38 | write_int(STDOUT_FD, __LINE__); \ |
| 39 | write_string(STDERR_FD, __FILE__); \ | 39 | write_string(STDOUT_FD, ":" __func__ "\n"); \ |
| 40 | write_string(STDERR_FD, ":"); \ | 40 | } while (0) |
| 41 | write_int(__LINE__); \ | 41 | |
| 42 | write_string(STDERR_FD, ": "); \ | 42 | #define test(expr) \ |
| 43 | write_string(STDERR_FD, (msg)); \ | 43 | do { \ |
| 44 | os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \ | 44 | if ((expr) != 0) { \ |
| 45 | write_string(STDERR_FD, "[FAILED] " __FILE__ ":"); \ | ||
| 46 | write_int(STDERR_FD, __LINE__); \ | ||
| 47 | write_string(STDERR_FD, ":" __func__ "\n"); \ | ||
| 48 | _exit(1); \ | ||
| 49 | } \ | ||
| 50 | } while (0) | ||
| 51 | |||
| 52 | #define verify(expr) \ | ||
| 53 | do { \ | ||
| 54 | if ((expr) != 0) { \ | ||
| 55 | write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ | ||
| 56 | write_int(STDERR_FD, __LINE__); \ | ||
| 57 | write_string(STDERR_FD, ":" __func__ "\n" Reset); \ | ||
| 58 | _exit(1); \ | ||
| 59 | } else { \ | ||
| 60 | write_string(STDERR_FD, Green "[OK] " __FILE__ ":"); \ | ||
| 61 | write_int(STDERR_FD, __LINE__); \ | ||
| 62 | write_string(STDERR_FD, ":" __func__ "\n" Reset); \ | ||
| 63 | } \ | ||
| 45 | } while (0) | 64 | } while (0) |
| 46 | 65 | ||
| 47 | #endif /* BASE_ERROR_H */ | 66 | #endif /* BASE_ERROR_H */ |
