From d2ea450fdcab108f38455b1221b99699715a71bc Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 3 Apr 2016 13:57:06 +0900 Subject: [PATCH] Imported SJIS -> Unicode converter from xsystem35 --- Makefile | 1 - Makefile.linux | 3 +-- src/common.h | 13 +++++++++---- src/linux/unicode.cpp | 13 ------------- src/sys/ags_text.cpp | 10 ++++++++++ src/win/unicode.cpp | 22 ---------------------- 6 files changed, 20 insertions(+), 42 deletions(-) delete mode 100644 src/linux/unicode.cpp delete mode 100644 src/win/unicode.cpp diff --git a/Makefile b/Makefile index 4ff1007..d427fb1 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,6 @@ OBJS = src/fileio.o \ src/sys/nact_sys3.o \ src/win/nact_win.o \ src/win/mako_win.o \ - src/win/unicode.o \ src/res3/Script1.o DEPS := $(OBJS:%.o=%.d) diff --git a/Makefile.linux b/Makefile.linux index 8c10820..293b776 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -25,8 +25,7 @@ OBJS = src/fileio.o \ src/sys/nact_input.o \ src/sys/nact_sys3.o \ src/linux/nact_linux.o \ - src/linux/mako_linux.o \ - src/linux/unicode.o + src/linux/mako_linux.o DEPS := $(OBJS:%.o=%.d) diff --git a/src/common.h b/src/common.h index fd7d1eb..3e4dc63 100644 --- a/src/common.h +++ b/src/common.h @@ -28,14 +28,19 @@ typedef signed char int8; typedef signed short int16; typedef signed long int32; + #ifndef WIN32 + #define _MAX_PATH PATH_MAX #define sscanf_s sscanf #define sprintf_s snprintf -void strcpy_s(char* dst, size_t n, const char* src); -#endif -// utilities -uint16 sjis_to_unicode(uint16 sjis); +inline void strcpy_s(char* dst, size_t n, const char* src) +{ + strncpy(dst, src, n); + dst[n - 1] = '\0'; +} + +#endif // !WIN32 #endif diff --git a/src/linux/unicode.cpp b/src/linux/unicode.cpp deleted file mode 100644 index b4a82b8..0000000 --- a/src/linux/unicode.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "common.h" - -uint16 sjis_to_unicode(uint16 code) -{ - // TODO: correct impl - return code; -} - -void strcpy_s(char* dst, size_t n, const char* src) -{ - strncpy(dst, src, n); - dst[n - 1] = '\0'; -} diff --git a/src/sys/ags_text.cpp b/src/sys/ags_text.cpp index da308fb..a3cbecf 100644 --- a/src/sys/ags_text.cpp +++ b/src/sys/ags_text.cpp @@ -5,6 +5,16 @@ */ #include "ags.h" +#include "s2utbl.h" + +inline uint16 sjis_to_unicode(uint16 code) +{ + if (code >= 0xa0 && code <= 0xdf) + return 0xff60 + code - 0xa0; + if (code < 0x100) + return code; + return s2u[(code >> 8) - 0x80][(code & 0xff) - 0x40]; +} void AGS::draw_text(char string[]) { diff --git a/src/win/unicode.cpp b/src/win/unicode.cpp deleted file mode 100644 index 28dad02..0000000 --- a/src/win/unicode.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "common.h" -#include - -uint16 sjis_to_unicode(uint16 code) -{ - char string[3]; - int length; - - if(code > 0xff) { - string[0] = code >> 8; - string[1] = code & 0xff; - string[2] = '\0'; - length = 2; - } else { - string[0] = code & 0xff; - string[1] = '\0'; - length = 1; - } - uint16 buf[2]; - MultiByteToWideChar(CP_ACP, 0, string, length, (LPWSTR)buf, 2); - return buf[0]; -}