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.

211 lines
4.3 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. nls.c
  5. Abstract:
  6. This module contains functions needed for the internationalisation
  7. of the TCP/IP utilities.
  8. Author:
  9. Ronald Meijer (ronaldm) Nov 8, 1992
  10. Revision History:
  11. Who When What
  12. -------- -------- ----------------------------------------------
  13. ronaldm 11-8-92 created
  14. Notes:
  15. --*/
  16. #include <io.h>
  17. #include <stdio.h>
  18. #include <windef.h>
  19. #include <winbase.h>
  20. #include <winuser.h>
  21. #include <nls.h>
  22. // see comment in nls.h
  23. //
  24. HMODULE NlsMsgSourcemModuleHandle = NULL;
  25. /*** NlsPutMsg - Print a message to a handle
  26. *
  27. * Purpose:
  28. * PutMsg takes the given message number from the
  29. * message table resource, and displays it on the requested
  30. * handle with the given parameters (optional)
  31. *
  32. * UINT PutMsg(UINT Handle, UINT MsgNum, ... )
  33. *
  34. * Args:
  35. * Handle - the handle to print to
  36. * MsgNum - the number of the message to print
  37. * Arg1 [Arg2...] - additonal arguments for the message as necessary
  38. *
  39. * Returns:
  40. * The number of characters printed.
  41. *
  42. */
  43. UINT
  44. NlsPutMsg (
  45. IN UINT Handle,
  46. IN UINT MsgNumber,
  47. IN ...)
  48. {
  49. UINT msglen;
  50. VOID * vp;
  51. va_list arglist;
  52. DWORD StrLen;
  53. va_start(arglist, MsgNumber);
  54. if (!(msglen = FormatMessage(
  55. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
  56. NlsMsgSourcemModuleHandle,
  57. MsgNumber,
  58. 0L, // Default country ID.
  59. (LPTSTR)&vp,
  60. 0,
  61. &arglist)))
  62. {
  63. return 0;
  64. }
  65. // Convert vp to oem
  66. StrLen=strlen(vp);
  67. CharToOemBuff((LPCTSTR)vp,(LPSTR)vp,StrLen);
  68. msglen = _write(Handle, vp, StrLen);
  69. LocalFree(vp);
  70. return msglen;
  71. }
  72. /*** NlsPerror - NLS compliant version of perror()
  73. *
  74. * Purpose:
  75. * NlsPerror takes a messagetable resource ID code, and an error
  76. * value (This function replaces perror()), loads the string
  77. * from the resource, and passes it with the error code to s_perror()
  78. *
  79. * void NlsPerror(UINT usMsgNum, int nError)
  80. *
  81. * Args:
  82. *
  83. * usMsgNum The message ID
  84. * nError Typically returned from GetLastError()
  85. *
  86. * Returns:
  87. * Nothing.
  88. *
  89. */
  90. extern void s_perror(
  91. char *yourmsg, // your message to be displayed
  92. int lerrno // errno to be converted
  93. );
  94. VOID
  95. NlsPerror (
  96. IN UINT usMsgNum,
  97. IN INT nError)
  98. {
  99. VOID * vp;
  100. UINT msglen;
  101. if (!(msglen = FormatMessage(
  102. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
  103. NlsMsgSourcemModuleHandle,
  104. usMsgNum,
  105. 0L, // Default country ID.
  106. (LPTSTR)&vp,
  107. 0,
  108. NULL)))
  109. {
  110. return;
  111. }
  112. s_perror(vp, nError);
  113. LocalFree(vp);
  114. }
  115. UINT
  116. NlsSPrintf (
  117. IN UINT usMsgNum,
  118. OUT char* pszBuffer,
  119. IN DWORD cbSize,
  120. IN ...)
  121. /*++
  122. Prints the given message into the buffer supplied.
  123. Arguments:
  124. usMsgNum message number for resource string.
  125. pszBuffer buffer into which we need to print the string
  126. cbSize size of buffer
  127. ... optional arguments
  128. Returns:
  129. Size of the message printed.
  130. History:
  131. MuraliK 10-19-94
  132. --*/
  133. {
  134. UINT msglen;
  135. va_list arglist;
  136. va_start(arglist, cbSize);
  137. msglen = FormatMessage(
  138. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_MAX_WIDTH_MASK,
  139. NlsMsgSourcemModuleHandle,
  140. usMsgNum,
  141. 0L,
  142. (LPTSTR) pszBuffer,
  143. cbSize,
  144. &arglist);
  145. va_end(arglist);
  146. return msglen;
  147. }
  148. /*** ConvertArgvToOem
  149. *
  150. * Purpose:
  151. * Convert all the command line arguments from Ansi to Oem.
  152. *
  153. * Args:
  154. *
  155. * argc Argument count
  156. * argv[] Array of command-line arguments
  157. *
  158. * Returns:
  159. * Nothing.
  160. *
  161. *
  162. */
  163. VOID
  164. ConvertArgvToOem(
  165. int argc,
  166. char* argv[]
  167. )
  168. {
  169. #if 0
  170. Bug 84807. Removed workaround of needing to convert args to Oem by placing
  171. conversion immediately before dumping.
  172. int i;
  173. for (i=1; i<argc; ++i)
  174. CharToOemA(argv[i], argv[i]);
  175. #endif
  176. }