diff options
author | Siteshwar Vashisht <siteshwar@gmail.com> | 2013-03-02 16:02:20 +0100 |
---|---|---|
committer | Siteshwar Vashisht <siteshwar@gmail.com> | 2013-03-02 20:54:12 +0530 |
commit | b989978dd3db7e27ce62d9b43aef8564c69f3e60 (patch) | |
tree | c3d685a8abce0c89531550ab25a440aa94904df2 /builtin_printf.cpp | |
parent | d9c9760aaca353da3deeb503da0a191b34683309 (diff) |
Fixed code to support field width and precision
Diffstat (limited to 'builtin_printf.cpp')
-rw-r--r-- | builtin_printf.cpp | 28 |
1 files 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<wchar_t*>(malloc (length + length_modifier_len + 2)); - q = static_cast<wchar_t*>(mempcpy (p, start, length)); - q = static_cast<wchar_t*>(mempcpy (q, length_modifier, length_modifier_len)); + p = new wchar_t[length + length_modifier_len + 2]; + q = static_cast<wchar_t*>(mempcpy (p, start, sizeof(wchar_t) * length)); + q = static_cast<wchar_t*>(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; |