From 6ff88a44f0c1cb2e16f948fbd7705d1a68e6ecac Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Sat, 2 Mar 2013 16:02:20 +0100 Subject: Fixed code to support field width and precision --- builtin_printf.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/builtin_printf.cpp b/builtin_printf.cpp index b633edd1..e5f0e4ae 100644 --- a/builtin_printf.cpp +++ b/builtin_printf.cpp @@ -97,7 +97,7 @@ C_STRTOD (wchar_t const *nptr, wchar_t **endptr) if (!saved_locale.empty()) { - setlocale (LC_NUMERIC, "C"); + wsetlocale (LC_NUMERIC, L"C"); } r = STRTOD (nptr, endptr); @@ -322,21 +322,24 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion length_modifier = L"L"; length_modifier_len = 1; break; - + case L's': + length_modifier = L"l"; + length_modifier_len = 1; + break; default: length_modifier = start; /* Any valid pointer will do. */ length_modifier_len = 0; break; } - p = static_cast(malloc (length + length_modifier_len + 2)); - q = static_cast(mempcpy (p, start, length)); - q = static_cast(mempcpy (q, length_modifier, length_modifier_len)); + p = new wchar_t[length + length_modifier_len + 2]; + q = static_cast(mempcpy (p, start, sizeof(wchar_t) * length)); + q = static_cast(mempcpy (q, length_modifier, sizeof(wchar_t) * length_modifier_len)); *q++ = conversion; *q = L'\0'; } - - append_format(fmt, L"%%l%lc", conversion); + + fmt = p; switch (conversion) { case L'd': @@ -393,7 +396,6 @@ static void print_direc (const wchar_t *start, size_t length, wchar_t conversion case L'g': case L'G': { -debug(0, "Field width %d, Precision %d", field_width, precision); long double arg = vstrtold (argument); if (!have_field_width) @@ -421,8 +423,6 @@ debug(0, "Field width %d, Precision %d", field_width, precision); break; case L's': - -debug(0, "Field width %d, Precision %d", field_width, precision); if (!have_field_width) { if (!have_precision){ @@ -529,16 +529,18 @@ debug(0, "Field width %d, Precision %d", field_width, precision); ++argv; --argc; } - else - field_width = 0; + else{ + field_width = 0; + } have_field_width = true; } - else + else { while (iswdigit(*f)) { ++f; ++direc_length; } + } if (*f == L'.') { ++f; -- cgit v1.2.3