|
|
| version 1.2, 2005/02/12 12:14:00 | version 1.3, 2005/04/01 15:35:50 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "oemtext.h" | #include "oemtext.h" |
| #if defined(UNICODE) && defined(OSLANG_UTF8) | |
| #include "codecnv.h" | // Use WinAPI version |
| UINT oemtext_sjistooem(char *dst, UINT dcnt, const char *src, UINT scnt) { | |
| UINT oemtext_sjistoucs2(UINT16 *dst, UINT dcnt, const char *src, UINT scnt) { | |
| int srccnt; | |
| int dstcnt; | |
| int r; | |
| if (((SINT)scnt) > 0) { | |
| srccnt = scnt; | |
| } | |
| else { | |
| srccnt = -1; | |
| } | |
| if (((SINT)dcnt) > 0) { | |
| dstcnt = dcnt; | |
| if (srccnt < 0) { | |
| dstcnt = dstcnt - 1; | |
| if (dstcnt == 0) { | |
| if (dst) { | |
| dst[0] = '\0'; | |
| } | |
| return(1); | |
| } | |
| } | |
| } | |
| else { | |
| dstcnt = 0; | |
| } | |
| r = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, srccnt, dst, dstcnt); | |
| if ((r == 0) && (dstcnt != 0)) { | |
| r = dstcnt; | |
| if (srccnt < 0) { | |
| if (dst) { | |
| dst[r] = '\0'; | |
| } | |
| r++; | |
| } | |
| } | |
| return(r); | |
| } | |
| UINT oemtext_ucs2tosjis(char *dst, UINT dcnt, const UINT16 *src, UINT scnt) { | |
| int srccnt; | |
| int dstcnt; | |
| int r; | |
| if (((SINT)scnt) > 0) { | |
| srccnt = scnt; | |
| } | |
| else { | |
| srccnt = -1; | |
| } | |
| if (((SINT)dcnt) > 0) { | |
| dstcnt = dcnt; | |
| if (srccnt < 0) { | |
| dstcnt = dstcnt - 1; | |
| if (dstcnt == 0) { | |
| if (dst) { | |
| dst[0] = '\0'; | |
| } | |
| return(1); | |
| } | |
| } | |
| } | |
| else { | |
| dstcnt = 0; | |
| } | |
| r = WideCharToMultiByte(CP_ACP, 0, src, srccnt, dst, dstcnt, NULL, NULL); | |
| if ((r == 0) && (dstcnt != 0)) { | |
| r = dstcnt; | |
| if (srccnt < 0) { | |
| if (dst) { | |
| dst[r] = '\0'; | |
| } | |
| r++; | |
| } | |
| } | |
| return(r); | |
| } | |
| UINT oemtext_sjistoutf8(char *dst, UINT dcnt, const char *src, UINT scnt) { | |
| UINT leng; | UINT leng; |
| UINT16 *ucs2; | UINT16 *ucs2; |
| Line 13 UINT oemtext_sjistooem(char *dst, UINT d | Line 93 UINT oemtext_sjistooem(char *dst, UINT d |
| (void)scnt; | (void)scnt; |
| leng = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, -1, NULL, 0); | leng = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, scnt, NULL, 0); |
| if (leng == 0) { | if (leng == 0) { |
| return(0); | return(0); |
| } | } |
| Line 21 UINT oemtext_sjistooem(char *dst, UINT d | Line 101 UINT oemtext_sjistooem(char *dst, UINT d |
| if (ucs2 == NULL) { | if (ucs2 == NULL) { |
| return(0); | return(0); |
| } | } |
| MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, -1, ucs2, leng); | MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, scnt, ucs2, leng); |
| if (((SINT)scnt) < 0) { | |
| leng = (UINT)-1; | |
| } | |
| ret = codecnv_ucs2toutf8(dst, dcnt, ucs2, leng); | ret = codecnv_ucs2toutf8(dst, dcnt, ucs2, leng); |
| _MFREE(ucs2); | _MFREE(ucs2); |
| return(ret); | return(ret); |
| } | } |
| UINT oemtext_oemtosjis(char *dst, UINT dcnt, const char *src, UINT scnt) { | UINT oemtext_utf8tosjis(char *dst, UINT dcnt, const char *src, UINT scnt) { |
| UINT leng; | UINT leng; |
| UINT16 *ucs2; | UINT16 *ucs2; |
| Line 35 UINT oemtext_oemtosjis(char *dst, UINT d | Line 118 UINT oemtext_oemtosjis(char *dst, UINT d |
| (void)scnt; | (void)scnt; |
| leng = codecnv_utf8toucs2(NULL, 0, src, (UINT)-1); | leng = codecnv_utf8toucs2(NULL, 0, src, scnt); |
| if (leng == 0) { | if (leng == 0) { |
| return(0); | return(0); |
| } | } |
| Line 43 UINT oemtext_oemtosjis(char *dst, UINT d | Line 126 UINT oemtext_oemtosjis(char *dst, UINT d |
| if (ucs2 == NULL) { | if (ucs2 == NULL) { |
| return(0); | return(0); |
| } | } |
| codecnv_utf8toucs2(ucs2, leng, src, (UINT)-1); | codecnv_utf8toucs2(ucs2, leng, src, scnt); |
| if (((SINT)scnt) < 0) { | |
| leng = (UINT)-1; | |
| } | |
| ret = WideCharToMultiByte(CP_ACP, 0, ucs2, leng, dst, dcnt, NULL, NULL); | ret = WideCharToMultiByte(CP_ACP, 0, ucs2, leng, dst, dcnt, NULL, NULL); |
| _MFREE(ucs2); | _MFREE(ucs2); |
| return(ret); | return(ret); |
| } | } |
| #endif | |