Author: greatlrd Date: Sun May 28 09:59:33 2006 New Revision: 22085
URL: http://svn.reactos.ru/svn/reactos?rev=22085&view=rev Log: copy number to numberf so people can bugfix it/rewrite it
Modified: trunk/reactos/lib/rtl/sprintf.c trunk/reactos/lib/rtl/swprintf.c
Modified: trunk/reactos/lib/rtl/sprintf.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/rtl/sprintf.c?rev=22085&... ============================================================================== --- trunk/reactos/lib/rtl/sprintf.c (original) +++ trunk/reactos/lib/rtl/sprintf.c Sun May 28 09:59:33 2006 @@ -126,6 +126,109 @@ tmp[i++] = '0'; else while (num != 0) tmp[i++] = digits[do_div(&num,base)]; + if (i > precision) + precision = i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) { + while(size-->0) { + if (buf <= end) + *buf = ' '; + ++buf; + } + } + if (sign) { + if (buf <= end) + *buf = sign; + ++buf; + } + if (type & SPECIAL) { + if (base==8) { + if (buf <= end) + *buf = '0'; + ++buf; + } else if (base==16) { + if (buf <= end) + *buf = '0'; + ++buf; + if (buf <= end) + *buf = digits[33]; + ++buf; + } + } + if (!(type & LEFT)) { + while (size-- > 0) { + if (buf <= end) + *buf = c; + ++buf; + } + } + while (i < precision--) { + if (buf <= end) + *buf = '0'; + ++buf; + } + while (i-- > 0) { + if (buf <= end) + *buf = tmp[i]; + ++buf; + } + while (size-- > 0) { + if (buf <= end) + *buf = ' '; + ++buf; + } + return buf; +} + +static char * +numberf(char * buf, char * end, double num, int base, int size, int precision, int type) +{ + char c,sign,tmp[66]; + const char *digits; + const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz"; + const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; + long long x; + + /* FIXME + the float version of number is direcly copy of number + */ + + digits = (type & LARGE) ? large_digits : small_digits; + if (type & LEFT) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return 0; + c = (type & ZEROPAD) ? '0' : ' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = '-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = '+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } + } + if (type & SPECIAL) { + if (base == 16) + size -= 2; + else if (base == 8) + size--; + } + i = 0; + if (num == 0) + tmp[i++] = '0'; + else while (num != 0) + { + x = num; + tmp[i++] = digits[do_div(&x,base)]; + num=x; + } if (i > precision) precision = i; size -= precision; @@ -516,9 +619,8 @@ } } else { if ( precision == -1 ) - precision = 6; - /* FIXME the float version of number */ - str = number(str, end, (int)_double, base, field_width, precision, flags); + precision = 6; + str = numberf(str, end, (int)_double, base, field_width, precision, flags); }
continue;
Modified: trunk/reactos/lib/rtl/swprintf.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/rtl/swprintf.c?rev=22085... ============================================================================== --- trunk/reactos/lib/rtl/swprintf.c (original) +++ trunk/reactos/lib/rtl/swprintf.c Sun May 28 09:59:33 2006 @@ -126,6 +126,110 @@ tmp[i++] = L'0'; else while (num != 0) tmp[i++] = digits[do_div(&num,base)]; + if (i > precision) + precision = i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) { + while(size-->0) { + if (buf <= end) + *buf = L' '; + ++buf; + } + } + if (sign) { + if (buf <= end) + *buf = sign; + ++buf; + } + if (type & SPECIAL) { + if (base==8) { + if (buf <= end) + *buf = L'0'; + ++buf; + } else if (base==16) { + if (buf <= end) + *buf = L'0'; + ++buf; + if (buf <= end) + *buf = digits[33]; + ++buf; + } + } + if (!(type & LEFT)) { + while (size-- > 0) { + if (buf <= end) + *buf = c; + ++buf; + } + } + while (i < precision--) { + if (buf <= end) + *buf = L'0'; + ++buf; + } + while (i-- > 0) { + if (buf <= end) + *buf = tmp[i]; + ++buf; + } + while (size-- > 0) { + if (buf <= end) + *buf = L' '; + ++buf; + } + return buf; +} + +static wchar_t * +numberf(wchar_t * buf, wchar_t * end, double num, int base, int size, int precision, int type) +{ + wchar_t c, sign, tmp[66]; + const wchar_t *digits; + const wchar_t *small_digits = L"0123456789abcdefghijklmnopqrstuvwxyz"; + const wchar_t *large_digits = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; + long long x; + + /* FIXME + the float version of number is direcly copy of number + */ + + + digits = (type & LARGE) ? large_digits : small_digits; + if (type & LEFT) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return 0; + c = (type & ZEROPAD) ? L'0' : L' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = L'-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = L'+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } + } + if (type & SPECIAL) { + if (base == 16) + size -= 2; + else if (base == 8) + size--; + } + i = 0; + if (num == 0) + tmp[i++] = L'0'; + else while (num != 0) + { + x = num; + tmp[i++] = digits[do_div(&x,base)]; + num = x; + } if (i > precision) precision = i; size -= precision; @@ -514,9 +618,8 @@ } } else { if ( precision == -1 ) - precision = 6; - /* FIXME the float version of number */ - str = number(str, end, (int)_double, base, field_width, precision, flags); + precision = 6; + str = numberf(str, end, _double, base, field_width, precision, flags); }
continue;