Increased precision of get_ratio() and swapped parameters.

committer: mfx <mfx> 977342070 +0000
This commit is contained in:
Markus F.X.J. Oberhumer
2000-12-20 19:54:30 +00:00
parent a42e72094a
commit 7d652fa42b
3 changed files with 27 additions and 30 deletions
+14 -14
View File
@@ -117,20 +117,15 @@ static const char *mkline(unsigned long fu_len, unsigned long fc_len,
char r[7+1]; char r[7+1];
const char *f; const char *f;
#if 0 unsigned ratio = get_ratio(fu_len, fc_len);
unsigned ratio = get_ratio(fc_len,fu_len); upx_snprintf(r,sizeof(r),"%3d.%02d%%", ratio / 10000, (ratio % 10000) / 100);
upx_snprintf(r,sizeof(r)," %1d.%03d", ratio / 10000, (ratio % 10000) / 10);
#else
unsigned ratio = get_ratio(fc_len,fu_len, 1000);
upx_snprintf(r,sizeof(r),"%3d.%02d%%", ratio / 1000, (ratio % 1000) / 10);
UNUSED(u_len); UNUSED(c_len);
#endif
if (decompress) if (decompress)
f = "%10ld <-%10ld %7s %13s %s"; f = "%10ld <-%10ld %7s %13s %s";
else else
f = "%10ld ->%10ld %7s %13s %s"; f = "%10ld ->%10ld %7s %13s %s";
upx_snprintf(buf,sizeof(buf),f, upx_snprintf(buf,sizeof(buf),f,
fu_len, fc_len, r, center_string(format_name,13), filename); fu_len, fc_len, r, center_string(format_name,13), filename);
UNUSED(u_len); UNUSED(c_len);
return buf; return buf;
} }
@@ -351,7 +346,7 @@ void __UPX_ENTRY UiPacker::callback(upx_uint isize, upx_uint osize, int state, v
void UiPacker::doCallback(unsigned isize, unsigned osize) void UiPacker::doCallback(unsigned isize, unsigned osize)
{ {
static const char spinner[] = "|\\-/"; static const char spinner[] = "|/-\\";
if (s->pass < 0) // no callback wanted if (s->pass < 0) // no callback wanted
return; return;
@@ -373,8 +368,13 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
// compute progress position // compute progress position
int pos = -1; int pos = -1;
if (isize > 0) if (isize >= s->u_len)
pos = get_ratio(isize,s->u_len) * s->bar_len / 10000; pos = s->bar_len;
else if (isize > 0)
{
pos = get_ratio(s->u_len, isize) * s->bar_len / 1000000;
assert(pos >= 0); assert(pos <= s->bar_len);
}
if (pos < s->pos) if (pos < s->pos)
return; return;
if (pos < 0 && pos == s->pos) if (pos < 0 && pos == s->pos)
@@ -397,12 +397,12 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
*m++ = ']'; *m++ = ']';
// compute current compression ratio // compute current compression ratio
unsigned ratio = 100*100; unsigned ratio = 1000000;
if (osize > 0) if (osize > 0)
ratio = get_ratio(osize,isize); ratio = get_ratio(isize, osize);
sprintf(m," %3d.%1d%% %c ", sprintf(m," %3d.%1d%% %c ",
ratio / 100, (ratio % 100) / 10, ratio / 10000, (ratio % 10000) / 1000,
spinner[s->counter]); spinner[s->counter]);
assert((int)strlen(s->msg_buf) < 1 + 80); assert((int)strlen(s->msg_buf) < 1 + 80);
+12 -14
View File
@@ -443,23 +443,21 @@ bool isafile(int fd)
/************************************************************************* /*************************************************************************
// // return compression ratio, where 100% == 1000*1000 == 1e6
**************************************************************************/ **************************************************************************/
unsigned get_ratio (unsigned long packedsize, unsigned long size, unsigned get_ratio (unsigned u_len, unsigned c_len)
unsigned long scale)
{ {
unsigned long n1, n2; #if defined(__GNUC__)
const unsigned long long n = 1000000;
n1 = 100 * scale; n2 = 1; #elif defined(_MSC_VER)
if (size <= 0) const unsigned __int64 n = 1000000;
return (unsigned) n1; #else
while (n1 > 1 && packedsize > (ULONG_MAX / n1)) #error
{ #endif
n1 /= 10; if (u_len <= 0)
n2 *= 10; return (unsigned) n;
} return (unsigned) ((c_len * n) / u_len) + 5;
return (unsigned) ((packedsize * n1) / (size / n2)) + 5;
} }
+1 -2
View File
@@ -48,8 +48,7 @@ bool maketempname(char *ofilename, const char *ifilename,
bool makebakname(char *ofilename, const char *ifilename, bool force=true); bool makebakname(char *ofilename, const char *ifilename, bool force=true);
bool isafile(int fd); bool isafile(int fd);
unsigned get_ratio(unsigned long packedsize, unsigned long size, unsigned get_ratio(unsigned u_len, unsigned c_len);
unsigned long scale=100);
char *center_string(const char *name, size_t s); char *center_string(const char *name, size_t s);