aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/print.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-23 19:28:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-23 19:28:08 -0400
commitfcda36561d668f43bac91ea31cd55cbbd605d330 (patch)
treeeb74c0b17df584af0fd8154422ad924e04c96cc2 /src/stdlib/print.h
parent414b0c7472c87c5a013029aefef49e2dbc41e700 (diff)
Autoformat everything with clang-format
Diffstat (limited to 'src/stdlib/print.h')
-rw-r--r--src/stdlib/print.h95
1 files changed, 55 insertions, 40 deletions
diff --git a/src/stdlib/print.h b/src/stdlib/print.h
index 56953866..c7e59f8b 100644
--- a/src/stdlib/print.h
+++ b/src/stdlib/print.h
@@ -38,19 +38,19 @@ typedef struct {
bool uppercase;
int digits;
} hex_format_t;
-#define hex(x, ...) ((hex_format_t){.n=x, __VA_ARGS__})
+#define hex(x, ...) ((hex_format_t){.n = x, __VA_ARGS__})
typedef struct {
double d;
} hex_double_t;
-#define hex_double(x, ...) ((hex_double_t){.d=x, __VA_ARGS__})
+#define hex_double(x, ...) ((hex_double_t){.d = x, __VA_ARGS__})
typedef struct {
uint64_t n;
bool no_prefix;
int digits;
} oct_format_t;
-#define oct(x, ...) ((oct_format_t){.n=x, __VA_ARGS__})
+#define oct(x, ...) ((oct_format_t){.n = x, __VA_ARGS__})
typedef struct {
const char *str;
@@ -67,7 +67,7 @@ typedef struct {
char c;
int length;
} repeated_char_t;
-#define repeated_char(ch, len) ((repeated_char_t){.c=ch, .length=len})
+#define repeated_char(ch, len) ((repeated_char_t){.c = ch, .length = len})
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define FMT64 "ll"
@@ -87,7 +87,9 @@ PRINT_FN _print_bool(FILE *f, bool b) { return fputs(b ? "yes" : "no", f); }
PRINT_FN _print_str(FILE *f, const char *s) { return fputs(s ? s : "(null)", f); }
int _print_char(FILE *f, char c);
int _print_quoted(FILE *f, quoted_t quoted);
-PRINT_FN _print_string_slice(FILE *f, string_slice_t slice) { return slice.str ? fwrite(slice.str, 1, slice.length, f) : (size_t)fputs("(null)", f); }
+PRINT_FN _print_string_slice(FILE *f, string_slice_t slice) {
+ return slice.str ? fwrite(slice.str, 1, slice.length, f) : (size_t)fputs("(null)", f);
+}
PRINT_FN _print_repeated_char(FILE *f, repeated_char_t repeated) {
int len = 0;
for (int n = 0; n < repeated.length; n++)
@@ -99,31 +101,32 @@ extern int Text$print(FILE *stream, Text_t text);
extern int Path$print(FILE *stream, Path_t path);
extern int Int$print(FILE *f, Int_t i);
#ifndef _fprint1
-#define _fprint1(f, x) _Generic((x), \
- char*: _print_str, \
- const char*: _print_str, \
- char: _print_char, \
- bool: _print_bool, \
- int64_t: _print_int, \
- int32_t: _print_int, \
- int16_t: _print_int, \
- int8_t: _print_int, \
- uint64_t: _print_uint, \
- uint32_t: _print_uint, \
- uint16_t: _print_uint, \
- uint8_t: _print_uint, \
- float: _print_float, \
- double: _print_double, \
- hex_format_t: _print_hex, \
- hex_double_t: _print_hex_double, \
- oct_format_t: _print_oct, \
- quoted_t: _print_quoted, \
- string_slice_t: _print_string_slice, \
- repeated_char_t: _print_repeated_char, \
- Text_t: Text$print, \
- Path_t: Path$print, \
- Int_t: Int$print, \
- void*: _print_pointer)(f, x)
+#define _fprint1(f, x) \
+ _Generic((x), \
+ char *: _print_str, \
+ const char *: _print_str, \
+ char: _print_char, \
+ bool: _print_bool, \
+ int64_t: _print_int, \
+ int32_t: _print_int, \
+ int16_t: _print_int, \
+ int8_t: _print_int, \
+ uint64_t: _print_uint, \
+ uint32_t: _print_uint, \
+ uint16_t: _print_uint, \
+ uint8_t: _print_uint, \
+ float: _print_float, \
+ double: _print_double, \
+ hex_format_t: _print_hex, \
+ hex_double_t: _print_hex_double, \
+ oct_format_t: _print_oct, \
+ quoted_t: _print_quoted, \
+ string_slice_t: _print_string_slice, \
+ repeated_char_t: _print_repeated_char, \
+ Text_t: Text$print, \
+ Path_t: Path$print, \
+ Int_t: Int$print, \
+ void *: _print_pointer)(f, x)
#endif
typedef struct {
@@ -135,19 +138,31 @@ typedef struct {
FILE *gc_memory_stream(char **buf, size_t *size);
#define _print(x) _n += _fprint1(_printing, x)
-#define _fprint(f, ...) ({ FILE *_printing = f; int _n = 0; MAP_LIST(_print, __VA_ARGS__); _n; })
+#define _fprint(f, ...) \
+ ({ \
+ FILE *_printing = f; \
+ int _n = 0; \
+ MAP_LIST(_print, __VA_ARGS__); \
+ _n; \
+ })
#define fprint(f, ...) _fprint(f, __VA_ARGS__, "\n")
#define print(...) fprint(stdout, __VA_ARGS__)
#define fprint_inline(f, ...) _fprint(f, __VA_ARGS__)
#define print_inline(...) fprint_inline(stdout, __VA_ARGS__)
-#define String(...) ({ \
- char *_buf = NULL; \
- size_t _size = 0; \
- FILE *_stream = gc_memory_stream(&_buf, &_size); \
- assert(_stream); \
- _fprint(_stream, __VA_ARGS__); \
- fflush(_stream); \
- _buf; })
-#define print_err(...) ({ fprint(stderr, "\033[31;1m", __VA_ARGS__, "\033[m"); exit(EXIT_FAILURE); })
+#define String(...) \
+ ({ \
+ char *_buf = NULL; \
+ size_t _size = 0; \
+ FILE *_stream = gc_memory_stream(&_buf, &_size); \
+ assert(_stream); \
+ _fprint(_stream, __VA_ARGS__); \
+ fflush(_stream); \
+ _buf; \
+ })
+#define print_err(...) \
+ ({ \
+ fprint(stderr, "\033[31;1m", __VA_ARGS__, "\033[m"); \
+ exit(EXIT_FAILURE); \
+ })
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0