"Jaco Greeff" jaco@puxedo.org wrote:
Changelog:
- dlls/msvcrt/vfprintf.c, dlls/msvcrt/Makefile.in,
dlls/msvcrt/tests/printf.c, dlls/msvcrt/tests/Makefile.in: Jaco Greeff jaco@puxedo.org
- Full implementation to allow for %C & %S in all printf related functions
- Test case for the printf functions to test all known cases of formatting
(test case based on example found on MSDN site)
I'm sorry for returning to that topic again and again, but it's really does matter.
+static void test_printf(void) +{
- FILE* f;
- char ch = 'a', *string = "computer";
- int count = -9234;
- double fp = 251.7366;
- wchar_t wch = L'w', *wstring = L"Unicode";
- void *p = 0x1234ABCD;
Please,
1. use explicit WCHAR type instead of wchar_t. 2. explicitly encode unicode strings.
wctomb(ch, wch);
3. directly use Win32 conversion APIs (WideCharToMultiByte in this case).
Take a look at other places in the Wine source how to do it properly.
Thanks.
Dmitry Timoshkov wrote:
- wchar_t wch = L'w', *wstring = L"Unicode";
- void *p = 0x1234ABCD;
- use explicit WCHAR type instead of wchar_t.
- explicitly encode unicode strings.
Agreed, that one is directly from the MS site (link attached to a previous mail) and I've used it as such as a test case. It is very ugly, and in addition you get millions of warnings just compiling it. I wanted to make sure that we get as close to a "real-world" example working hence not stuffing around (making it "real-wine-code") too much. The point has been proven, real-world code works, I'll fix that up to be compilant.
wctomb(ch, wch);
- directly use Win32 conversion APIs (WideCharToMultiByte in this case).
Damnit, must have missed that one. I'm sure I had WideCharToMultiByte before.
Take a look at other places in the Wine source how to do it properly.
I know how to do it properly, reasons for the irritations explained above. Back to the real question: is there anything else missing that should be looked at in the patch? (Apart for the ugly test case and char conversion.)
Greetings, Jaco
"Jaco Greeff" jaco@puxedo.org wrote:
Back to the real question: is there anything else missing that should be looked at in the patch? (Apart for the ugly test case and char conversion.)
Doing a cursory look I don't see anything other (again, apart from L"something" and (WCHAR)L'%').
Dmitry Timoshkov wrote:
Doing a cursory look I don't see anything other (again, apart from L"something" and (WCHAR)L'%').
That (the WCHARL'%' switch/case) is the one case for which I don't have an answer for. Originally I had the code looking as follows:
INT somefunc(LPCWSTR lpszStr) { while (*lpszStr) { switch (*lpszStr) { case '%': do_something(); break; ...
In other parts of the wine code (I need to find it again, but a grep on the sources should turn it up), generally these types of things gets written as (maybe I just looked in entirely the wrong place ;),
INT somefunc(LPCWSTR lpszStr) { while (*lpszStr) { switch (*lpszStr) { case (WCHAR)L'%': do_something(); break; ...
and consequently I've adapted my code to do the same. I'm not sure what is the "correct" approach to take in this regard. So, yes, I'm quite happy to rid ourselves of the L"something" in the test code and making sure I use WideCharToMultiByte in the correct place, for the above case I need some guidance.
What is the best way to handle these? If the (WCHAR)L'%' thing is not the way to go, I'll be happy to make a patch for the other parts as well. (Once I have an idea of the best way to handle this.)
Greetings, Jaco
As far as C is concerned, there can be no difference between
case '%': do_something(); break;
and
case (WCHAR)L'%': do_something(); break;
except that the latter is rather more complicated!
Remember '%' is an int constant.
David
David Laight wrote:
Remember '%' is an int constant.
Agreed. The question of (WCHAR)L'%' vs. '%' is really one of semantics. Yes, the "WCHAR" approach looks more complicated, but is potentially better to understand the "gist" of what it supposed to happen and what is required. You know that you are working with WCHARs instead of CHARs, complicating things but potentially making it more understandable...
Anyway, let me get back to fixing Dimitri's nigglies and stop worrying about semantics :)
"Jaco Greeff" jaco@puxedo.org wrote:
What is the best way to handle these? If the (WCHAR)L'%' thing is not the way to go, I'll be happy to make a patch for the other parts as well. (Once I have an idea of the best way to handle this.)
As there was already discussed many times and as David Laight pointed out, there is no need to make simple things look complicated.
In your sample above, simple '%' will perfectly do the job.