Compare commits
2 commits
7c0333124b
...
2248f9e3aa
| Author | SHA1 | Date | |
|---|---|---|---|
| 2248f9e3aa | |||
| 27224cdd4c |
6 changed files with 158 additions and 9 deletions
45
CMakeLists.txt
Normal file
45
CMakeLists.txt
Normal file
|
|
@ -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 <stdint.h>
|
||||
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)
|
||||
13
config.h.cmake
Normal file
13
config.h.cmake
Normal file
|
|
@ -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 */
|
||||
5
configure
vendored
5
configure
vendored
|
|
@ -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 <stdint.h> /* 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}
|
||||
|
|
|
|||
66
sj_stdint.h
Normal file
66
sj_stdint.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Small fixed-width integer compatibility layer for SJ3.
|
||||
*
|
||||
* In C99 or newer translation units, use <stdint.h>. 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 <stdint.h>
|
||||
#else
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#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_ */
|
||||
17
sj_typedef.h
17
sj_typedef.h
|
|
@ -40,17 +40,18 @@
|
|||
#define _SJ_TYPEDEF 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#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
|
||||
|
|
|
|||
21
tests.c
21
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 <stdint.h>
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue