- Timestamp:
- Dec 15, 2021 3:29:06 PM (3 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 3 edited
-
Makefile.kmk (modified) (2 diffs)
-
VBoxManage.cpp (modified) (2 diffs)
-
VBoxManageHelp.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/Makefile.kmk
r92842 r92937 307 307 'RT_C_DECLS_END' \ 308 308 '' \ 309 'HELP_LANG_ENTRY g_apHelpLangEntries[] = ' \309 'HELP_LANG_ENTRY_T const g_aHelpLangEntries[] = ' \ 310 310 '{' \ 311 ' { "en_US", 5, &g_apHelpEntries_en_US[0], g_cHelpEntries_en_US},'311 ' { "en_US", 5, &g_apHelpEntries_en_US[0], &g_cHelpEntries_en_US },' 312 312 ifdef VBOX_WITH_VBOXMANAGE_NLS 313 313 $(foreach lang,$(VBOX_APPROVED_VBOXMANAGE_DOCBOOK_LANGUAGES) \ 314 ,$(NLTAB)$(QUIET)$(APPEND) "$@" ' { "$(lang)", $(length $(lang)), &g_apHelpEntries_$(lang)[0], g_cHelpEntries_$(lang)},' )314 ,$(NLTAB)$(QUIET)$(APPEND) "$@" ' { "$(lang)", $(length $(lang)), &g_apHelpEntries_$(lang)[0], &g_cHelpEntries_$(lang) },' ) 315 315 endif 316 316 $(QUIET)$(APPEND) -n "$@" \ 317 317 '};' \ 318 318 '' \ 319 ' const uint32_t g_cHelpLangEntries = RT_ELEMENTS(g_apHelpLangEntries);' \320 '' \ 321 'P HELP_LANG_ENTRY volatile g_pHelpLangEntry = &g_apHelpLangEntries[0];'\319 'uint32_t const g_cHelpLangEntries = RT_ELEMENTS(g_aHelpLangEntries);' \ 320 '' \ 321 'PCHELP_LANG_ENTRY_T volatile g_pHelpLangEntry = &g_aHelpLangEntries[0];'\ 322 322 '' 323 323 $(QUIET)$(CP) --changed -- "$@" "$(patsubst %.ts,%,$@)" … … 354 354 $(QUIET)$(APPEND) -n "$@" \ 355 355 '' \ 356 'typedef struct HELP_LANG_ENTRY ' \356 'typedef struct HELP_LANG_ENTRY_T' \ 357 357 '{' \ 358 358 ' const char *pszLang;' \ 359 ' size_t c bLang;' \359 ' size_t cchLang;' \ 360 360 ' PCRTMSGREFENTRY *papHelpEntries;' \ 361 ' const uint32_tcHelpEntries;' \362 '} HELP_LANG_ENTRY ;' \363 'typedef HELP_LANG_ENTRY *PHELP_LANG_ENTRY;' \364 '' \ 365 'extern HELP_LANG_ENTRY g_apHelpLangEntries[];' \366 'extern const uint32_t g_cHelpLangEntries;' \367 '' \ 368 'extern P HELP_LANG_ENTRYvolatile g_pHelpLangEntry;' \361 ' uint32_t const *pcHelpEntries;' \ 362 '} HELP_LANG_ENTRY_T;' \ 363 'typedef HELP_LANG_ENTRY_T const *PCHELP_LANG_ENTRY_T;' \ 364 '' \ 365 'extern HELP_LANG_ENTRY_T const g_aHelpLangEntries[];' \ 366 'extern const uint32_t g_cHelpLangEntries;' \ 367 '' \ 368 'extern PCHELP_LANG_ENTRY_T volatile g_pHelpLangEntry;' \ 369 369 '' \ 370 370 'RT_C_DECLS_END' \ -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r92842 r92937 509 509 { 510 510 #ifdef VBOX_WITH_VBOXMANAGE_NLS 511 if (pszLang == NULL || pszLang[0] == 0 || (pszLang[0] == 'C' && pszLang[1] == 0))511 if (pszLang == NULL || pszLang[0] == '\0' || (pszLang[0] == 'C' && pszLang[1] == '\0')) 512 512 pszLang = "en_US"; 513 PHELP_LANG_ENTRY pHelpLangEntry = NULL; 513 514 514 /* find language entry matching exactly pszLang */ 515 PCHELP_LANG_ENTRY_T pHelpLangEntry = NULL; 515 516 for (uint32_t i = 0; i < g_cHelpLangEntries; i++) 516 517 { 517 if (strcmp(g_a pHelpLangEntries[i].pszLang, pszLang) == 0)518 { 519 pHelpLangEntry = &g_a pHelpLangEntries[i];518 if (strcmp(g_aHelpLangEntries[i].pszLang, pszLang) == 0) 519 { 520 pHelpLangEntry = &g_aHelpLangEntries[i]; 520 521 break; 521 522 } 522 523 } 524 523 525 /* find first entry containing language specified if pszLang contains only language */ 524 526 if (pHelpLangEntry == NULL) 525 527 { 526 size_t c bLang = strlen(pszLang);528 size_t const cchLang = strlen(pszLang); 527 529 for (uint32_t i = 0; i < g_cHelpLangEntries; i++) 528 530 { 529 if ( c bLang < g_apHelpLangEntries[i].cbLang530 && memcmp(g_a pHelpLangEntries[i].pszLang, pszLang, cbLang) == 0)531 { 532 pHelpLangEntry = &g_a pHelpLangEntries[i];531 if ( cchLang < g_aHelpLangEntries[i].cchLang 532 && memcmp(g_aHelpLangEntries[i].pszLang, pszLang, cchLang) == 0) 533 { 534 pHelpLangEntry = &g_aHelpLangEntries[i]; 533 535 break; 534 536 } 535 537 } 536 538 } 539 537 540 /* set to en_US (i.e. untranslated) if not found */ 538 541 if (pHelpLangEntry == NULL) 539 pHelpLangEntry = &g_a pHelpLangEntries[0];542 pHelpLangEntry = &g_aHelpLangEntries[0]; 540 543 541 544 ASMAtomicWritePtr(&g_pHelpLangEntry, pHelpLangEntry); … … 585 588 if (RT_SUCCESS(vrc)) 586 589 vrc = RTPathAppend(szNlsPath, sizeof(szNlsPath), "nls" RTPATH_SLASH_STR "VBoxManageNls"); 587 588 590 if (RT_SUCCESS(vrc)) 589 591 { -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r92842 r92937 31 31 #include <iprt/stream.h> 32 32 #include <iprt/message.h> 33 #include <iprt/uni.h> 33 34 34 35 #include "VBoxManage.h" … … 85 86 * 86 87 * @returns pointer to string starting from next char. 87 * @param pszSrc Source string. 88 * @param pszFirstCharBuffer Pointer to buffer to place first char uppercase 89 */ 90 static const char *firstCharUppercase(const char *pszSrc, char *pszFirstCharBuffer) 91 { 92 RTUNICP Cp; 93 RTStrGetCpEx(&pszSrc, &Cp); 94 char *pszBuffer = RTStrPutCp(pszFirstCharBuffer, Cp); 95 RTStrToUpper(pszBuffer); 96 pszBuffer[0] = 0; 97 return pszSrc; 88 * @param pszSrc Source string. 89 * @param pszDst Pointer to buffer to place first char uppercase. 90 */ 91 static const char *captialize(const char *pszSrc, char *pszDst) 92 { 93 *RTStrPutCp(pszDst, RTUniCpToUpper(RTStrGetCp(pszSrc))) = '\0'; 94 return RTStrNextCp(pszSrc); 98 95 } 99 96 … … 110 107 static uint32_t printBriefCommandOrSubcommandHelp(enum HELP_CMD_VBOXMANAGE enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm) 111 108 { 112 uint32_t cLinesWritten = 0; 113 uint32_t cPendingBlankLines = 0; 114 uint32_t cFound = 0; 109 /* 110 * Try to find translated, falling back untranslated. 111 */ 112 uint32_t cLinesWritten = 0; 113 uint32_t cPendingBlankLines = 0; 114 uint32_t cFound = 0; 115 PCHELP_LANG_ENTRY_T const apHelpLangEntries[] = 116 { 117 ASMAtomicUoReadPtrT(&g_pHelpLangEntry, PCHELP_LANG_ENTRY_T), 115 118 #ifdef VBOX_WITH_VBOXMANAGE_NLS 116 PHELP_LANG_ENTRY pHelpLangEntry[2] = {ASMAtomicReadPtrT(&g_pHelpLangEntry, PHELP_LANG_ENTRY), &g_apHelpLangEntries[0] }; 117 #else 118 PHELP_LANG_ENTRY pHelpLangEntry[1] = {(PHELP_LANG_ENTRY)g_pHelpLangEntry}; 119 #endif 120 /* Try to find translated, then untranslated */ 121 for (uint32_t k = 0; k < RT_ELEMENTS(pHelpLangEntry) && cFound == 0; k++) 119 &g_aHelpLangEntries[0] 120 #endif 121 }; 122 for (uint32_t k = 0; k < RT_ELEMENTS(apHelpLangEntries) && cFound == 0; k++) 122 123 { 123 124 /* skip if english is used */ 124 if (k > 0 && pHelpLangEntry[k] == pHelpLangEntry[0])125 if (k > 0 && apHelpLangEntries[k] == apHelpLangEntries[0]) 125 126 break; 126 for (uint32_t i = 0; i < pHelpLangEntry[k]->cHelpEntries; i++) 127 uint32_t const cHelpEntries = *apHelpLangEntries[k]->pcHelpEntries; 128 for (uint32_t i = 0; i < cHelpEntries; i++) 127 129 { 128 PCRTMSGREFENTRY pHelp = pHelpLangEntry[k]->papHelpEntries[i];130 PCRTMSGREFENTRY pHelp = apHelpLangEntries[k]->papHelpEntries[i]; 129 131 if (pHelp->idInternal == (int64_t)enmCommand) 130 132 { … … 134 136 if (fSubcommandScope == RTMSGREFENTRYSTR_SCOPE_GLOBAL) 135 137 { 136 char szFirstChar[16] = {0}; 137 const char *pszNext = firstCharUppercase(pHelp->pszBrief, szFirstChar); 138 RTStrmPrintf(pStrm, Help::tr("Usage - %s%s:\n"), szFirstChar, pszNext); 138 char szFirstChar[8]; 139 RTStrmPrintf(pStrm, Help::tr("Usage - %s%s:\n"), szFirstChar, captialize(pHelp->pszBrief, szFirstChar)); 139 140 } 140 141 else … … 173 174 static void printFullCommandOrSubcommandHelp(enum HELP_CMD_VBOXMANAGE enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm) 174 175 { 175 uint32_t cPendingBlankLines = 0; 176 uint32_t cFound = 0; 176 /* Try to find translated, then untranslated */ 177 uint32_t cPendingBlankLines = 0; 178 uint32_t cFound = 0; 179 PCHELP_LANG_ENTRY_T const apHelpLangEntries[] = 180 { 181 ASMAtomicUoReadPtrT(&g_pHelpLangEntry, PCHELP_LANG_ENTRY_T), 177 182 #ifdef VBOX_WITH_VBOXMANAGE_NLS 178 PHELP_LANG_ENTRY pHelpLangEntry[2] = {ASMAtomicReadPtrT(&g_pHelpLangEntry, PHELP_LANG_ENTRY), &g_apHelpLangEntries[0] }; 179 #else 180 PHELP_LANG_ENTRY pHelpLangEntry[1] = {(PHELP_LANG_ENTRY)g_pHelpLangEntry}; 181 #endif 182 /* Try to find translated, then untranslated */ 183 for (uint32_t k = 0; k < RT_ELEMENTS(pHelpLangEntry) && cFound == 0; k++) 183 &g_aHelpLangEntries[0] 184 #endif 185 }; 186 for (uint32_t k = 0; k < RT_ELEMENTS(apHelpLangEntries) && cFound == 0; k++) 184 187 { 185 188 /* skip if english is used */ 186 if (k > 0 && pHelpLangEntry[k] == pHelpLangEntry[0])189 if (k > 0 && apHelpLangEntries[k] == apHelpLangEntries[0]) 187 190 break; 188 for (uint32_t i = 0; i < pHelpLangEntry[k]->cHelpEntries; i++) 191 uint32_t const cHelpEntries = *apHelpLangEntries[k]->pcHelpEntries; 192 for (uint32_t i = 0; i < cHelpEntries; i++) 189 193 { 190 PCRTMSGREFENTRY pHelp = pHelpLangEntry[k]->papHelpEntries[i];194 PCRTMSGREFENTRY pHelp = apHelpLangEntries[k]->papHelpEntries[i]; 191 195 192 196 if ( pHelp->idInternal == (int64_t)enmCommand … … 1034 1038 if (enmCommand == USAGE_S_ALL) 1035 1039 { 1036 uint32_t cPendingBlankLines = 0; 1037 #ifdef VBOX_WITH_VBOXMANAGE_NLS 1038 PHELP_LANG_ENTRY pHelpLangEntry = ASMAtomicReadPtrT(&g_pHelpLangEntry, PHELP_LANG_ENTRY); 1039 #else 1040 PHELP_LANG_ENTRY pHelpLangEntry = (PHELP_LANG_ENTRY)g_pHelpLangEntry; 1041 #endif 1042 for (uint32_t i = 0; i < pHelpLangEntry->cHelpEntries; i++) 1040 uint32_t cPendingBlankLines = 0; 1041 PCHELP_LANG_ENTRY_T pHelpLangEntry = ASMAtomicUoReadPtrT(&g_pHelpLangEntry, PCHELP_LANG_ENTRY_T); 1042 uint32_t const cHelpEntries = *pHelpLangEntry->pcHelpEntries; 1043 for (uint32_t i = 0; i < cHelpEntries; i++) 1043 1044 { 1044 1045 PCRTMSGREFENTRY pHelp = pHelpLangEntry->papHelpEntries[i]; … … 1046 1047 while (cPendingBlankLines-- > 0) 1047 1048 RTStrmPutCh(pStrm, '\n'); 1048 char szFirstChar[16] = {0}; 1049 const char *pszNext = firstCharUppercase(pHelp->pszBrief, szFirstChar); 1050 RTStrmPrintf(pStrm, " %s%s:\n", szFirstChar, pszNext); 1049 1050 char szFirstChar[8]; 1051 RTStrmPrintf(pStrm, " %s%s:\n", szFirstChar, captialize(pHelp->pszBrief, szFirstChar)); 1052 1051 1053 cPendingBlankLines = 0; 1052 1054 RTMsgRefEntryPrintStringTable(pStrm, &pHelp->Synopsis, RTMSGREFENTRYSTR_SCOPE_GLOBAL, 1053 &cPendingBlankLines, NULL /*pcLinesWritten*/);1055 &cPendingBlankLines, NULL /*pcLinesWritten*/); 1054 1056 cPendingBlankLines = RT_MAX(cPendingBlankLines, 1); 1055 1057 }
Note:
See TracChangeset
for help on using the changeset viewer.

