Derive-C
Loading...
Searching...
No Matches
fmt.h
Go to the documentation of this file.
1
2#pragma once
3
6
7#include <stdarg.h>
8#include <stdio.h>
9#include <stdlib.h>
10
11typedef struct {
12 size_t indent;
14
16 dc_debug_fmt fmt = {.indent = 0};
17 return fmt;
18}
19
21 for (size_t i = 0; i < fmt.indent; i++) {
22 fprintf(stream, " ");
23 }
24}
25
26DC_PUBLIC static void dc_debug_fmt_print(dc_debug_fmt fmt, FILE* stream, const char* format, ...)
27#if defined(__clang__) || defined(__GNUC__)
28 __attribute__((format(printf, 3, 4)))
29#endif
30 ;
31
32DC_PUBLIC static void dc_debug_fmt_print(dc_debug_fmt fmt, FILE* stream, const char* format, ...) {
34
35 va_list args;
36 va_start(args, format);
37#if defined(__clang__)
38 #pragma clang diagnostic push
39 #pragma clang diagnostic ignored "-Wformat-nonliteral"
40#endif
41 vfprintf(stream, format, args);
42#if defined(__clang__)
43 #pragma clang diagnostic pop
44#endif
45 va_end(args);
46}
47
51 dc_debug_fmt next = {.indent = fmt.indent + 1};
52 return next;
53}
54
58 DC_ASSERT(fmt.indent > 0);
59 dc_debug_fmt next = {.indent = fmt.indent - 1};
60 return next;
61}
static DC_PUBLIC IV_PAIR next(ITER *iter)
Definition template.h:355
static DC_PUBLIC void dc_debug_fmt_print(dc_debug_fmt fmt, FILE *stream, const char *format,...)
Definition fmt.h:32
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new()
Definition fmt.h:15
static DC_PUBLIC void dc_debug_fmt_print_indents(dc_debug_fmt fmt, FILE *stream)
Definition fmt.h:20
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end(dc_debug_fmt fmt)
Definition fmt.h:57
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin(dc_debug_fmt fmt)
Definition fmt.h:50
#define DC_PUBLIC
Definition namespace.h:25
#define DC_ASSERT(expr,...)
Definition panic.h:37
Debug format helpers for debug printin data structures.
Definition fmt.h:11
size_t indent
Definition fmt.h:12
static DC_PUBLIC FILE * stream(SELF *self)
Definition template.h:108