[2/2] xcopy: Use FormatMessage() for better internationalization support.
Francois Gouget
fgouget at free.fr
Tue Oct 18 09:44:32 CDT 2011
This makes it possible to reorder the format string placeholders in message translations.
---
This is the right fix for the Korean translation that reordered the
format placeholders of "Copying of '%s' to '%s' failed with r/c %d\n".
programs/xcopy/xcopy.c | 16 +++++++++-------
programs/xcopy/xcopy.rc | 18 +++++++++---------
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/programs/xcopy/xcopy.c b/programs/xcopy/xcopy.c
index f684a55..cfe58f3 100644
--- a/programs/xcopy/xcopy.c
+++ b/programs/xcopy/xcopy.c
@@ -120,10 +120,12 @@ static int XCOPY_wprintf(const WCHAR *format, ...) {
}
va_start(parms, format);
- len = vsnprintfW(output_bufW, MAX_WRITECONSOLE_SIZE/sizeof(WCHAR), format, parms);
+ SetLastError(NO_ERROR);
+ len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, format, 0, 0, output_bufW,
+ MAX_WRITECONSOLE_SIZE/sizeof(*output_bufW), &parms);
va_end(parms);
- if (len < 0) {
- WINE_FIXME("String too long.\n");
+ if (len == 0 && GetLastError() != NO_ERROR) {
+ WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_w(format));
return 0;
}
@@ -183,7 +185,7 @@ static void XCOPY_FailMessage(DWORD err) {
WINE_FIXME("FIXME: Cannot display message for error %d, status %d\n",
err, GetLastError());
} else {
- const WCHAR infostr[] = {'%', 's', '\n', 0};
+ const WCHAR infostr[] = {'%', '1', '\n', 0};
XCOPY_wprintf(infostr, lpMsgBuf);
LocalFree ((HLOCAL)lpMsgBuf);
}
@@ -534,12 +536,12 @@ static int XCOPY_DoCopy(WCHAR *srcstem, WCHAR *srcspec,
if (flags & OPT_QUIET) {
/* Skip message */
} else if (flags & OPT_FULL) {
- const WCHAR infostr[] = {'%', 's', ' ', '-', '>', ' ',
- '%', 's', '\n', 0};
+ const WCHAR infostr[] = {'%', '1', ' ', '-', '>', ' ',
+ '%', '2', '\n', 0};
XCOPY_wprintf(infostr, copyFrom, copyTo);
} else {
- const WCHAR infostr[] = {'%', 's', '\n', 0};
+ const WCHAR infostr[] = {'%', '1', '\n', 0};
XCOPY_wprintf(infostr, copyFrom);
}
diff --git a/programs/xcopy/xcopy.rc b/programs/xcopy/xcopy.rc
index 72e7632..d3bf7bd 100644
--- a/programs/xcopy/xcopy.rc
+++ b/programs/xcopy/xcopy.rc
@@ -25,18 +25,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
STRINGTABLE
{
STRING_INVPARMS, "Invalid number of parameters - Use xcopy /? for help\n"
- STRING_INVPARM, "Invalid parameter '%s' - Use xcopy /? for help\n"
+ STRING_INVPARM, "Invalid parameter '%1' - Use xcopy /? for help\n"
STRING_PAUSE, "Press <enter> to begin copying\n"
- STRING_SIMCOPY, "%d file(s) would be copied\n"
- STRING_COPY, "%d file(s) copied\n"
- STRING_QISDIR, "Is '%s' a filename or directory\n\
+ STRING_SIMCOPY, "%1!d! file(s) would be copied\n"
+ STRING_COPY, "%1!d! file(s) copied\n"
+ STRING_QISDIR, "Is '%1' a filename or directory\n\
on the target?\n\
(F - File, D - Directory)\n"
- STRING_SRCPROMPT,"%s? (Yes|No)\n"
- STRING_OVERWRITE,"Overwrite %s? (Yes|No|All)\n"
- STRING_COPYFAIL, "Copying of '%s' to '%s' failed with r/c %d\n"
- STRING_OPENFAIL, "Failed to open '%s'\n"
- STRING_READFAIL, "Failed during reading of '%s'\n"
+ STRING_SRCPROMPT,"%1? (Yes|No)\n"
+ STRING_OVERWRITE,"Overwrite %1? (Yes|No|All)\n"
+ STRING_COPYFAIL, "Copying of '%1' to '%2' failed with r/c %3!d!\n"
+ STRING_OPENFAIL, "Failed to open '%1'\n"
+ STRING_READFAIL, "Failed during reading of '%1'\n"
STRING_YES_CHAR, "#msgctxt#Yes key#Y"
STRING_NO_CHAR, "#msgctxt#No key#N"
STRING_ALL_CHAR, "#msgctxt#All key#A"
--
1.7.6.3
More information about the wine-patches
mailing list