aboutsummaryrefslogtreecommitdiffstats
path: root/src/badlib.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-15 00:24:21 +0200
committerBad Diode <bd@badd10de.dev>2024-06-15 00:24:21 +0200
commit1d2f07f27aa0862e88ee44c85930284932742fa0 (patch)
tree856071b41364fac0ea8bb6e64e4c18305d70ae2e /src/badlib.h
parentd14873524d41f4c1537d29392f3e4bb234bd6785 (diff)
downloadbdl-1d2f07f27aa0862e88ee44c85930284932742fa0.tar.gz
bdl-1d2f07f27aa0862e88ee44c85930284932742fa0.zip
Fix some __VA_ARGS__ macro issues (ugh)
Diffstat (limited to 'src/badlib.h')
-rw-r--r--src/badlib.h26
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
1124void 1116void
1125log_print(Logger *l, Str format, ...) { 1117log_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.
1289Logger logger_inf, logger_err; 1281Logger 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
1297void 1295void
1298log_func_register(Logger *l, LogFuncMap map) { 1296log_func_register(Logger *l, LogFuncMap map) {