Compare commits

...

29 Commits

Author SHA1 Message Date
0bb85e6364 Fix SunOS build
All checks were successful
CMake / ubuntu-latest - shared=OFF, posix=ON (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, posix=ON (push) Successful in 15s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:49:32 +03:00
0fb0160b5e remove patch
All checks were successful
CMake / ubuntu-latest - shared=OFF, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, posix=ON (push) Successful in 12s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:48:44 +03:00
fdb22819b4 Fix SunOS build
Some checks failed
CMake / ubuntu-latest - shared=OFF, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, posix=ON (push) Has been cancelled
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:48:20 +03:00
6f79fb9c44 fuck macros
All checks were successful
CMake / ubuntu-latest - shared=OFF, posix=ON (push) Successful in 18s
CMake / ubuntu-latest - shared=ON, posix=ON (push) Successful in 10s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:44:31 +03:00
ef5e3e1706 Idk
Some checks failed
CMake / ubuntu-latest - shared=OFF, posix=ON (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, posix=ON (push) Failing after 11s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:42:49 +03:00
8e247c7a0b Remove pthread from CI
Some checks failed
CMake / ubuntu-latest - shared=OFF, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, posix=ON (push) Failing after 11s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:40:24 +03:00
ec3bf6061d Remove pthreads
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 15s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Has been cancelled
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Has been cancelled
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Has been cancelled
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Has been cancelled
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:39:55 +03:00
41badf33d9 Hopefully shut the compiler up on ubuntu
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 10s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 10s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 11s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 12s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 14s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 11s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:35:32 +03:00
8c1694d3d9 Fix build on FreeBSD
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 10s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 11s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 14s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Has been cancelled
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:34:14 +03:00
055f0bc2f5 fix cmakelists
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 18s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 18s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 9s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-09 08:26:33 +03:00
b1e03148b7 Make this buildable on SunOS
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 19s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 20s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 11s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-07 00:23:46 +03:00
da1725982c Fix use-after-free
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 19s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 23s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 20s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 14s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 10s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-04 03:36:41 +03:00
75c2f27f8b Make UTF-8 optional
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 10s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 13s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-04 02:35:42 +03:00
570a5fab88 Add support for emoji identifiers
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 17s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 18s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 18s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-04 02:28:47 +03:00
296e6467c6 Add UTF-8 sample
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 19s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 15s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 20s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 17s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-04 02:25:52 +03:00
1d40c785f8 Get something working
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Failing after 16s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 14s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 13s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-01 07:38:13 +03:00
80af330d1b Finish parser
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 15s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 17s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 13s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-01 06:10:13 +03:00
3d8f2270ef Make strtoll and strtod malloc-free
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 19s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 18s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 22s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 20s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 19s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 20s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-01 04:08:00 +03:00
2ec675a320 Update lexer to allow ' in numbers
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 18s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 15s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-01 03:18:14 +03:00
1a2b697349 Add copyright disclaimer to files
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 12s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 10s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-01 03:04:05 +03:00
92eefe800b Mayhaps I overengineered versioning
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 11s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 11s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 13s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-01 03:01:13 +03:00
e8f34b341e Add some evaluation stuff + versioning
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 15s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 17s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 16s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 17s
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-01 02:56:44 +03:00
f1e4804167 Remove typeof dependency
Some checks failed
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 16s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 15s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Failing after 14s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Failing after 15s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Failing after 13s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Failing after 8s
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-27 23:23:34 +03:00
a8ea92dd5c Fix another leak
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 15s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 12s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 10s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 10s
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-27 23:16:47 +03:00
dbaf6d16ce Fix more leaks...
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 16s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 16s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 15s
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-27 22:44:02 +03:00
3bc6e879d8 Fix some memory leaks
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 16s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 15s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 14s
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-27 22:21:10 +03:00
8b0463c94a Add block invalid sample
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 15s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 9s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 10s
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-27 21:59:01 +03:00
5fcbb97f7a Add object support
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 11s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 11s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 11s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 11s
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-27 21:56:54 +03:00
93ddf7738c Add cleaning script
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-27 21:38:39 +03:00
17 changed files with 1290 additions and 304 deletions

View File

@@ -14,13 +14,11 @@ jobs:
matrix: matrix:
os: [ubuntu-latest] os: [ubuntu-latest]
shared: ["ON", "OFF"] shared: ["ON", "OFF"]
pthread_support: ["ON", "OFF"]
posix_support: ["ON", "OFF"] posix_support: ["ON", "OFF"]
exclude: exclude:
- posix_support: "OFF" - posix_support: "OFF"
pthread_support: "ON"
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} - shared=${{ matrix.shared }}, pthread=${{ matrix.pthread_support }}, posix=${{ matrix.posix_support }} name: ${{ matrix.os }} - shared=${{ matrix.shared }}, posix=${{ matrix.posix_support }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Install dependencies - name: Install dependencies
@@ -31,7 +29,6 @@ jobs:
run: | run: |
cmake -Bbuild -S . \ cmake -Bbuild -S . \
-DDCFG_BUILD_SHARED=${{ matrix.shared }} \ -DDCFG_BUILD_SHARED=${{ matrix.shared }} \
-DDCFG_PTHREAD_SUPPORT=${{ matrix.pthread_support }} \
-DDCFG_POSIX_SUPPORT=${{ matrix.posix_support }} -DDCFG_POSIX_SUPPORT=${{ matrix.posix_support }}
- name: Build - name: Build
run: | run: |

View File

@@ -2,36 +2,40 @@ cmake_minimum_required(VERSION 3.10)
project(DCFG C) project(DCFG C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON) # Would've done OFF but I need typeof (for now)
option(DCFG_PTHREAD_SUPPORT "Enable pthreads support" ON)
option(DCFG_POSIX_SUPPORT "Enable POSIX support" ON) option(DCFG_POSIX_SUPPORT "Enable POSIX support" ON)
option(DCFG_BUILD_PROGRAMS "Build DCFG example programs" ON) option(DCFG_BUILD_PROGRAMS "Build DCFG example programs" ON)
option(DCFG_ASAN "Enable AddressSanitizer" OFF)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
find_package(Threads) find_package(Threads)
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
if(DCFG_ASAN)
if(MSVC)
set(ASAN_COMPILE_FLAGS /fsanitize=address)
set(ASAN_LINK_FLAGS /fsanitize=address)
else()
set(ASAN_COMPILE_FLAGS -fsanitize=address -fno-omit-frame-pointer)
set(ASAN_LINK_FLAGS -fsanitize=address)
endif()
endif()
# Shared library # Shared library
add_library(${PROJECT_NAME}_shared SHARED ${SRC_DIR}/dcfg.c) add_library(${PROJECT_NAME}_shared SHARED ${SRC_DIR}/dcfg.c)
target_include_directories(${PROJECT_NAME}_shared PUBLIC ${INCLUDE_DIR}) target_include_directories(${PROJECT_NAME}_shared PUBLIC ${INCLUDE_DIR})
set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME "dcfg") set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME "dcfg")
# Static library # Static library
add_library(${PROJECT_NAME}_static STATIC ${SRC_DIR}/dcfg.c) add_library(${PROJECT_NAME}_static STATIC ${SRC_DIR}/dcfg.c)
target_include_directories(${PROJECT_NAME}_static PUBLIC ${INCLUDE_DIR}) target_include_directories(${PROJECT_NAME}_static PUBLIC ${INCLUDE_DIR})
set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME "dcfg") set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME "dcfg")
# Common settings for both libraries
foreach(TARGET ${PROJECT_NAME}_shared ${PROJECT_NAME}_static) foreach(TARGET ${PROJECT_NAME}_shared ${PROJECT_NAME}_static)
if(DCFG_PTHREAD_SUPPORT)
find_package(Threads REQUIRED)
target_link_libraries(${TARGET} PRIVATE Threads::Threads)
target_compile_definitions(${TARGET} PRIVATE DCFG_PTHREAD_SUPPORT)
endif()
if(DCFG_POSIX_SUPPORT) if(DCFG_POSIX_SUPPORT)
target_compile_definitions(${TARGET} PRIVATE DCFG_POSIX_SUPPORT) target_compile_definitions(${TARGET} PRIVATE DCFG_POSIX_SUPPORT)
endif() endif()
@@ -41,13 +45,21 @@ foreach(TARGET ${PROJECT_NAME}_shared ${PROJECT_NAME}_static)
else() else()
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token) target_compile_options(${TARGET} PRIVATE -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token)
endif() endif()
if(NOT MSVC)
target_link_libraries(${TARGET} PRIVATE m)
endif()
# AddressSanitizer
if(DCFG_ASAN)
target_compile_options(${TARGET} PRIVATE ${ASAN_COMPILE_FLAGS})
target_link_libraries(${TARGET} PRIVATE ${ASAN_LINK_FLAGS})
endif()
endforeach() endforeach()
# Install libraries
install(TARGETS ${PROJECT_NAME}_shared ${PROJECT_NAME}_static DESTINATION lib) install(TARGETS ${PROJECT_NAME}_shared ${PROJECT_NAME}_static DESTINATION lib)
install(DIRECTORY ${INCLUDE_DIR}/ DESTINATION include) install(DIRECTORY ${INCLUDE_DIR}/ DESTINATION include)
# Build example programs
if(DCFG_BUILD_PROGRAMS) if(DCFG_BUILD_PROGRAMS)
set(PROGRAMS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/programs) set(PROGRAMS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/programs)
file(GLOB PROGRAM_SOURCES "${PROGRAMS_DIR}/*.c") file(GLOB PROGRAM_SOURCES "${PROGRAMS_DIR}/*.c")
@@ -56,15 +68,19 @@ if(DCFG_BUILD_PROGRAMS)
get_filename_component(PROG_NAME ${PROG_SRC} NAME_WE) get_filename_component(PROG_NAME ${PROG_SRC} NAME_WE)
add_executable(${PROG_NAME} ${PROG_SRC}) add_executable(${PROG_NAME} ${PROG_SRC})
target_include_directories(${PROG_NAME} PRIVATE ${INCLUDE_DIR}) target_include_directories(${PROG_NAME} PRIVATE ${INCLUDE_DIR})
target_link_libraries(${PROG_NAME} PRIVATE ${PROJECT_NAME}_shared) target_link_libraries(${PROG_NAME} PRIVATE ${PROJECT_NAME}_static)
if(DCFG_PTHREAD_SUPPORT)
target_link_libraries(${PROG_NAME} PRIVATE Threads::Threads)
endif()
if(MSVC) if(MSVC)
target_compile_options(${PROG_NAME} PRIVATE /W4 /permissive-) target_compile_options(${PROG_NAME} PRIVATE /W4 /permissive-)
else() else()
target_compile_options(${PROG_NAME} PRIVATE -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token) target_compile_options(${PROG_NAME} PRIVATE -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token)
endif() endif()
if(DCFG_ASAN)
target_compile_options(${PROG_NAME} PRIVATE ${ASAN_COMPILE_FLAGS})
target_link_libraries(${PROG_NAME} PRIVATE ${ASAN_LINK_FLAGS})
endif()
install(TARGETS ${PROG_NAME} DESTINATION bin) install(TARGETS ${PROG_NAME} DESTINATION bin)
endforeach() endforeach()
endif() endif()

