diff options
Diffstat (limited to 'printf')
-rw-r--r-- | printf/doprnt.c | 708 | ||||
-rw-r--r-- | printf/doprntf.c | 226 | ||||
-rw-r--r-- | printf/doprnti.c | 6 | ||||
-rw-r--r-- | printf/obprntffuns.c | 2 | ||||
-rw-r--r-- | printf/repl-vsnprintf.c | 372 | ||||
-rw-r--r-- | printf/sprintffuns.c | 6 |
6 files changed, 660 insertions, 660 deletions
diff --git a/printf/doprnt.c b/printf/doprnt.c index e05af0174..a6e8c082e 100644 --- a/printf/doprnt.c +++ b/printf/doprnt.c @@ -62,7 +62,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ /* change this to "#define TRACE(x) x" for diagnostics */ -#define TRACE(x) +#define TRACE(x) /* Should be portable, but in any case this is only used under some ASSERTs. */ @@ -132,15 +132,15 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ do { \ if (this_fmt == last_fmt) \ { \ - TRACE (printf ("nothing to flush\n")); \ - ASSERT (va_equal (this_ap, last_ap)); \ + TRACE (printf ("nothing to flush\n")); \ + ASSERT (va_equal (this_ap, last_ap)); \ } \ else \ { \ - ASSERT (*this_fmt == '%'); \ - *this_fmt = '\0'; \ - TRACE (printf ("flush \"%s\"\n", last_fmt)); \ - DOPRNT_FORMAT (last_fmt, last_ap); \ + ASSERT (*this_fmt == '%'); \ + *this_fmt = '\0'; \ + TRACE (printf ("flush \"%s\"\n", last_fmt)); \ + DOPRNT_FORMAT (last_fmt, last_ap); \ } \ } while (0) @@ -151,7 +151,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int __gmp_doprnt (const struct doprnt_funs_t *funs, void *data, - const char *orig_fmt, va_list orig_ap) + const char *orig_fmt, va_list orig_ap) { va_list ap, this_ap, last_ap; size_t alloc_fmt_size; @@ -195,7 +195,7 @@ __gmp_doprnt (const struct doprnt_funs_t *funs, void *data, fmt = strchr (fmt, '%'); if (fmt == NULL) - break; + break; /* this_fmt and this_ap are the current '%' sequence being considered */ this_fmt = fmt; @@ -203,12 +203,12 @@ __gmp_doprnt (const struct doprnt_funs_t *funs, void *data, fmt++; /* skip the '%' */ TRACE (printf ("considering\n"); - printf (" last: \"%s\"\n", last_fmt); - printf (" this: \"%s\"\n", this_fmt)); + printf (" last: \"%s\"\n", last_fmt); + printf (" this: \"%s\"\n", this_fmt)); type = '\0'; value = ¶m.width; - + param.base = 10; param.conv = 0; param.expfmt = "e%c%02d"; @@ -224,379 +224,379 @@ __gmp_doprnt (const struct doprnt_funs_t *funs, void *data, seen_precision = 0; /* This loop parses a single % sequence. "break" from the switch - means continue with this %, "goto next" means the conversion - character has been seen and a new % should be sought. */ + means continue with this %, "goto next" means the conversion + character has been seen and a new % should be sought. */ for (;;) - { - fchar = *fmt++; - if (fchar == '\0') - break; - - switch (fchar) { - - case 'a': - /* %a behaves like %e, but defaults to all significant digits, - and there's no leading zeros on the exponent (which is in - fact bit-based) */ - param.base = 16; - param.expfmt = "p%c%d"; - goto conv_a; - case 'A': - param.base = -16; - param.expfmt = "P%c%d"; - conv_a: - param.conv = DOPRNT_CONV_SCIENTIFIC; - param.exptimes4 = 1; - if (! seen_precision) - param.prec = -1; /* default to all digits */ - param.showbase = DOPRNT_SHOWBASE_YES; - param.showtrailing = 1; - goto floating_a; - - case 'c': - /* Let's assume wchar_t will be promoted to "int" in the call, - the same as char will be. */ - (void) va_arg (ap, int); - goto next; - - case 'd': - case 'i': - case 'u': - integer: - TRACE (printf ("integer, base=%d\n", param.base)); - if (! seen_precision) - param.prec = -1; - switch (type) { - case 'j': - /* Let's assume uintmax_t is the same size as intmax_t. */ + { + fchar = *fmt++; + if (fchar == '\0') + break; + + switch (fchar) { + + case 'a': + /* %a behaves like %e, but defaults to all significant digits, + and there's no leading zeros on the exponent (which is in + fact bit-based) */ + param.base = 16; + param.expfmt = "p%c%d"; + goto conv_a; + case 'A': + param.base = -16; + param.expfmt = "P%c%d"; + conv_a: + param.conv = DOPRNT_CONV_SCIENTIFIC; + param.exptimes4 = 1; + if (! seen_precision) + param.prec = -1; /* default to all digits */ + param.showbase = DOPRNT_SHOWBASE_YES; + param.showtrailing = 1; + goto floating_a; + + case 'c': + /* Let's assume wchar_t will be promoted to "int" in the call, + the same as char will be. */ + (void) va_arg (ap, int); + goto next; + + case 'd': + case 'i': + case 'u': + integer: + TRACE (printf ("integer, base=%d\n", param.base)); + if (! seen_precision) + param.prec = -1; + switch (type) { + case 'j': + /* Let's assume uintmax_t is the same size as intmax_t. */ #if HAVE_INTMAX_T - (void) va_arg (ap, intmax_t); + (void) va_arg (ap, intmax_t); #else - ASSERT_FAIL (intmax_t not available); + ASSERT_FAIL (intmax_t not available); #endif - break; - case 'l': - (void) va_arg (ap, long); - break; - case 'L': + break; + case 'l': + (void) va_arg (ap, long); + break; + case 'L': #if HAVE_LONG_LONG - (void) va_arg (ap, long long); + (void) va_arg (ap, long long); #else - ASSERT_FAIL (long long not available); + ASSERT_FAIL (long long not available); #endif - break; - case 'N': - { - mp_ptr xp; - mp_size_t xsize, abs_xsize; - mpz_t z; - FLUSH (); - xp = va_arg (ap, mp_ptr); - PTR(z) = xp; - xsize = (int) va_arg (ap, mp_size_t); - abs_xsize = ABS (xsize); - MPN_NORMALIZE (xp, abs_xsize); - SIZ(z) = (xsize >= 0 ? abs_xsize : -abs_xsize); - ASSERT_CODE (ALLOC(z) = abs_xsize); - gmp_str = mpz_get_str (NULL, param.base, z); - goto gmp_integer; - } - /* break; */ - case 'q': - /* quad_t is probably the same as long long, but let's treat - it separately just to be sure. Also let's assume u_quad_t - will be the same size as quad_t. */ + break; + case 'N': + { + mp_ptr xp; + mp_size_t xsize, abs_xsize; + mpz_t z; + FLUSH (); + xp = va_arg (ap, mp_ptr); + PTR(z) = xp; + xsize = (int) va_arg (ap, mp_size_t); + abs_xsize = ABS (xsize); + MPN_NORMALIZE (xp, abs_xsize); + SIZ(z) = (xsize >= 0 ? abs_xsize : -abs_xsize); + ASSERT_CODE (ALLOC(z) = abs_xsize); + gmp_str = mpz_get_str (NULL, param.base, z); + goto gmp_integer; + } + /* break; */ + case 'q': + /* quad_t is probably the same as long long, but let's treat + it separately just to be sure. Also let's assume u_quad_t + will be the same size as quad_t. */ #if HAVE_QUAD_T - (void) va_arg (ap, quad_t); + (void) va_arg (ap, quad_t); #else - ASSERT_FAIL (quad_t not available); + ASSERT_FAIL (quad_t not available); #endif - break; - case 'Q': - FLUSH (); - gmp_str = mpq_get_str (NULL, param.base, va_arg(ap, mpq_srcptr)); - goto gmp_integer; - case 't': + break; + case 'Q': + FLUSH (); + gmp_str = mpq_get_str (NULL, param.base, va_arg(ap, mpq_srcptr)); + goto gmp_integer; + case 't': #if HAVE_PTRDIFF_T - (void) va_arg (ap, ptrdiff_t); + (void) va_arg (ap, ptrdiff_t); #else - ASSERT_FAIL (ptrdiff_t not available); + ASSERT_FAIL (ptrdiff_t not available); #endif - break; - case 'z': - (void) va_arg (ap, size_t); - break; - case 'Z': - { - int ret; - FLUSH (); - gmp_str = mpz_get_str (NULL, param.base, - va_arg (ap, mpz_srcptr)); - gmp_integer: - ret = __gmp_doprnt_integer (funs, data, ¶m, gmp_str); - (*__gmp_free_func) (gmp_str, strlen(gmp_str)+1); - DOPRNT_ACCUMULATE (ret); - va_copy (last_ap, ap); - last_fmt = fmt; - } - break; - default: - /* default is an "int", and this includes h=short and hh=char - since they're promoted to int in a function call */ - (void) va_arg (ap, int); - break; - } - goto next; - - case 'E': - param.base = -10; - param.expfmt = "E%c%02d"; - /*FALLTHRU*/ - case 'e': - param.conv = DOPRNT_CONV_SCIENTIFIC; - floating: - if (param.showbase == DOPRNT_SHOWBASE_NONZERO) - { - /* # in %e, %f and %g */ - param.showpoint = 1; - param.showtrailing = 1; - } - floating_a: - switch (type) { - case 'F': - FLUSH (); - DOPRNT_ACCUMULATE (__gmp_doprnt_mpf (funs, data, ¶m, - GMP_DECIMAL_POINT, - va_arg (ap, mpf_srcptr))); - va_copy (last_ap, ap); - last_fmt = fmt; - break; - case 'L': + break; + case 'z': + (void) va_arg (ap, size_t); + break; + case 'Z': + { + int ret; + FLUSH (); + gmp_str = mpz_get_str (NULL, param.base, + va_arg (ap, mpz_srcptr)); + gmp_integer: + ret = __gmp_doprnt_integer (funs, data, ¶m, gmp_str); + (*__gmp_free_func) (gmp_str, strlen(gmp_str)+1); + DOPRNT_ACCUMULATE (ret); + va_copy (last_ap, ap); + last_fmt = fmt; + } + break; + default: + /* default is an "int", and this includes h=short and hh=char + since they're promoted to int in a function call */ + (void) va_arg (ap, int); + break; + } + goto next; + + case 'E': + param.base = -10; + param.expfmt = "E%c%02d"; + /*FALLTHRU*/ + case 'e': + param.conv = DOPRNT_CONV_SCIENTIFIC; + floating: + if (param.showbase == DOPRNT_SHOWBASE_NONZERO) + { + /* # in %e, %f and %g */ + param.showpoint = 1; + param.showtrailing = 1; + } + floating_a: + switch (type) { + case 'F': + FLUSH (); + DOPRNT_ACCUMULATE (__gmp_doprnt_mpf (funs, data, ¶m, + GMP_DECIMAL_POINT, + va_arg (ap, mpf_srcptr))); + va_copy (last_ap, ap); + last_fmt = fmt; + break; + case 'L': #if HAVE_LONG_DOUBLE - (void) va_arg (ap, long double); + (void) va_arg (ap, long double); #else - ASSERT_FAIL (long double not available); + ASSERT_FAIL (long double not available); #endif - break; - default: - (void) va_arg (ap, double); - break; - } - goto next; - - case 'f': - param.conv = DOPRNT_CONV_FIXED; - goto floating; - - case 'F': /* mpf_t */ - case 'j': /* intmax_t */ - case 'L': /* long long */ - case 'N': /* mpn */ - case 'q': /* quad_t */ - case 'Q': /* mpq_t */ - case 't': /* ptrdiff_t */ - case 'z': /* size_t */ - case 'Z': /* mpz_t */ - set_type: - type = fchar; - break; - - case 'G': - param.base = -10; - param.expfmt = "E%c%02d"; - /*FALLTHRU*/ - case 'g': - param.conv = DOPRNT_CONV_GENERAL; - param.showtrailing = 0; - goto floating; - - case 'h': - if (type != 'h') - goto set_type; - type = 'H'; /* internal code for "hh" */ - break; - - case 'l': - if (type != 'l') - goto set_type; - type = 'L'; /* "ll" means "L" */ - break; - - case 'm': - /* glibc strerror(errno), no argument */ - goto next; - - case 'M': /* mp_limb_t */ - /* mung format string to l or ll and let plain printf handle it */ + break; + default: + (void) va_arg (ap, double); + break; + } + goto next; + + case 'f': + param.conv = DOPRNT_CONV_FIXED; + goto floating; + + case 'F': /* mpf_t */ + case 'j': /* intmax_t */ + case 'L': /* long long */ + case 'N': /* mpn */ + case 'q': /* quad_t */ + case 'Q': /* mpq_t */ + case 't': /* ptrdiff_t */ + case 'z': /* size_t */ + case 'Z': /* mpz_t */ + set_type: + type = fchar; + break; + + case 'G': + param.base = -10; + param.expfmt = "E%c%02d"; + /*FALLTHRU*/ + case 'g': + param.conv = DOPRNT_CONV_GENERAL; + param.showtrailing = 0; + goto floating; + + case 'h': + if (type != 'h') + goto set_type; + type = 'H'; /* internal code for "hh" */ + break; + + case 'l': + if (type != 'l') + goto set_type; + type = 'L'; /* "ll" means "L" */ + break; + + case 'm': + /* glibc strerror(errno), no argument */ + goto next; + + case 'M': /* mp_limb_t */ + /* mung format string to l or ll and let plain printf handle it */ #if _LONG_LONG_LIMB - memmove (fmt+1, fmt, strlen (fmt)+1); - fmt[-1] = 'l'; - fmt[0] = 'l'; - fmt++; - type = 'L'; + memmove (fmt+1, fmt, strlen (fmt)+1); + fmt[-1] = 'l'; + fmt[0] = 'l'; + fmt++; + type = 'L'; #else - fmt[-1] = 'l'; - type = 'l'; + fmt[-1] = 'l'; + type = 'l'; #endif - break; - - case 'n': - { - void *p; - FLUSH (); - p = va_arg (ap, void *); - switch (type) { - case '\0': * (int *) p = retval; break; - case 'F': mpf_set_si ((mpf_ptr) p, (long) retval); break; - case 'H': * (char *) p = retval; break; - case 'h': * (short *) p = retval; break; + break; + + case 'n': + { + void *p; + FLUSH (); + p = va_arg (ap, void *); + switch (type) { + case '\0': * (int *) p = retval; break; + case 'F': mpf_set_si ((mpf_ptr) p, (long) retval); break; + case 'H': * (char *) p = retval; break; + case 'h': * (short *) p = retval; break; #if HAVE_INTMAX_T - case 'j': * (intmax_t *) p = retval; break; + case 'j': * (intmax_t *) p = retval; break; #else - case 'j': ASSERT_FAIL (intmax_t not available); break; + case 'j': ASSERT_FAIL (intmax_t not available); break; #endif - case 'l': * (long *) p = retval; break; + case 'l': * (long *) p = retval; break; #if HAVE_QUAD_T && HAVE_LONG_LONG - case 'q': - ASSERT_ALWAYS (sizeof (quad_t) == sizeof (long long)); - /*FALLTHRU*/ + case 'q': + ASSERT_ALWAYS (sizeof (quad_t) == sizeof (long long)); + /*FALLTHRU*/ #else - case 'q': ASSERT_FAIL (quad_t not available); break; + case 'q': ASSERT_FAIL (quad_t not available); break; #endif #if HAVE_LONG_LONG - case 'L': * (long long *) p = retval; break; + case 'L': * (long long *) p = retval; break; #else - case 'L': ASSERT_FAIL (long long not available); break; + case 'L': ASSERT_FAIL (long long not available); break; #endif - case 'N': - { - mp_size_t n; - n = va_arg (ap, mp_size_t); - n = ABS (n); - if (n != 0) - { - * (mp_ptr) p = retval; - MPN_ZERO ((mp_ptr) p + 1, n - 1); - } - } - break; - case 'Q': mpq_set_si ((mpq_ptr) p, (long) retval, 1L); break; + case 'N': + { + mp_size_t n; + n = va_arg (ap, mp_size_t); + n = ABS (n); + if (n != 0) + { + * (mp_ptr) p = retval; + MPN_ZERO ((mp_ptr) p + 1, n - 1); + } + } + break; + case 'Q': mpq_set_si ((mpq_ptr) p, (long) retval, 1L); break; #if HAVE_PTRDIFF_T - case 't': * (ptrdiff_t *) p = retval; break; + case 't': * (ptrdiff_t *) p = retval; break; #else - case 't': ASSERT_FAIL (ptrdiff_t not available); break; + case 't': ASSERT_FAIL (ptrdiff_t not available); break; #endif - case 'z': * (size_t *) p = retval; break; - case 'Z': mpz_set_si ((mpz_ptr) p, (long) retval); break; - } - } - va_copy (last_ap, ap); - last_fmt = fmt; - goto next; - - case 'o': - param.base = 8; - goto integer; - - case 'p': - case 's': - /* "void *" will be good enough for "char *" or "wchar_t *", no - need for separate code. */ - (void) va_arg (ap, const void *); - goto next; - - case 'x': - param.base = 16; - goto integer; - case 'X': - param.base = -16; - goto integer; - - case '%': - goto next; - - case '#': - param.showbase = DOPRNT_SHOWBASE_NONZERO; - break; - - case '\'': - /* glibc digit grouping, just pass it through, no support for it - on gmp types */ - break; - - case '+': - case ' ': - param.sign = fchar; - break; - - case '-': - param.justify = DOPRNT_JUSTIFY_LEFT; - break; - case '.': - seen_precision = 1; - param.prec = -1; /* "." alone means all necessary digits */ - value = ¶m.prec; - break; - - case '*': - { - int n = va_arg (ap, int); - - if (value == ¶m.width) - { - /* negative width means left justify */ - if (n < 0) - { - param.justify = DOPRNT_JUSTIFY_LEFT; - n = -n; - } - param.width = n; - } - else - { - /* don't allow negative precision */ - param.prec = MAX (0, n); - } - } - break; - - case '0': - if (value == ¶m.width) - { - /* in width field, set fill */ - param.fill = '0'; - - /* for right justify, put the fill after any minus sign */ - if (param.justify == DOPRNT_JUSTIFY_RIGHT) - param.justify = DOPRNT_JUSTIFY_INTERNAL; - } - else - { - /* in precision field, set value */ - *value = 0; - } - break; - - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - /* process all digits to form a value */ - { - int n = 0; - do { - n = n * 10 + (fchar-'0'); - fchar = *fmt++; - } while (isascii (fchar) && isdigit (fchar)); - fmt--; /* unget the non-digit */ - *value = n; - } - break; - - default: - /* something invalid */ - ASSERT (0); - goto next; - } - } + case 'z': * (size_t *) p = retval; break; + case 'Z': mpz_set_si ((mpz_ptr) p, (long) retval); break; + } + } + va_copy (last_ap, ap); + last_fmt = fmt; + goto next; + + case 'o': + param.base = 8; + goto integer; + + case 'p': + case 's': + /* "void *" will be good enough for "char *" or "wchar_t *", no + need for separate code. */ + (void) va_arg (ap, const void *); + goto next; + + case 'x': + param.base = 16; + goto integer; + case 'X': + param.base = -16; + goto integer; + + case '%': + goto next; + + case '#': + param.showbase = DOPRNT_SHOWBASE_NONZERO; + break; + + case '\'': + /* glibc digit grouping, just pass it through, no support for it + on gmp types */ + break; + + case '+': + case ' ': + param.sign = fchar; + break; + + case '-': + param.justify = DOPRNT_JUSTIFY_LEFT; + break; + case '.': + seen_precision = 1; + param.prec = -1; /* "." alone means all necessary digits */ + value = ¶m.prec; + break; + + case '*': + { + int n = va_arg (ap, int); + + if (value == ¶m.width) + { + /* negative width means left justify */ + if (n < 0) + { + param.justify = DOPRNT_JUSTIFY_LEFT; + n = -n; + } + param.width = n; + } + else + { + /* don't allow negative precision */ + param.prec = MAX (0, n); + } + } + break; + + case '0': + if (value == ¶m.width) + { + /* in width field, set fill */ + param.fill = '0'; + + /* for right justify, put the fill after any minus sign */ + if (param.justify == DOPRNT_JUSTIFY_RIGHT) + param.justify = DOPRNT_JUSTIFY_INTERNAL; + } + else + { + /* in precision field, set value */ + *value = 0; + } + break; + + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + /* process all digits to form a value */ + { + int n = 0; + do { + n = n * 10 + (fchar-'0'); + fchar = *fmt++; + } while (isascii (fchar) && isdigit (fchar)); + fmt--; /* unget the non-digit */ + *value = n; + } + break; + + default: + /* something invalid */ + ASSERT (0); + goto next; + } + } next: /* Stop parsing the current "%" format, look for a new one. */ diff --git a/printf/doprntf.c b/printf/doprntf.c index 9c0608b1e..e713a21a0 100644 --- a/printf/doprntf.c +++ b/printf/doprntf.c @@ -39,7 +39,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ /* change this to "#define TRACE(x) x" for diagnostics */ -#define TRACE(x) +#define TRACE(x) /* The separate of __gmp_doprnt_float_digits and __gmp_doprnt_float is so @@ -52,10 +52,10 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, - void *data, - const struct doprnt_params_t *p, - const char *point, - mpf_srcptr f) + void *data, + const struct doprnt_params_t *p, + const char *point, + mpf_srcptr f) { int prec, ndigits, free_size, len, newlen, justify, justlen, explen; int showbaselen, sign, signlen, intlen, intzeros, pointlen; @@ -67,7 +67,7 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, int retval = 0; TRACE (printf ("__gmp_doprnt_float\n"); - printf (" conv=%d prec=%d\n", p->conv, p->prec)); + printf (" conv=%d prec=%d\n", p->conv, p->prec)); prec = p->prec; if (prec <= -1) @@ -76,40 +76,40 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, ndigits = 0; /* arrange the fixed/scientific decision on a "prec" implied by how - many significant digits there are */ + many significant digits there are */ if (p->conv == DOPRNT_CONV_GENERAL) - MPF_SIGNIFICANT_DIGITS (prec, PREC(f), ABS(p->base)); + MPF_SIGNIFICANT_DIGITS (prec, PREC(f), ABS(p->base)); } else { switch (p->conv) { case DOPRNT_CONV_FIXED: - /* Precision is digits after the radix point. Try not to generate - too many more than will actually be required. If f>=1 then - overestimate the integer part, and add prec. If f<1 then - underestimate the zeros between the radix point and the first - digit and subtract that from prec. In either case add 2 so the - round to nearest can be applied accurately. */ - ndigits = prec + 2 - + EXP(f) * (__mp_bases[ABS(p->base)].chars_per_limb + (EXP(f)>=0)); - ndigits = MAX (ndigits, 1); - break; + /* Precision is digits after the radix point. Try not to generate + too many more than will actually be required. If f>=1 then + overestimate the integer part, and add prec. If f<1 then + underestimate the zeros between the radix point and the first + digit and subtract that from prec. In either case add 2 so the + round to nearest can be applied accurately. */ + ndigits = prec + 2 + + EXP(f) * (__mp_bases[ABS(p->base)].chars_per_limb + (EXP(f)>=0)); + ndigits = MAX (ndigits, 1); + break; case DOPRNT_CONV_SCIENTIFIC: - /* precision is digits after the radix point, and there's one digit - before */ - ndigits = prec + 1; - break; + /* precision is digits after the radix point, and there's one digit + before */ + ndigits = prec + 1; + break; default: - ASSERT (0); - /*FALLTHRU*/ - + ASSERT (0); + /*FALLTHRU*/ + case DOPRNT_CONV_GENERAL: - /* precision is total digits, but be sure to ask mpf_get_str for at - least 1, not 0 */ - ndigits = MAX (prec, 1); - break; + /* precision is total digits, but be sure to ask mpf_get_str for at + least 1, not 0 */ + ndigits = MAX (prec, 1); + break; } } TRACE (printf (" ndigits %d\n", ndigits)); @@ -119,13 +119,13 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, free_ptr = s; free_size = len + 1; TRACE (printf (" s %s\n", s); - printf (" exp %ld\n", exp); - printf (" len %d\n", len)); + printf (" exp %ld\n", exp); + printf (" len %d\n", len)); /* For fixed mode check the ndigits formed above was in fact enough for the integer part plus p->prec after the radix point. */ ASSERT ((p->conv == DOPRNT_CONV_FIXED && p->prec > -1) - ? ndigits >= MAX (1, exp + p->prec + 2) : 1); + ? ndigits >= MAX (1, exp + p->prec + 2) : 1); sign = p->sign; if (s[0] == '-') @@ -146,85 +146,85 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, newlen = exp + prec; if (newlen < 0) { - /* first non-zero digit is below target prec, and at least one zero - digit in between, so print zero */ - len = 0; - exp = 0; + /* first non-zero digit is below target prec, and at least one zero + digit in between, so print zero */ + len = 0; + exp = 0; } else if (len <= newlen) { - /* already got few enough digits */ + /* already got few enough digits */ } else { - /* discard excess digits and round to nearest */ - - const char *num_to_text = (p->base >= 0 - ? "0123456789abcdefghijklmnopqrstuvwxyz" - : "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - int base = ABS(p->base); - int n; - - ASSERT (base <= 36); - - len = newlen; - n = DIGIT_VALUE (s[len]); - TRACE (printf (" rounding with %d\n", n)); - if (n >= (base + 1) / 2) - { - /* propagate a carry */ - for (;;) - { - if (len == 0) - { - s[0] = '1'; - len = 1; - exp++; - break; - } - n = DIGIT_VALUE (s[len-1]); - ASSERT (n >= 0 && n < base); - n++; - if (n != base) - { - TRACE (printf (" storing now %d\n", n)); - s[len-1] = num_to_text[n]; - break; - } - len--; - } - } - else - { - /* truncate only, strip any trailing zeros now exposed */ - while (len > 0 && s[len-1] == '0') - len--; - } - - /* Can have newlen==0, in which case the truncate was just to check - for a carry turning it into "1". If we're left with len==0 then - adjust exp to match. */ - if (len == 0) - exp = 0; - } + /* discard excess digits and round to nearest */ + + const char *num_to_text = (p->base >= 0 + ? "0123456789abcdefghijklmnopqrstuvwxyz" + : "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + int base = ABS(p->base); + int n; + + ASSERT (base <= 36); + + len = newlen; + n = DIGIT_VALUE (s[len]); + TRACE (printf (" rounding with %d\n", n)); + if (n >= (base + 1) / 2) + { + /* propagate a carry */ + for (;;) + { + if (len == 0) + { + s[0] = '1'; + len = 1; + exp++; + break; + } + n = DIGIT_VALUE (s[len-1]); + ASSERT (n >= 0 && n < base); + n++; + if (n != base) + { + TRACE (printf (" storing now %d\n", n)); + s[len-1] = num_to_text[n]; + break; + } + len--; + } + } + else + { + /* truncate only, strip any trailing zeros now exposed */ + while (len > 0 && s[len-1] == '0') + len--; + } + + /* Can have newlen==0, in which case the truncate was just to check + for a carry turning it into "1". If we're left with len==0 then + adjust exp to match. */ + if (len == 0) + exp = 0; + } fixed: ASSERT (len == 0 ? exp == 0 : 1); if (exp <= 0) { - TRACE (printf (" fixed 0.000sss\n")); - intlen = 0; - intzeros = 1; - fraczeros = -exp; - fraclen = len; + TRACE (printf (" fixed 0.000sss\n")); + intlen = 0; + intzeros = 1; + fraczeros = -exp; + fraclen = len; } else { - TRACE (printf (" fixed sss.sss or sss000\n")); - intlen = MIN (len, exp); - intzeros = exp - intlen; - fraczeros = 0; - fraclen = len - intlen; + TRACE (printf (" fixed sss.sss or sss000\n")); + intlen = MIN (len, exp); + intzeros = exp - intlen; + fraczeros = 0; + fraclen = len - intlen; } explen = 0; break; @@ -235,7 +235,7 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, char expsign; if (prec <= -1) - prec = MAX (0, len-1); /* retain all digits */ + prec = MAX (0, len-1); /* retain all digits */ scientific: TRACE (printf (" scientific s.sss\n")); @@ -247,18 +247,18 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, expval = (exp-intlen); if (p->exptimes4) - expval <<= 2; + expval <<= 2; /* Split out the sign since %o or %x in expfmt give negatives as twos - complement, not with a sign. */ + complement, not with a sign. */ expsign = (expval >= 0 ? '+' : '-'); expval = ABS (expval); #if HAVE_VSNPRINTF explen = snprintf (exponent, sizeof(exponent), - p->expfmt, expsign, expval); + p->expfmt, expsign, expval); /* test for < sizeof-1 since a glibc 2.0.x return of sizeof-1 might - mean truncation */ + mean truncation */ ASSERT (explen >= 0 && explen < sizeof(exponent)-1); #else sprintf (exponent, p->expfmt, expsign, expval); @@ -286,24 +286,24 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, } TRACE (printf (" intlen %d intzeros %d fraczeros %d fraclen %d\n", - intlen, intzeros, fraczeros, fraclen)); + intlen, intzeros, fraczeros, fraclen)); ASSERT (p->prec <= -1 - ? intlen + fraclen == strlen (s) - : intlen + fraclen <= strlen (s)); + ? intlen + fraclen == strlen (s) + : intlen + fraclen <= strlen (s)); if (p->showtrailing) { /* Pad to requested precision with trailing zeros, for general this is - all digits, for fixed and scientific just the fraction. */ + all digits, for fixed and scientific just the fraction. */ preczeros = prec - (fraczeros + fraclen - + (p->conv == DOPRNT_CONV_GENERAL - ? intlen + intzeros : 0)); + + (p->conv == DOPRNT_CONV_GENERAL + ? intlen + intzeros : 0)); preczeros = MAX (0, preczeros); } else preczeros = 0; TRACE (printf (" prec=%d showtrailing=%d, pad with preczeros %d\n", - prec, p->showtrailing, preczeros)); + prec, p->showtrailing, preczeros)); /* radix point if needed, or if forced */ pointlen = ((fraczeros + fraclen + preczeros) != 0 || p->showpoint != 0) @@ -333,11 +333,11 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, break; } TRACE (printf (" showbase %s showbaselen %d\n", - showbase == NULL ? "" : showbase, showbaselen)); + showbase == NULL ? "" : showbase, showbaselen)); /* left over field width */ justlen = p->width - (signlen + showbaselen + intlen + intzeros + pointlen - + fraczeros + fraclen + preczeros + explen); + + fraczeros + fraclen + preczeros + explen); TRACE (printf (" justlen %d fill 0x%X\n", justlen, p->fill)); justify = p->justify; @@ -345,7 +345,7 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, justify = DOPRNT_JUSTIFY_NONE; TRACE (printf (" justify type %d intlen %d pointlen %d fraclen %d\n", - justify, intlen, pointlen, fraclen)); + justify, intlen, pointlen, fraclen)); if (justify == DOPRNT_JUSTIFY_RIGHT) /* pad for right */ DOPRNT_REPS (p->fill, justlen); @@ -370,7 +370,7 @@ __gmp_doprnt_mpf (const struct doprnt_funs_t *funs, DOPRNT_MEMORY_MAYBE (exponent, explen); /* exp */ - if (justify == DOPRNT_JUSTIFY_LEFT) /* pad for left */ + if (justify == DOPRNT_JUSTIFY_LEFT) /* pad for left */ DOPRNT_REPS (p->fill, justlen); done: diff --git a/printf/doprnti.c b/printf/doprnti.c index 1202eaacc..df474df3e 100644 --- a/printf/doprnti.c +++ b/printf/doprnti.c @@ -39,9 +39,9 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ int __gmp_doprnt_integer (const struct doprnt_funs_t *funs, - void *data, - const struct doprnt_params_t *p, - const char *s) + void *data, + const struct doprnt_params_t *p, + const char *s) { int retval = 0; int slen, justlen, showbaselen, sign, signlen, slashlen, zeros; diff --git a/printf/obprntffuns.c b/printf/obprntffuns.c index 256c6b3bb..092e6cca2 100644 --- a/printf/obprntffuns.c +++ b/printf/obprntffuns.c @@ -46,7 +46,7 @@ static int gmp_obstack_memory (struct obstack *ob, const char *ptr, size_t len) { obstack_grow (ob, ptr, len); - return len; + return len; } static int diff --git a/printf/repl-vsnprintf.c b/printf/repl-vsnprintf.c index 5587c5b7b..06809dcb8 100644 --- a/printf/repl-vsnprintf.c +++ b/printf/repl-vsnprintf.c @@ -92,7 +92,7 @@ strnlen (const char *s, size_t n) int __gmp_replacement_vsnprintf (char *buf, size_t buf_size, - const char *orig_fmt, va_list orig_ap) + const char *orig_fmt, va_list orig_ap) { va_list ap; const char *fmt; @@ -127,7 +127,7 @@ __gmp_replacement_vsnprintf (char *buf, size_t buf_size, #ifdef DBL_MAX_10_EXP /* but in any case prefer a value the compiler says */ double_digits = DBL_MAX_10_EXP; -#endif +#endif /* IEEE 128-bit quad, Intel 80-bit temporary, or VAX H floats all have 15 bit exponents, so the default is a maximum 4932 decimal digits. */ @@ -140,13 +140,13 @@ __gmp_replacement_vsnprintf (char *buf, size_t buf_size, #ifdef LDBL_MAX_10_EXP /* but in any case prefer a value the compiler says */ long_double_digits = LDBL_MAX_10_EXP; -#endif +#endif for (;;) { fmt = strchr (fmt, '%'); if (fmt == NULL) - break; + break; fmt++; type = '\0'; @@ -156,202 +156,202 @@ __gmp_replacement_vsnprintf (char *buf, size_t buf_size, value = &width; for (;;) - { - fchar = *fmt++; - switch (fchar) { - - case 'c': - /* char, already accounted for by strlen(fmt) */ - goto next; - - case 'd': - case 'i': - case 'o': - case 'x': - case 'X': - case 'u': - /* at most 3 digits per byte in hex, dec or octal, plus a sign */ - total_width += 3 * integer_sizeof + 1; - - switch (type) { - case 'j': - /* Let's assume uintmax_t is the same size as intmax_t. */ + { + fchar = *fmt++; + switch (fchar) { + + case 'c': + /* char, already accounted for by strlen(fmt) */ + goto next; + + case 'd': + case 'i': + case 'o': + case 'x': + case 'X': + case 'u': + /* at most 3 digits per byte in hex, dec or octal, plus a sign */ + total_width += 3 * integer_sizeof + 1; + + switch (type) { + case 'j': + /* Let's assume uintmax_t is the same size as intmax_t. */ #if HAVE_INTMAX_T - (void) va_arg (ap, intmax_t); + (void) va_arg (ap, intmax_t); #else - ASSERT_FAIL (intmax_t not available); + ASSERT_FAIL (intmax_t not available); #endif - break; - case 'l': - (void) va_arg (ap, long); - break; - case 'L': + break; + case 'l': + (void) va_arg (ap, long); + break; + case 'L': #if HAVE_LONG_LONG - (void) va_arg (ap, long long); + (void) va_arg (ap, long long); #else - ASSERT_FAIL (long long not available); + ASSERT_FAIL (long long not available); #endif - break; - case 'q': - /* quad_t is probably the same as long long, but let's treat - it separately just to be sure. Also let's assume u_quad_t - will be the same size as quad_t. */ + break; + case 'q': + /* quad_t is probably the same as long long, but let's treat + it separately just to be sure. Also let's assume u_quad_t + will be the same size as quad_t. */ #if HAVE_QUAD_T - (void) va_arg (ap, quad_t); + (void) va_arg (ap, quad_t); #else - ASSERT_FAIL (quad_t not available); + ASSERT_FAIL (quad_t not available); #endif - break; - case 't': + break; + case 't': #if HAVE_PTRDIFF_T - (void) va_arg (ap, ptrdiff_t); + (void) va_arg (ap, ptrdiff_t); #else - ASSERT_FAIL (ptrdiff_t not available); + ASSERT_FAIL (ptrdiff_t not available); #endif - break; - case 'z': - (void) va_arg (ap, size_t); - break; - default: - /* default is an "int", and this includes h=short and hh=char - since they're promoted to int in a function call */ - (void) va_arg (ap, int); - break; - } - goto next; - - case 'E': - case 'e': - case 'G': - case 'g': - /* Requested decimals, sign, point and e, plus an overestimate - of exponent digits (the assumption is all the float is - exponent!). */ - total_width += prec + 3 + floating_sizeof * 3; - if (type == 'L') - { + break; + case 'z': + (void) va_arg (ap, size_t); + break; + default: + /* default is an "int", and this includes h=short and hh=char + since they're promoted to int in a function call */ + (void) va_arg (ap, int); + break; + } + goto next; + + case 'E': + case 'e': + case 'G': + case 'g': + /* Requested decimals, sign, point and e, plus an overestimate + of exponent digits (the assumption is all the float is + exponent!). */ + total_width += prec + 3 + floating_sizeof * 3; + if (type == 'L') + { #if HAVE_LONG_DOUBLE - (void) va_arg (ap, long double); + (void) va_arg (ap, long double); #else - ASSERT_FAIL (long double not available); + ASSERT_FAIL (long double not available); #endif - } - else + } + else (void) va_arg (ap, double); - break; - - case 'f': - /* Requested decimals, sign and point, and a margin for error, - then add the maximum digits that can be in the integer part, - based on the maximum exponent value. */ - total_width += prec + 2 + 10; - if (type == 'L') - { + break; + + case 'f': + /* Requested decimals, sign and point, and a margin for error, + then add the maximum digits that can be in the integer part, + based on the maximum exponent value. */ + total_width += prec + 2 + 10; + if (type == 'L') + { #if HAVE_LONG_DOUBLE - (void) va_arg (ap, long double); - total_width += long_double_digits; + (void) va_arg (ap, long double); + total_width += long_double_digits; #else - ASSERT_FAIL (long double not available); + ASSERT_FAIL (long double not available); #endif - } - else - { - (void) va_arg (ap, double); - total_width += double_digits; - } - break; - - case 'h': /* short or char */ - case 'j': /* intmax_t */ - case 'L': /* long long or long double */ - case 'q': /* quad_t */ - case 't': /* ptrdiff_t */ - set_type: - type = fchar; - break; - - case 'l': - /* long or long long */ - if (type != 'l') - goto set_type; - type = 'L'; /* "ll" means "L" */ - break; - - case 'n': - /* bytes written, no output as such */ - (void) va_arg (ap, void *); - goto next; - - case 's': - /* If no precision was given, then determine the string length - and put it there, to be added to the total under "next". If - a precision was given then that's already the maximum from - this field, but see whether the string is shorter than that, - in case the limit was very big. */ - { - const char *s = va_arg (ap, const char *); - prec = (seen_prec ? strnlen (s, prec) : strlen (s)); - } - goto next; - - case 'p': - /* pointer, let's assume at worst it's octal with some padding */ - (void) va_arg (ap, const void *); - total_width += 3 * sizeof (void *) + 16; - goto next; - - case '%': - /* literal %, already accounted for by strlen(fmt) */ - goto next; - - case '#': - /* showbase, at most 2 for "0x" */ - total_width += 2; - break; - - case '+': - case ' ': - /* sign, already accounted for under numerics */ - break; - - case '-': - /* left justify, no effect on total width */ - break; - - case '.': - seen_prec = 1; - value = ≺ - break; - - case '*': - { - /* negative width means left justify which can be ignored, - negative prec would be invalid, just use absolute value */ - int n = va_arg (ap, int); - *value = ABS (n); - } - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* process all digits to form a value */ - { - int n = 0; - do { - n = n * 10 + (fchar-'0'); - fchar = *fmt++; - } while (isascii (fchar) && isdigit (fchar)); - fmt--; /* unget the non-digit */ - *value = n; - } - break; - - default: - /* incomplete or invalid % sequence */ - ASSERT (0); - goto next; - } - } + } + else + { + (void) va_arg (ap, double); + total_width += double_digits; + } + break; + + case 'h': /* short or char */ + case 'j': /* intmax_t */ + case 'L': /* long long or long double */ + case 'q': /* quad_t */ + case 't': /* ptrdiff_t */ + set_type: + type = fchar; + break; + + case 'l': + /* long or long long */ + if (type != 'l') + goto set_type; + type = 'L'; /* "ll" means "L" */ + break; + + case 'n': + /* bytes written, no output as such */ + (void) va_arg (ap, void *); + goto next; + + case 's': + /* If no precision was given, then determine the string length + and put it there, to be added to the total under "next". If + a precision was given then that's already the maximum from + this field, but see whether the string is shorter than that, + in case the limit was very big. */ + { + const char *s = va_arg (ap, const char *); + prec = (seen_prec ? strnlen (s, prec) : strlen (s)); + } + goto next; + + case 'p': + /* pointer, let's assume at worst it's octal with some padding */ + (void) va_arg (ap, const void *); + total_width += 3 * sizeof (void *) + 16; + goto next; + + case '%': + /* literal %, already accounted for by strlen(fmt) */ + goto next; + + case '#': + /* showbase, at most 2 for "0x" */ + total_width += 2; + break; + + case '+': + case ' ': + /* sign, already accounted for under numerics */ + break; + + case '-': + /* left justify, no effect on total width */ + break; + + case '.': + seen_prec = 1; + value = ≺ + break; + + case '*': + { + /* negative width means left justify which can be ignored, + negative prec would be invalid, just use absolute value */ + int n = va_arg (ap, int); + *value = ABS (n); + } + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* process all digits to form a value */ + { + int n = 0; + do { + n = n * 10 + (fchar-'0'); + fchar = *fmt++; + } while (isascii (fchar) && isdigit (fchar)); + fmt--; /* unget the non-digit */ + *value = n; + } + break; + + default: + /* incomplete or invalid % sequence */ + ASSERT (0); + goto next; + } + } next: total_width += width; @@ -371,11 +371,11 @@ __gmp_replacement_vsnprintf (char *buf, size_t buf_size, vsprintf (s, orig_fmt, orig_ap); len = strlen (s); if (buf_size != 0) - { - size_t copylen = MIN (len, buf_size-1); - memcpy (buf, s, copylen); - buf[copylen] = '\0'; - } + { + size_t copylen = MIN (len, buf_size-1); + memcpy (buf, s, copylen); + buf[copylen] = '\0'; + } (*__gmp_free_func) (s, total_width); } diff --git a/printf/sprintffuns.c b/printf/sprintffuns.c index 7a4dc6264..01fb3c98e 100644 --- a/printf/sprintffuns.c +++ b/printf/sprintffuns.c @@ -53,7 +53,7 @@ gmp_sprintf_format (char **bufp, const char *fmt, va_list ap) vsprintf (buf, fmt, ap); ret = strlen (buf); *bufp = buf + ret; - return ret; + return ret; } static int @@ -62,7 +62,7 @@ gmp_sprintf_memory (char **bufp, const char *str, size_t len) char *buf = *bufp; *bufp = buf + len; memcpy (buf, str, len); - return len; + return len; } static int @@ -72,7 +72,7 @@ gmp_sprintf_reps (char **bufp, int c, int reps) ASSERT (reps >= 0); *bufp = buf + reps; memset (buf, c, reps); - return reps; + return reps; } static int |