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.

224 lines
8.7 KiB

  1. #include "precomp.hxx"
  2. int PC_to_UNIX ( int CodePage,
  3. int CodeSet,
  4. UCHAR *pPCChar,
  5. int PCChar_len,
  6. UCHAR *pUNIXChar,
  7. int UNIXChar_len
  8. )
  9. // The PC_to_UNIX function convert a character string as PC code
  10. // set string to a UNIX code set string.
  11. //
  12. // int CodePage Country Code Page.
  13. // If this value is -1, the function use OS CodePage from
  14. // Operating System automatically.
  15. //
  16. // Value Meaning
  17. // -1 Auto Detect Mode.
  18. // 932 Japan.
  19. // ??? Taiwan.
  20. // ??? Korea.
  21. // ??? PRC(Chaina)?
  22. //
  23. // int CodeSet Code Set Type.
  24. // There are three Japanese Code set in UNIX world.
  25. // These code sets are JIS, EUC and Shift JIS.
  26. // When CodePage is Japanese, the following Code set
  27. // constants are defined:
  28. //
  29. // Value Meaning
  30. // CODE_JPN_JIS JIS Code Set. The function convert
  31. // pPCChar string
  32. // to a JIS code set string.
  33. // CODE_JPN_EUC EUC Code Set. The function convert
  34. // pPCChar string
  35. // to a EUC code set string.
  36. // CODE_JPN_SJIS Shift JIS Code Set.
  37. //
  38. // UCHAR *pPCChar Points to the character string to be converted.
  39. //
  40. // int PCChar_len Specifies the size in bytes of the string pointed
  41. // to by the pPCChar parameter. If this value is -1,
  42. // the string is assumed to be NULL terminated and the
  43. // length is calculated automatically.
  44. //
  45. //
  46. // UCHAR *pUNIXChar Points to a buffer that receives the convert string
  47. // from PC Code to UNIX Code.
  48. //
  49. // int UNIXChar_len Specifies the size, in UNIX characters of the buffer
  50. // pointed to by the pUNIXChar parameter. If the value is
  51. // zero, the function returns the number of UNIX characters
  52. // required for the buffer, and makes no use of the
  53. // pUNIXChar buffer.
  54. //
  55. // Return Value
  56. // If the function succeeds, and UNIXChar_len is nonzero, the return value is
  57. // the number of UNIX characters written to the buffer pointed to by pUNIXChar.
  58. //
  59. // If the function succeeds, and UNIXChar_len is zero, the return value is the
  60. // required size, in UNIX characters, for a buffer that can receive the
  61. // converted string.
  62. //
  63. // If the function fails, the return value is -1. The error mean pUNIXChar
  64. // buffer is small for setting converted strings.
  65. //
  66. //@
  67. {
  68. int re;
  69. if ( CodePage == -1 )
  70. {
  71. CodePage = ( int )GetOEMCP();
  72. }
  73. switch ( CodePage ) {
  74. case 932: // Japanese Code Page
  75. // re = PC_to_JPNUNIX ( CodeSet,
  76. // pPCChar,
  77. // PCChar_len,
  78. // pUNIXChar,
  79. // UNIXChar_len );
  80. // break;
  81. // case ???: // Taiwan Code Page
  82. // re = PC_to_TAIWANUNIX (,,,,,,);
  83. // break;
  84. // case ???: // Korea Code Page
  85. // re = PC_to_KOREAUNIX (,,,,,,);
  86. // break;
  87. // case ???: // PRC Code Page
  88. // re = PC_to_PRCUNIX (,,,,,,);
  89. // break;
  90. default:
  91. // Start Only Copy Process
  92. if ( PCChar_len == -1 )
  93. {
  94. PCChar_len = strlen ( ( CHAR * )pPCChar ) + 1;
  95. }
  96. if ( UNIXChar_len != 0 )
  97. {
  98. if ( PCChar_len > UNIXChar_len )
  99. {
  100. // Is the buffer small?
  101. return ( -1 );
  102. }
  103. memmove ( pUNIXChar, pPCChar, PCChar_len );
  104. }
  105. re = PCChar_len;
  106. break;
  107. }
  108. return ( re );
  109. }
  110. int UNIX_to_PC (
  111. int CodePage,
  112. int CodeSet,
  113. UCHAR *pUNIXChar,
  114. int UNIXChar_len,
  115. UCHAR *pPCChar,
  116. int PCChar_len
  117. )
  118. // The UNIX_to_PC function convert a character string as UNIX code
  119. // set string to a PC code set string.
  120. //
  121. // int CodePage Country Code Page.
  122. // If this value is -1, the function use OS CodePage from
  123. // Operating System automatically.
  124. //
  125. // Value Meaning
  126. // -1 Auto Detect Mode.
  127. // 932 Japan.
  128. // ??? Taiwan.
  129. // ??? Korea.
  130. // ??? PRC(Chaina)?
  131. //
  132. // int CodeSet Code Set Type.
  133. // There are three Japanese Code set in UNIX world.
  134. // These code sets are JIS, EUC and Shift JIS.
  135. // When CodePage is Japanese, the following Code set
  136. // constants are defined:
  137. //
  138. // Value Meaning
  139. // CODE_UNKNOWN Unknown. If this value is CODE_UNKNOWN,
  140. // Code Type is checked automatically.
  141. //
  142. // CODE_JPN_JIS JIS Code Set. The function convert
  143. // pUNIXChar string as JIS code set string
  144. // to a PC code set string.
  145. // CODE_JPN_EUC EUC Code Set. The function convert
  146. // pUNIXChar string as EUC code set string
  147. // to a PC code set string.
  148. // CODE_JPN_SJIS Shift JIS Code Set.
  149. //
  150. // UCHAR *pUNIXChar Points to the character string to be converted.
  151. //
  152. // int UNIXChar_len Specifies the size in bytes of the string pointed
  153. // to by the pUNIXChar parameter. If this value is -1,
  154. // the string is assumed to be NULL terminated and the
  155. // length is calculated automatically.
  156. //
  157. // UCHAR *pPCChar Points to a buffer that receives the convert string
  158. // from UNIX Code to PC Code.
  159. //
  160. // int PCChar_len Specifies the size, in PC characters of the buffer
  161. // pointed to by the pPCChar parameter. If the value is zero,
  162. // the function returns the number of PC characters
  163. // required for the buffer, and makes no use of the pPCChar
  164. // buffer.
  165. //
  166. // Return Value
  167. // If the function succeeds, and PCChar_len is nonzero, the return value is the
  168. // number of PC characters written to the buffer pointed to by pPCChar.
  169. //
  170. // If the function succeeds, and PCChar_len is zero, the return value is the
  171. // required size, in PC characters, for a buffer that can receive the
  172. // converted string.
  173. //
  174. // If the function fails, the return value is -1. The error mean pPCChar buffer
  175. // is small for setting converted strings.
  176. //
  177. //@
  178. {
  179. int re;
  180. if ( CodePage == -1 ) {
  181. CodePage = (int)GetOEMCP();
  182. }
  183. switch ( CodePage ) {
  184. case 932: // Japanese Code Page
  185. // re = JPNUNIX_to_PC ( CodeSet, pUNIXChar, UNIXChar_len,
  186. // pPCChar, PCChar_len );
  187. // break;
  188. // case ???: // Taiwan Code Page
  189. // re = TAIWANUNIX_to_PC (,,,,,,);
  190. // break;
  191. // case ???: // Korea Code Page
  192. // re = KOREAUNIX_to_PC (,,,,,,);
  193. // break;
  194. // case ???: // PRC Code Page
  195. // re = PRCUNIX_to_PC (,,,,,,);
  196. // break;
  197. default:
  198. // Start Only Copy Process
  199. if ( UNIXChar_len == -1 )
  200. {
  201. UNIXChar_len = strlen ( ( CHAR * )pUNIXChar ) + 1;
  202. }
  203. if ( PCChar_len != 0 )
  204. {
  205. if ( UNIXChar_len > PCChar_len )
  206. {
  207. // Is the buffer small?
  208. return ( -1 );
  209. }
  210. memmove ( pPCChar, pUNIXChar, UNIXChar_len );
  211. }
  212. re = UNIXChar_len;
  213. break;
  214. }
  215. return ( re );
  216. }