net: Convert to Unicode. (take 2)

Francois Gouget fgouget at free.fr
Wed Aug 3 11:20:29 CDT 2011


Also use WriteConsoleW() instead of the native printf()/fputs() 
functions, which fixes the output of localized strings.
---

The switch is because trying to stick with printf()/fputs() style APIs 
felt like more trouble than they are worth. Incidentally it also fixes 
the display of accentuated characters which is actually the reason I 
looked into this in the first place.

I sort of modeled this after ipconfig's ipconfig_vprintfW() function. 
However that function has a WriteFile() fallback in case WriteConsole() 
fails. But I don't see what's the point of this or when using 
WriteFile() instead of WriteConsole() would work. So I'm hoping someone 
can enlighten me as I see no reason for these two tools to handle things 
so differently. But in any case I see this as being the subject of a 
separate patch so I think this one can go in.

 po/da.po                 |    4 +-
 po/de.po                 |    4 +-
 po/en.po                 |    4 +-
 po/en_US.po              |    4 +-
 po/fr.po                 |    4 +-
 po/he.po                 |    4 +-
 po/it.po                 |    4 +-
 po/ja.po                 |    4 +-
 po/ko.po                 |    4 +-
 po/lt.po                 |    4 +-
 po/nb_NO.po              |    4 +-
 po/nl.po                 |    4 +-
 po/pl.po                 |    4 +-
 po/pt_BR.po              |    4 +-
 po/pt_PT.po              |    4 +-
 po/ro.po                 |    4 +-
 po/ru.po                 |    4 +-
 po/sl.po                 |    4 +-
 po/sv.po                 |    4 +-
 po/uk.po                 |    4 +-
 programs/net/Makefile.in |    2 +-
 programs/net/net.c       |   65 ++++++++++++++++++++++++++++-----------------
 programs/net/net.rc      |    2 +-
 23 files changed, 82 insertions(+), 67 deletions(-)

diff --git a/po/da.po b/po/da.po
index eb9efb4..4cc50aa 100644
--- a/po/da.po
+++ b/po/da.po
@@ -8920,8 +8920,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      ??bne resourser: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      ??bne resourser: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/de.po b/po/de.po
index 5b9f0e4..7cb7ae8 100644
--- a/po/de.po
+++ b/po/de.po
@@ -8906,8 +8906,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Offene Ressourcen: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Offene Ressourcen: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/en.po b/po/en.po
index e2c5e2b..26030aa 100644
--- a/po/en.po
+++ b/po/en.po
@@ -8546,8 +8546,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Open resources: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Open resources: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/en_US.po b/po/en_US.po
index 1fd9b10..ec62884 100644
--- a/po/en_US.po
+++ b/po/en_US.po
@@ -8654,8 +8654,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Open resources: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Open resources: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/fr.po b/po/fr.po
index 3839d3f..df1b977 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -8745,8 +8745,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Ressources ouvertes??: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Ressources ouvertes??: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/he.po b/po/he.po
index a092141..72f21d5 100644
--- a/po/he.po
+++ b/po/he.po
@@ -8755,8 +8755,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Open resources: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Open resources: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/it.po b/po/it.po
index 0a9a229..d2e27b4 100644
--- a/po/it.po
+++ b/po/it.po
@@ -9006,8 +9006,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Risorse aperte: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Risorse aperte: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/ja.po b/po/ja.po
index a61c863..39233c1 100644
--- a/po/ja.po
+++ b/po/ja.po
@@ -8641,8 +8641,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S       %S      ???????????????: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s       %s      ???????????????: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/ko.po b/po/ko.po
index d00d929..107fc45 100644
--- a/po/ko.po
+++ b/po/ko.po
@@ -8617,8 +8617,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      ?????? ?????????: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      ?????? ?????????: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/lt.po b/po/lt.po
index 63a44a7..0f58c0d 100644
--- a/po/lt.po
+++ b/po/lt.po
@@ -8668,8 +8668,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Atverti i??tekliai: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Atverti i??tekliai: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/nb_NO.po b/po/nb_NO.po
index 836f349..d32a71e 100644
--- a/po/nb_NO.po
+++ b/po/nb_NO.po
@@ -8922,8 +8922,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      ??pne ressurser: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      ??pne ressurser: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/nl.po b/po/nl.po
index ff02420..2e20aaa 100644
--- a/po/nl.po
+++ b/po/nl.po
@@ -8808,8 +8808,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Open resources: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Open resources: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/pl.po b/po/pl.po
index 30cbb43..8c222a1 100644
--- a/po/pl.po
+++ b/po/pl.po
@@ -8672,8 +8672,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Otwarte zasoby: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Otwarte zasoby: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/pt_BR.po b/po/pt_BR.po
index 11978e5..8c2125a 100644
--- a/po/pt_BR.po
+++ b/po/pt_BR.po
@@ -8950,8 +8950,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Recursos dispon??veis: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Recursos dispon??veis: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/pt_PT.po b/po/pt_PT.po
index 7c62228..f27ee90 100644
--- a/po/pt_PT.po
+++ b/po/pt_PT.po
@@ -9003,8 +9003,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Recursos dispon??veis: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Recursos dispon??veis: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/ro.po b/po/ro.po
index 68c4cd6..0e990ba 100644
--- a/po/ro.po
+++ b/po/ro.po
@@ -9239,8 +9239,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Resurse deschise: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Resurse deschise: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/ru.po b/po/ru.po
index adcd5ca..838bfc7 100644
--- a/po/ru.po
+++ b/po/ru.po
@@ -8662,8 +8662,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S         %S      ???????????????? ????????????????: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s         %s      ???????????????? ????????????????: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/sl.po b/po/sl.po
index 5af9aea..46ddb3f 100644
--- a/po/sl.po
+++ b/po/sl.po
@@ -8693,8 +8693,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      Odprta sredstva: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      Odprta sredstva: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/sv.po b/po/sv.po
index 0d2a6e2..646233c 100644
--- a/po/sv.po
+++ b/po/sv.po
@@ -8672,8 +8672,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      ??ppna resurser: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      ??ppna resurser: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/po/uk.po b/po/uk.po
index 14e9822..c40fada 100644
--- a/po/uk.po
+++ b/po/uk.po
@@ -8650,8 +8650,8 @@ msgstr ""
 "---------------------------------------------------------------\n"
 
 #: net.rc:44
