diff options
author | tege <tege@gmplib.org> | 2007-09-24 17:19:27 +0200 |
---|---|---|
committer | tege <tege@gmplib.org> | 2007-09-24 17:19:27 +0200 |
commit | 7f6e0a4930a18e221ea2d45d621bea82c9c9c34e (patch) | |
tree | 13f6076dca2ab33d5e59b8847b03226cc30a7be5 /printf/repl-vsnprintf.c | |
parent | 4c893cee7bc42b6f874b4729f7afc767512e8f34 (diff) | |
download | gmp-7f6e0a4930a18e221ea2d45d621bea82c9c9c34e.tar.gz |
Clean up spacing.
Diffstat (limited to 'printf/repl-vsnprintf.c')
-rw-r--r-- | printf/repl-vsnprintf.c | 372 |
1 files changed, 186 insertions, 186 deletions
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); } |