Added request am41635 and fixed a bug with passing (1<<31)

This commit is contained in:
David Anderson 2006-08-19 22:15:34 +00:00
parent e7cc87a610
commit 67f53505ce

View File

@ -224,6 +224,50 @@ void AddFloat(U **buf_p, size_t &maxlen, double fval, int width, int prec)
} }
} }
template <typename U>
void AddUInt(U **buf_p, size_t &maxlen, unsigned int val, int width, int flags)
{
U text[32];
int digits;
U *buf;
digits = 0;
do {
text[digits++] = '0' + val % 10;
val /= 10;
} while (val);
buf = *buf_p;
if( !(flags & LADJUST) )
{
while (digits < width && maxlen)
{
*buf++ = (flags & ZEROPAD) ? '0' : ' ';
width--;
maxlen--;
}
}
while (digits-- && maxlen)
{
*buf++ = text[digits];
width--;
maxlen--;
}
if (flags & LADJUST)
{
while (width-- && maxlen)
{
*buf++ = (flags & ZEROPAD) ? '0' : ' ';
maxlen--;
}
}
*buf_p = buf;
}
template <typename U> template <typename U>
void AddInt(U **buf_p, size_t &maxlen, int val, int width, int flags) void AddInt(U **buf_p, size_t &maxlen, int val, int width, int flags)
{ {
@ -231,15 +275,22 @@ void AddInt(U **buf_p, size_t &maxlen, int val, int width, int flags)
int digits; int digits;
int signedVal; int signedVal;
U *buf; U *buf;
unsigned int unsignedVal;
digits = 0; digits = 0;
signedVal = val; signedVal = val;
if (val < 0) if (val < 0)
val = -val; {
/* we want the unsigned version */
val--;
unsignedVal = ~val;
} else {
unsignedVal = val;
}
do { do {
text[digits++] = '0' + val % 10; text[digits++] = '0' + unsignedVal % 10;
val /= 10; unsignedVal /= 10;
} while (val); } while (unsignedVal);
if (signedVal < 0) if (signedVal < 0)
text[digits++] = '-'; text[digits++] = '-';
@ -360,6 +411,11 @@ reswitch:
AddInt(&buf_p, llen, *get_amxaddr(amx, params[arg]), width, flags); AddInt(&buf_p, llen, *get_amxaddr(amx, params[arg]), width, flags);
arg++; arg++;
break; break;
case 'u':
CHECK_ARGS(0);
AddUInt(&buf_p, llen, static_cast<unsigned int>(*get_amxaddr(amx, params[arg])), width, flags);
arg++;
break;
case 'f': case 'f':
CHECK_ARGS(0); CHECK_ARGS(0);
AddFloat(&buf_p, llen, amx_ctof(*get_amxaddr(amx, params[arg])), width, prec); AddFloat(&buf_p, llen, amx_ctof(*get_amxaddr(amx, params[arg])), width, prec);