From: Oliver Kurth Date: Wed, 1 Apr 2020 18:31:37 +0000 (-0700) Subject: Fix localization issue on windows guests. X-Git-Tag: stable-11.2.0~260 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e221a1311bab1f526bef16d97d9d2798bf09e49;p=thirdparty%2Fopen-vm-tools.git Fix localization issue on windows guests. Some fields of GOptionContext used in help are not public, so add 2 arguments to Usage to get needed info. --- diff --git a/open-vm-tools/vgauth/cli/l10n/de.vmsg b/open-vm-tools/vgauth/cli/l10n/de.vmsg index 6e838445d..aa65fa6f3 100644 --- a/open-vm-tools/vgauth/cli/l10n/de.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/de.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2017 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2017,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "Benutzer, dessen Zertifikatsspeicher hinzugefügt wird zu addoptions.verbose = "Detaillierter Vorgang" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "Die Analyse der Befehlszeile ist fehlgeschlagen" cmdline.summary.pemfile = "PEM-Datei" diff --git a/open-vm-tools/vgauth/cli/l10n/en.vmsg b/open-vm-tools/vgauth/cli/l10n/en.vmsg index 20306720c..b3d91876b 100644 --- a/open-vm-tools/vgauth/cli/l10n/en.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/en.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2017 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2017,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "User whose certificate store is being added to" addoptions.verbose = "Verbose operation" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "Command line parsing failed" cmdline.summary.pemfile = "PEM-file" diff --git a/open-vm-tools/vgauth/cli/l10n/es.vmsg b/open-vm-tools/vgauth/cli/l10n/es.vmsg index c4c499e3b..8a773367b 100644 --- a/open-vm-tools/vgauth/cli/l10n/es.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/es.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2017 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2017,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "El usuario cuyo almacén de certificados se está añadie addoptions.verbose = "Operación detallada" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "Error de análisis de línea de comando" cmdline.summary.pemfile = "Archivo PEM" diff --git a/open-vm-tools/vgauth/cli/l10n/fr.vmsg b/open-vm-tools/vgauth/cli/l10n/fr.vmsg index 6147d4139..6be5f26ae 100644 --- a/open-vm-tools/vgauth/cli/l10n/fr.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/fr.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2017 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2017,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "Utilisateur dont le magasin de certificats est ajouté à addoptions.verbose = "Opération en mode détaillé" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "Échec de l'analyse de la ligne de commande" cmdline.summary.pemfile = "Fichier PEM" diff --git a/open-vm-tools/vgauth/cli/l10n/it.vmsg b/open-vm-tools/vgauth/cli/l10n/it.vmsg index 34b35f7a0..46dd3fab5 100644 --- a/open-vm-tools/vgauth/cli/l10n/it.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/it.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2018 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2018,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "Utente a cui viene aggiunto l'archivio certificati" addoptions.verbose = "Operazione Verbose" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "Analisi della riga di comando non riuscita" cmdline.summary.pemfile = "File PEM" diff --git a/open-vm-tools/vgauth/cli/l10n/ja.vmsg b/open-vm-tools/vgauth/cli/l10n/ja.vmsg index 2bee2fba5..028d74dd3 100644 --- a/open-vm-tools/vgauth/cli/l10n/ja.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/ja.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2017 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2017,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "証明書ストアが追加されているユーザー" addoptions.verbose = "詳細な操作" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "コマンド ラインの解析に失敗しました" cmdline.summary.pemfile = "PEM ファイル" diff --git a/open-vm-tools/vgauth/cli/l10n/ko.vmsg b/open-vm-tools/vgauth/cli/l10n/ko.vmsg index 23603f35a..aaa51e2d8 100644 --- a/open-vm-tools/vgauth/cli/l10n/ko.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/ko.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2017 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2017,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "인증서 저장소를 추가 중인 사용자" addoptions.verbose = "자세한 정보 표시 작업" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "명령줄 구문 분석 실패" cmdline.summary.pemfile = "PEM 파일" diff --git a/open-vm-tools/vgauth/cli/l10n/zh_CN.vmsg b/open-vm-tools/vgauth/cli/l10n/zh_CN.vmsg index 7c97afbaf..954f22f45 100644 --- a/open-vm-tools/vgauth/cli/l10n/zh_CN.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/zh_CN.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2017 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2017,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "要在以下位置添加证书存储的用户" addoptions.verbose = "详细操作" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "命令行分析失败" cmdline.summary.pemfile = "PEM 文件" diff --git a/open-vm-tools/vgauth/cli/l10n/zh_TW.vmsg b/open-vm-tools/vgauth/cli/l10n/zh_TW.vmsg index 164bd3c87..f6519ff0f 100644 --- a/open-vm-tools/vgauth/cli/l10n/zh_TW.vmsg +++ b/open-vm-tools/vgauth/cli/l10n/zh_TW.vmsg @@ -1,5 +1,5 @@ ########################################################## -# Copyright (C) 2011-2017 VMware, Inc. All rights reserved. +# Copyright (C) 2011-2017,2020 VMware, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -31,7 +31,10 @@ addoptions.username = "正將其憑證存放區新增至以下項目的使用者 addoptions.verbose = "詳細資訊作業" - +cmdline.help.appoption = "Application Options" +cmdline.help.helpoption = "Help Options" +cmdline.help.hint = "Show help options" +cmdline.help.usage = "Usage" cmdline.parse = "命令行剖析失敗" cmdline.summary.pemfile = "PEM 檔案" diff --git a/open-vm-tools/vgauth/cli/main.c b/open-vm-tools/vgauth/cli/main.c index 7561699a6..899d7dd63 100644 --- a/open-vm-tools/vgauth/cli/main.c +++ b/open-vm-tools/vgauth/cli/main.c @@ -47,6 +47,82 @@ static gchar *appName; static gboolean verbose = FALSE; +#ifdef _WIN32 + + +/* + ****************************************************************************** + * GetHelp -- */ /** + * + * Get help message for CLI on windows + * + * @param[in] context The GOptionContext for generating the message + * @param[in] paramStr The command line operation arguments + * @param[in] cmdOptions The command line options for given operation + * + ****************************************************************************** + */ + +static gchar * +GetHelp(GOptionContext *context, + const char *paramStr, + const GOptionEntry *cmdOptions) +{ + gchar *helpMsg; + const gchar *lUsage = SU_(cmdline.help.usage, "Usage"); + const gchar *lHelpOption = SU_(cmdline.help.helpoption, "Help Options"); + const gchar *lAppOption = SU_(cmdline.help.appoption, "Application Options"); + const gchar *lHint = SU_(cmdline.help.hint, "Show help options"); + + if (cmdOptions == NULL){ + helpMsg = g_strdup_printf("%s:\n" + " %s %s\n\n" + "%s\n\n" + "%s:\n" + " -h, --help %s\n", + lUsage, + appName, paramStr, + g_option_context_get_summary(context), + lHelpOption, + lHint); + } else { + gchar *optionMsg; + GString *optStr; + int i; + optStr = g_string_new(NULL); + for (i = 0; cmdOptions[i].long_name != NULL; i++) { + g_string_append_printf(optStr, + " -%c, --%-8s %s\n", + cmdOptions[i].short_name, + cmdOptions[i].long_name, + cmdOptions[i].description); + } + optionMsg = g_string_free(optStr, FALSE); + + helpMsg = g_strdup_printf("%s:\n" + " %s %s\n\n" + "%s\n\n" + "%s:\n" + " -h, --help %s\n" + "%s:\n" + "%s", + lUsage, + appName, paramStr, + g_option_context_get_summary(context), + lHelpOption, + lHint, + lAppOption, + optionMsg); + g_free(optionMsg); + } + + return helpMsg; +} + +#endif + + + /* ****************************************************************************** * Usage -- */ /** @@ -54,16 +130,24 @@ static gboolean verbose = FALSE; * Usage message for CLI * * @param[in] optContext The GOptionContext for generating the message + * @param[in] paramStr The command line operation arguments + * @param[in] cmdOptions The command line options for given operation * ****************************************************************************** */ static void -Usage(GOptionContext *optContext) +Usage(GOptionContext *optContext, + const char *paramStr, + const GOptionEntry *cmdOptions) { gchar *usage; - +#ifdef _WIN32 + usage = GetHelp(optContext, paramStr, cmdOptions); +#else usage = g_option_context_get_help(optContext, TRUE, NULL); +#endif + g_printerr("%s", usage); g_free(usage); exit(-1); @@ -456,6 +540,8 @@ mainRun(int argc, gchar *comment = NULL; gchar *summaryMsg; gchar *subject = NULL; + GOptionEntry *cmdOptions = NULL; + const gchar *paramStr = "[add | list | remove]\n"; const gchar *lUsername = SU_(cmdline.summary.username, "username"); const gchar *lSubject = SU_(cmdline.summary.subject, "subject"); const gchar *lPEMfile = SU_(cmdline.summary.pemfile, "PEM-file"); @@ -463,7 +549,6 @@ mainRun(int argc, #if (use_glib_parser == 0) int i; - GOptionEntry *cmdOptions; #else GError *gErr = NULL; #endif @@ -521,7 +606,7 @@ mainRun(int argc, * Set up the option parser */ g_set_prgname(appName); - context = g_option_context_new("[add | list | remove]\n"); + context = g_option_context_new(paramStr); summaryMsg = g_strdup_printf( "add --global --username=%s --file=%s --subject=%s " "[ --comment=%s ]\n" @@ -534,7 +619,7 @@ mainRun(int argc, g_option_context_set_summary(context, summaryMsg); g_free(summaryMsg); if (argc < 2) { - Usage(context); + Usage(context, paramStr, cmdOptions); } /* @@ -543,31 +628,25 @@ mainRun(int argc, if (strcmp(argvCopy[1], "add") == 0) { doAdd = TRUE; g_option_context_add_main_entries(context, addOptions, NULL); -#if (use_glib_parser == 0) cmdOptions = addOptions; -#endif } else if (strcmp(argvCopy[1], "remove") == 0) { doRemove = TRUE; g_option_context_add_main_entries(context, removeOptions, NULL); -#if (use_glib_parser == 0) cmdOptions = removeOptions; -#endif } else if (strcmp(argvCopy[1], "list") == 0) { doList = TRUE; g_option_context_add_main_entries(context, listOptions, NULL); -#if (use_glib_parser == 0) cmdOptions = listOptions; -#endif } else { - Usage(context); + Usage(context, paramStr, cmdOptions); } #if (use_glib_parser == 0) /* - * In Windows, g_option_context_parse() does the wrong thing for locale - * conversion of the incoming Unicode cmdline. Modern glib (2.40 or - * later) solves this with g_option_context_parse_strv(), but we're stuck - * with an older glib for now. + * In Windows, g_option_context_parse() does the wrong thing for the + * incoming Unicode cmdline. Modern glib (2.40 or later) solves this + * with g_option_context_parse_strv(), but we're stuck with an older + * glib for now. * * So instead lets do it all by hand. * @@ -599,14 +678,14 @@ mainRun(int argc, *(gchar **) e->arg_data = argv[++i]; match = TRUE; } else { - Usage(context); + Usage(context, paramStr, cmdOptions); } } else if (e->arg == G_OPTION_ARG_NONE) { *(gboolean *) e->arg_data = TRUE; match = TRUE; } } else if (strncmp(longName, argv[i], len) == 0 && - (argv[i][len] == '=' || argv[i][len] == '\0')) { + (argv[i][len] == '=' || argv[i][len] == '\0')) { gchar *val = NULL; if (e->arg == G_OPTION_ARG_STRING) { @@ -621,7 +700,7 @@ mainRun(int argc, *(gboolean *) e->arg_data = TRUE; match = TRUE; } else { - Usage(context); + Usage(context, paramStr, cmdOptions); } } if (match) { @@ -631,7 +710,7 @@ mainRun(int argc, } next: if (!match) { - Usage(context); + Usage(context, paramStr, cmdOptions); } } #else @@ -648,7 +727,7 @@ next: * XXX pull this if we use stdin for the cert contents. */ if ((doAdd || doRemove) && !pemFilename) { - Usage(context); + Usage(context, paramStr, cmdOptions); } err = VGAuth_Init(appName, 0, NULL, &ctx);