Derive-C
Loading...
Searching...
No Matches
fmt.h File Reference
#include <derive-c/core/panic.h>
#include <derive-c/core/namespace.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  dc_debug_fmt
 Debug format helpers for debug printin data structures. More...

Functions

static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new ()
static DC_PUBLIC void dc_debug_fmt_print_indents (dc_debug_fmt fmt, FILE *stream)
static DC_PUBLIC void dc_debug_fmt_print (dc_debug_fmt fmt, FILE *stream, const char *format,...)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin (dc_debug_fmt fmt)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end (dc_debug_fmt fmt)

Function Documentation

◆ dc_debug_fmt_new()

DC_PUBLIC dc_debug_fmt dc_debug_fmt_new ( )
static
Examples
complex/employees.c, container/arena.c, container/bitset.c, container/map.c, container/queue.c, container/set.c, container/vector.c, utils/option.c, utils/result.c, and utils/string_builder.c.

Definition at line 15 of file fmt.h.

15 {
16 dc_debug_fmt fmt = {.indent = 0};
17 return fmt;
18}
Debug format helpers for debug printin data structures.
Definition fmt.h:11

◆ dc_debug_fmt_print()

DC_PUBLIC void dc_debug_fmt_print ( dc_debug_fmt fmt,
FILE * stream,
const char * format,
... )
static
Examples
complex/employees.c, container/arena.c, container/map.c, container/set.c, utils/option.c, and utils/result.c.

Definition at line 32 of file fmt.h.

32 {
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}
static DC_PUBLIC void dc_debug_fmt_print_indents(dc_debug_fmt fmt, FILE *stream)
Definition fmt.h:20
static DC_PUBLIC FILE * stream(SELF *self)
Definition template.h:108

◆ dc_debug_fmt_print_indents()

DC_PUBLIC void dc_debug_fmt_print_indents ( dc_debug_fmt fmt,
FILE * stream )
static

Definition at line 20 of file fmt.h.

20 {
21 for (size_t i = 0; i < fmt.indent; i++) {
22 fprintf(stream, " ");
23 }
24}
size_t indent
Definition fmt.h:12

◆ dc_debug_fmt_scope_begin()

DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin ( dc_debug_fmt fmt)
inlinestatic

Starts a scope { ... }

  • Does not prepend with the indent
Examples
complex/employees.c, container/arena.c, container/map.c, container/set.c, utils/option.c, and utils/result.c.

Definition at line 50 of file fmt.h.

50 {
51 dc_debug_fmt next = {.indent = fmt.indent + 1};
52 return next;
53}
static DC_PUBLIC IV_PAIR next(ITER *iter)
Definition template.h:355

◆ dc_debug_fmt_scope_end()

DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end ( dc_debug_fmt fmt)
inlinestatic

Ends a scope { ... }

  • prepends with the fmt specified indent
Examples
complex/employees.c, container/arena.c, container/map.c, container/set.c, utils/option.c, and utils/result.c.

Definition at line 57 of file fmt.h.

57 {
58 DC_ASSERT(fmt.indent > 0);
59 dc_debug_fmt next = {.indent = fmt.indent - 1};
60 return next;
61}
#define DC_ASSERT(expr,...)
Definition panic.h:37