-msgid "%s      %S      %S      Open resources: %lu\n"
-msgstr "%s      %S      %S      ?????????????????? ????????????????: %lu\n"
+msgid "%s      %s      %s      Open resources: %lu\n"
+msgstr "%s      %s      %s      ?????????????????? ????????????????: %lu\n"
 
 #: net.rc:45
 msgid "OK"
diff --git a/programs/net/Makefile.in b/programs/net/Makefile.in
index 0369b51..ab8781d 100644
--- a/programs/net/Makefile.in
+++ b/programs/net/Makefile.in
@@ -1,5 +1,5 @@
 MODULE    = net.exe
-APPMODE   = -mconsole
+APPMODE   = -mconsole -municode
 IMPORTS   = netapi32 user32 advapi32
 EXTRADEFS = -DWINE_NO_UNICODE_MACROS
 
diff --git a/programs/net/net.c b/programs/net/net.c
index 92f6ea7..985150b 100644
--- a/programs/net/net.c
+++ b/programs/net/net.c
@@ -16,10 +16,10 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdio.h>
-#include <string.h>
 #include <windows.h>
 #include <lm.h>
+#include <wine/unicode.h>
+
 #include "resources.h"
 
 #define NET_START 0001
@@ -27,35 +27,41 @@
 
 static int output_string(int msg, ...)
 {
-    char msg_buffer[8192];
+    WCHAR fmt[8192];
+    WCHAR str[8192];
+    int len;
+    DWORD count;
     va_list arguments;
 
-    LoadStringA(GetModuleHandleW(NULL), msg, msg_buffer, sizeof(msg_buffer));
+    LoadStringW(GetModuleHandleW(NULL), msg, fmt, sizeof(fmt));
     va_start(arguments, msg);
-    vprintf(msg_buffer, arguments);
+    len = vsprintfW(str, fmt, arguments);
+    WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, len, &count, NULL);
     va_end(arguments);
     return 0;
 }
 
 static BOOL output_error_string(DWORD error)
 {
-    LPSTR pBuffer;
-    if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+    LPWSTR pBuffer;
+    if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
             FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
-            NULL, error, 0, (LPSTR)&pBuffer, 0, NULL))
+            NULL, error, 0, (LPWSTR)&pBuffer, 0, NULL))
     {
-        fputs(pBuffer, stdout);
+        DWORD count;
+        int len = lstrlenW(pBuffer);
+        WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), pBuffer, len, &count, NULL);
         LocalFree(pBuffer);
         return TRUE;
     }
     return FALSE;
 }
 
