Source code of Windows XP (NT5)
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.

252 lines
8.5 KiB

  1. // File Name: pc2unix.c
  2. // Owner: Tetsuhide Akaishi
  3. // Revision: 1.00 02/21/'93 Tetsuhide Akaishi
  4. //
  5. #include "win32.h"
  6. #include "fechrcnv.h"
  7. int PC_to_JPNUNIX ( int CodeSet,
  8. UCHAR *pPCChar, int PCChar_len,
  9. UCHAR *pUNIXChar, int UNIXChar_len )
  10. // The PC_to_JPNUNIX 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. re = ShiftJIS_to_JIS ( pPCChar, PCChar_len,
  65. pUNIXChar, UNIXChar_len );
  66. break;
  67. case CODE_JPN_EUC: // Japanese EUC Code
  68. // Convert from Shift JIS to EUC
  69. re = ShiftJIS_to_EUC ( pPCChar, PCChar_len,
  70. pUNIXChar, UNIXChar_len );
  71. break;
  72. case CODE_JPN_SJIS: // Japanese Shift JIS Code
  73. // Convert from Shift JIS to Shift JIS
  74. if ( PCChar_len == -1 ) {
  75. PCChar_len = strlen ( pPCChar ) + 1;
  76. }
  77. if ( UNIXChar_len != 0 ) {
  78. if ( PCChar_len > UNIXChar_len ) { // Is the buffer small?
  79. return ( -1 );
  80. }
  81. // Copy from pPCChar to pUNIXChar
  82. memmove ( pUNIXChar, pPCChar, PCChar_len );
  83. }
  84. re = PCChar_len;
  85. break;
  86. }
  87. return ( re );
  88. }
  89. int WINAPI PC_to_UNIX ( int CodePage, int CodeSet,
  90. UCHAR *pPCChar, int PCChar_len,
  91. UCHAR *pUNIXChar, int UNIXChar_len )
  92. // The PC_to_UNIX function convert a character string as PC code
  93. // set string to a UNIX code set string.
  94. //
  95. // int CodePage Country Code Page.
  96. // If this value is -1, the function use OS CodePage from
  97. // Operating System automatically.
  98. //
  99. // Value Meaning
  100. // -1 Auto Detect Mode.
  101. // 932 Japan.
  102. // ??? Taiwan.
  103. // ??? Korea.
  104. // ??? PRC(Chaina)?
  105. //
  106. // int CodeSet Code Set Type.
  107. // There are three Japanese Code set in UNIX world.
  108. // These code sets are JIS, EUC and Shift JIS.
  109. // When CodePage is Japanese, the following Code set
  110. // constants are defined:
  111. //
  112. // Value Meaning
  113. // CODE_JPN_JIS JIS Code Set. The function convert
  114. // pPCChar string
  115. // to a JIS code set string.
  116. // CODE_JPN_EUC EUC Code Set. The function convert
  117. // pPCChar string
  118. // to a EUC code set string.
  119. // CODE_JPN_SJIS Shift JIS Code Set.
  120. //
  121. // UCHAR *pPCChar Points to the character string to be converted.
  122. //
  123. // int PCChar_len Specifies the size in bytes of the string pointed
  124. // to by the pPCChar parameter. If this value is -1,
  125. // the string is assumed to be NULL terminated and the
  126. // length is calculated automatically.
  127. //
  128. //
  129. // UCHAR *pUNIXChar Points to a buffer that receives the convert string
  130. // from PC Code to UNIX Code.
  131. //
  132. // int UNIXChar_len Specifies the size, in UNIX characters of the buffer
  133. // pointed to by the pUNIXChar parameter. If the value is
  134. // zero, the function returns the number of UNIX characters
  135. // required for the buffer, and makes no use of the
  136. // pUNIXChar buffer.
  137. //
  138. // Return Value
  139. // If the function succeeds, and UNIXChar_len is nonzero, the return value is
  140. // the number of UNIX characters written to the buffer pointed to by pUNIXChar.
  141. //
  142. // If the function succeeds, and UNIXChar_len is zero, the return value is the
  143. // required size, in UNIX characters, for a buffer that can receive the
  144. // converted string.
  145. //
  146. // If the function fails, the return value is -1. The error mean pUNIXChar
  147. // buffer is small for setting converted strings.
  148. //
  149. //@
  150. {
  151. int re;
  152. if ( CodePage == -1 ) {
  153. CodePage = (int)GetOEMCP();
  154. }
  155. switch ( CodePage ) {
  156. case 932: // Japanese Code Page
  157. re = PC_to_JPNUNIX ( CodeSet, pPCChar, PCChar_len,
  158. pUNIXChar, UNIXChar_len );
  159. break;
  160. // case ???: // Taiwan Code Page
  161. // re = PC_to_TAIWANUNIX (,,,,,,);
  162. // break;
  163. // case ???: // Korea Code Page
  164. // re = PC_to_KOREAUNIX (,,,,,,);
  165. // break;
  166. // case ???: // PRC Code Page
  167. // re = PC_to_PRCUNIX (,,,,,,);
  168. // break;
  169. default:
  170. // Start Only Copy Process
  171. if ( PCChar_len == -1 ) {
  172. PCChar_len = strlen ( pPCChar ) + 1;
  173. }
  174. if ( UNIXChar_len != 0 ) {
  175. if ( PCChar_len > UNIXChar_len ) { // Is the buffer small?
  176. return ( -1 );
  177. }
  178. memmove ( pUNIXChar, pPCChar, PCChar_len );
  179. }
  180. re = PCChar_len;
  181. break;
  182. }
  183. return ( re );
  184. }
  185. #if 1//#ifdef INETSERVER
  186. UCHAR
  187. SJISCheckLastChar( UCHAR *pShiftJIS, int len )
  188. /*
  189. It check the last character of strings whether it is Shift-JIS 1st byte
  190. or not.
  191. UCHAR *pShiftJIS Shift-JIS strings to check
  192. int len byte size of ShiftJIS strings
  193. Return value
  194. 0 last character is not a Shift-JIS 1st byte
  195. last character(Shift-JIS 1st byte)
  196. */
  197. {
  198. int ch;
  199. while ( len-- )
  200. {
  201. ch = *pShiftJIS++;
  202. if ( SJISISKANJI(ch) )
  203. if ( 0 == len )
  204. return (UCHAR)ch;
  205. else
  206. {
  207. --len;
  208. ++pShiftJIS;
  209. }
  210. }
  211. return 0;
  212. }
  213. #endif // INETSERVER
  214. BOOL WINAPI DLLEntry( HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved )
  215. {
  216. BOOL fReturn = TRUE;
  217. switch ( dwReason )
  218. {
  219. case DLL_PROCESS_ATTACH:
  220. case DLL_PROCESS_DETACH:
  221. case DLL_THREAD_ATTACH:
  222. case DLL_THREAD_DETACH:
  223. default:
  224. break ;
  225. }
  226. return ( fReturn);
  227. }