|
56 | 56 | #define false ((_Bool) + 0u) |
57 | 57 | #endif |
58 | 58 | #define CPRINTF_MAJOR 2 |
59 | | -#define CPRINTF_MINOR 0 |
| 59 | +#define CPRINTF_MINOR 1 |
60 | 60 | bool cp_xterm_is_dark_mode(void); |
61 | 61 | int cprintf__(const char *_Nonnull buf); |
62 | 62 | int cfprintf__(FILE *_Nonnull stream, const char *_Nonnull buf); |
@@ -129,30 +129,19 @@ extern bool cprintf_print_color_only_tty; |
129 | 129 | #define F(cp_f_data__, cp_f_format__) \ |
130 | 130 | cprintf_to_char__(cp_f_data__, cprintf_get_fmt__(cp_f_data__, cp_f_format__)) |
131 | 131 | #define T(cp_t_data__) F(cp_t_data__, NULL) |
132 | | -#define cprintf_len__(cpl_format__, ...) \ |
133 | | - (snprintf(NULL, 0, \ |
134 | | - cprintf_regen_format__(cpl_format__, CPRINTF_COUNT_ARGS(cpl_format__, ##__VA_ARGS__)), \ |
135 | | - ##__VA_ARGS__) + \ |
136 | | - 8) |
137 | | -// Count the number of arguments passed to the csprintf(). |
138 | | -#define CPRINTF_COUNT_ARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, COUNT, ...) \ |
139 | | - _Generic((COUNT), int: COUNT, default: 0) |
140 | | -#define CPRINTF_COUNT_ARGS(...) \ |
141 | | - CPRINTF_COUNT_ARGS_IMPL(__VA_ARGS__, ((int)15), ((int)14), ((int)13), ((int)12), ((int)11), ((int)10), \ |
142 | | - ((int)9), ((int)8), ((int)7), ((int)6), ((int)5), ((int)4), ((int)3), ((int)2), \ |
143 | | - ((int)1), ((int)0)) |
144 | | -#define csprintf(string, format, ...) \ |
145 | | - ({ \ |
146 | | - int csp_ret__ = 0; \ |
147 | | - if (format == NULL) { \ |
148 | | - csp_ret__ = sprintf(string, "%s", "(null)"); \ |
149 | | - } else { \ |
150 | | - char *csp_fmt__ = \ |
151 | | - cprintf_regen_format__(format, CPRINTF_COUNT_ARGS(format, ##__VA_ARGS__)); \ |
152 | | - csp_ret__ = sprintf(string, csp_fmt__, ##__VA_ARGS__); \ |
153 | | - cprintf_free_buf__(); \ |
154 | | - } \ |
155 | | - csp_ret__; \ |
| 132 | +#define cprintf_len__(cpl_format__, ...) \ |
| 133 | + (snprintf(NULL, 0, cprintf_regen_format__(cpl_format__), ##__VA_ARGS__) + 8) |
| 134 | +#define csprintf(string, format, ...) \ |
| 135 | + ({ \ |
| 136 | + int csp_ret__ = 0; \ |
| 137 | + if (format == NULL) { \ |
| 138 | + csp_ret__ = sprintf(string, "%s", "(null)"); \ |
| 139 | + } else { \ |
| 140 | + char *csp_fmt__ = cprintf_regen_format__(format); \ |
| 141 | + csp_ret__ = sprintf(string, csp_fmt__, ##__VA_ARGS__); \ |
| 142 | + cprintf_free_buf__(); \ |
| 143 | + } \ |
| 144 | + csp_ret__; \ |
156 | 145 | }) |
157 | 146 | #define cprintf(format, ...) \ |
158 | 147 | ({ \ |
@@ -187,7 +176,7 @@ extern bool cprintf_print_color_only_tty; |
187 | 176 | free(cfp_buf__); \ |
188 | 177 | } |
189 | 178 | // For generic support. |
190 | | -char *cprintf_regen_format__(const char *f, int limit); |
| 179 | +char *cprintf_regen_format__(const char *f); |
191 | 180 | void cprintf_free_buf__(void); |
192 | 181 | void cprintf_mark_buf__(char *b); |
193 | 182 | // NOLINTEND |
0 commit comments