From 27224cdd4c1363b2785111fac329df0f9f9f161c Mon Sep 17 00:00:00 2001 From: Shinki Nishikori Date: Thu, 18 Jun 2026 08:33:32 +0900 Subject: [PATCH 1/2] Add C89 stdint compatibility --- configure | 5 +++- sj_stdint.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sj_typedef.h | 17 +++++++------- tests.c | 21 +++++++++++++++++ 4 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 sj_stdint.h diff --git a/configure b/configure index b54848f..0e5de75 100755 --- a/configure +++ b/configure @@ -221,6 +221,7 @@ HAVE_B64_NTOP= HAVE_CAPSICUM= HAVE_CRYPT= HAVE_CRYPT_NEWHASH= +HAVE_C99_STDINT= HAVE_ENDIAN_H= HAVE_ERR= HAVE_EXPLICIT_BZERO= @@ -391,6 +392,7 @@ runtest b64_ntop B64_NTOP "" "" "-lresolv" || true runtest capsicum CAPSICUM || true runtest crypt CRYPT "" "" "-lcrypt" || true runtest crypt_newhash CRYPT_NEWHASH || true +runtest c99_stdint C99_STDINT || true runtest endian_h ENDIAN_H || true runtest err ERR || true runtest explicit_bzero EXPLICIT_BZERO || true @@ -513,7 +515,7 @@ fi if [ ${HAVE_MD5} -eq 0 -o \ ${HAVE_SHA2} -eq 0 ] then - echo "#include /* C99 [u]int[nn]_t types */" + echo "#include \"sj_stdint.h\" /* C99 stdint.h or C89 fallback types */" echo fi @@ -555,6 +557,7 @@ cat << __HEREDOC__ #define HAVE_CAPSICUM ${HAVE_CAPSICUM} #define HAVE_CRYPT ${HAVE_CRYPT} #define HAVE_CRYPT_NEWHASH ${HAVE_CRYPT_NEWHASH} +#define HAVE_C99_STDINT ${HAVE_C99_STDINT} #define HAVE_ENDIAN_H ${HAVE_ENDIAN_H} #define HAVE_ERR ${HAVE_ERR} #define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO} diff --git a/sj_stdint.h b/sj_stdint.h new file mode 100644 index 0000000..22a2e87 --- /dev/null +++ b/sj_stdint.h @@ -0,0 +1,66 @@ +/* + * SPDX-License-Identifier: MIT + * + * Small fixed-width integer compatibility layer for SJ3. + * + * In C99 or newer translation units, use . In C89 translation + * units, provide the fixed-width names that SJ3 needs when the host integer + * model has matching types. + */ + +#ifndef SJ_STDINT_H_ +#define SJ_STDINT_H_ + +#if defined(HAVE_C99_STDINT) && HAVE_C99_STDINT && \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#include +#else + +#include + +#if !defined(UINT8_MAX) +# if UCHAR_MAX == 255 +typedef signed char int8_t; +typedef unsigned char uint8_t; +# define UINT8_MAX UCHAR_MAX +# else +# error "SJ3 requires an 8-bit unsigned char" +# endif +#endif + +#if !defined(UINT16_MAX) +# if USHRT_MAX == 65535 +typedef short int16_t; +typedef unsigned short uint16_t; +# define UINT16_MAX USHRT_MAX +# else +# error "SJ3 requires a 16-bit unsigned short" +# endif +#endif + +#if !defined(UINT32_MAX) +# if UINT_MAX == 4294967295U +typedef int int32_t; +typedef unsigned int uint32_t; +# define UINT32_MAX UINT_MAX +# elif ULONG_MAX == 4294967295UL +typedef long int32_t; +typedef unsigned long uint32_t; +# define UINT32_MAX ULONG_MAX +# else +# error "SJ3 requires a 32-bit integer type" +# endif +#endif + +#if !defined(UINT64_MAX) && (ULONG_MAX > 4294967295UL) +typedef long int64_t; +typedef unsigned long uint64_t; +# define UINT64_MAX ULONG_MAX +#elif !defined(UINT64_MAX) && (defined(_MSC_VER) || defined(_WIN32)) +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#endif + +#endif + +#endif /* SJ_STDINT_H_ */ diff --git a/sj_typedef.h b/sj_typedef.h index 55d79e0..87d0df5 100644 --- a/sj_typedef.h +++ b/sj_typedef.h @@ -40,17 +40,18 @@ #define _SJ_TYPEDEF 1 #include +#include "sj_stdint.h" -typedef unsigned char TypeGroup; -typedef unsigned char TypeGram; -typedef unsigned short TypeIdxOfs; +typedef uint8_t TypeGroup; +typedef uint8_t TypeGram; +typedef uint16_t TypeIdxOfs; typedef short TypeDicSeg; -typedef unsigned short TypeDicOfs; +typedef uint16_t TypeDicOfs; typedef ino_t TypeDicID; -typedef unsigned char TypeCnct; -typedef unsigned short TypeStyNum; -typedef unsigned char TypeClass; -typedef unsigned char TypeBunNum; +typedef uint8_t TypeCnct; +typedef uint16_t TypeStyNum; +typedef uint8_t TypeClass; +typedef uint8_t TypeBunNum; #ifndef NULL # define NULL 0 diff --git a/tests.c b/tests.c index d927388..70a8635 100644 --- a/tests.c +++ b/tests.c @@ -81,6 +81,27 @@ main(void) return 0; } #endif /* TEST_CRYPT_NEWHASH */ +#if TEST_C99_STDINT +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) +# error "C99 is required for stdint.h" +#endif +#include + +int +main(void) +{ + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + + u8 = 0; + u16 = 0; + u32 = 0; + u64 = 0; + return (int)(u8 + u16 + u32 + u64); +} +#endif /* TEST_C99_STDINT */ #if TEST_ENDIAN_H #if defined(__linux__) || defined(__wasi__) # define _DEFAULT_SOURCE From 2248f9e3aae1665e8d18004a09d41f12c00ea225 Mon Sep 17 00:00:00 2001 From: Shinki Nishikori Date: Thu, 18 Jun 2026 08:34:16 +0900 Subject: [PATCH 2/2] Add minimal CMake build files --- CMakeLists.txt | 45 +++++++++++++++++++++++++++++++++++++++++++++ config.h.cmake | 13 +++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 config.h.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9274c09 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.16) + +project(sj3 VERSION 2.0.99 LANGUAGES C) + +include(CheckCSourceCompiles) + +if(NOT DEFINED CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 90) +endif() +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) + +set(SJ3CONFDIR "/etc/sj3" CACHE PATH "SJ3 configuration directory") +set(SJ3DICTDIR "${CMAKE_INSTALL_PREFIX}/share/sj3/dict" CACHE PATH + "SJ3 dictionary directory") + +check_c_source_compiles(" +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) +# error C99 required +#endif +#include +int main(void) { + uint8_t u8 = 0; + uint16_t u16 = 0; + uint32_t u32 = 0; + uint64_t u64 = 0; + return (int)(u8 + u16 + u32 + u64); +} +" HAVE_C99_STDINT) + +configure_file(config.h.cmake config.h @ONLY) +configure_file(Paths.h.in Paths.h @ONLY) + +add_library(sj3types INTERFACE) +target_include_directories(sj3types INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) + +add_library(sj3_core_types OBJECT + wc16_str.c + string.c + string2.c +) +target_link_libraries(sj3_core_types PRIVATE sj3types) diff --git a/config.h.cmake b/config.h.cmake new file mode 100644 index 0000000..423bc8b --- /dev/null +++ b/config.h.cmake @@ -0,0 +1,13 @@ +#ifndef OCONFIGURE_CONFIG_H +#define OCONFIGURE_CONFIG_H + +#cmakedefine01 HAVE_C99_STDINT + +#ifndef HAVE_MD5 +# define HAVE_MD5 1 +#endif +#ifndef HAVE_SHA2 +# define HAVE_SHA2 1 +#endif + +#endif /* OCONFIGURE_CONFIG_H */