diff options
Diffstat (limited to 'src/badlib.h')
-rw-r--r-- | src/badlib.h | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/badlib.h b/src/badlib.h index 837d377..496f106 100644 --- a/src/badlib.h +++ b/src/badlib.h | |||
@@ -16,22 +16,16 @@ | |||
16 | // thing or at least a small range). | 16 | // thing or at least a small range). |
17 | // | 17 | // |
18 | 18 | ||
19 | #include <stdarg.h> | ||
19 | #include <stdbool.h> | 20 | #include <stdbool.h> |
20 | #include <stddef.h> | 21 | #include <stddef.h> |
21 | #include <stdint.h> | 22 | #include <stdint.h> |
22 | #include <stdio.h> | 23 | #include <stdio.h> |
23 | #include <stdlib.h> | 24 | #include <stdlib.h> |
24 | #include <strings.h> | 25 | #include <strings.h> |
25 | #define printstr(s) \ | ||
26 | if (s) printf("%.*s", (int)(s)->size, (s)->mem); | ||
27 | #define printstrln(s) \ | ||
28 | if (s) printf("%.*s\n", (int)(s)->size, (s)->mem); | ||
29 | 26 | ||
30 | // | 27 | // |
31 | // This simple header just typedefs the basic C define types to a shorter name, | 28 | // Basic types. |
32 | // loads the quality of life bool macro for _Bool and defines shorthand macros | ||
33 | // for byte sizes. We need that the targeted architecture uses the floating | ||
34 | // point representation as described on the IEEE-754 standard. | ||
35 | // | 29 | // |
36 | 30 | ||
37 | _Static_assert(sizeof(double) == 8, "no support for IEEE-754"); | 31 | _Static_assert(sizeof(double) == 8, "no support for IEEE-754"); |
@@ -1119,8 +1113,6 @@ log_float(Logger *l, f64 num, sz precision) { | |||
1119 | log_int(l, fractional); | 1113 | log_int(l, fractional); |
1120 | } | 1114 | } |
1121 | 1115 | ||
1122 | #include <stdarg.h> | ||
1123 | |||
1124 | void | 1116 | void |
1125 | log_print(Logger *l, Str format, ...) { | 1117 | log_print(Logger *l, Str format, ...) { |
1126 | assert(l); | 1118 | assert(l); |
@@ -1287,12 +1279,18 @@ log_init(sz memsize, FILE *dest, Arena arena) { | |||
1287 | 1279 | ||
1288 | // Default loggers and convenience macros for printing. | 1280 | // Default loggers and convenience macros for printing. |
1289 | Logger logger_inf, logger_err; | 1281 | Logger logger_inf, logger_err; |
1290 | #define print(format, ...) \ | 1282 | |
1283 | #define _print(format, ...) \ | ||
1291 | log_print(&logger_inf, (Str){(u8 *)(format), LEN(format) - 1}, __VA_ARGS__) | 1284 | log_print(&logger_inf, (Str){(u8 *)(format), LEN(format) - 1}, __VA_ARGS__) |
1292 | #define println(format, ...) print(format "\n", __VA_ARGS__) | 1285 | #define _println(format, ...) print(format "\n", __VA_ARGS__) |
1293 | #define printerr(format, ...) \ | 1286 | #define print(...) _print(__VA_ARGS__, "") |
1287 | #define println(...) _println(__VA_ARGS__, "") | ||
1288 | |||
1289 | #define _printerr(format, ...) \ | ||
1294 | log_print(&logger_err, (Str){(u8 *)(format), LEN(format) - 1}, __VA_ARGS__) | 1290 | log_print(&logger_err, (Str){(u8 *)(format), LEN(format) - 1}, __VA_ARGS__) |
1295 | #define printerrln(format, ...) printerr(format "\n", __VA_ARGS__) | 1291 | #define _printerrln(format, ...) printerr(format "\n", __VA_ARGS__) |
1292 | #define printerr(...) _printerr(__VA_ARGS__, "") | ||
1293 | #define printerrln(...) _printerrln(__VA_ARGS__, "") | ||
1296 | 1294 | ||
1297 | void | 1295 | void |
1298 | log_func_register(Logger *l, LogFuncMap map) { | 1296 | log_func_register(Logger *l, LogFuncMap map) { |