-static BOOL net_use(int argc, char *argv[])
+static BOOL net_use(int argc, const WCHAR* argv[])
 {
     USE_INFO_2 *buffer, *connection;
     DWORD read, total, resume_handle, rc, i;
-    char *status[STRING_RECONN-STRING_OK+1];
+    WCHAR* status[STRING_RECONN-STRING_OK+1];
     resume_handle = 0;
     buffer = NULL;
 
@@ -66,8 +72,8 @@ static BOOL net_use(int argc, char *argv[])
         /* Load the status strings */
         for (i = 0; i < sizeof(status)/sizeof(*status); i++)
         {
-            status[i] = HeapAlloc(GetProcessHeap(), 0, 1024);
-            LoadStringA(hmod, STRING_OK+i, status[i], 1024);
+            status[i] = HeapAlloc(GetProcessHeap(), 0, 1024 * sizeof(**status));
+            LoadStringW(hmod, STRING_OK+i, status[i], 1024);
         }
 
         do {
@@ -133,12 +139,12 @@ static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle)
     return result;
 }
 
-static BOOL net_service(int operation, char *service_name)
+static BOOL net_service(int operation, const WCHAR* service_name)
 {
     SC_HANDLE SCManager, serviceHandle;
     BOOL result = 0;
-    char service_display_name[4096];
-    DWORD buffer_size = sizeof(service_display_name);
+    WCHAR service_display_name[4096];
+    DWORD buffer_size;
 
     SCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
     if(!SCManager)
@@ -146,7 +152,7 @@ static BOOL net_service(int operation, char *service_name)
         output_string(STRING_NO_SCM);
         return FALSE;
     }
-    serviceHandle = OpenServiceA(SCManager, service_name, SC_MANAGER_ALL_ACCESS);
+    serviceHandle = OpenServiceW(SCManager, service_name, SC_MANAGER_ALL_ACCESS);
     if(!serviceHandle)
     {
         output_string(STRING_NO_SVCHANDLE);
@@ -154,9 +160,9 @@ static BOOL net_service(int operation, char *service_name)
         return FALSE;
     }
 
-
-    GetServiceDisplayNameA(SCManager, service_name, service_display_name, &buffer_size);
-    if (!service_display_name[0]) strcpy(service_display_name, service_name);
+    buffer_size = sizeof(service_display_name)/sizeof(*service_display_name);
+    GetServiceDisplayNameW(SCManager, service_name, service_display_name, &buffer_size);
+    if (!service_display_name[0]) lstrcpyW(service_display_name, service_name);
 
     switch(operation)
     {
@@ -189,20 +195,29 @@ static BOOL net_service(int operation, char *service_name)
     return result;
 }
 
-int main(int argc, char *argv[])
+int arg_is(const WCHAR* str1, const WCHAR* str2)
+{
+    return CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, str1, -1, str2, -1) == CSTR_EQUAL;
+}
+
+int wmain(int argc, const WCHAR* argv[])
 {
+    static const WCHAR helpW[]={'h','e','l','p',0};
+    static const WCHAR startW[]={'s','t','a','r','t',0};
+    static const WCHAR stopW[]={'s','t','o','p',0};
+    static const WCHAR useW[]={'u','s','e',0};
     if (argc < 2)
     {
         output_string(STRING_USAGE);
         return 1;
     }
 
-    if(!strcasecmp(argv[1], "help"))
+    if(arg_is(argv[1], helpW))
     {
         output_string(STRING_HELP_USAGE);
     }
 
-    if(!strcasecmp(argv[1], "start"))
+    if(arg_is(argv[1], startW))
     {
         if(argc < 3)
         {
@@ -217,7 +232,7 @@ int main(int argc, char *argv[])
         return 0;
     }
 
-    if(!strcasecmp(argv[1], "stop"))
+    if(arg_is(argv[1], stopW))
     {
         if(argc < 3)
         {
@@ -232,7 +247,7 @@ int main(int argc, char *argv[])
         return 0;
     }
 
-    if(!strcasecmp(argv[1], "use"))
+    if(arg_is(argv[1], useW))
     {
         if(!net_use(argc, argv)) return 1;
     }
diff --git a/programs/net/net.rc b/programs/net/net.rc
index b8df6c9..9b691f9 100644
--- a/programs/net/net.rc
+++ b/programs/net/net.rc
@@ -41,7 +41,7 @@ STRINGTABLE
                        "   Commands available are:\n   NET HELP    NET START    NET STOP    NET USE\n"
     STRING_NO_ENTRIES, "There are no entries in the list.\n"
     STRING_USE_HEADER, "\nStatus  Local   Remote\n---------------------------------------------------------------\n"
-    STRING_USE_ENTRY,  "%s      %S      %S      Open resources: %lu\n"
+    STRING_USE_ENTRY,  "%s      %s      %s      Open resources: %lu\n"
     STRING_OK, "OK"
     STRING_PAUSED, "Paused"
     STRING_SESSLOST, "Disconnected"
-- 
1.7.5.4




More information about the wine-patches mailing list