]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix unicode support in toolbox-cmd.
authorVMware, Inc <>
Tue, 19 Oct 2010 20:08:47 +0000 (13:08 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 19 Oct 2010 20:08:47 +0000 (13:08 -0700)
On Win32, use the wide-character entry point function, and convert the
command line arguments to UTF-8 on all platforms before using them.

Also make sure we use UTF8-friendly g_print everywhere, instead of printf.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/toolbox/toolbox-cmd.c
open-vm-tools/toolbox/toolboxcmd-devices.c
open-vm-tools/toolbox/toolboxcmd-scripts.c
open-vm-tools/toolbox/toolboxcmd-shrink.c
open-vm-tools/toolbox/toolboxcmd-stat.c

index aa5641978b344c1b13c4f508cdebd3ffcbf3d0d5..896d5fef7f4fb4e2b48338ac0eed7a32caab4cfd 100644 (file)
@@ -32,6 +32,7 @@
 #include "toolboxCmdInt.h"
 #include "toolboxcmd_version.h"
 #include "system.h"
+#include "unicode.h"
 #include "vmware/tools/guestrpc.h"
 #include "vmware/tools/i18n.h"
 #include "vmware/tools/utils.h"
@@ -393,8 +394,13 @@ ParseCommand(char **argv, // IN: Command line arguments
  */
 
 int
+#if defined(_WIN32)
+wmain(int argc,         // IN: length of command line arguments
+      wchar_t **wargv)  // IN: Command line arguments
+#else
 main(int argc,    // IN: length of command line arguments
      char **argv) // IN: Command line arguments
+#endif
 {
    Bool show_help = FALSE;
    Bool show_version = FALSE;
@@ -402,6 +408,13 @@ main(int argc,    // IN: length of command line arguments
    int c;
    int retval;
 
+#if defined(_WIN32)
+   char **argv;
+   Unicode_InitW(argc, wargv, NULL, &argv, NULL);
+#else
+   Unicode_Init(argc, &argv, NULL);
+#endif
+
    setlocale(LC_ALL, "");
    VMTools_ConfigLogging("toolboxcmd", NULL, FALSE, FALSE);
    VMTools_BindTextDomain(VMW_TEXT_DOMAIN, NULL, NULL);
@@ -453,7 +466,7 @@ main(int argc,    // IN: length of command line arguments
    }
 
    if (show_version) {
-      printf("%s (%s)\n", TOOLBOXCMD_VERSION_STRING, BUILD_NUMBER);
+      g_print("%s (%s)\n", TOOLBOXCMD_VERSION_STRING, BUILD_NUMBER);
    } else if (show_help) {
       ToolboxCmdHelp(argv[0], "help");
    } else {
index d41b8f650c2cff8afff6b9a401b763de88bc21c6..b49b20f193fc02e48854541fb1e1496a17c26a24 100644 (file)
@@ -55,7 +55,7 @@ DevicesList(void)
       if (GuestApp_GetDeviceInfo(i, &info) && strlen(info.name) > 0) {
          const char *status = info.enabled ? SU_(option.enabled, "Enabled")
                                            : SU_(option.disabled, "Disabled");
-         printf("%s: %s\n", info.name, status);
+         g_print("%s: %s\n", info.name, status);
       }
    }
    return EXIT_SUCCESS;
index 207e8c85d77bd46a9ed6dac6c7b1f5721fde831d..da88bb30366c836b700c35792ace935bc395730d 100644 (file)
@@ -159,7 +159,7 @@ GetConfEntry(const char *progName,  // IN: program name (argv[0])
    }
 
    if (strlen(entry) > 0) {
-      printf("%s\n", entry);
+      g_print("%s\n", entry);
       ret = EXIT_SUCCESS;
    } else {
       ToolsCmd_PrintErr(SU_(script.unknownop, "No script for operation %s.\n"),
index ac57185cdd805835edcf383b887e58667d5b7cfa..dc5fe6e618a0997d9f319c2e5fd7dc5b72607139 100644 (file)
@@ -153,7 +153,7 @@ ShrinkList(void)
    DblLnkLst_ForEach(curr, &plist.link) {
       WiperPartition *p = DblLnkLst_Container(curr, WiperPartition, link);
       if (p->type != PARTITION_UNSUPPORTED) {
-         printf("%s\n", p->mountPoint);
+         g_print("%s\n", p->mountPoint);
       }
    }
 
@@ -242,11 +242,11 @@ ShrinkDoShrink(char *mountPoint, // IN: mount point
       }
 
       if (!quiet) {
-         printf("\rProgress: %d [", progress);
+         g_print("\rProgress: %d [", progress);
          for (i = 0; i <= progress / 10; i++) {
             putchar('=');
          }
-         printf(">%*c", 10 - i + 1, ']');
+         g_print(">%*c", 10 - i + 1, ']');
          fflush(stdout);
       }
    }
index 60280dfa43c9d79974953abccca4bbadc473557a..5d917400d8f7e18f7a37bb8524a9df7b371d21ba 100644 (file)
@@ -99,7 +99,7 @@ StatProcessorSpeed(void)
                         SU_(stat.getspeed.failed, "Unable to get processor speed.\n"));
       return EX_TEMPFAIL;
    }
-   printf("%u MHz\n", speed);
+   g_print("%u MHz\n", speed);
    return EXIT_SUCCESS;
 }
 
@@ -154,7 +154,7 @@ StatHostTime(void)
                         SU_(stat.formattime.failed, "Unable to format host time.\n"));
       return EX_TEMPFAIL;
    }
