diff --git a/CMakeLists.txt b/CMakeLists.txt index bd1abd7..a91f22a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ project(sj4) option(SJ4_GLOBAL "Use global variables or not" OFF) option(SJ4_EMBED "Embed main dictionary or not" OFF) option(SJ4_EMBED_PLUS "Embed pubdic+ as main dictionary or not" OFF) +option(SJ4_NO_UNICODE "Remove Unicode code completely" OFF) file(GLOB_RECURSE SJ4COMMON_SRCS lib/sj4common/**.c) add_library(sj4common STATIC ${SJ4COMMON_SRCS}) @@ -37,13 +38,19 @@ if(NOT SJ4_GLOBAL) target_include_directories(sj4lib PUBLIC include/sj4common include/sj4core include/sj4lib) target_include_directories(sj4lib PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(sj4lib PUBLIC sj4common sj4core) + if(NOT SJ4_NO_UNICODE) + target_compile_definitions(sj4lib PRIVATE UCS) + endif() endif() file(GLOB_RECURSE SJ4MKDIC_SRCS src/sj4mkdic/**.c) add_executable(sj4mkdic ${SJ4MKDIC_SRCS}) target_include_directories(sj4mkdic PRIVATE include/sj4common include/sj4core) -target_compile_definitions(sj4mkdic PRIVATE UTF8 ENGLISH) +target_compile_definitions(sj4mkdic PRIVATE ENGLISH) target_link_libraries(sj4mkdic PRIVATE sj4common) +if(NOT SJ4_NO_UNICODE) + target_compile_definitions(sj4mkdic PRIVATE UTF8) +endif() if(NOT SJ4_GLOBAL) file(GLOB_RECURSE SJ4TEST_SRCS src/sj4test/**.c) diff --git a/lib/sj4lib/sj.c b/lib/sj4lib/sj.c index c51ba80..7eaeb82 100644 --- a/lib/sj4lib/sj.c +++ b/lib/sj4lib/sj.c @@ -4,8 +4,10 @@ #include +#ifdef UCS #include #include +#endif struct sj4lib { Sj4Context* ctx; @@ -17,6 +19,7 @@ struct sj4lib { u_char wrkbuf[SJ4BUFSZ]; }; +#ifdef UCS static u_int ucs_to_euc(u_int in) { if(0 <= in && in <= 0xffff) { const T_U2E_BITMAP_INDEX* b = &utf16_to_euc_jp_table[(in >> 8) & 0xff]; @@ -85,6 +88,7 @@ static int eucjp_write(u_char* out, u_int n) { return 3; } } +#endif static int from_sjis(u_char* out, const u_char* in, int len) { unsigned char d[] = {0, 0}; @@ -93,6 +97,7 @@ static int from_sjis(u_char* out, const u_char* in, int len) { return sj4_str_sjistoeuc(out, SJ4BUFSZ, (u_char*)in, len, d, &uf); } +#ifdef UCS static int utf8_later(unsigned char c) { return 0x80 <= c && c < 0xc0; } @@ -225,6 +230,7 @@ static int eucjp_codesize(u_int n) { return 3; } } +#endif static int to_sjis(u_char* out, const u_char* in, int len) { unsigned char d[] = {0, 0}; @@ -233,6 +239,7 @@ static int to_sjis(u_char* out, const u_char* in, int len) { return sj4_str_euctosjis(out, SJ4BUFSZ, (u_char*)in, len, d, &uf); } +#ifdef UCS static int to_utf8(u_char* out, const u_char* in, int len) { const u_char* o_in = in; u_char* o_out = out; @@ -292,10 +299,15 @@ static int to_utf16(u_char* out, const u_char* in, int len) { return w_out - o_out; } +#endif Sj4Lib* sj4_open(int charset, const char* dic) { Sj4Lib* ctx; +#ifndef UCS + if(charset == SJ4UTF8 || charset == SJ4UTF16) return NULL; +#endif + if((ctx = calloc(1, sizeof(*ctx))) == NULL) return NULL; if((ctx->ctx = alloccontext(dic)) == NULL) { @@ -309,6 +321,7 @@ Sj4Lib* sj4_open(int charset, const char* dic) { return ctx; } +#ifdef UCS #define ICONV(to, from, len, mode) \ if(ctx->charset == SJ4EUCJP) { \ memcpy(to, from, len); \ @@ -319,6 +332,14 @@ Sj4Lib* sj4_open(int charset, const char* dic) { } else if(ctx->charset == SJ4UTF16) { \ len = mode##_utf16(to, from, len); \ } +#else +#define ICONV(to, from, len, mode) \ + if(ctx->charset == SJ4EUCJP) { \ + memcpy(to, from, len); \ + } else if(ctx->charset == SJ4SJIS) { \ + len = mode##_sjis(to, from, len); \ + } +#endif int sj4_getkan(Sj4Lib* ctx, const void* input, int len, Sj4Kouho* kouho) { int len2;