Mercurial > hg > th-libs
comparison th_string.c @ 568:2fbe42d957c4
Actually, partially revert the previous commit and unbreak the API. Leave
the format specifier code in a separate function tho, it's cleaner.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 08 Jan 2020 02:25:04 +0200 |
parents | b75f42ca08ef |
children | 390c66af09cf |
comparison
equal
deleted
inserted
replaced
567:b75f42ca08ef | 568:2fbe42d957c4 |
---|---|
155 ctx.buf = buf; | 155 ctx.buf = buf; |
156 ctx.size = size; | 156 ctx.size = size; |
157 ctx.pos = 0; | 157 ctx.pos = 0; |
158 ctx.ipos = 0; | 158 ctx.ipos = 0; |
159 | 159 |
160 ret = th_vprintf_do(&ctx, th_pbuf_vputch, th_vprintf_do_format, fmt, ap); | 160 ret = th_vprintf_do(&ctx, th_pbuf_vputch, fmt, ap); |
161 | 161 |
162 if (ctx.pos < size) | 162 if (ctx.pos < size) |
163 buf[ctx.pos] = 0; | 163 buf[ctx.pos] = 0; |
164 else | 164 else |
165 if (size > 0) | 165 if (size > 0) |
203 th_vprintf_ctx ctx; | 203 th_vprintf_ctx ctx; |
204 ctx.data = (void *) fh; | 204 ctx.data = (void *) fh; |
205 ctx.pos = 0; | 205 ctx.pos = 0; |
206 ctx.ipos = 0; | 206 ctx.ipos = 0; |
207 | 207 |
208 return th_vprintf_do(&ctx, th_stdio_vputch, th_vprintf_do_format, fmt, ap); | 208 return th_vprintf_do(&ctx, th_stdio_vputch, fmt, ap); |
209 #else | 209 #else |
210 return vfprintf(fh, fmt, ap); | 210 return vfprintf(fh, fmt, ap); |
211 #endif | 211 #endif |
212 } | 212 } |
213 | 213 |
224 #ifdef TH_USE_INTERNAL_SPRINTF | 224 #ifdef TH_USE_INTERNAL_SPRINTF |
225 ctx.data = (void *) fh; | 225 ctx.data = (void *) fh; |
226 ctx.pos = 0; | 226 ctx.pos = 0; |
227 ctx.ipos = 0; | 227 ctx.ipos = 0; |
228 | 228 |
229 ret = th_vprintf_do(&ctx, th_stdio_vputch, th_vprintf_do_format, fmt, ap); | 229 ret = th_vprintf_do(&ctx, th_stdio_vputch, fmt, ap); |
230 #else | 230 #else |
231 ret = fprintf(fh, fmt, ap); | 231 ret = fprintf(fh, fmt, ap); |
232 #endif | 232 #endif |
233 va_end(ap); | 233 va_end(ap); |
234 | 234 |
261 va_list ap; | 261 va_list ap; |
262 | 262 |
263 // Get size | 263 // Get size |
264 va_copy(ap, args); | 264 va_copy(ap, args); |
265 ctx.pos = 0; | 265 ctx.pos = 0; |
266 th_vprintf_do(&ctx, th_pbuf_alloc_vputch1, th_vprintf_do_format, fmt, ap); | 266 th_vprintf_do(&ctx, th_pbuf_alloc_vputch1, fmt, ap); |
267 va_end(ap); | 267 va_end(ap); |
268 | 268 |
269 // Allocate memory | 269 // Allocate memory |
270 ctx.size = ctx.pos + 1; | 270 ctx.size = ctx.pos + 1; |
271 if ((ctx.buf = th_malloc(ctx.size)) == NULL) | 271 if ((ctx.buf = th_malloc(ctx.size)) == NULL) |
272 return NULL; | 272 return NULL; |
273 | 273 |
274 va_copy(ap, args); | 274 va_copy(ap, args); |
275 ctx.pos = 0; | 275 ctx.pos = 0; |
276 th_vprintf_do(&ctx, th_pbuf_alloc_vputch2, th_vprintf_do_format, fmt, ap); | 276 th_vprintf_do(&ctx, th_pbuf_alloc_vputch2, fmt, ap); |
277 va_end(ap); | 277 va_end(ap); |
278 ctx.buf[ctx.pos] = 0; | 278 ctx.buf[ctx.pos] = 0; |
279 | 279 |
280 return ctx.buf; | 280 return ctx.buf; |
281 | 281 |