-   printf("%s\n", buf);
+   g_print("%s\n", buf);
    return EXIT_SUCCESS;
 }
 
@@ -196,7 +196,7 @@ StatGetSessionID(void)
                         VMGuestLib_GetErrorText(glError));
       exitStatus = EX_TEMPFAIL;
    } else {
-      printf("0x%"FMT64"x\n", session);
+      g_print("0x%"FMT64"x\n", session);
    }
    VMGuestLib_CloseHandle(glHandle);
    return exitStatus;
@@ -240,7 +240,7 @@ StatGetMemoryBallooned(void)
                         VMGuestLib_GetErrorText(glError));
       exitStatus = EX_TEMPFAIL;
    } else {
-      printf("%u MHz\n", memBallooned);
+      g_print("%u MHz\n", memBallooned);
    }
    VMGuestLib_CloseHandle(glHandle);
    return exitStatus;
@@ -284,7 +284,7 @@ StatGetMemoryReservation(void)
                         VMGuestLib_GetErrorText(glError));
       exitStatus = EX_TEMPFAIL;
    } else {
-      printf("%u MB\n", memReservation);
+      g_print("%u MB\n", memReservation);
    }
    VMGuestLib_CloseHandle(glHandle);
    return exitStatus;
@@ -329,7 +329,7 @@ StatGetMemorySwapped(void)
                         VMGuestLib_GetErrorText(glError));
       exitStatus = EX_TEMPFAIL;
    } else {
-      printf("%u MB\n", memSwapped);
+      g_print("%u MB\n", memSwapped);
    }
    VMGuestLib_CloseHandle(glHandle);
    return exitStatus;
@@ -373,7 +373,7 @@ StatGetMemoryLimit(void)
                         VMGuestLib_GetErrorText(glError));
       exitStatus = EX_TEMPFAIL;
    } else {
-      printf("%u MB\n", memLimit);
+      g_print("%u MB\n", memLimit);
    }
    VMGuestLib_CloseHandle(glHandle);
    return exitStatus;
@@ -417,7 +417,7 @@ StatGetCpuReservation(void)
                         VMGuestLib_GetErrorText(glError));
       exitStatus = EX_TEMPFAIL;
    } else {
-      printf("%u MHz\n", cpuReservation);
+      g_print("%u MHz\n", cpuReservation);
    }
    VMGuestLib_CloseHandle(glHandle);
    return exitStatus;
@@ -461,7 +461,7 @@ StatGetCpuLimit(void)
                         VMGuestLib_GetErrorText(glError));
       exitStatus = EX_TEMPFAIL;
    } else {
-      printf("%u MHz\n", cpuLimit);
+      g_print("%u MHz\n", cpuLimit);
    }
    VMGuestLib_CloseHandle(glHandle);
    return exitStatus;