View File

@@ -3,10 +3,9 @@
set -e set -e
BUILD_DIR="BUILD" BUILD_DIR="BUILD"
INSTALL_DIR="$(pwd)/install" INSTALL_DIR=$PWD/install
CFLAGS="-std=gnu99 -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token" CFLAGS="-Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token -Wno-unused-command-line-argument"
BUILD_SHARED=1 BUILD_SHARED=1
PTHREAD_SUPPORT=1
POSIX_SUPPORT=1 POSIX_SUPPORT=1
BUILD_PROGRAMS=1 BUILD_PROGRAMS=1
SRC_DIR="src" SRC_DIR="src"
@@ -18,55 +17,68 @@ for arg in "$@"; do
case $arg in case $arg in
--debug) CFLAGS="$CFLAGS -g -O0" ;; --debug) CFLAGS="$CFLAGS -g -O0" ;;
--release) CFLAGS="$CFLAGS -O2" ;; --release) CFLAGS="$CFLAGS -O2" ;;
--no-pthread) PTHREAD_SUPPORT=0 ;;
--no-posix) POSIX_SUPPORT=0 ;; --no-posix) POSIX_SUPPORT=0 ;;
--with-programs) BUILD_PROGRAMS=1 ;; --no-programs) BUILD_PROGRAMS=0 ;;
--clean) rm -rf "$BUILD_DIR" "$INSTALL_DIR"; echo "Cleaned."; exit 0 ;; --clean) rm -rf "$BUILD_DIR" "$INSTALL_DIR"; echo "Cleaned."; exit 0 ;;
esac esac
done done
# Detect SunOS
OS=`uname`
echo "Detected os:" $OS
SHARED_FLAG="-shared"
PIC_FLAG="-fPIC"
if [ "$OS" = "SunOS" ]; then
SHARED_FLAG="-G"
PIC_FLAG="-KPIC"
CFLAGS=`echo "$CFLAGS" | sed 's/-pedantic//g'`
fi
# Setup directories # Setup directories
mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include" "$INSTALL_DIR/bin" mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include" "$INSTALL_DIR/bin"
# Compiler and linker # Compiler and linker
CC=${CC:-cc} CC=${CC:-cc}
if [ "$PTHREAD_SUPPORT" -eq 1 ]; then if [ "$OS" = "SunOS" ] && [ "$CC" = "cc" ]; then
CFLAGS="$CFLAGS -DDCFG_PTHREAD_SUPPORT" CFLAGS="$CFLAGS -xc99"
LIBS="$LIBS -lpthread" else
CFLAGS="$CFLAGS -std=c99"
fi fi
if [ "$POSIX_SUPPORT" -eq 1 ]; then if [ "$POSIX_SUPPORT" -eq 1 ]; then
CFLAGS="$CFLAGS -DDCFG_POSIX_SUPPORT" CFLAGS="$CFLAGS -DDCFG_POSIX_SUPPORT=1"
fi fi
CFLAGS="$CFLAGS $PIC_FLAG -lm"
echo "Building DCFG..." echo "Building DCFG..."
cd "$BUILD_DIR" cd "$BUILD_DIR"
set -x set -x
# Shared library # Shared library
$CC $CFLAGS -fPIC -shared "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o "$OUTPUT_NAME.so" $LIBS $CC $CFLAGS $SHARED_FLAG "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o "$OUTPUT_NAME.so" $LIBS
# Static library # Static library
$CC $CFLAGS -c "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" $CC -c $CFLAGS "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o dcfg.o
ar rcs "$OUTPUT_NAME.a" dcfg.o if [ "$OS" = "SunOS" ]; then
set +x CC -xar -o "$OUTPUT_NAME.a" dcfg.o
# else
# Build programs if requested ar rcs "$OUTPUT_NAME.a" dcfg.o
fi
cp "$OUTPUT_NAME.so" "$INSTALL_DIR/lib/"
cp "$OUTPUT_NAME.a" "$INSTALL_DIR/lib/"
cp -r "../$INCLUDE_DIR/"* "$INSTALL_DIR/include/"
if [ "$BUILD_PROGRAMS" -eq 1 ]; then if [ "$BUILD_PROGRAMS" -eq 1 ]; then
echo "Building example programs..." for prog in ../"$PROGRAMS_DIR"/*.c; do
for src in "../$PROGRAMS_DIR"/*.c; do prog_name=`basename "$prog" .c`
prog=$(basename "$src" .c) $CC $CFLAGS "$prog" -I"../$INCLUDE_DIR" $OUTPUT_NAME.a $LIBS -o "$prog_name"
echo "Building $prog..." cp "$prog_name" "$INSTALL_DIR/bin/"
$CC $CFLAGS -c "$src" -I"../$INCLUDE_DIR"
mkdir -p bin
$CC $CFLAGS "$prog.o" "$OUTPUT_NAME.a" $LIBS -o "bin/$prog"
done done
fi fi
echo "Installing library..."
cp -r "../$INCLUDE_DIR/"* "$INSTALL_DIR/include/"
cp "$OUTPUT_NAME.so" "$INSTALL_DIR/lib/"
cp "$OUTPUT_NAME.a" "$INSTALL_DIR/lib/"
cp -r "bin/"* "$INSTALL_DIR/bin/"
echo "Done. Installed to $INSTALL_DIR" echo "Done. Installed to $INSTALL_DIR"

View File

@@ -28,6 +28,7 @@
lldb lldb
pkg-config pkg-config
tokei tokei
valgrind
]; ];
}; };

View File

@@ -1,3 +1,25 @@
/*
* Copyright 2025 Slendi <slendi@socopon.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef DCFG_H #ifndef DCFG_H
#define DCFG_H #define DCFG_H
@@ -49,9 +71,19 @@ typedef enum dcfg_ValueKind {
dcfg_ValueType_Object, dcfg_ValueType_Object,
dcfg_ValueType_Array, dcfg_ValueType_Array,
dcfg_ValueType_Function, dcfg_ValueType_Function,
dcfg_ValueType_MemberAccess,
dcfg_ValueType_FunctionCall, dcfg_ValueType_FunctionCall,
} dcfg_ValueType; } dcfg_ValueType;
typedef dcfg_Value *(*dcfg_BuiltIn)(dcfg_Value **argv, size_t argc);
typedef uint64_t dcfg_Version;
#define DCFG_GET_MAJOR(v) (((v) >> 48) & 0xFFFF)
#define DCFG_GET_MINOR(v) (((v) >> 32) & 0xFFFF)
#define DCFG_GET_PATCH(v) ((v) & 0xFFFFFFFF)
dcfg_Version dcfg_get_version(void);
dcfg_Instance *dcfg_make_instance(dcfg_InstanceCreateInfo const *create_info); dcfg_Instance *dcfg_make_instance(dcfg_InstanceCreateInfo const *create_info);
void dcfg_destroy_instance(dcfg_Instance *instance); void dcfg_destroy_instance(dcfg_Instance *instance);
@@ -105,9 +137,15 @@ static inline bool dcfg_Value_get_function_body(
return dcfg_Value_get_function_body_ex(value, out_value, true); return dcfg_Value_get_function_body_ex(value, out_value, true);
} }
// Allocates new values
bool dcfg_call_function(dcfg_Value *function, dcfg_Value **args, bool dcfg_call_function(dcfg_Value *function, dcfg_Value **args,
size_t arg_count, dcfg_Value **out_value); size_t arg_count, dcfg_Value **out_value);
// Allocates new values
bool dcfg_Value_evaluate(dcfg_Value *value, dcfg_Value **out_value); bool dcfg_Value_evaluate(dcfg_Value *value, dcfg_Value **out_value);
// Allocates new values
bool dcfg_Value_evaluate_toplevel(dcfg_Value *top, dcfg_Value **out_value,
dcfg_StringView *function_names, dcfg_BuiltIn *functions,
size_t function_count);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -1,18 +1,41 @@
#include <dcfg.h> #include <dcfg.h>
#include <getopt.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
void walk_value(dcfg_Value *value, bool evaluate, int indent); void walk_value(dcfg_Value *value, bool evaluate, int indent, bool first);
#define WALK(v, e, i) walk_value((v), (e), (i), true)
static void print_indent(int indent)
{
for (int i = 0; i < indent; ++i)
putchar('\t');
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc < 2) { bool evaluate = false;
printf("Usage: %s <dcfg file>\n", argv[0]); int opt;
while ((opt = getopt(argc, argv, "e")) != -1) {
switch (opt) {
case 'e':
evaluate = true;
break;
default:
fprintf(stderr, "Usage: %s [-e] <dcfg file>\n", argv[0]);
return 1;
}
}
if (optind >= argc) {
fprintf(stderr, "Usage: %s [-e] <dcfg file>\n", argv[0]);
return 1; return 1;
} }
char const *path = argv[optind];
dcfg_InstanceCreateInfo ci = { 0 }; dcfg_InstanceCreateInfo ci = { 0 };
dcfg_Instance *instance = dcfg_make_instance(&ci); dcfg_Instance *instance = dcfg_make_instance(&ci);
if (!instance) { if (!instance) {
@@ -21,28 +44,24 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
dcfg_Value *value = dcfg_parse(instance, dcfg_SV(argv[1])); dcfg_Value *value = dcfg_parse(instance, dcfg_SV(path));
if (!value) { if (!value) {
printf("Failed to parse DCFG file. Error: %s\n", printf("Failed to parse DCFG file. Error: %s\n",
dcfg_last_error(instance)); dcfg_last_error(instance));
dcfg_destroy_instance(instance);
return 1; return 1;
} }
walk_value(value, false, 0); WALK(value, evaluate, 0);
dcfg_destroy(value); dcfg_destroy(value);
dcfg_destroy_instance(instance); dcfg_destroy_instance(instance);
} }
static void print_indent(int indent) void walk_value(dcfg_Value *value, bool evaluate, int indent, bool first)
{ {
for (int i = 0; i < indent; ++i) if (first)
putchar('\t'); print_indent(indent);
}
void walk_value(dcfg_Value *value, bool evaluate, int indent)
{
print_indent(indent);
dcfg_ValueType type = dcfg_Value_type_ex(value, evaluate); dcfg_ValueType type = dcfg_Value_type_ex(value, evaluate);
@@ -85,7 +104,7 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
size_t n = 0; size_t n = 0;
dcfg_Value_get_object_keys(value, 0, &n, NULL); dcfg_Value_get_object_keys(value, 0, &n, NULL);
dcfg_StringView *keys dcfg_StringView *keys
= n ? (dcfg_StringView *)alloca(n * sizeof(*keys)) : NULL; = n ? (dcfg_StringView *)calloc(1, n * sizeof(*keys)) : NULL;
dcfg_Value_get_object_keys(value, n, &n, keys); dcfg_Value_get_object_keys(value, n, &n, keys);
printf("{\n"); printf("{\n");
@@ -97,7 +116,7 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
print_indent(indent + 1); print_indent(indent + 1);
printf("\"%.*s\": ", (int)keys[i].size, keys[i].data); printf("\"%.*s\": ", (int)keys[i].size, keys[i].data);
walk_value(child, evaluate, indent + 1); walk_value(child, evaluate, indent + 1, false);
if (i + 1 < n) if (i + 1 < n)
printf(","); printf(",");
printf("\n"); printf("\n");
@@ -116,7 +135,8 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
if (!dcfg_Value_get_array_item_ex(value, i, &item, evaluate)) if (!dcfg_Value_get_array_item_ex(value, i, &item, evaluate))
continue; continue;
walk_value(item, evaluate, indent + 1); print_indent(indent + 1);
walk_value(item, evaluate, indent + 1, false);
if (i + 1 < sz) if (i + 1 < sz)
printf(","); printf(",");
printf("\n"); printf("\n");
@@ -129,8 +149,8 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
dcfg_Value *body = NULL; dcfg_Value *body = NULL;
if (dcfg_Value_get_function_body_ex(value, &body, evaluate) && body) { if (dcfg_Value_get_function_body_ex(value, &body, evaluate) && body) {
printf("<fn> "); printf("<fn>\t");
walk_value(body, evaluate, indent + 1); walk_value(body, evaluate, indent + 1, false);
} else { } else {
printf("<builtin-fn>"); printf("<builtin-fn>");
} }
@@ -140,7 +160,7 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
if (evaluate) { if (evaluate) {
dcfg_Value *res; dcfg_Value *res;
if (dcfg_Value_evaluate(value, &res)) if (dcfg_Value_evaluate(value, &res))
walk_value(res, evaluate, indent); walk_value(res, evaluate, indent, first);
else else
printf("<error-evaluating-call>"); printf("<error-evaluating-call>");
} else { } else {

143
programs/dcfgq.c Normal file
View File

@@ -0,0 +1,143 @@
#include <dcfg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef enum {
T_FIELD,
T_INDEX,
} TokenType;
typedef struct {
TokenType type;
union {
dcfg_StringView field;
size_t index;
} v;
} Token;
#define MAX_TOKENS 256
static size_t tokenize(char const *query, Token *out)
{
size_t count = 0;
size_t i = 0;
if (query[i] == '.')
i++;
while (query[i] && count < MAX_TOKENS) {
if (query[i] == '.') {
i++;
size_t start = i;
while (query[i] && query[i] != '.' && query[i] != '[')
i++;
out[count].type = T_FIELD;
out[count].v.field.data = query + start;
out[count].v.field.size = i - start;
count++;
} else if (query[i] == '[') {
i++;
char *end;
size_t idx = strtoul(query + i, &end, 10);
if (*end != ']') {
fprintf(stderr, "invalid index\n");
exit(1);
}
i = (size_t)(end - query) + 1;
out[count].type = T_INDEX;
out[count].v.index = idx;
count++;
} else {
size_t start = i;
while (query[i] && query[i] != '.' && query[i] != '[')
i++;
out[count].type = T_FIELD;
out[count].v.field.data = query + start;
out[count].v.field.size = i - start;
count++;
}
}
return count;
}
static void print_value(dcfg_Value *v)
{
dcfg_StringView sv;
if (dcfg_serialize_value(v, &sv)) {
fwrite(sv.data, 1, sv.size, stdout);
free((void *)sv.data);
putchar('\n');
} else {
puts("null");
}
}
int main(int argc, char **argv)
{
if (argc < 3) {
fprintf(stderr, "usage: %s <query> <file>\n", argv[0]);
return 1;
}
char const *query = argv[1];
char const *file = argv[2];
dcfg_Instance *inst = dcfg_make_instance(&(dcfg_InstanceCreateInfo) { 0 });
if (!inst) {
fprintf(stderr, "failed to create instance\n");
return 1;
}
dcfg_Value *root = dcfg_parse(inst, dcfg_SV(file));
if (!root) {
fprintf(stderr, "parse error: %s\n", dcfg_last_error(inst));
dcfg_destroy_instance(inst);
return 1;
}
Token toks[MAX_TOKENS];
size_t n = tokenize(query, toks);
dcfg_Value *evaled;
if (!dcfg_Value_evaluate_toplevel(root, &evaled, NULL, NULL, 0)) {
fprintf(stderr, "evaluation error: %s\n", dcfg_last_error(inst));
dcfg_destroy(root);
dcfg_destroy_instance(inst);
return 1;
}
dcfg_Value *cur = evaled;
for (size_t i = 0; i < n; i++) {
Token *t = &toks[i];
dcfg_Value *next = NULL;
if (t->type == T_FIELD) {
if (!dcfg_Value_get_object_field_ex(cur, t->v.field, &next, true)) {
fprintf(stderr, "no such field\n");
dcfg_destroy(evaled);
dcfg_destroy(root);
dcfg_destroy_instance(inst);
return 1;
}
} else {
if (!dcfg_Value_get_array_item_ex(cur, t->v.index, &next, true)) {
fprintf(stderr, "index out of bounds\n");
dcfg_destroy(evaled);
dcfg_destroy(root);
dcfg_destroy_instance(inst);
return 1;
}
}
if (cur != evaled)
dcfg_destroy(cur);
cur = next;
}
print_value(cur);
if (cur != evaled)
dcfg_destroy(cur);
dcfg_destroy(evaled);
dcfg_destroy(root);
dcfg_destroy_instance(inst);
return 0;
}

View File

@@ -8,6 +8,6 @@ fn lib = {
partitions = { partitions = {
automount = [ 'boot' 'root' ] automount = [ 'boot' 'root' ]
swap.enable = true swap.enable = true
swap.size = 2g swap.size = 2_000_000_000
} }
} }

View File

@@ -0,0 +1,5 @@
{
test = 123
test.field = 456 # This should be invalid. `test` is an int, not an object.
}

View File

@@ -1,2 +1,12 @@
fn lib = [ 123 "string" ./path 80085.3 ] fn lib = [
123
"string"
./path
80085.3
{
key1 = 123
key2.member = "str"
key2.another_member = ./amazing
}
]

11
samples/utf8.dcfg Normal file
View File

@@ -0,0 +1,11 @@
fn lib = {
english = "The quick brown fox jumps over the lazy dog."
日本語 = "はじめまして!"
Română = "Salutare! ĂÂÎȘȚăâîșț"
😀 = "👋🌍😊🚀🤖"
diacritics = "ŠĐĆŽšđž"
français = "Ça déjà vu?"
español = "¡El pingüino Wenceslao bebe whisky y zumo de piña!"
русский = "Съешь же ещё этих мягких французских булок, да выпей чаю."
}

View File

@@ -1,8 +1,8 @@
fn lib = { fn lib = {
keybindings = [ keybindings = [
{ key = 'Main-Shift-Escape' action = lib.quit_wm } { key = 'Main-Shift-Escape' action = (lib.quit_wm) }
{ key = 'Main-Shift-Q' action = lib.kill_application } { key = 'Main-Shift-Q' action = (lib.kill_application) }
{ key = 'Main-Shift-C' action = lib.close_application } { key = 'Main-Shift-C' action = (lib.close_application) }
{ key = 'Main-Space' action = (lib.execute 'alacritty') } { key = 'Main-Space' action = (lib.execute 'alacritty') }
] ]
} }

1014
src/dcfg.c

File diff suppressed because it is too large Load Diff

30
src/meta.h Normal file
View File

@@ -0,0 +1,30 @@
/*
* Copyright 2025 Slendi <slendi@socopon.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef META_H
#define META_H
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_PATCH 0
#endif // META_H

74
src/vendor/vec.c vendored
View File

@@ -33,18 +33,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vec.h" #include "vec.h"
#include <string.h> #include <string.h>
typedef struct typedef struct {
{
vec_size_t size; vec_size_t size;
vec_size_t capacity; vec_size_t capacity;
unsigned char data[]; unsigned char data[];
} vector_header; } vector_header;
vector_header* vector_get_header(vector vec) { return &((vector_header*)vec)[-1]; } vector_header *vector_get_header(vector vec)
{
return &((vector_header *)vec)[-1];
}
vector vector_create(void) vector vector_create(void)
{ {
vector_header* h = (vector_header*)malloc(sizeof(vector_header)); vector_header *h = (vector_header *)malloc(sizeof(vector_header));
h->capacity = 0; h->capacity = 0;
h->size = 0; h->size = 0;
@@ -55,28 +57,28 @@ void vector_free(vector vec) { free(vector_get_header(vec)); }
vec_size_t vector_size(vector vec) { return vector_get_header(vec)->size; } vec_size_t vector_size(vector vec) { return vector_get_header(vec)->size; }
vec_size_t vector_capacity(vector vec) { return vector_get_header(vec)->capacity; } vec_size_t vector_capacity(vector vec)
{
return vector_get_header(vec)->capacity;
}
vector_header* vector_realloc(vector_header* h, vec_type_t type_size) vector_header *vector_realloc(vector_header *h, vec_type_t type_size)
{ {
vec_size_t new_capacity = (h->capacity == 0) ? 1 : h->capacity * 2; vec_size_t new_capacity = (h->capacity == 0) ? 1 : h->capacity * 2;
vector_header* new_h = (vector_header*)realloc(h, sizeof(vector_header) + new_capacity * type_size); vector_header *new_h = (vector_header *)realloc(
h, sizeof(vector_header) + new_capacity * type_size);
new_h->capacity = new_capacity; new_h->capacity = new_capacity;
return new_h; return new_h;
} }
bool vector_has_space(vector_header* h) bool vector_has_space(vector_header *h) { return h->capacity - h->size > 0; }
{
return h->capacity - h->size > 0;
}
void* _vector_add_dst(vector* vec_addr, vec_type_t type_size) void *_vector_add_dst(vector *vec_addr, vec_type_t type_size)
{ {
vector_header* h = vector_get_header(*vec_addr); vector_header *h = vector_get_header(*vec_addr);
if (!vector_has_space(h)) if (!vector_has_space(h)) {
{
h = vector_realloc(h, type_size); h = vector_realloc(h, type_size);
*vec_addr = h->data; *vec_addr = h->data;
} }
@@ -84,34 +86,32 @@ void* _vector_add_dst(vector* vec_addr, vec_type_t type_size)
return &h->data[type_size * h->size++]; return &h->data[type_size * h->size++];
} }
void* _vector_insert_dst(vector* vec_addr, vec_type_t type_size, vec_size_t pos) void *_vector_insert_dst(vector *vec_addr, vec_type_t type_size, vec_size_t pos)
{ {
vector_header* h = vector_get_header(*vec_addr); vector_header *h = vector_get_header(*vec_addr);
vec_size_t new_length = h->size + 1; vec_size_t new_length = h->size + 1;
// make sure there is enough room for the new element // make sure there is enough room for the new element
if (!vector_has_space(h)) if (!vector_has_space(h)) {
{
h = vector_realloc(h, type_size); h = vector_realloc(h, type_size);
*vec_addr = h->data; *vec_addr = h->data;
} }
// move trailing elements // move trailing elements
memmove(&h->data[(pos + 1) * type_size], memmove(&h->data[(pos + 1) * type_size], &h->data[pos * type_size],
&h->data[pos * type_size], (h->size - pos) * type_size);
(h->size - pos) * type_size);
h->size = new_length; h->size = new_length;
return &h->data[pos * type_size]; return &h->data[pos * type_size];
} }
void _vector_erase(vector vec, vec_type_t type_size, vec_size_t pos, vec_size_t len) void _vector_erase(
vector vec, vec_type_t type_size, vec_size_t pos, vec_size_t len)
{ {
vector_header* h = vector_get_header(vec); vector_header *h = vector_get_header(vec);
memmove(&h->data[pos * type_size], memmove(&h->data[pos * type_size], &h->data[(pos + len) * type_size],
&h->data[(pos + len) * type_size], (h->size - pos - len) * type_size);
(h->size - pos - len) * type_size);
h->size -= len; h->size -= len;
} }
@@ -123,26 +123,28 @@ void _vector_remove(vector vec, vec_type_t type_size, vec_size_t pos)
void vector_pop(vector vec) { --vector_get_header(vec)->size; } void vector_pop(vector vec) { --vector_get_header(vec)->size; }
void _vector_reserve(vector* vec_addr, vec_type_t type_size, vec_size_t capacity) void _vector_reserve(
vector *vec_addr, vec_type_t type_size, vec_size_t capacity)
{ {
vector_header* h = vector_get_header(*vec_addr); vector_header *h = vector_get_header(*vec_addr);
if (h->capacity >= capacity) if (h->capacity >= capacity) {
{
return; return;
} }
h = (vector_header*)realloc(h, sizeof(vector_header) + capacity * type_size); h = (vector_header *)realloc(
h, sizeof(vector_header) + capacity * type_size);
h->capacity = capacity; h->capacity = capacity;
*vec_addr = &h->data; *vec_addr = &h->data;
} }
vector _vector_copy(vector vec, vec_type_t type_size) vector _vector_copy(vector vec, vec_type_t type_size)
{ {
vector_header* h = vector_get_header(vec); vector_header *h = vector_get_header(vec);
size_t alloc_size = sizeof(vector_header) + h->size * type_size; size_t alloc_size = sizeof(vector_header) + h->size * type_size;
vector_header* copy_h = (vector_header*)malloc(alloc_size); vector_header *copy_h = (vector_header *)malloc(alloc_size);
memcpy(copy_h, h, alloc_size); memcpy(copy_h, h, alloc_size);
copy_h->capacity = copy_h->size; copy_h->capacity = copy_h->size;
return &copy_h->data; return &copy_h->data;
} }

65
src/vendor/vec.h vendored
View File

@@ -33,11 +33,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef vec_h #ifndef vec_h
#define vec_h #define vec_h
#ifdef __cpp_decltype
#include <type_traits>
#define typeof(T) std::remove_reference<std::add_lvalue_reference<decltype(T)>::type>::type
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@@ -46,72 +41,50 @@ extern "C" {
#include <stdlib.h> #include <stdlib.h>
// generic type for internal use // generic type for internal use
typedef void* vector; typedef void *vector;
// number of elements in a vector // number of elements in a vector
typedef size_t vec_size_t; typedef size_t vec_size_t;
// number of bytes for a type // number of bytes for a type
typedef size_t vec_type_t; typedef size_t vec_type_t;
// TODO: more rigorous check for typeof support with different compilers #define vector_add_dst(vec_addr, type) \
#if _MSC_VER == 0 || __STDC_VERSION__ >= 202311L || defined __cpp_decltype ((type *)_vector_add_dst((vector *)vec_addr, sizeof(type)))
#define vector_insert_dst(vec_addr, type, pos) \
((type *)_vector_insert_dst((vector *)vec_addr, sizeof(type), pos))
// shortcut defines #define vector_add(vec_addr, type, value) \
// vec_addr is a vector* (aka type**)
#define vector_add_dst(vec_addr)\
((typeof(*vec_addr))(\
_vector_add_dst((vector*)vec_addr, sizeof(**vec_addr))\
))
#define vector_insert_dst(vec_addr, pos)\
((typeof(*vec_addr))(\
_vector_insert_dst((vector*)vec_addr, sizeof(**vec_addr), pos)))
#define vector_add(vec_addr, value)\
(*vector_add_dst(vec_addr) = value)
#define vector_insert(vec_addr, pos, value)\
(*vector_insert_dst(vec_addr, pos) = value)
#else
#define vector_add_dst(vec_addr, type)\
((type*)_vector_add_dst((vector*)vec_addr, sizeof(type)))
#define vector_insert_dst(vec_addr, type, pos)\
((type*)_vector_insert_dst((vector*)vec_addr, sizeof(type), pos))
#define vector_add(vec_addr, type, value)\
(*vector_add_dst(vec_addr, type) = value) (*vector_add_dst(vec_addr, type) = value)
#define vector_insert(vec_addr, type, pos, value)\ #define vector_insert(vec_addr, type, pos, value) \
(*vector_insert_dst(vec_addr, type, pos) = value) (*vector_insert_dst(vec_addr, type, pos) = value)
#endif
// vec is a vector (aka type*) // vec is a vector (aka type*)
#define vector_erase(vec, pos, len)\ #define vector_erase(vec, pos, len) \
(_vector_erase((vector)vec, sizeof(*vec), pos, len)) (_vector_erase((vector)vec, sizeof(*vec), pos, len))
#define vector_remove(vec, pos)\ #define vector_remove(vec, pos) (_vector_remove((vector)vec, sizeof(*vec), pos))
(_vector_remove((vector)vec, sizeof(*vec), pos))
#define vector_reserve(vec_addr, capacity)\ #define vector_reserve(vec_addr, capacity) \
(_vector_reserve((vector*)vec_addr, sizeof(**vec_addr), capacity)) (_vector_reserve((vector *)vec_addr, sizeof(**vec_addr), capacity))
#define vector_copy(vec)\ #define vector_copy(vec) (_vector_copy((vector)vec, sizeof(*vec)))
(_vector_copy((vector)vec, sizeof(*vec)))
vector vector_create(void); vector vector_create(void);
void vector_free(vector vec); void vector_free(vector vec);
void* _vector_add_dst(vector* vec_addr, vec_type_t type_size); void *_vector_add_dst(vector *vec_addr, vec_type_t type_size);
void* _vector_insert_dst(vector* vec_addr, vec_type_t type_size, vec_size_t pos); void *_vector_insert_dst(
vector *vec_addr, vec_type_t type_size, vec_size_t pos);
void _vector_erase(vector vec_addr, vec_type_t type_size, vec_size_t pos, vec_size_t len); void _vector_erase(
vector vec_addr, vec_type_t type_size, vec_size_t pos, vec_size_t len);
void _vector_remove(vector vec_addr, vec_type_t type_size, vec_size_t pos); void _vector_remove(vector vec_addr, vec_type_t type_size, vec_size_t pos);
void vector_pop(vector vec); void vector_pop(vector vec);
void _vector_reserve(vector* vec_addr, vec_type_t type_size, vec_size_t capacity); void _vector_reserve(
vector *vec_addr, vec_type_t type_size, vec_size_t capacity);
vector _vector_copy(vector vec, vec_type_t type_size); vector _vector_copy(vector vec, vec_type_t type_size);

4
tools/clean.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
rm -rf install build BUILD result