diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-27 17:26:51 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-27 17:26:51 -0400 |
| commit | 3c52a756339a2d96824d21a7d3ad5de7fc1085a0 (patch) | |
| tree | e5299a25ebb76186d6372b700710d7c8c7fe0728 /src/stdlib/stdlib.h | |
| parent | 2186e84de0c0fd47ba48eaa35f74ea2754c3b81f (diff) | |
Deprecate custom printf specifiers in favor of print() function that
uses _Generic() to generically convert any value to a string or print as
a string.
Diffstat (limited to 'src/stdlib/stdlib.h')
| -rw-r--r-- | src/stdlib/stdlib.h | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/stdlib/stdlib.h b/src/stdlib/stdlib.h index 49ec43fb..d8b26eb4 100644 --- a/src/stdlib/stdlib.h +++ b/src/stdlib/stdlib.h @@ -7,6 +7,8 @@ #include <stdio.h> #include "datatypes.h" +#include "files.h" +#include "print.h" #include "types.h" #include "util.h" @@ -23,11 +25,42 @@ void tomo_init(void); void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, int spec_len, cli_arg_t spec[spec_len]); #define tomo_parse_args(argc, argv, usage, help, ...) \ _tomo_parse_args(argc, argv, usage, help, sizeof((cli_arg_t[]){__VA_ARGS__})/sizeof(cli_arg_t), (cli_arg_t[]){__VA_ARGS__}) -__attribute__((format(printf, 1, 2))) -_Noreturn void fail(const char *fmt, ...); + +#define fail(...) ({ \ + fflush(stdout); \ + if (USE_COLOR) fputs("\x1b[31;7m ==================== ERROR ==================== \n\n\x1b[0;1m", stderr); \ + else fputs("==================== ERROR ====================\n\n", stderr); \ + fprint_inline(stderr, __VA_ARGS__); \ + if (USE_COLOR) fputs("\x1b[m", stderr); \ + fputs("\n\n", stderr); \ + print_stack_trace(stderr, 2, 4); \ + fflush(stderr); \ + raise(SIGABRT); \ + _exit(1); \ +}) + +#define fail_source(filename, start, end, ...) ({ \ + fflush(stdout); \ + if (USE_COLOR) fputs("\x1b[31;7m ==================== ERROR ==================== \n\n\x1b[0;1m", stderr); \ + else fputs("==================== ERROR ====================\n\n", stderr); \ + fprint_inline(stderr, __VA_ARGS__); \ + if (USE_COLOR) fputs("\x1b[m", stderr); \ + file_t *_file = (filename) ? load_file(filename) : NULL; \ + if ((filename) && _file) { \ + fputs("\n", stderr); \ + highlight_error(_file, _file->text+(start), _file->text+(end), "\x1b[31;1m", 2, USE_COLOR); \ + fputs("\n", stderr); \ + } \ + if (USE_COLOR) fputs("\x1b[m", stderr); \ + print_stack_trace(stderr, 2, 4); \ + fputs("\n\n", stderr); \ + print_stack_trace(stderr, 2, 4); \ + fflush(stderr); \ + raise(SIGABRT); \ + _exit(1); \ +}) + _Noreturn void fail_text(Text_t message); -__attribute__((format(printf, 4, 5))) -_Noreturn void fail_source(const char *filename, int64_t start, int64_t end, const char *fmt, ...); Text_t builtin_last_err(); __attribute__((nonnull)) void start_inspect(const char *filename, int64_t start, int64_t end); |
