// sb.h --- string builder #ifndef INCLUDED_SB_H #define INCLUDED_SB_H #include "utils.h" #include "da.h" typedef struct sb { char *items; size_t count; size_t capacity; } *SB; #define SB_APPEND_BUF(SB, BUF, SIZE) DA_APPEND_MANY(SB, BUF, SIZE) #define SB_APPEND_CSTR(SB, CSTR) \ ({ \ const char *s = (CSTR); \ size_t n = strlen (s); \ DA_APPEND_MANY(SB, s, n); \ }) #define SB_APPEND_CSTRS(SB, ...) sb_append_cstrs (&(SB), __VA_ARGS__, NULL) #define SB_APPEND_NULL(SB) DA_APPEND(SB, '\0') #define SB_RESET(SB) DA_RESET(SB) #define SB_FREE(SB) DA_FREE(SB) extern void sb_append_cstrs (SB sb, ...); extern void sb_printf (SB sb, const char *format, ...); #endif