Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. engine.c
  5. Abstract:
  6. Token Generator for Cross Language Migration Tool
  7. Author:
  8. Rerkboon Suwanasuk 01-May-2002 Created
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. #include "common.h"
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <shellapi.h>
  16. #include <locale.h>
  17. BOOL ProcessCommandLine()
  18. {
  19. LPWSTR *plpwszArgv;
  20. LPWSTR *argv;
  21. LPWSTR lpFilePart;
  22. DWORD dwErr;
  23. INT nArgc;
  24. BOOL bRet = TRUE;
  25. HRESULT hr;
  26. plpwszArgv = CommandLineToArgvW(GetCommandLine(), &nArgc);
  27. argv = plpwszArgv;
  28. g_bUseDefaultTemplate = TRUE;
  29. g_bUseDefaultOuputFile = TRUE;
  30. while (--nArgc > 0 && ++argv)
  31. {
  32. if (argv[0][0] != TEXT('-'))
  33. continue;
  34. if (CompareEngString(&argv[0][1], TEXT("LCID")) == CSTR_EQUAL)
  35. {
  36. //
  37. // This is "-LCID [lcid]" parameters (required)
  38. //
  39. LPWSTR lpStop;
  40. nArgc--;
  41. if (nArgc == 0)
  42. {
  43. return FALSE;
  44. }
  45. argv++;
  46. g_lcidTarget = wcstol(argv[0], &lpStop, 0);
  47. }
  48. else if (CompareEngString(&argv[0][1], TEXT("i")) == CSTR_EQUAL)
  49. {
  50. //
  51. // This is "-i [TemplateFile]" parameters (optional)
  52. // Default will use "clmres.txt"
  53. //
  54. nArgc--;
  55. if (nArgc == 0)
  56. {
  57. return FALSE;
  58. }
  59. argv++;
  60. g_bUseDefaultTemplate = FALSE;
  61. if (!GetFullPathName(argv[0],
  62. ARRAYSIZE(g_wszTemplateFile),
  63. g_wszTemplateFile,
  64. &lpFilePart))
  65. {
  66. return FALSE;
  67. }
  68. g_bUseDefaultTemplate = FALSE;
  69. }
  70. else if (CompareEngString(&argv[0][1], TEXT("o")) == CSTR_EQUAL)
  71. {
  72. //
  73. // This is "-o [OutputFile]" parameters (optional)
  74. // Default
  75. //
  76. nArgc--;
  77. if (nArgc == 0)
  78. {
  79. return FALSE;
  80. }
  81. argv++;
  82. if (!GetFullPathName(argv[0],
  83. ARRAYSIZE(g_wszOutputFile),
  84. g_wszOutputFile,
  85. &lpFilePart))
  86. {
  87. return FALSE;
  88. }
  89. g_bUseDefaultOuputFile = FALSE;
  90. }
  91. else
  92. {
  93. return FALSE;
  94. }
  95. }
  96. GlobalFree(plpwszArgv);
  97. if (!IsValidLocale(g_lcidTarget, LCID_SUPPORTED))
  98. {
  99. wprintf(TEXT("Error! Invalid locale ID - 0x%X\n"), g_lcidTarget);
  100. return FALSE;
  101. }
  102. if (g_bUseDefaultTemplate)
  103. {
  104. dwErr = GetFullPathName(TEXT_DEFAULT_TEMPLATE_FILE,
  105. ARRAYSIZE(g_wszTemplateFile),
  106. g_wszTemplateFile,
  107. &lpFilePart);
  108. if (dwErr == 0)
  109. {
  110. bRet = FALSE;
  111. }
  112. }
  113. if (g_bUseDefaultOuputFile)
  114. {
  115. dwErr = GetFullPathName(TEXT_DEFAULT_OUTPUT_FILE,
  116. ARRAYSIZE(g_wszOutputFile),
  117. g_wszOutputFile,
  118. &lpFilePart);
  119. if (dwErr == 0)
  120. {
  121. bRet = FALSE;
  122. }
  123. }
  124. return bRet;
  125. }
  126. VOID PrintUsage(VOID)
  127. {
  128. DWORD i;
  129. LPCWSTR lpUsage[] = {
  130. TEXT("Usage:\n"),
  131. TEXT(" CLMTOK -lcid LocaleID [-i TemplateFile] [-o OutputFile]\n"),
  132. NULL
  133. };
  134. for (i = 0 ; lpUsage[i] != NULL ; i++)
  135. {
  136. wprintf(TEXT("%s"), lpUsage[i]);
  137. }
  138. }
  139. HRESULT InitGlobalVariables()
  140. {
  141. HRESULT hr;
  142. hr = CreateTempDirectory(g_wszTempFolder, ARRAYSIZE(g_wszTempFolder));
  143. if (FAILED(hr))
  144. {
  145. return hr;
  146. }
  147. hr = StringCchPrintf(g_wszTargetLCIDSection,
  148. ARRAYSIZE(g_wszTargetLCIDSection),
  149. TEXT("Strings.%.4X"),
  150. g_lcidTarget);
  151. return hr;
  152. }
  153. int __cdecl wmain()
  154. {
  155. HRESULT hr;
  156. HMODULE hDLL;
  157. // Set the locale to default
  158. _wsetlocale(LC_ALL, TEXT(""));
  159. // Verify the command line
  160. if (!ProcessCommandLine())
  161. {
  162. PrintUsage();
  163. return -1;
  164. }
  165. hr = InitGlobalVariables();
  166. if (FAILED(hr))
  167. {
  168. return hr;
  169. }
  170. hr = GenerateTokenFile();
  171. return hr;
  172. }