X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/002eaee36ed12caf6cf7f2a7188111240a427d80..0680be67c7d22d9b58fd8c309bb24f537cf717b5:/dputf.c?ds=sidebyside diff --git a/dputf.c b/dputf.c index 9c827bc..5df210c 100644 --- a/dputf.c +++ b/dputf.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: dputf.c,v 1.1 1999/10/04 21:44:47 mdw Exp $ + * $Id: dputf.c,v 1.3 2001/01/20 12:06:01 mdw Exp $ * * `printf'-style formatting for dynamic strings * @@ -30,6 +30,12 @@ /*----- Revision history --------------------------------------------------* * * $Log: dputf.c,v $ + * Revision 1.3 2001/01/20 12:06:01 mdw + * Define flags with macros, to ensure unsignedness. + * + * Revision 1.2 2000/08/15 21:26:45 mdw + * (dstr_vputf): Don't try calling @va_arg@ on things @char@-sized. + * * Revision 1.1 1999/10/04 21:44:47 mdw * Move `dstr_putf' and `dstr_vputf' into a separate source file. * @@ -81,13 +87,11 @@ int dstr_vputf(dstr *d, const char *p, va_list ap) unsigned f; int wd, prec; - enum { - f_short = 1, - f_long = 2, - f_Long = 4, - f_wd = 8, - f_prec = 16 - }; +#define f_short 1u +#define f_long 2u +#define f_Long 4u +#define f_wd 8u +#define f_prec 16u /* --- Most stuff gets passed on through --- */ @@ -195,9 +199,9 @@ int dstr_vputf(dstr *d, const char *p, va_list ap) if (mx > sz) sz = mx; } - if ((f & f_prec) == 0) + if (!(f & f_prec)) prec = 6; - if ((f & f_prec)) + else sz += prec + 16; if ((f & f_wd) && wd + 1 > sz) sz = wd + 1; @@ -217,7 +221,7 @@ int dstr_vputf(dstr *d, const char *p, va_list ap) sz = wd + 1; DENSURE(d, sz); d->len += sprintf(d->buf + d->len, dd.buf, - va_arg(ap, unsigned char)); + va_arg(ap, unsigned)); goto formatted; case 's': { @@ -267,6 +271,12 @@ int dstr_vputf(dstr *d, const char *p, va_list ap) formatted: DRESET(&dd); q = ++p; + +#undef f_short +#undef f_long +#undef f_Long +#undef f_wd +#undef f_prec } DPUTM(d, q, p - q);