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.

213 lines
8.4 KiB

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