Avoid shadowing warnings.
From: Jim Meyering <meyering@ascend.com> Date: 15 Jun 2000 14:40:00 +0200
This commit is contained in:
84
lib/human.c
84
lib/human.c
@@ -117,10 +117,6 @@ human_readable_inexact (uintmax_t n, char *buf,
|
|||||||
int base;
|
int base;
|
||||||
int to_block_size;
|
int to_block_size;
|
||||||
int tenths = 0;
|
int tenths = 0;
|
||||||
int multiplier;
|
|
||||||
int divisor;
|
|
||||||
int r2;
|
|
||||||
int r10;
|
|
||||||
int power;
|
int power;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@@ -151,49 +147,55 @@ human_readable_inexact (uintmax_t n, char *buf,
|
|||||||
|
|
||||||
/* Adjust AMT out of FROM_BLOCK_SIZE units and into TO_BLOCK_SIZE units. */
|
/* Adjust AMT out of FROM_BLOCK_SIZE units and into TO_BLOCK_SIZE units. */
|
||||||
|
|
||||||
if (to_block_size <= from_block_size
|
{
|
||||||
? (from_block_size % to_block_size != 0
|
int multiplier;
|
||||||
|| (multiplier = from_block_size / to_block_size,
|
int divisor;
|
||||||
(amt = n * multiplier) / multiplier != n))
|
int r2;
|
||||||
: (from_block_size == 0
|
int r10;
|
||||||
|| to_block_size % from_block_size != 0
|
if (to_block_size <= from_block_size
|
||||||
|| (divisor = to_block_size / from_block_size,
|
? (from_block_size % to_block_size != 0
|
||||||
r10 = (n % divisor) * 10,
|
|| (multiplier = from_block_size / to_block_size,
|
||||||
r2 = (r10 % divisor) * 2,
|
(amt = n * multiplier) / multiplier != n))
|
||||||
amt = n / divisor,
|
: (from_block_size == 0
|
||||||
tenths = r10 / divisor,
|
|| to_block_size % from_block_size != 0
|
||||||
rounding = r2 < divisor ? 0 < r2 : 2 + (divisor < r2),
|
|| (divisor = to_block_size / from_block_size,
|
||||||
0)))
|
r10 = (n % divisor) * 10,
|
||||||
{
|
r2 = (r10 % divisor) * 2,
|
||||||
/* Either the result cannot be computed easily using uintmax_t,
|
amt = n / divisor,
|
||||||
or from_block_size is zero. Fall back on floating point.
|
tenths = r10 / divisor,
|
||||||
FIXME: This can yield answers that are slightly off. */
|
rounding = r2 < divisor ? 0 < r2 : 2 + (divisor < r2),
|
||||||
|
0)))
|
||||||
|
{
|
||||||
|
/* Either the result cannot be computed easily using uintmax_t,
|
||||||
|
or from_block_size is zero. Fall back on floating point.
|
||||||
|
FIXME: This can yield answers that are slightly off. */
|
||||||
|
|
||||||
double damt = n * (from_block_size / (double) to_block_size);
|
double damt = n * (from_block_size / (double) to_block_size);
|
||||||
|
|
||||||
if (! base)
|
if (! base)
|
||||||
sprintf (buf, "%.0f", damt);
|
sprintf (buf, "%.0f", damt);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double e = 1;
|
double e = 1;
|
||||||
power = 0;
|
power = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
e *= base;
|
e *= base;
|
||||||
power++;
|
power++;
|
||||||
}
|
}
|
||||||
while (e * base <= damt && power < sizeof suffixes - 1);
|
while (e * base <= damt && power < sizeof suffixes - 1);
|
||||||
|
|
||||||
damt /= e;
|
damt /= e;
|
||||||
|
|
||||||
sprintf (buf, "%.1f%c", damt, suffixes[power]);
|
sprintf (buf, "%.1f%c", damt, suffixes[power]);
|
||||||
if (4 < strlen (buf))
|
if (4 < strlen (buf))
|
||||||
sprintf (buf, "%.0f%c", damt, suffixes[power]);
|
sprintf (buf, "%.0f%c", damt, suffixes[power]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Use power of BASE notation if adjusted AMT is large enough. */
|
/* Use power of BASE notation if adjusted AMT is large enough. */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user