diff --git a/README.md b/README.md index 96a4cc5..b2154bd 100644 --- a/README.md +++ b/README.md @@ -11,27 +11,17 @@ Cross-Platform C SDK. Build portable desktop applications for Windows, macOS and ### Open the Developer Command Prompt ``` -(from C:\) - -// Clone the NAppGUI repo -git clone --depth 1 https://github.com/frang75/nappgui_src.git nappgui_sdk - -// Create a build directory -mkdir nappgui_build -cd nappgui_build - -// Generate the Visual Studio Solution -cmake -G "Visual Studio 16 2019" ../nappgui_sdk/src - -// Build the examples -msbuild NAppGUI.sln +git clone --depth 1 https://github.com/frang75/nappgui_src.git +cd nappgui_src +cmake -S ./src -B ./build +cmake --build ./build --config Debug // Run examples in 'demo' and 'howto' folders -.\demo\die\Debug\Die.exe -.\demo\bricks\Debug\Bricks.exe -.\demo\products\Debug\Products.exe -.\howto\col2dhello\Debug\Col2dHello.exe -.\howto\guihello\Debug\GuiHello.exe +.\build\Debug\bin\Die.exe +.\build\Debug\bin\Bricks.exe +.\build\Debug\bin\Products.exe +.\build\Debug\bin\Col2dHello.exe +.\build\Debug\bin\GuiHello.exe ... ``` ![Running demo project in Windows](https://nappgui.com/img/start/run_demo_windows.png) @@ -44,27 +34,17 @@ msbuild NAppGUI.sln ### Open the Terminal ``` -(from your home dir ~/) - -// Clone the NAppGUI repo -git clone --depth 1 https://github.com/frang75/nappgui_src.git nappgui_sdk - -// Create a build directory -mkdir nappgui_build -cd nappgui_build - -// Generate the Xcode project -cmake -G "Xcode" ../nappgui_sdk/src - -// Build the examples -xcodebuild +git clone --depth 1 https://github.com/frang75/nappgui_src.git +cd nappgui_src +cmake -G Xcode -S ./src -B ./build +cmake --build ./build --config Debug // Run examples in 'demo' and 'howto' folders -./demo/die/Debug/Die.app/Contents/MacOS/Die -./demo/bricks/Debug/Bricks.app/Contents/MacOS/Bricks -./demo/products/Debug/Products.app/Contents/MacOS/Products -./howto/col2dhello/Debug/Col2dHello.app/Contents/MacOS/Col2dHello -./howto/guihello/Debug/GuiHello.app/Contents/MacOS/GuiHello +./build/Debug/bin/Die.app/Contents/MacOS/Die +./build/Debug/bin/Bricks.app/Contents/MacOS/Bricks +./build/Debug/bin/Products.app/Contents/MacOS/Products +./build/Debug/bin/Col2dHello.app/Contents/MacOS/Col2dHello +./build/Debug/bin/GuiHello.app/Contents/MacOS/GuiHello ... ``` ![Running demo project in macOS](https://nappgui.com/img/start/run_demo_macos.png) @@ -74,10 +54,8 @@ xcodebuild ### Prerequisites ``` // Development tools -sudo apt-get install gcc -sudo apt-get install g++ +sudo apt-get install build-essential sudo apt-get install git -sudo apt-get install make sudo apt-get install cmake // Development libraries @@ -87,27 +65,17 @@ sudo apt-get install libcurl4-openssl-dev ``` ### Open the Terminal ``` -(from your home dir ~/) - -// Clone the NAppGUI repo -git clone --depth 1 https://github.com/frang75/nappgui_src.git nappgui_sdk - -// Create a build directory -mkdir nappgui_build -cd nappgui_build - -// Generate the Makefiles -cmake -G "Unix Makefiles" ../nappgui_sdk/src - -// Build the examples -make +git clone --depth 1 https://github.com/frang75/nappgui_src.git +cd nappgui_src +cmake -S ./src -B ./build -DCMAKE_BUILD_CONFIG=Debug +cmake --build ./build -j 4 // Run examples in 'demo' and 'howto' folders -./demo/die/Debug/Die -./demo/bricks/Debug/Bricks -./demo/products/Debug/Products -./howto/col2dhello/Debug/Col2dHello -./howto/guihello/Debug/GuiHello +./build/Debug/bin/Die +./build/Debug/bin/Bricks +./build/Debug/bin/Products +./build/Debug/bin/Col2dHello +./build/Debug/bin/GuiHello ... ``` ![Running demo project in Linux](https://nappgui.com/img/start/run_demo_linux.png) @@ -115,5 +83,5 @@ make ## More info - [NAppGUI Quick Start](https://nappgui.com/en/start/quick.html) - [NAppGUI Hello World](https://nappgui.com/en/start/hello.html) -- [Create a new project](https://nappgui.com/en/start/newprj.html) -- [About Portability](https://nappgui.com/en/start/win_mac_linux.html) +- [Create a new project](https://nappgui.com/en/guide/newprj.html) +- [About Portability](https://nappgui.com/en/guide/win_mac_linux.html) diff --git a/prj/CMakeCompilers.txt b/prj/CMakeCompilers.cmake similarity index 74% rename from prj/CMakeCompilers.txt rename to prj/CMakeCompilers.cmake index 1d169e3..9618601 100644 --- a/prj/CMakeCompilers.txt +++ b/prj/CMakeCompilers.cmake @@ -5,7 +5,7 @@ #------------------------------------------------------------------------------ function(removeFlag var flag) - if ("${${var}}" MATCHES ${flag}) + if ("${${var}}" STREQUAL ${flag}) string(REGEX REPLACE ${flag} "" var_without_flag ${${var}}) endif() set(${var} ${var_without_flag} PARENT_SCOPE) @@ -30,14 +30,18 @@ set(CMAKE_SHARED_LINKER_FLAGS_RELEASEWITHASSERT ${CMAKE_SHARED_LINKER_FLAGS_RELE #------------------------------------------------------------------------------ if (WIN32) - set(NAPPGUI_LIB_PREFIX "") - set(NAPPGUI_LIB_SUFFIX ".lib") + set(NAPPGUI_STATIC_LIB_PREFIX "") + set(NAPPGUI_STATIC_LIB_SUFFIX ".lib") + set(NAPPGUI_DYNAMIC_LIB_PREFIX "") + set(NAPPGUI_DYNAMIC_LIB_SUFFIX ".dll") unset(CMAKE_INSTALL_PREFIX CACHE) - if (${CMAKE_SIZEOF_VOID_P} MATCHES 4) - set(NAPPGUI_ARCH "x86") - elseif (${CMAKE_SIZEOF_VOID_P} MATCHES 8) - set(NAPPGUI_ARCH "x64") + if (${CMAKE_SIZEOF_VOID_P} STREQUAL 4) + set(NAPPGUI_HOST "x86") + set(NAPPGUI_ARCH "x86") + elseif (${CMAKE_SIZEOF_VOID_P} STREQUAL 8) + set(NAPPGUI_HOST "x64") + set(NAPPGUI_ARCH "x64") else () message (FATAL_ERROR "Unknown processor architecture") endif() @@ -80,7 +84,7 @@ if (WIN32) else() message(FATAL_ERROR "Unknown NAPPGUI_RUNTIME_LIBRARY property") endif() - + # Visual Studio properties string(REPLACE ";" " " AdditionalDefinitions "${AdditionalDefinitions}") string(REGEX REPLACE "/W[1-3]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast ${AdditionalDefinitions}") @@ -88,16 +92,14 @@ if (WIN32) add_definitions(-DUNICODE -D_UNICODE /nologo) # Package tool - set(CMAKE_PACKAGE FALSE CACHE BOOL "Pack executables On/Off") - set(CMAKE_PACKAGE_PATH "" CACHE PATH "Path to generated packages") - set(CMAKE_PACKAGE_GEN "NSIS" CACHE STRING "Package generator utility") - set_property(CACHE CMAKE_PACKAGE_GEN PROPERTY STRINGS "NSIS;TGZ") + # set(CMAKE_PACKAGE FALSE CACHE BOOL "Pack executables On/Off") + # set(CMAKE_PACKAGE_PATH "" CACHE PATH "Path to generated packages") + # set(CMAKE_PACKAGE_GEN "NSIS" CACHE STRING "Package generator utility") + # set_property(CACHE CMAKE_PACKAGE_GEN PROPERTY STRINGS "NSIS;TGZ") - # Enhanced instruction set x86 Processors + # Enhaced instruction set x86 Processors if (${NAPPGUI_ARCH} STREQUAL "x86") - if (Z${CMAKE_VS_PLATFORM_TOOLSET}Z STREQUAL "ZZ") - # add_definitions(/arch:SSE2) - elseif (${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v80") + if (${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v80") # Not Set in VS2005 is /arch:IA32 elseif (${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v90") add_definitions(/arch:SSE) @@ -114,10 +116,12 @@ if (WIN32) # Apple configuration #------------------------------------------------------------------------------ -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - set(NAPPGUI_LIB_PREFIX "lib") - set(NAPPGUI_LIB_SUFFIX ".a") + set(NAPPGUI_STATIC_LIB_PREFIX "lib") + set(NAPPGUI_STATIC_LIB_SUFFIX ".a") + set(NAPPGUI_DYNAMIC_LIB_PREFIX "lib") + set(NAPPGUI_DYNAMIC_LIB_SUFFIX ".dylib") set(OSX_SYSROOT ${CMAKE_OSX_SYSROOT}) unset(CMAKE_EXECUTABLE_FORMAT CACHE) unset(CMAKE_OSX_ARCHITECTURES CACHE) @@ -170,7 +174,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") #unset(CMAKE_STRIP CACHE) #unset(CMAKE_VERBOSE_MAKEFILE CACHE) #unset(CMAKE_USE_RELATIVE_PATHS CACHE) - + set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT}) # Xcode version, base SDK and deployment target @@ -178,7 +182,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") osxSDKName(${BASE_OSX_SDK} OSX_SDK_NAME) message(STATUS "- Xcode: ${XCODE_VERSION} SDK: ${BASE_OSX_SDK}-${OSX_SDK_NAME}") - + # Deployment target set(CMAKE_OSX_DEPLOYMENT_TARGET ${CMAKE_DEPLOYMENT_TARGET}) osxSDKName(${CMAKE_OSX_DEPLOYMENT_TARGET} OSX_SDK_NAME) @@ -186,7 +190,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") string(REPLACE "." "_" NAPPGUI_COMPILER_TOOLSET ${NAPPGUI_COMPILER_TOOLSET}) message(STATUS "- Deployment Target: ${CMAKE_OSX_DEPLOYMENT_TARGET}-${OSX_SDK_NAME}") - if (CMAKE_CXX_FLAGS MATCHES "/EHsc") + if (CMAKE_CXX_FLAGS STREQUAL "/EHsc") string(REGEX REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() @@ -228,10 +232,10 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") message(STATUS "- Host architecture: ${HOST_ARCH}") # Package tool - set(CMAKE_PACKAGE FALSE CACHE BOOL "Pack executables On/Off") - set(CMAKE_PACKAGE_PATH "" CACHE PATH "Path to generated packages") - set(CMAKE_PACKAGE_GEN "DragNDrop" CACHE STRING "Package generator utility") - set_property(CACHE CMAKE_PACKAGE_GEN PROPERTY STRINGS "DragNDrop;TGZ") + # set(CMAKE_PACKAGE FALSE CACHE BOOL "Pack executables On/Off") + # set(CMAKE_PACKAGE_PATH "" CACHE PATH "Path to generated packages") + # set(CMAKE_PACKAGE_GEN "DragNDrop" CACHE STRING "Package generator utility") + # set_property(CACHE CMAKE_PACKAGE_GEN PROPERTY STRINGS "DragNDrop;TGZ") # Libraries set(COCOA_LIB ${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/Cocoa.framework) @@ -239,7 +243,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") if (USE_UTTYPE) set(COCOA_LIB ${COCOA_LIB};${CMAKE_OSX_SYSROOT}/System/Library/Frameworks/UniformTypeIdentifiers.framework) endif() - + # NRC executable permissions set(NRC_FILE ${CMAKE_PRJ_PATH}/script/osx/${NAPPGUI_HOST}/nrc) file(TO_NATIVE_PATH \"${NRC_FILE}\" NRC_FILE) @@ -247,15 +251,17 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Linux configuration #------------------------------------------------------------------------------ -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set(NAPPGUI_LIB_PREFIX "lib") - set(NAPPGUI_LIB_SUFFIX ".a") + set(NAPPGUI_STATIC_LIB_PREFIX "lib") + set(NAPPGUI_STATIC_LIB_SUFFIX ".a") + set(NAPPGUI_DYNAMIC_LIB_PREFIX "lib") + set(NAPPGUI_DYNAMIC_LIB_SUFFIX ".so") find_program(LSB_RELEASE lsb_release) execute_process(COMMAND ${LSB_RELEASE} -is OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${LSB_RELEASE} -rs OUTPUT_VARIABLE LSB_RELEASE_VERSION_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) - + execute_process(COMMAND ${LSB_RELEASE} -rs OUTPUT_VARIABLE LSB_RELEASE_VERSION_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) + unset(LSB_RELEASE CACHE) unset(CMAKE_BUILD_TYPE CACHE) unset(CMAKE_ECLIPSE_EXECUTABLE CACHE) @@ -264,99 +270,97 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") unset(CMAKE_ECLIPSE_VERSION CACHE) unset(CMAKE_INSTALL_PREFIX CACHE) set(CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES FALSE) - + # GCC Version checkGCCVersion() message(STATUS "- Linux Platform: ${LSB_RELEASE_ID_SHORT} ${LSB_RELEASE_VERSION_SHORT}") - message(STATUS "- GCC compiler: ${CMAKE_CXX_COMPILER_VERSION}") - + message(STATUS "- GCC compiler: ${CMAKE_CXX_COMPILER_VERSION}") + # Warnings - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -std=c99 -fPIE") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++0x -fPIE") - + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -fPIE -Wno-long-long -Wno-overlength-strings -Wno-comment") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -fPIE") + + if(${CMAKE_VERSION} VERSION_LESS "3.1.0" OR ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "5.0.0") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu90") + endif() + # Host architecture set(HOST_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR}) if (${HOST_ARCH} STREQUAL "i386" OR ${HOST_ARCH} STREQUAL "i486" OR ${HOST_ARCH} STREQUAL "i586" OR ${HOST_ARCH} STREQUAL "i686") set(NAPPGUI_HOST x86) set(CMAKE_ARCHITECTURE "i386" CACHE STRING "Processor architecture") - set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS i386) - + set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS i386) + elseif (${HOST_ARCH} STREQUAL "x86_64") set(NAPPGUI_HOST x64) set(CMAKE_ARCHITECTURE "x64" CACHE STRING "Processor architecture") set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS i386 x64) - + elseif (${HOST_ARCH} STREQUAL "aarch64") - set(NAPPGUI_HOST aarch64) - set(CMAKE_ARCHITECTURE "aarch64" CACHE STRING "Processor architecture") - set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS aarch64) + set(NAPPGUI_HOST arm64) + set(CMAKE_ARCHITECTURE "arm64" CACHE STRING "Processor architecture") + set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS arm64) + + elseif (${HOST_ARCH} STREQUAL "armv7") + set(NAPPGUI_HOST arm) + set(CMAKE_ARCHITECTURE "arm" CACHE STRING "Processor architecture") + set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS arm) else() - string(FIND ${HOST_ARCH} "armv7" ARM_RES) - if (${ARM_RES} EQUAL -1) - message("- Unknown host architecture") - else() - set(NAPPGUI_HOST arm) - set(CMAKE_ARCHITECTURE "armv7" CACHE STRING "Processor architecture") - set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS armv7) - endif() + message(FATAL_ERROR "- Unknown host architecture") + endif() - # Architecture - if (CMAKE_ARCHITECTURE MATCHES "i386") - set(NAPPGUI_ARCH x86) + # Architecture + if (CMAKE_ARCHITECTURE STREQUAL "i386") + set(NAPPGUI_ARCH x86) set(IDE_PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long") - elseif (CMAKE_ARCHITECTURE MATCHES "x64") + elseif (CMAKE_ARCHITECTURE STREQUAL "x64") set(NAPPGUI_ARCH x64) set(IDE_PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-m64") - - elseif (CMAKE_ARCHITECTURE MATCHES "aarch64") - set(NAPPGUI_ARCH aarch64) + + elseif (CMAKE_ARCHITECTURE STREQUAL "aarch64") + set(NAPPGUI_ARCH arm64) set(IDE_PROPERTIES COMPILE_FLAGS " " LINK_FLAGS " ") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long") - elseif (CMAKE_ARCHITECTURE MATCHES "armv7") - set(NAPPGUI_RASPBIAN 1) - set(NAPPGUI_ARCH armv7) + elseif (CMAKE_ARCHITECTURE STREQUAL "armv7") + set(NAPPGUI_ARCH arm) set(IDE_PROPERTIES COMPILE_FLAGS "-march=armv7-a") - + else() message(FATAL_ERROR "Unknown processor architecture '${CMAKE_ARCHITECTURE}'") - + endif() message(STATUS "- Build architecture: ${CMAKE_ARCHITECTURE}") message(STATUS "- Host architecture: ${HOST_ARCH}") - + # Build configurations set(CMAKE_BUILD_CONFIG "Debug" CACHE STRING "Build configuration") set_property(CACHE CMAKE_BUILD_CONFIG PROPERTY STRINGS "Debug;Release;ReleaseWithAssert") - set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_CONFIG}) + set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_CONFIG}) message(STATUS "- Build Config: ${CMAKE_BUILD_TYPE}") # Package tool - set(CMAKE_PACKAGE FALSE CACHE BOOL "Pack executables On/Off") - set(CMAKE_PACKAGE_PATH "" CACHE PATH "Path to generated packages") - set(CMAKE_PACKAGE_GEN "TGZ" CACHE STRING "Package generator utility") - set_property(CACHE CMAKE_PACKAGE_GEN PROPERTY STRINGS "TGZ") + # set(CMAKE_PACKAGE FALSE CACHE BOOL "Pack executables On/Off") + # set(CMAKE_PACKAGE_PATH "" CACHE PATH "Path to generated packages") + # set(CMAKE_PACKAGE_GEN "TGZ" CACHE STRING "Package generator utility") + # set_property(CACHE CMAKE_PACKAGE_GEN PROPERTY STRINGS "TGZ") # ToolKit set(CMAKE_TOOLKIT "GTK3" CACHE STRING "User interface Toolkit") - set_property(CACHE CMAKE_TOOLKIT PROPERTY STRINGS "GTK3") - - # GTK3 Toolkit - if (${CMAKE_TOOLKIT} MATCHES "None") + set_property(CACHE CMAKE_TOOLKIT PROPERTY STRINGS "GTK3") + + # GTK3 Toolkit + if (${CMAKE_TOOLKIT} STREQUAL "None") message(STATUS "- Toolkit: None (command line projects only).") - elseif (${CMAKE_TOOLKIT} MATCHES "GTK3") + elseif (${CMAKE_TOOLKIT} STREQUAL "GTK3") message(STATUS "- Toolkit: Gtk+3") set(NAPPGUI_COMPILER_TOOLSET ${GCC_VERSION}_gtk3) - + else() message(FATAL_ERROR "Unknown toolkit ${CMAKE_TOOLKIT}") @@ -366,26 +370,8 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(NRC_FILE ${CMAKE_PRJ_PATH}/script/linux/${NAPPGUI_HOST}/nrc) file(TO_NATIVE_PATH \"${NRC_FILE}\" NRC_FILE) execute_process(COMMAND "chmod" "+x" "${NRC_FILE}") - - set(CMAKE_CODELITE_USE_TARGETS ON) - #find_package(PNG REQUIRED) - + else() message(FATAL_ERROR "Unknown Platform (${CMAKE_SYSTEM_NAME})") endif() - -# Check if toolset is available in distribution -#------------------------------------------------------------------------------ - -# We are in a binary dist -if (EXISTS ${CMAKE_LIB_PATH}) - if (NOT EXISTS ${CMAKE_LIB_PATH}/${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}) - message(STATUS "- The platform '${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}' is not supported by this distribution") - message(STATUS "- Please check '${CMAKE_LIB_PATH}' directory") - message(STATUS " and 'https://nappgui.com/en/start/win_mac_linux.html#h1'") - message(STATUS " to see the compilers you can use.") - message(FATAL_ERROR "You can't continue") - endif() -endif() - diff --git a/prj/CMakeFunctions.cmake b/prj/CMakeFunctions.cmake new file mode 100644 index 0000000..72408f1 --- /dev/null +++ b/prj/CMakeFunctions.cmake @@ -0,0 +1,1572 @@ +# CMake build functions script +# This file is part of NAppGUI-SDK project +# See README.txt and LICENSE.txt + +#------------------------------------------------------------------------------ + +function(getSubDirectories dir _ret) + set(dirList "") + + file(GLOB children RELATIVE ${dir} ${dir}/[a-zA-z_]*) + + foreach(child ${children}) + if(IS_DIRECTORY ${dir}/${child}) + list(APPEND dirList ${child}) + endif() + endforeach() + + set(${_ret} ${dirList} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------------ + +function(resourceGlobPatterns dir _ret) + set(list_res "") + + foreach (item ${RES_EXTENSION}) + list(APPEND list_res ${dir}/${item}) + endforeach() + + set(${_ret} ${list_res} PARENT_SCOPE) +endfunction() + +#------------------------------------------------------------------------------ + +function(isSourceSubDir subDirName _ret) + + string(TOLOWER ${subDirName} subDirLower) + if (${subDirLower} STREQUAL win) + if (WIN32) + set(${_ret} TRUE PARENT_SCOPE) + else() + set(${_ret} FALSE PARENT_SCOPE) + endif() + elseif (${subDirLower} STREQUAL unix) + if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" + OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(${_ret} TRUE PARENT_SCOPE) + else() + set(${_ret} FALSE PARENT_SCOPE) + endif() + elseif (${subDirLower} STREQUAL osx) + if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + set(${_ret} TRUE PARENT_SCOPE) + else() + set(${_ret} FALSE PARENT_SCOPE) + endif() + elseif (${subDirLower} STREQUAL linux) + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(${_ret} TRUE PARENT_SCOPE) + else() + set(${_ret} FALSE PARENT_SCOPE) + endif() + elseif (${subDirLower} STREQUAL gtk3) + if (CMAKE_TOOLKIT) + if (${CMAKE_TOOLKIT} STREQUAL "GTK3") + set(${_ret} TRUE PARENT_SCOPE) + else() + set(${_ret} FALSE PARENT_SCOPE) + endif() + else() + set(${_ret} FALSE PARENT_SCOPE) + endif() + elseif (${subDirLower} STREQUAL res) + set(${_ret} FALSE PARENT_SCOPE) + else () + set(${_ret} TRUE PARENT_SCOPE) + endif () + +endfunction() + +#------------------------------------------------------------------------------ + +function(appendSrcFile targetName file) + + if ("${${targetName}_SRCFILES}" STREQUAL "") + set(${targetName}_SRCFILES "${file}" CACHE INTERNAL "") + else() + list (FIND ${targetName}_SRCFILES ${file} index) + if (${index} EQUAL -1) + set(${targetName}_SRCFILES "${${targetName}_SRCFILES};${file}" CACHE INTERNAL "") + else() + message(FATAL_ERROR "Duplicated source file '${file}'") + endif() + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(appendPublicHeader targetName file extLower publicHeaders) + + if (publicHeaders) + list (FIND PUBLIC_HEADER_EXTENSION "*${extLower}" index) + if (${index} GREATER -1) + if ("${${targetName}_PUBLICHEADERS}" STREQUAL "") + set(${targetName}_PUBLICHEADERS "${file}" CACHE INTERNAL "") + else() + list (FIND ${targetName}_PUBLICHEADERS ${file} index) + if (${index} EQUAL -1) + set(${targetName}_PUBLICHEADERS "${${targetName}_PUBLICHEADERS};${file}" CACHE INTERNAL "") + else() + message(FATAL_ERROR "Duplicated public header file '${file}'") + endif() + endif() + endif() + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(appendSrcSubDir targetName subDir) + + if ("${${targetName}_SRCSUBDIRS}" STREQUAL "") + set(${targetName}_SRCSUBDIRS "${subDir}" CACHE INTERNAL "") + else() + list (FIND ${targetName}_SRCSUBDIRS ${subDir} index) + if (${index} EQUAL -1) + set(${targetName}_SRCSUBDIRS "${${targetName}_SRCSUBDIRS};${subDir}" CACHE INTERNAL "") + endif () + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(getRecursiveSourceFiles targetName dir group publicHeaders) + + file(GLOB children RELATIVE ${dir} ${dir}/[a-zA-z_]*) + + foreach(child ${children}) + if (IS_DIRECTORY ${dir}/${child}) + isSourceSubDir(${child} isSource) + if (${isSource}) + getRecursiveSourceFiles(${targetName} "${dir}/${child}" "${group}/${child}" FALSE) + endif() + else() + get_filename_component(ext ${child} EXT) + string(TOLOWER ${ext} extLower) + + # VisualStudio 2005 treat all .def files as module definitions + # Even if you mark then as headers + # .def files will not be shown as source files in VS2005 + if (${CMAKE_GENERATOR} STREQUAL "Visual Studio 8 2005" AND ${extLower} STREQUAL ".def") + set(index -1) + else() + list (FIND SRC_EXTENSION "*${extLower}" index) + endif() + + if (${index} GREATER -1) + string(REPLACE "/" "\\" groupname ${group}) + source_group(${groupname} FILES ${dir}/${child}) + + # Force header files 'Build errors with CMake >= 3.21.2' + # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5926 + list (FIND HEADER_EXTENSION "*${extLower}" index) + if (${index} GREATER -1) + set_source_files_properties(${dir}/${child} PROPERTIES HEADER_FILE_ONLY ON) + if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + set_source_files_properties(${dir}/${child} PROPERTIES XCODE_EXPLICIT_FILE_TYPE sourcecode.c.h) + endif() + endif() + + appendSrcSubDir(${targetName} ${dir}) + appendSrcFile(${targetName} ${dir}/${child}) + appendPublicHeader(${targetName} ${dir}/${child} ${extLower} ${publicHeaders}) + + endif() + + endif() + + endforeach() + +endfunction() + +#------------------------------------------------------------------------------ + +function(getResourceFiles targetName targetType dir _ret _include_dir) + # All resource files in package + set(res_files "") + set(resPath ${dir}/res) + + if (EXISTS ${resPath}) + # Process Win32 .rc files + if (targetType STREQUAL WIN_DESKTOP) + # VS2005 does not support .ico with 256 res + if(MSVC_VERSION EQUAL 1400 OR MSVC_VERSION LESS 1400) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/res.rc "APPLICATION_ICON ICON \"res\\\\logo48.ico\"\n") + set(globalRes ${CMAKE_CURRENT_BINARY_DIR}/res.rc ${resPath}/logo48.ico) + else() + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/res.rc "APPLICATION_ICON ICON \"res\\\\logo256.ico\"\n") + set(globalRes ${CMAKE_CURRENT_BINARY_DIR}/res.rc ${resPath}/logo256.ico) + endif() + endif() + + if (EXISTS ${resPath}/license.txt) + list(APPEND globalRes ${resPath}/license.txt) + endif() + + if (EXISTS ${resPath}/pack.txt) + list(APPEND globalRes ${resPath}/pack.txt) + endif() + + source_group(res FILES ${globalRes}) + list(APPEND res_files ${globalRes}) + + endif() + + # Target Resources + set(nrc_mode ${NAPPGUI_CACHE_TARGET_NRC_MODE_${targetName}}) + if (NOT ${nrc_mode} STREQUAL "NRC_NONE") + getSubDirectories(${resPath} resPackDirs) + + # Clean the resource destiny directory + set(DEST_RESDIR ${CMAKE_CURRENT_BINARY_DIR}/resgen) + set(CMAKE_OUTPUT ${DEST_RESDIR}/NRCLog.txt) + file(REMOVE_RECURSE ${DEST_RESDIR}) + file(MAKE_DIRECTORY ${DEST_RESDIR}) + + foreach(resPack ${resPackDirs}) + # Add resources to IDE + set(resPackPath ${resPath}/${resPack}) + resourceGlobPatterns(${resPackPath} resGlob) + file(GLOB resPackPathFiles ${resGlob}) + source_group("res\\${resPack}" FILES ${resPackPathFiles}) + list(APPEND res_files ${resPackPathFiles}) + + # Add localized resources to IDE + getSubDirectories(${resPath}/${resPack} resLocalDirs) + foreach(resLocalDir ${resLocalDirs}) + set(resLocalPath ${resPath}/${resPack}/${resLocalDir}) + resourceGlobPatterns(${resLocalPath} resLocalGlob) + file(GLOB resLocalPathFiles ${resLocalGlob}) + source_group("res\\${resPack}\\${resLocalDir}" FILES ${resLocalPathFiles}) + list(APPEND res_files ${resLocalPathFiles}) + endforeach() + + if (${nrc_mode} STREQUAL "NRC_EMBEDDED") + set(NRC_OPTION "-dc") + # '*.res' package will be copied in executable location + elseif (${nrc_mode} STREQUAL "NRC_PACKED") + set(NRC_OPTION "-dp") + else() + message (FATAL_ERROR "Unknown nrc mode") + endif() + + file(TO_NATIVE_PATH \"${CMAKE_NRC}\" CMAKE_NRC) + file(TO_NATIVE_PATH ${resPackPath} RESPACK_NATIVE) + file(TO_NATIVE_PATH ${DEST_RESDIR}/${resPack}.c RESDEST_NATIVE) + execute_process(COMMAND "${CMAKE_NRC}" "${NRC_OPTION}" "${RESPACK_NATIVE}" "${RESDEST_NATIVE}" RESULT_VARIABLE nrcRes OUTPUT_VARIABLE nrcOut ERROR_VARIABLE nrcErr) + file(APPEND ${CMAKE_OUTPUT} ${nrcOut}) + file(APPEND ${CMAKE_OUTPUT} ${nrcErr}) + if (NOT ${nrcRes} EQUAL "0") + if (${nrcRes} EQUAL "1") + message("- nrc '${resPack}' warnings (See ${CMAKE_OUTPUT})") + else() + message("- nrc '${resPack}' errors (${nrcRes}) (See ${CMAKE_OUTPUT})") + message("- ${nrcOut}") + message("- ${nrcErr}") + endif() + endif() + + list(APPEND resCompiled ${DEST_RESDIR}/${resPack}.c) + list(APPEND resCompiled ${DEST_RESDIR}/${resPack}.h) + source_group("res\\${resPack}\\gen" FILES ${resCompiled}) + + list(APPEND res_files ${resCompiled}) + + set(${_include_dir} ${DEST_RESDIR} PARENT_SCOPE) + + endforeach() + + endif() + + set(${_ret} ${res_files} PARENT_SCOPE) + +endfunction() + +#------------------------------------------------------------------------------ + +function(installResourcePacks targetName targetType sourceDir) + set (resourcePath ${sourceDir}/res) + toolsetName(toolset) + + # Apple Bundle always have a resource dir + if (targetType STREQUAL APPLE_BUNDLE) + set(resourceDestPath "../resources") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/${resourceDestPath}) + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/${resourceDestPath}/en.lproj) + + # Bundle icon + if (EXISTS ${resourcePath}/logo.icns) + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${resourcePath}/logo.icns $/${resourceDestPath}) + else() + message(WARNING "logo.icns doesn't exists in '${resourcePath}'") + endif() + + # Linux needs the app icon near the executable + elseif (targetType STREQUAL LINUX_DESKTOP) + + if (EXISTS ${resourcePath}/logo48.ico) + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${resourcePath}/logo48.ico $/${targetName}.ico) + + # Copy the icon into install directory + foreach(config ${CMAKE_CONFIGURATION_TYPES}) + install(FILES $/${targetName}.ico CONFIGURATIONS "${config}" DESTINATION "bin/${toolset}/${config}") + endforeach() + + else() + message(WARNING "logo48.ico doesn't exists in '${resourcePath}'") + endif() + + endif() + + set(nrc_mode ${NAPPGUI_CACHE_TARGET_NRC_MODE_${targetName}}) + if (nrc_mode) + if (${nrc_mode} STREQUAL "NRC_PACKED") + set(resPath ${sourceDir}/res) + set(DEST_RESDIR ${CMAKE_CURRENT_BINARY_DIR}/resgen) + + # Create 'res' directory for packed resources + # In the same location as executable + if (WIN32) + set(resRelative "res") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/${resRelative}) + + elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + # For macOS bundles, resource dir is created in 'macOSBundle' + set(resRelative "../resources") + + elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(resRelative "res") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/${resRelative}) + + else() + message(FATAL_ERROR "Unknown system") + + endif() + + getSubDirectories(${resPath} resPackDirs) + + # Create a 'res' directory in install bin dir (for 'PACKED' resource packages) + foreach(config ${CMAKE_CONFIGURATION_TYPES}) + install(DIRECTORY CONFIGURATIONS "${config}" DESTINATION "bin/${toolset}/${config}/res") + endforeach() + + # Copy all resource packs + foreach(resSubDir ${resPackDirs}) + add_custom_command(TARGET ${bundleName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${DEST_RESDIR}/${resSubDir}.res $/${resRelative}) + + # Copy the resource pack into install directory + foreach(config ${CMAKE_CONFIGURATION_TYPES}) + install(FILES ${DEST_RESDIR}/${resSubDir}.res CONFIGURATIONS "${config}" DESTINATION "bin/${toolset}/${config}/res") + endforeach() + + endforeach() + + endif() + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(getDirectDepends targetName _ret) + + if (NAPPGUI_CACHE_DEPENDS_${targetName}) + set(${_ret} ${NAPPGUI_CACHE_DEPENDS_${targetName}} PARENT_SCOPE) + + else() + set(${_ret} "" PARENT_SCOPE) + + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(appendIncludeDependency targetName depend) + + if ("${${targetName}_INCLUDEDEPENDS}" STREQUAL "") + set(${targetName}_INCLUDEDEPENDS "${depend}" CACHE INTERNAL "") + else() + list (FIND ${targetName}_INCLUDEDEPENDS ${depend} index) + if (${index} EQUAL -1) + set(${targetName}_INCLUDEDEPENDS "${${targetName}_INCLUDEDEPENDS};${depend}" CACHE INTERNAL "") + endif () + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(getRecursiveTargetIncludes targetName dependList) + + foreach(depend ${dependList}) + if (TARGET ${depend}) + appendIncludeDependency(${targetName} ${CMAKE_SRC_PATH}/${NAPPGUI_CACHE_LIBPATH_${depend}}) + getDirectDepends(${depend} childDependList) + elseif (EXISTS ${CMAKE_INC_PATH}/${NAPPGUI_CACHE_LIBPATH_${depend}}) + appendIncludeDependency(${targetName} ${CMAKE_INC_PATH}/${NAPPGUI_CACHE_LIBPATH_${depend}}) + getDirectDepends(${depend} childDependList) + + else() + # May exists binaries in 'lib' without include files + set(childDependList "") + + endif() + + if (childDependList) + getRecursiveTargetIncludes(${targetName} "${childDependList}") + endif() + + endforeach() + +endfunction() + +#------------------------------------------------------------------------------ + +function(targetDependsIncludeDirectories targetName firstLevelDepends) + + set(${targetName}_INCLUDEDEPENDS "" CACHE INTERNAL "") + getRecursiveTargetIncludes(${targetName} "${firstLevelDepends}") + + if (${targetName}_INCLUDEDEPENDS) + target_include_directories(${targetName} PUBLIC "${${targetName}_INCLUDEDEPENDS}") + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(toolsetName _ret) + + if (NOT NAPPGUI_COMPILER_TOOLSET) + message(FATAL_ERROR "NAPPGUI_COMPILER_TOOLSET Not Set") + endif() + + if (NOT NAPPGUI_ARCH) + message(FATAL_ERROR "NAPPGUI_ARCH Not Set") + endif() + + set(${_ret} "${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}" PARENT_SCOPE) + +endfunction() + +#------------------------------------------------------------------------------ + +function(processTarget targetName targetType dependList) + + # Get Files + set(${targetName}_SRCFILES "" CACHE INTERNAL "") + set(${targetName}_SRCSUBDIRS "" CACHE INTERNAL "") + set(${targetName}_PUBLICHEADERS "" CACHE INTERNAL "") + getRecursiveSourceFiles(${targetName} ${CMAKE_CURRENT_SOURCE_DIR} "src" TRUE) + set(srcFiles ${${targetName}_SRCFILES}) + set(srcSubDirs ${${targetName}_SRCSUBDIRS}) + set(publicHeaders ${${targetName}_PUBLICHEADERS}) + getResourceFiles(${targetName} ${targetType} ${CMAKE_CURRENT_SOURCE_DIR} resFiles resIncludeDir) + + # TARGET Build + if (targetType STREQUAL STATIC_LIB) + message(STATUS "- [OK] ${targetName}: Static library") + add_library(${targetName} STATIC ${srcFiles} ${resFiles}) + + # Clang, GNU, Intel, MSVC + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${targetName} PUBLIC "-fPIC") + endif() + + # Install the public headers + if (publicHeaders) + set_target_properties(${targetName} PROPERTIES PUBLIC_HEADER "${publicHeaders}") + endif() + + elseif (targetType STREQUAL DYNAMIC_LIB) + message(STATUS "- [OK] ${targetName}: Dynamic library") + add_library(${targetName} SHARED ${srcFiles} ${resFiles}) + set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS NAPPGUI_SHARED_LIB) + + # Clang, GNU, Intel, MSVC + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${targetName} PUBLIC "-fPIC;-fvisibility=hidden") + endif() + + # Install the public headers + if (publicHeaders) + set_target_properties(${targetName} PROPERTIES PUBLIC_HEADER "${publicHeaders}") + endif() + + elseif (targetType STREQUAL WIN_DESKTOP) + message(STATUS "- [OK] ${targetName}: Desktop application") + add_executable(${targetName} WIN32 ${srcFiles} ${resFiles}) + + elseif (targetType STREQUAL WIN_CONSOLE) + message(STATUS "- [OK] ${targetName}: Command-line application") + add_executable(${targetName} ${srcFiles} ${resFiles}) + + elseif (targetType STREQUAL APPLE_BUNDLE) + message(STATUS "- [OK] ${targetName}: Desktop application") + add_executable(${targetName} MACOSX_BUNDLE ${srcFiles} ${resFiles}) + + elseif (targetType STREQUAL APPLE_CONSOLE) + message(STATUS "- [OK] ${targetName}: Command-line application") + add_executable(${targetName} ${srcFiles} ${resFiles}) + + elseif (targetType STREQUAL LINUX_DESKTOP) + message(STATUS "- [OK] ${targetName}: Desktop application") + add_executable(${targetName} ${srcFiles} ${resFiles}) + + elseif (targetType STREQUAL LINUX_CONSOLE) + message(STATUS "- [OK] ${targetName}: Command-line application") + add_executable(${targetName} ${srcFiles} ${resFiles}) + + else() + message(FATAL_ERROR "Unknown target type") + + endif() + + # IDE Properties for TARGET + if (IDE_PROPERTIES) + set_target_properties(${targetName} PROPERTIES ${IDE_PROPERTIES}) + endif() + + # Output directories + foreach(config ${CMAKE_CONFIGURATION_TYPES}) + string(TOUPPER ${config} configUpper) + set_property(TARGET ${targetName} APPEND PROPERTY ARCHIVE_OUTPUT_DIRECTORY_${configUpper} "${CMAKE_BINARY_DIR}/${config}/lib") + set_property(TARGET ${targetName} APPEND PROPERTY LIBRARY_OUTPUT_DIRECTORY_${configUpper} "${CMAKE_BINARY_DIR}/${config}/bin") + set_property(TARGET ${targetName} APPEND PROPERTY RUNTIME_OUTPUT_DIRECTORY_${configUpper} "${CMAKE_BINARY_DIR}/${config}/bin") + endforeach() + + # Install binaries and headers + toolsetName(toolset) + targetSourceDir(${targetName} targetSource) + set(RTPERM "OWNER_READ;OWNER_WRITE;OWNER_EXECUTE;GROUP_READ;GROUP_EXECUTE;WORLD_READ;WORLD_EXECUTE") + foreach(config ${CMAKE_CONFIGURATION_TYPES}) + install(TARGETS ${targetName} CONFIGURATIONS "${config}" ARCHIVE DESTINATION "lib/${toolset}/${config}" PERMISSIONS ${RTPERM} LIBRARY DESTINATION "bin/${toolset}/${config}" PERMISSIONS ${RTPERM} RUNTIME DESTINATION "bin/${toolset}/${config}" PERMISSIONS ${RTPERM} BUNDLE DESTINATION "bin/${toolset}/${config}" PUBLIC_HEADER DESTINATION "inc/${targetSource}") + + # Install the .pdb files + if (targetType STREQUAL STATIC_LIB) + install(FILES "$/${targetName}.pdb" CONFIGURATIONS "${config}" DESTINATION "lib/${toolset}/${config}" PERMISSIONS ${RTPERM} OPTIONAL) + else() + install(FILES "$/${targetName}.pdb" CONFIGURATIONS "${config}" DESTINATION "bin/${toolset}/${config}" PERMISSIONS ${RTPERM} OPTIONAL) + endif() + + # Install the .exp files + # install(FILES "$/${targetName}.exp" CONFIGURATIONS "${config}" DESTINATION "lib/${toolset}/${config}" PERMISSIONS ${RTPERM} OPTIONAL) + + endforeach() + + # Resource packs + installResourcePacks(${targetName} ${targetType} ${CMAKE_CURRENT_SOURCE_DIR}) + + get_target_property(TARGET_TYPE ${targetName} TYPE) + + # Target Definitions + set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS $<$:CMAKE_DEBUG>) + set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS $<$:CMAKE_RELEASE>) + set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS $<$:CMAKE_RELEASEWITHASSERT>) + + if (WIN32) + # Visual Studio 2005/2008 doesn't have + if(MSVC_VERSION EQUAL 1500 OR MSVC_VERSION LESS 1500) + target_include_directories(${targetName} PUBLIC ${CMAKE_PRJ_PATH}/depend) + endif() + + # Platform toolset macro + set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS VS_PLATFORM=${VS_TOOLSET_NUMBER}) + + # Disable linker '4099' "pdb" warnings + # Disable linker '4098' mixed (static/dynamic) runtime library warnings + set_target_properties(${targetName} PROPERTIES LINK_FLAGS "/ignore:4099 /ignore:4098") + + endif() + + # GTK Include directories + if (CMAKE_TOOLKIT) + if (${CMAKE_TOOLKIT} STREQUAL "GTK3") + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/gtk3) + # Use the package PkgConfig to detect GTK+ headers/library files + find_package(PkgConfig REQUIRED) + pkg_check_modules(GTK3 REQUIRED gtk+-3.0) + target_include_directories(${targetName} PUBLIC ${GTK3_INCLUDE_DIRS}) + set_target_properties(${targetName} PROPERTIES COMPILE_FLAGS "-D__GTK3_TOOLKIT__") + endif() + endif() + endif() + + # TARGET local directory include + target_include_directories(${targetName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + + # Include dir for target generated resources + if (resIncludeDir) + target_include_directories(${targetName} PUBLIC ${resIncludeDir}) + endif() + + if (dependList) + foreach(dependency ${dependList}) + get_filename_component(dependencyName ${dependency} NAME) + if (TARGET ${dependencyName}) + add_dependencies(${targetName} ${dependencyName}) + endif() + endforeach() + + # Recursive directory includes + targetDependsIncludeDirectories(${targetName} "${dependList}") + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(targetRPath targetName isMacOsBundle rpath) + + if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(RUNPATH "\${ORIGIN}") + + foreach(path ${rpath}) + set (RUNPATH "${RUNPATH}:${path}") + endforeach(path ) + + # Will disable the CMake automatic setting of the RPATH + # RPaths included in target will be the current directory (ORIGIN) + # and the provided in 'rpath' parameter + set_property(TARGET ${targetName} PROPERTY SKIP_BUILD_RPATH FALSE) + set_property(TARGET ${targetName} PROPERTY BUILD_WITH_INSTALL_RPATH TRUE) + set_property(TARGET ${targetName} PROPERTY INSTALL_RPATH "${RUNPATH}") + + elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + # otool -L libdraw2d.dylib + # @rpath/libgeom2d.dylib (compatibility version 0.0.0, current version 0.0.0) + # Force to use paths relative to @rpath in dylibs and execs + set_property(TARGET ${targetName} PROPERTY MACOSX_RPATH TRUE) + + if (isMacOsBundle) + set(RUNPATH "@executable_path/../../..") + else() + set(RUNPATH "@executable_path/.") + endif() + + set_property(TARGET ${targetName} PROPERTY SKIP_BUILD_RPATH FALSE) + set_property(TARGET ${targetName} PROPERTY BUILD_RPATH ${RUNPATH}) + set_property(TARGET ${targetName} PROPERTY INSTALL_RPATH ${RUNPATH}) + + # Delete Build RPATH manually (only if bundle have dynamic lib dependencies) + # if (isMacOsBundle) + # add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -delete_rpath "${CMAKE_BINARY_DIR}/$/bin" $) + # endif() + + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(targetOptions targetName options) + set(c_lang_standard "90") + set(cxx_lang_standard "98") + + foreach(opt ${options}) + + if (${opt} STREQUAL "C90") + set(c_lang_standard "90") + + elseif(${opt} STREQUAL "C99") + set(c_lang_standard "99") + + elseif(${opt} STREQUAL "C11") + set(c_lang_standard "11") + + elseif(${opt} STREQUAL "C17") + # New in version 3.21. + if(${CMAKE_VERSION} VERSION_GREATER "3.20.999") + set(c_lang_standard "17") + else() + set(c_lang_standard "11") + endif() + + elseif(${opt} STREQUAL "C23") + # New in version 3.21. + if(${CMAKE_VERSION} VERSION_GREATER "3.20.999") + set(c_lang_standard "23") + else() + set(c_lang_standard "11") + endif() + + elseif(${opt} STREQUAL "C++98") + set(cxx_lang_standard "98") + + elseif(${opt} STREQUAL "C++11") + set(cxx_lang_standard "11") + + elseif(${opt} STREQUAL "C++14") + set(cxx_lang_standard "14") + + elseif(${opt} STREQUAL "C++17") + # New in version 3.8. + if(${CMAKE_VERSION} VERSION_GREATER "3.7.999") + set(cxx_lang_standard "17") + else() + set(cxx_lang_standard "14") + endif() + + elseif(${opt} STREQUAL "C++20") + # New in version 3.12. + if(${CMAKE_VERSION} VERSION_GREATER "3.11.999") + set(cxx_lang_standard "20") + elseif(${CMAKE_VERSION} VERSION_GREATER "3.7.999") + set(cxx_lang_standard "17") + else() + set(cxx_lang_standard "14") + endif() + + elseif(${opt} STREQUAL "C++23") + # New in version 3.20. + if(${CMAKE_VERSION} VERSION_GREATER "3.19.999") + set(cxx_lang_standard "23") + elseif(${CMAKE_VERSION} VERSION_GREATER "3.11.999") + set(cxx_lang_standard "20") + elseif(${CMAKE_VERSION} VERSION_GREATER "3.7.999") + set(cxx_lang_standard "17") + else() + set(cxx_lang_standard "14") + endif() + + endif() + + endforeach() + + # Language standard support in CMake 3.1 + if(${CMAKE_VERSION} VERSION_GREATER "3.0.999") + set_property(TARGET ${targetName} PROPERTY C_STANDARD ${c_lang_standard}) + set_property(TARGET ${targetName} PROPERTY CXX_STANDARD ${cxx_lang_standard}) + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(processStaticLib libName dependList) + set(dependencies "") + list(APPEND dependencies "${dependList}") + processTarget("${libName}" "STATIC_LIB" "${dependencies}") + + # In Linux, static libs must link with other libs + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + targetLinkWithLibraries(${libName} "${dependencies}") + endif() + + targetOptions(${libName} "${options}") + +endfunction() + +#------------------------------------------------------------------------------ + +function(processDynamicLib libName dependList) + set(dependencies "") + list(APPEND dependencies "${dependList}") + processTarget("${libName}" "DYNAMIC_LIB" "${dependList}") + targetLinkWithLibraries(${libName} "${dependencies}") + targetOptions(${libName} "${options}") + targetRPath(${libName} NO "") + +endfunction() + +#------------------------------------------------------------------------------ + +function(windowsBundle bundleName bundleType dependList) + processTarget("${bundleName}" "${bundleType}" "${dependList}") +endfunction() + +#------------------------------------------------------------------------------ + +function(bundleProp bundleName property value) + # Fails in XCode 3.2, 4 + # /bin/bash -c "plutil -replace NSHumanReadableCopyright -string 2019\ NAppGUI .../Info.plist" + # unrecognized option: -replace + if(${XCODE_VERSION} VERSION_GREATER "5.99") + add_custom_command(TARGET ${bundleName} POST_BUILD COMMAND /bin/bash -c \"plutil -replace ${property} -string "${value}" $/../Info.plist\") + endif() +endfunction() + +#------------------------------------------------------------------------------ + +function(macOSBundle bundleName dependList) + + processTarget("${bundleName}" APPLE_BUNDLE "${dependList}") + + # Info.plist configure + # Proyect provides its own Info.plist? + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) + set_target_properties(${bundleName} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) + # Use default template + else() + set_target_properties(${bundleName} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_PRJ_PATH}/templates/Info.plist) + endif() + + # Overwrite some properties + # bundleProp(${bundleName} "NSHumanReadableCopyright" "${CURRENT_YEAR} ${PACK_VENDOR}") + # bundleProp(${bundleName} "CFBundleVersion" "${PACK_VERSION}") + +endfunction() + +#------------------------------------------------------------------------------ + +function(linuxBundle bundleName dependList) + processTarget("${bundleName}" LINUX_DESKTOP "${dependList}") + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) + set_target_properties(${bundleName} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}") +endfunction() + +#------------------------------------------------------------------------------ + +function(appendLinkDependency targetName depend) + + if ("${${targetName}_LINKDEPENDS}" STREQUAL "") + set(${targetName}_LINKDEPENDS "${depend}" CACHE INTERNAL "") + else() + set(${targetName}_LINKDEPENDS "${${targetName}_LINKDEPENDS};${depend}" CACHE INTERNAL "") + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(existsPrecompiledStaticLib libName _ret) + + foreach(config ${CMAKE_CONFIGURATION_TYPES}) + set(libBinPath ${CMAKE_LIB_PATH}/${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}/${config}/${NAPPGUI_STATIC_LIB_PREFIX}${libName}${NAPPGUI_STATIC_LIB_SUFFIX}) + if (EXISTS ${libBinPath}) + set(${_ret} "TRUE" PARENT_SCOPE) + return() + endif() + endforeach() + + set(${_ret} "FALSE" PARENT_SCOPE) + +endfunction() + +#------------------------------------------------------------------------------ + +function(existsPrecompiledDynamicLib libName _ret) + + foreach(config ${CMAKE_CONFIGURATION_TYPES}) + set(libBinPath ${CMAKE_BIN_PATH}/${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}/${config}/${NAPPGUI_DYNAMIC_LIB_PREFIX}${libName}${NAPPGUI_DYNAMIC_LIB_SUFFIX}) + if (EXISTS ${libBinPath}) + set(${_ret} "TRUE" PARENT_SCOPE) + return() + endif() + endforeach() + + set(${_ret} "FALSE" PARENT_SCOPE) + +endfunction() + +#------------------------------------------------------------------------------ + +function(getRecursiveTargetLinks targetName dependList) + + foreach(depend ${dependList}) + # Dependency is a Target of this solution + if (TARGET ${depend}) + get_target_property(TARGET_TYPE ${depend} TYPE) + if (${TARGET_TYPE} STREQUAL "STATIC_LIBRARY" OR ${TARGET_TYPE} STREQUAL "SHARED_LIBRARY") + appendLinkDependency(${targetName} ${depend}) + getDirectDepends(${depend} childDependList) + else() + message(FATAL_ERROR "- ${targetName}: Unknown dependency type '${depend}-${TARGET_TYPE}'") + endif () + + else() + existsPrecompiledDynamicLib(${depend} existsDynamic) + existsPrecompiledStaticLib(${depend} existsStatic) + + # Dependency is a precompiled dynamic library + if (existsDynamic) + if (WIN32) + if (NOT existsStatic) + message(FATAL_ERROR "- ${targetName}: Dinamic dependency '${depend}' has not present .lib import library.") + endif() + endif() + + appendLinkDependency(${targetName} "__DYNAMIC_LIB__${depend}") + getDirectDepends(${depend} childDependList) + + # Dependency is a precompiled static library + elseif (existsStatic) + appendLinkDependency(${targetName} "__STATIC_LIB__${depend}") + getDirectDepends(${depend} childDependList) + + else() + message(FATAL_ERROR "- ${targetName}: Unknown dependency '${depend}'") + + endif() + + endif() + + if (childDependList) + getRecursiveTargetLinks(${targetName} "${childDependList}") + endif() + + endforeach() + +endfunction() + +#------------------------------------------------------------------------------ + +function(targetSourceDir targetName _ret) + set(${_ret} "" PARENT_SCOPE) + foreach(path ${NAPPGUI_CACHE_SOURCE_DIRECTORIES}) + list (FIND NAPPGUI_CACHE_PATH_TARGETS_${path} ${targetName} index) + if (NOT ${index} EQUAL -1) + set(${_ret} ${path} PARENT_SCOPE) + return() + endif() + endforeach() +endfunction() + +#------------------------------------------------------------------------------ + +function(targetDependOnLib targetName libName _ret) + + set(${_ret} "NO" PARENT_SCOPE) + targetSourceDir(${targetName} targetDir) + targetSourceDir(${libName} libDir) + + if (${targetDir} STREQUAL "${libDir}") + set(${_ret} "YES" PARENT_SCOPE) + return() + endif() + + foreach(depend ${${targetName}_LINKDEPENDS}) + + if (depend MATCHES "__STATIC_LIB__*") + string(SUBSTRING ${depend} 14 -1 dependName) + elseif(depend MATCHES "__DYNAMIC_LIB__*") + string(SUBSTRING ${depend} 15 -1 dependName) + else() + set(dependName ${depend}) + endif() + + targetSourceDir(${dependName} dependDir) + if (${dependDir} STREQUAL "${libDir}") + set(${_ret} "YES" PARENT_SCOPE) + return() + endif() + + endforeach() + +endfunction() + +#------------------------------------------------------------------------------ + +function(installPrecompiledSharedLibrary targetName libName) + set(DYNLIB_SOURCE "${CMAKE_BIN_PATH}/${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}/$/${NAPPGUI_DYNAMIC_LIB_PREFIX}${libName}${NAPPGUI_DYNAMIC_LIB_SUFFIX}") + set(DEST_PATH "${CMAKE_BINARY_DIR}/$/bin/${NAPPGUI_DYNAMIC_LIB_PREFIX}${libName}${NAPPGUI_DYNAMIC_LIB_SUFFIX}") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DYNLIB_SOURCE} ${DEST_PATH}) +endfunction() + +#------------------------------------------------------------------------------ + +function(targetLinkWithLibraries targetName firstLevelDepends) + + set(${targetName}_LINKDEPENDS "" CACHE INTERNAL "") + getRecursiveTargetLinks(${targetName} "${firstLevelDepends}") + get_target_property(TARGET_TYPE ${targetName} TYPE) + + toolsetName(toolset) + + if (${targetName}_LINKDEPENDS) + + foreach(depend ${${targetName}_LINKDEPENDS}) + set(DEPEND_IS_SHAREDLIB FALSE) + + # The dependency is a precompiled static library + if (depend MATCHES "__STATIC_LIB__*") + string(SUBSTRING ${depend} 14 -1 dependName) + set(linkerName ${CMAKE_LIB_PATH}/${toolset}/$/${NAPPGUI_STATIC_LIB_PREFIX}${dependName}${NAPPGUI_STATIC_LIB_SUFFIX}) + + # The dependency is a precompiled dynamic library + elseif(depend MATCHES "__DYNAMIC_LIB__*") + string(SUBSTRING ${depend} 15 -1 dependName) + # In Win32 dynamic libraries link with .lib (static symbol-export library) + if (WIN32) + set(linkerName ${CMAKE_LIB_PATH}/${toolset}/$/${NAPPGUI_STATIC_LIB_PREFIX}${dependName}${NAPPGUI_STATIC_LIB_SUFFIX}) + + elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + set(linkerName ${CMAKE_BIN_PATH}/${toolset}/$/${NAPPGUI_DYNAMIC_LIB_PREFIX}${dependName}${NAPPGUI_DYNAMIC_LIB_SUFFIX}) + + endif() + + # Copy the precompiled shared library into executable directory + if (${TARGET_TYPE} STREQUAL "EXECUTABLE") + installPrecompiledSharedLibrary(${targetName} ${dependName}) + endif() + + set(DEPEND_IS_SHAREDLIB TRUE) + + # The dependency is a target + else() + set(linkerName ${depend}) + set(dependName ${depend}) + get_target_property(DEPEND_TARGET_TYPE ${depend} TYPE) + if (${DEPEND_TARGET_TYPE} STREQUAL "SHARED_LIBRARY") + set(DEPEND_IS_SHAREDLIB TRUE) + endif() + + endif() + + if (linkerName) + target_link_libraries(${targetName} ${linkerName}) + else() + message(FATAL_ERROR "Cannot resolve the dependendy ${depend} for target ${targetName}") + endif() + + # If target depends on shared library, we define the 'TARGET_IMPORT' preprocessor macro + if (DEPEND_IS_SHAREDLIB) + targetSourceDir(${dependName} targetPath) + get_filename_component(targetSource ${targetPath} NAME) + string(TOUPPER ${targetSource} targetSourceUpper) + set(TARGET_IMPORT ${targetSourceUpper}_IMPORT) + set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS ${TARGET_IMPORT}) + endif() + + endforeach() + + endif() + + # Target should link with math + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + target_link_libraries(${targetName} "m") + endif() + + # Target should link with pthread + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + targetDependOnLib(${targetName} "osbs" _depends) + if (_depends) + find_package(Threads) + if (Threads_FOUND) + target_link_libraries(${targetName} ${CMAKE_THREAD_LIBS_INIT}) + else() + message(ERROR "- PThread library not found") + endif() + + target_link_libraries(${targetName} ${CMAKE_DL_LIBS}) + endif() + endif() + + # Target should link with GTK3 + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + if (${CMAKE_TOOLKIT} STREQUAL "GTK3") + targetDependOnLib(${targetName} "draw2d" _depends) + if (_depends) + # Use the package PkgConfig to detect GTK+ headers/library files + find_package(PkgConfig REQUIRED) + pkg_check_modules(GTK3 REQUIRED gtk+-3.0) + target_link_libraries(${targetName} ${GTK3_LIBRARIES}) + endif() + endif() + endif() + + # Target should link with libCurl + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + targetDependOnLib(${targetName} "inet" _depends) + if (_depends) + find_package(CURL) + if (${CURL_FOUND}) + target_link_libraries(${targetName} ${CURL_LIBRARY}) + else() + message(ERROR "- libCURL is required. Try 'sudo apt-get install libcurl4-openssl-dev'") + endif() + endif() + endif() + + # Target should link with Cocoa + if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + targetDependOnLib(${targetName} "draw2d" _depends1) + targetDependOnLib(${targetName} "inet" _depends2) + if (_depends1 OR _depends2) + if (NOT ${TARGET_TYPE} STREQUAL "STATIC_LIBRARY") + target_link_libraries(${targetName} ${COCOA_LIB}) + endif() + endif() + endif() + + # In GCC the g++ linker must be used + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + set_target_properties(${targetName} PROPERTIES LINKER_LANGUAGE CXX) + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(readPackFile) + + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/res/pack.txt) + file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/res/pack.txt PackContents) + foreach(NameAndValue ${PackContents}) + # Strip leading spaces + string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) + # Find variable name + string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) + # Find the value + string(REPLACE "${Name}=" "" Value ${NameAndValue}) + # Set the variable + set(PACK_${Name} "${Value}" PARENT_SCOPE) + endforeach() + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(installerScript targetName platform generator config) + set(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/CPack-${targetName}-${config}.cmake) + file(WRITE ${SCRIPT} "# CPack script for ${targetName} project\n") + file(APPEND ${SCRIPT} "# Automatic generated by NAppGUI\n") + file(APPEND ${SCRIPT} "# You can configure the installer from /res/pack.txt\n") + file(APPEND ${SCRIPT} "set(CPACK_GENERATOR \"${generator}\")\n") + file(APPEND ${SCRIPT} "set(CPACK_INSTALLED_DIRECTORIES \"${CMAKE_CURRENT_BINARY_DIR}/${config};.\")\n") + file(APPEND ${SCRIPT} "set(CPACK_SYSTEM_NAME \"${platform}_${NAPPGUI_ARCH}\")\n") + file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_NAME \"${targetName}\")\n") + file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_VENDOR \"${PACK_VENDOR}\")\n") + file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_VERSION \"${PACK_VERSION}\")\n") + file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_DESCRIPTION \"${PACK_DESC}\")\n") + file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_FILE_NAME \"\${CPACK_PACKAGE_NAME}\")\n") + #file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_FILE_NAME \"\${CPACK_PACKAGE_NAME}-\${CPACK_PACKAGE_VERSION}-\${CPACK_SYSTEM_NAME}\")\n") + file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY \"\${PACK_VENDOR}/\${CPACK_PACKAGE_NAME}-${NAPPGUI_ARCH}\")\n") + + if (${generator} STREQUAL "NSIS") + file(APPEND ${SCRIPT} "\n") + file(APPEND ${SCRIPT} "# NSIS generator specific options\n") + file(APPEND ${SCRIPT} "set(CPACK_NSIS_PACKAGE_NAME \"\${CPACK_PACKAGE_FILE_NAME}\")\n") + file(APPEND ${SCRIPT} "set(CPACK_NSIS_DISPLAY_NAME \"\${CPACK_PACKAGE_NAME} (${NAPPGUI_ARCH})\")\n") + file(APPEND ${SCRIPT} "set(CPACK_NSIS_MUI_ICON \"${CMAKE_CURRENT_SOURCE_DIR}/res\\\\logo256.ico\")\n") + file(APPEND ${SCRIPT} "set(CPACK_NSIS_MUI_UNIICON \"${CMAKE_CURRENT_SOURCE_DIR}/res\\\\logo256.ico\")\n") + file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_ICON \"${CMAKE_CURRENT_SOURCE_DIR}/res\\\\banner.bmp\")\n") + file(APPEND ${SCRIPT} "set(CPACK_RESOURCE_FILE_LICENSE \"${CMAKE_CURRENT_SOURCE_DIR}/res/license.txt\")\n") + + if (${NAPPGUI_ARCH} STREQUAL "x64") + file(APPEND ${SCRIPT} "set(CPACK_NSIS_INSTALL_ROOT \"\$PROGRAMFILES64\\\\\${CPACK_PACKAGE_VENDOR}\\\\\${CPACK_PACKAGE_NAME}\")\n") + else() + file(APPEND ${SCRIPT} "set(CPACK_NSIS_INSTALL_ROOT \"\$PROGRAMFILES\\\\\${CPACK_PACKAGE_VENDOR}\\\\\${CPACK_PACKAGE_NAME}\")\n") + endif() + + file(APPEND ${SCRIPT} "set(CPACK_NSIS_INSTALLED_ICON_NAME \"\${CPACK_PACKAGE_NAME}.exe\")\n") + file(APPEND ${SCRIPT} "set(CPACK_NSIS_MENU_LINKS \"\${CPACK_PACKAGE_NAME}.exe\" \"\${CPACK_PACKAGE_NAME} (${NAPPGUI_ARCH})\")\n") + file(APPEND ${SCRIPT} "set(CPACK_NSIS_DEFINES \"!define MUI_STARTMENUPAGE_DEFAULTFOLDER \\\\\${CPACK_PACKAGE_VENDOR}\\\\\${CPACK_PACKAGE_NAME}\")\n") + + elseif (${generator} STREQUAL "DragNDrop") + file(APPEND ${SCRIPT} "set(CPACK_DMG_VOLUME_NAME \"\${CPACK_PACKAGE_NAME}\")\n") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/license.txt ${CMAKE_CURRENT_BINARY_DIR}/$) + + elseif (${generator} STREQUAL "TGZ") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/license.txt ${CMAKE_CURRENT_BINARY_DIR}/$) + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(processInstaller targetName) + if (CMAKE_PACKAGE_PATH) + + if (NOT EXISTS ${CMAKE_PACKAGE_PATH}/Debug) + file(MAKE_DIRECTORY ${CMAKE_PACKAGE_PATH}/Debug) + endif() + + if (NOT EXISTS ${CMAKE_PACKAGE_PATH}/Release) + file(MAKE_DIRECTORY ${CMAKE_PACKAGE_PATH}/Release) + endif() + + if (NOT EXISTS ${CMAKE_PACKAGE_PATH}/ReleaseWithAssert) + file(MAKE_DIRECTORY ${CMAKE_PACKAGE_PATH}/ReleaseWithAssert) + endif() + + if (WIN32) + installerScript(${targetName} "win" ${CMAKE_PACKAGE_GEN} "Debug") + installerScript(${targetName} "win" ${CMAKE_PACKAGE_GEN} "Release") + installerScript(${targetName} "win" ${CMAKE_PACKAGE_GEN} "ReleaseWithAssert") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND cd ${CMAKE_PACKAGE_PATH}/$ & cpack --config ${CMAKE_CURRENT_BINARY_DIR}/CPack-${targetName}-$.cmake) + + elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + installerScript(${targetName} "macos" ${CMAKE_PACKAGE_GEN} "Debug") + installerScript(${targetName} "macos" ${CMAKE_PACKAGE_GEN} "Release") + installerScript(${targetName} "macos" ${CMAKE_PACKAGE_GEN} "ReleaseWithAssert") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND /bin/bash -c \"cd ${CMAKE_PACKAGE_PATH}/$ && ${CPACK_COMMAND} --config ${CMAKE_CURRENT_BINARY_DIR}/CPack-${targetName}-$.cmake\") + + else() + installerScript(${targetName} "linux" ${CMAKE_PACKAGE_GEN} "Debug") + installerScript(${targetName} "linux" ${CMAKE_PACKAGE_GEN} "Release") + installerScript(${targetName} "linux" ${CMAKE_PACKAGE_GEN} "ReleaseWithAssert") + add_custom_command(TARGET ${targetName} POST_BUILD COMMAND /bin/bash -c \"cd ${CMAKE_PACKAGE_PATH}/$ && ${CPACK_COMMAND} --config ${CMAKE_CURRENT_BINARY_DIR}/CPack-${targetName}-$.cmake\") + + endif() + else() + message("- ${targetName}: set CMAKE_PACKAGE_PATH to create packages") + endif() +endfunction() + +#------------------------------------------------------------------------------ + +function(processDesktopApp appName dependList options) + + readPackFile() + set(dependencies "") + list(APPEND dependencies "${dependList}") + if (WIN32) + windowsBundle(${appName} WIN_DESKTOP "${dependencies}") + set_target_properties(${appName} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS") + set_target_properties(${appName} PROPERTIES LINK_FLAGS_RELASE "/SUBSYSTEM:WINDOWS") + set_target_properties(${appName} PROPERTIES LINK_FLAGS_RELASEWITHASSERT "/SUBSYSTEM:WINDOWS") + set(macOSBundle NO) + elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + macOSBundle(${appName} "${dependencies}") + set(macOSBundle YES) + + elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + linuxBundle(${appName} "${dependencies}") + set(macOSBundle NO) + + else() + message("Unknown platform") + + endif() + + targetLinkWithLibraries(${appName} "${dependencies}") + targetOptions(${appName} "${options}") + targetRPath(${appName} ${macOSBundle} "") + + if (${CMAKE_PACKAGE}) + processInstaller(${appName}) + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(macOSCommand appName dependList) + processTarget("${appName}" APPLE_CONSOLE "${dependList}") +endfunction() + +#------------------------------------------------------------------------------ + +function(linuxCommand appName dependList) + processTarget("${appName}" LINUX_CONSOLE "${dependList}") +endfunction() + +#------------------------------------------------------------------------------ + +function(processCommandApp appName dependList options) + + set(dependencies "") + list(APPEND dependencies "${dependList}") + + if (WIN32) + windowsBundle(${appName} WIN_CONSOLE "${dependencies}") + set_target_properties(${appName} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") + set_target_properties(${appName} PROPERTIES LINK_FLAGS_RELASE "/SUBSYSTEM:CONSOLE") + set_target_properties(${appName} PROPERTIES LINK_FLAGS_RELEASEWITHASSERT "/SUBSYSTEM:CONSOLE") + + elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + macOSCommand("${appName}" "${dependencies}") + + elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + linuxCommand("${appName}" "${dependencies}") + + else() + message(ERROR "- ${appName} Unknown system") + + endif() + + targetLinkWithLibraries(${appName} "${dependencies}") + targetOptions(${appName} "${options}") + targetRPath(${appName} NO "") + +endfunction() + +#------------------------------------------------------------------------------ + +function(setTargetFilter targetName targetPath) + + get_filename_component(filter ${targetPath} PATH) + + if (filter) + set_target_properties(${targetName} PROPERTIES FOLDER ${filter}) + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(addTargetCache targetName targetPath nrcMode) + + # Add a new target to target list + if (NAPPGUI_CACHE_TARGETS) + list (FIND NAPPGUI_CACHE_TARGETS ${targetName} index) + if (${index} EQUAL -1) + set(NAPPGUI_CACHE_TARGETS "${NAPPGUI_CACHE_TARGETS};${targetName}" CACHE INTERNAL "") + else() + message(FATAL_ERROR "Target: ${targetName} already defined.") + endif() + else() + set(NAPPGUI_CACHE_TARGETS "${targetName}" CACHE INTERNAL "") + endif() + + # Append the path to sources + set(FIRST_TARGET_IN_PATH False) + if (NAPPGUI_CACHE_SOURCE_DIRECTORIES) + list (FIND NAPPGUI_CACHE_SOURCE_DIRECTORIES ${targetPath} index) + if (${index} EQUAL -1) + set(NAPPGUI_CACHE_SOURCE_DIRECTORIES "${NAPPGUI_CACHE_SOURCE_DIRECTORIES};${targetPath}" CACHE INTERNAL "") + set(NAPPGUI_CACHE_PATH_TARGETS_${targetPath} "" CACHE INTERNAL "") + set(FIRST_TARGET_IN_PATH True) + endif() + + else() + set(NAPPGUI_CACHE_SOURCE_DIRECTORIES "${targetPath}" CACHE INTERNAL "") + set(NAPPGUI_CACHE_PATH_TARGETS_${targetPath} "" CACHE INTERNAL "") + set(FIRST_TARGET_IN_PATH True) + + endif() + + if (FIRST_TARGET_IN_PATH) + # The target can be a precompiled one + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${targetPath}) + file(REMOVE "${targetPath}/CMakeLists.txt") + endif() + endif() + + # Append the target to this source path + if (NAPPGUI_CACHE_PATH_TARGETS_${targetPath}) + set(NAPPGUI_CACHE_PATH_TARGETS_${targetPath} "${NAPPGUI_CACHE_PATH_TARGETS_${targetPath}};${targetName}" CACHE INTERNAL "") + else() + set(NAPPGUI_CACHE_PATH_TARGETS_${targetPath} "${targetName}" CACHE INTERNAL "") + endif() + + # Set NRC mode for target + set(NAPPGUI_CACHE_TARGET_NRC_MODE_${targetName} ${nrcMode} CACHE INTERNAL "") + +endfunction() + +#------------------------------------------------------------------------------ + +function(createLibFiles libPath dependencies) + + get_filename_component(libName ${libPath} NAME) + set(libPathName ${libPath}/${libName}) + string(TOUPPER ${libName} libNameUpper) + + # New directory + file(MAKE_DIRECTORY ${libPath}) + + # lib.def file + file(WRITE ${libPathName}.def "/* ${libName} library import/export */\n\n") + file(APPEND ${libPathName}.def "#if defined(${libNameUpper}_IMPORT)\n") + file(APPEND ${libPathName}.def " #if defined(__GNUC__)\n") + file(APPEND ${libPathName}.def " #define _${libName}_api\n") + file(APPEND ${libPathName}.def " #elif defined(_MSC_VER)\n") + file(APPEND ${libPathName}.def " #define _${libName}_api __declspec(dllimport)\n") + file(APPEND ${libPathName}.def " #else\n") + file(APPEND ${libPathName}.def " #error Unknown compiler\n") + file(APPEND ${libPathName}.def " #endif\n") + file(APPEND ${libPathName}.def "#elif defined(NAPPGUI_SHARED_LIB)\n") + file(APPEND ${libPathName}.def " #if defined(__GNUC__)\n") + file(APPEND ${libPathName}.def " #define _${libName}_api __attribute__((visibility(\"default\")))\n") + file(APPEND ${libPathName}.def " #elif defined(_MSC_VER)\n") + file(APPEND ${libPathName}.def " #define _${libName}_api __declspec(dllexport)\n") + file(APPEND ${libPathName}.def " #else\n") + file(APPEND ${libPathName}.def " #error Unknown compiler\n") + file(APPEND ${libPathName}.def " #endif\n") + file(APPEND ${libPathName}.def "#else\n") + file(APPEND ${libPathName}.def " #define _${libName}_api\n") + file(APPEND ${libPathName}.def "#endif\n") + + # lib.hxx file + file(WRITE ${libPathName}.hxx "/* ${libName} */\n\n") + file(APPEND ${libPathName}.hxx "#ifndef __${libNameUpper}_HXX__\n") + file(APPEND ${libPathName}.hxx "#define __${libNameUpper}_HXX__\n\n") + + foreach(dependency ${dependencies}) + file(APPEND ${libPathName}.hxx "#include \"${dependency}.hxx\"\n") + endforeach() + + file(APPEND ${libPathName}.hxx "#include \"${libName}.def\"\n") + file(APPEND ${libPathName}.hxx "\n") + file(APPEND ${libPathName}.hxx "/* TODO: Define data types here */\n\n") + file(APPEND ${libPathName}.hxx "#endif\n") + + # lib.h file + file(WRITE ${libPathName}.h "/* ${libName} */\n\n") + file(APPEND ${libPathName}.h "#include \"${libName}.hxx\"\n\n") + file(APPEND ${libPathName}.h "__EXTERN_C\n\n") + file(APPEND ${libPathName}.h "_${libName}_api void ${libName}_start(void);\n\n") + file(APPEND ${libPathName}.h "_${libName}_api void ${libName}_finish(void);\n\n") + file(APPEND ${libPathName}.h "__END_C\n") + + # lib.c file + file(WRITE ${libPathName}.c "/* ${libName} */\n\n") + file(APPEND ${libPathName}.c "#include \"${libName}.h\"\n\n") + file(APPEND ${libPathName}.c "/*---------------------------------------------------------------------------*/\n\n") + file(APPEND ${libPathName}.c "void ${libName}_start(void)\n") + file(APPEND ${libPathName}.c "{\n") + file(APPEND ${libPathName}.c " /*TODO: Implement library initialization code here */\n") + file(APPEND ${libPathName}.c "}\n\n") + file(APPEND ${libPathName}.c "/*---------------------------------------------------------------------------*/\n\n") + file(APPEND ${libPathName}.c "void ${libName}_finish(void)\n") + file(APPEND ${libPathName}.c "{\n") + file(APPEND ${libPathName}.c " /*TODO: Implement library ending code here */\n") + file(APPEND ${libPathName}.c "}\n\n") + +endfunction() + +#------------------------------------------------------------------------------ + +function(staticLib libName libPath dependencies nrcMode) + + # Cache variables + set(NAPPGUI_CACHE_DEPENDS_${libName} "${dependencies}" CACHE INTERNAL "") + set(NAPPGUI_CACHE_LIBPATH_${libName} "${libPath}" CACHE INTERNAL "") + addTargetCache(${libName} ${libPath} ${nrcMode}) + + # Library exists as precompiled binary + existsPrecompiledStaticLib(${libName} existsBin) + if (${existsBin}) + message(STATUS "- [OK] ${libName}: Precompiled static library") + + else() + # Library source location + set(libSourcePath ${CMAKE_CURRENT_SOURCE_DIR}/${libPath}) + + # New Library (doesn't exists yet) + if (NOT EXISTS ${libSourcePath}) + createLibFiles(${libSourcePath} ${dependencies}) + message("- [WARN] ${libName}: Library not found. Create a new project") + endif() + + file(APPEND ${libSourcePath}/CMakeLists.txt "processStaticLib(${libName} \"${dependencies}\" \"${ARGV4}\")\n") + configure_file("${libSourcePath}/CMakeLists.txt" "${libSourcePath}/CMakeLists.txt" NEWLINE_STYLE UNIX) + + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(dynamicLib libName libPath dependencies nrcMode) + + # Cache variables + set(NAPPGUI_CACHE_DEPENDS_${libName} "${dependencies}" CACHE INTERNAL "") + set(NAPPGUI_CACHE_LIBPATH_${libName} "${libPath}" CACHE INTERNAL "") + addTargetCache(${libName} ${libPath} ${nrcMode}) + + # Library exists as precompiled binary + existsPrecompiledDynamicLib(${libName} existsBin) + if (${existsBin}) + message(STATUS "- [OK] ${libName}: Precompiled dynamic library") + + else() + # Library source location + set(libSourcePath ${CMAKE_CURRENT_SOURCE_DIR}/${libPath}) + + # New Library (doesn't exists yet) + if (NOT EXISTS ${libSourcePath}) + createLibFiles(${libSourcePath} ${dependencies}) + message("- [WARN] ${libName}: Library not found. Create a new project") + endif() + + file(APPEND ${libSourcePath}/CMakeLists.txt "processDynamicLib(${libName} \"${dependencies}\" \"${ARGV4}\")\n") + configure_file("${libSourcePath}/CMakeLists.txt" "${libSourcePath}/CMakeLists.txt" NEWLINE_STYLE UNIX) + + endif() + +endfunction() + +#------------------------------------------------------------------------------ + +function(commandApp appName appPath dependencies nrcMode) + + addTargetCache(${appName} ${appPath} ${nrcMode}) + set(appFullPath ${CMAKE_CURRENT_SOURCE_DIR}/${appPath}) + + if (NOT EXISTS ${appFullPath}) + file(MAKE_DIRECTORY ${appFullPath}) + + # main.c + string(TOLOWER ${appName} appNameLower) + file(COPY ${CMAKE_PRJ_PATH}/templates/cmdmain.c DESTINATION ${appFullPath}) + file(RENAME ${appFullPath}/cmdmain.c ${appFullPath}/${appNameLower}.c) + + message(NOTICE "- [WARN] ${appName}: Application not found. Create a new project") + endif() + + file(APPEND ${appFullPath}/CMakeLists.txt "processCommandApp(${appName} \"${dependencies}\" \"${ARGV4}\")\n") + configure_file("${appFullPath}/CMakeLists.txt" "${appFullPath}/CMakeLists.txt" NEWLINE_STYLE UNIX) + +endfunction() + +#------------------------------------------------------------------------------ + +function(desktopApp appName appPath dependencies nrcMode) + + addTargetCache(${appName} ${appPath} ${nrcMode}) + set(appFullPath ${CMAKE_CURRENT_SOURCE_DIR}/${appPath}) + + if (NOT EXISTS ${appFullPath}) + set(resPath ${appFullPath}/res) + file(MAKE_DIRECTORY ${appFullPath}) + file(MAKE_DIRECTORY ${resPath}) + + # logo + file(COPY ${CMAKE_PRJ_PATH}/templates/logo.icns DESTINATION ${resPath}) + file(COPY ${CMAKE_PRJ_PATH}/templates/logo256.ico DESTINATION ${resPath}) + file(COPY ${CMAKE_PRJ_PATH}/templates/logo48.ico DESTINATION ${resPath}) + + # Disabled support for installers + #file(COPY ${CMAKE_PRJ_PATH}/templates/banner.bmp DESTINATION ${resPath}) + + # license + #file(COPY ${CMAKE_PRJ_PATH}/templates/license.txt DESTINATION ${resPath}) + + # pack.txt + #file(WRITE ${resPath}/pack.txt "VENDOR=NAppGUI\n") + #file(APPEND ${resPath}/pack.txt "VERSION=1.0\n") + #file(APPEND ${resPath}/pack.txt "DESC=Write here the application description\n") + + # main.c + file(COPY ${CMAKE_PRJ_PATH}/templates/main.c DESTINATION ${appFullPath}) + string(TOLOWER ${appName} appNameLower) + file(RENAME ${appFullPath}/main.c ${appFullPath}/${appNameLower}.c) + + message(NOTICE "- [WARN] ${appName}: Application not found. Create a new project") + endif() + + file(APPEND ${appFullPath}/CMakeLists.txt "processDesktopApp(${appName} \"${dependencies}\" \"${ARGV4}\")\n") + configure_file("${appFullPath}/CMakeLists.txt" "${appFullPath}/CMakeLists.txt" NEWLINE_STYLE UNIX) + +endfunction() + +#------------------------------------------------------------------------------ + +function(generateSolution) + + foreach(sourcePath ${NAPPGUI_CACHE_SOURCE_DIRECTORIES}) + + # Precompiled targets don't have to be added + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${sourcePath}) + add_subdirectory(${sourcePath}) + + foreach(target ${NAPPGUI_CACHE_PATH_TARGETS_${sourcePath}}) + setTargetFilter(${target} ${sourcePath}) + endforeach() + + # We can't remove project specific 'CMakeLists.txt' because problems in macOS + # file(REMOVE "${sourcePath}/CMakeLists.txt") + endif() + + endforeach() + +endfunction() diff --git a/prj/CMakeFunctions.txt b/prj/CMakeFunctions.txt deleted file mode 100644 index 4a4528b..0000000 --- a/prj/CMakeFunctions.txt +++ /dev/null @@ -1,1125 +0,0 @@ -# CMake build functions script -# This file is part of NAppGUI-SDK project -# See README.txt and LICENSE.txt - -#------------------------------------------------------------------------------ - -function(getSubDirectories dir _ret) - set(dirList "") - - file(GLOB children RELATIVE ${dir} ${dir}/[a-zA-z_]*) - - foreach(child ${children}) - if(IS_DIRECTORY ${dir}/${child}) - list(APPEND dirList ${child}) - endif() - endforeach() - - set(${_ret} ${dirList} PARENT_SCOPE) -endfunction() - -#------------------------------------------------------------------------------ - -function(resourceGlobPatterns dir _ret) - set(list_res "") - - foreach (item ${RES_EXTENSION}) - list(APPEND list_res ${dir}/${item}) - endforeach() - - set(${_ret} ${list_res} PARENT_SCOPE) -endfunction() - -#------------------------------------------------------------------------------ - -function(isSourceSubDir subDirName _ret) - - string(TOLOWER ${subDirName} subDirLower) - if (${subDirLower} STREQUAL win) - if (WIN32) - set(${_ret} TRUE PARENT_SCOPE) - else() - set(${_ret} FALSE PARENT_SCOPE) - endif() - elseif (${subDirLower} STREQUAL unix) - if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" - OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(${_ret} TRUE PARENT_SCOPE) - else() - set(${_ret} FALSE PARENT_SCOPE) - endif() - elseif (${subDirLower} STREQUAL osx) - if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(${_ret} TRUE PARENT_SCOPE) - else() - set(${_ret} FALSE PARENT_SCOPE) - endif() - elseif (${subDirLower} STREQUAL linux) - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(${_ret} TRUE PARENT_SCOPE) - else() - set(${_ret} FALSE PARENT_SCOPE) - endif() - elseif (${subDirLower} STREQUAL gtk3) - if (${CMAKE_TOOLKIT} MATCHES "GTK3") - set(${_ret} TRUE PARENT_SCOPE) - else() - set(${_ret} FALSE PARENT_SCOPE) - endif() - elseif (${subDirLower} STREQUAL res) - set(${_ret} FALSE PARENT_SCOPE) - else () - set(${_ret} TRUE PARENT_SCOPE) - endif () - -endfunction() - -#------------------------------------------------------------------------------ - -function(appendSrcFile targetName file) - - if ("${${targetName}_SRCFILES}" STREQUAL "") - set(${targetName}_SRCFILES "${file}" CACHE INTERNAL "") - else() - list (FIND ${targetName}_SRCFILES ${file} index) - if (${index} EQUAL -1) - set(${targetName}_SRCFILES "${${targetName}_SRCFILES};${file}" CACHE INTERNAL "") - else() - message(FATAL_ERROR "Duplicated source file '${file}'") - endif() - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(appendSrcSubDir targetName subDir) - - if ("${${targetName}_SRCSUBDIRS}" STREQUAL "") - set(${targetName}_SRCSUBDIRS "${subDir}" CACHE INTERNAL "") - else() - list (FIND ${targetName}_SRCSUBDIRS ${subDir} index) - if (${index} EQUAL -1) - set(${targetName}_SRCSUBDIRS "${${targetName}_SRCSUBDIRS};${subDir}" CACHE INTERNAL "") - endif () - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(getRecursiveSourceFiles targetName dir group) - - file(GLOB children RELATIVE ${dir} ${dir}/[a-zA-z_]*) - - foreach(child ${children}) - if (IS_DIRECTORY ${dir}/${child}) - isSourceSubDir(${child} isSource) - if (${isSource}) - getRecursiveSourceFiles(${targetName} "${dir}/${child}" "${group}/${child}") - endif() - else() - get_filename_component(ext ${child} EXT) - string(TOLOWER ${ext} extLower) - list (FIND SRC_EXTENSION "*${extLower}" index) - if (${index} GREATER -1) - string(REPLACE "/" "\\" groupname ${group}) - source_group(${groupname} FILES ${dir}/${child}) - - # Force header files 'Build errors with CMake >= 3.21.2' - # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5926 - list (FIND HEADER_EXTENSION "*${extLower}" index) - if (${index} GREATER -1) - set_source_files_properties(${dir}/${child} PROPERTIES HEADER_FILE_ONLY ON) - if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set_source_files_properties(${dir}/${child} PROPERTIES XCODE_EXPLICIT_FILE_TYPE sourcecode.c.h) - endif() - endif() - - appendSrcSubDir(${targetName} ${dir}) - appendSrcFile(${targetName} ${dir}/${child}) - endif() - - endif() - - endforeach() - -endfunction() - -#------------------------------------------------------------------------------ - -function(getResourceFiles targetName targetType dir _ret _include_dir) - # All resource files in package - set(res_files "") - set(resPath ${dir}/res) - - if (EXISTS ${resPath}) - # Process Win32 .rc files - if (targetType MATCHES WIN_EXE) - # VS2005 does not support .ico with 256 res - if(MSVC_VERSION EQUAL 1400 OR MSVC_VERSION LESS 1400) - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/res.rc "APPLICATION_ICON ICON \"res\\\\logo48.ico\"\n") - set(globalRes ${CMAKE_CURRENT_BINARY_DIR}/res.rc ${resPath}/logo48.ico) - else() - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/res.rc "APPLICATION_ICON ICON \"res\\\\logo256.ico\"\n") - set(globalRes ${CMAKE_CURRENT_BINARY_DIR}/res.rc ${resPath}/logo256.ico) - endif() - endif() - - if (EXISTS ${resPath}/license.txt) - list(APPEND globalRes ${resPath}/license.txt) - endif() - - if (EXISTS ${resPath}/pack.txt) - list(APPEND globalRes ${resPath}/pack.txt) - endif() - - source_group(res FILES ${globalRes}) - list(APPEND res_files ${globalRes}) - - endif() - - # Target Resources - set(nrc_mode ${TARGET_NRC_MODE_${targetName}}) - if (NOT ${nrc_mode} STREQUAL "NRC_NONE") - getSubDirectories(${resPath} resPackDirs) - - # Clean the resource destiny directory - set(DEST_RESDIR ${CMAKE_CURRENT_BINARY_DIR}/resgen) - set(CMAKE_OUTPUT ${DEST_RESDIR}/NRCLog.txt) - file(REMOVE_RECURSE ${DEST_RESDIR}) - file(MAKE_DIRECTORY ${DEST_RESDIR}) - - foreach(resPack ${resPackDirs}) - # Add resources to IDE - set(resPackPath ${resPath}/${resPack}) - resourceGlobPatterns(${resPackPath} resGlob) - file(GLOB resPackPathFiles ${resGlob}) - source_group("res\\${resPack}" FILES ${resPackPathFiles}) - list(APPEND res_files ${resPackPathFiles}) - - # Add localized resources to IDE - getSubDirectories(${resPath}/${resPack} resLocalDirs) - foreach(resLocalDir ${resLocalDirs}) - set(resLocalPath ${resPath}/${resPack}/${resLocalDir}) - resourceGlobPatterns(${resLocalPath} resLocalGlob) - file(GLOB resLocalPathFiles ${resLocalGlob}) - source_group("res\\${resPack}\\${resLocalDir}" FILES ${resLocalPathFiles}) - list(APPEND res_files ${resLocalPathFiles}) - endforeach() - - if (${nrc_mode} STREQUAL "NRC_EMBEDDED") - set(NRC_OPTION "-dc") - # '*.res' package will be copied in executable location - elseif (${nrc_mode} STREQUAL "NRC_PACKED") - set(NRC_OPTION "-dp") - else() - message (FATAL_ERROR "Unknown nrc mode") - endif() - - file(TO_NATIVE_PATH \"${CMAKE_NRC}\" CMAKE_NRC) - file(TO_NATIVE_PATH ${resPackPath} RESPACK_NATIVE) - file(TO_NATIVE_PATH ${DEST_RESDIR}/${resPack}.c RESDEST_NATIVE) - execute_process(COMMAND "${CMAKE_NRC}" "${NRC_OPTION}" "${RESPACK_NATIVE}" "${RESDEST_NATIVE}" RESULT_VARIABLE nrcRes OUTPUT_VARIABLE nrcOut ERROR_VARIABLE nrcErr) - file(APPEND ${CMAKE_OUTPUT} ${nrcOut}) - file(APPEND ${CMAKE_OUTPUT} ${nrcErr}) - if (NOT ${nrcRes} EQUAL "0") - if (${nrcRes} EQUAL "1") - message("- nrc '${resPack}' warnings (See ${CMAKE_OUTPUT})") - else() - message("- nrc '${resPack}' errors (${nrcRes}) (See ${CMAKE_OUTPUT})") - message("- ${nrcOut}") - message("- ${nrcErr}") - endif() - endif() - - list(APPEND resCompiled ${DEST_RESDIR}/${resPack}.c) - list(APPEND resCompiled ${DEST_RESDIR}/${resPack}.h) - source_group("res\\${resPack}\\gen" FILES ${resCompiled}) - list(APPEND res_files ${resCompiled}) - - set(${_include_dir} ${DEST_RESDIR} PARENT_SCOPE) - - endforeach() - - endif() - - set(${_ret} ${res_files} PARENT_SCOPE) - -endfunction() - -#------------------------------------------------------------------------------ - -function(installResourcePacks targetName targetType sourceDir) - set (resourcePath ${sourceDir}/res) - - # Apple Bundle always have a resource dir - if (targetType MATCHES APPLE_BUNDLE) - set(resourceDestPath "../resources") - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/${resourceDestPath}) - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/${resourceDestPath}/en.lproj) - - # Bundle icon - if (EXISTS ${resourcePath}/logo.icns) - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${resourcePath}/logo.icns $/${resourceDestPath}) - else() - message(WARNING "logo.icns doesn't exists in '${resourcePath}'") - endif() - - # Linux needs the app icon near the executable - elseif (targetType MATCHES LINUX_BUNDLE) - - if (EXISTS ${resourcePath}/logo48.ico) - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${resourcePath}/logo48.ico $/logo.ico) - else() - message(WARNING "logo48.ico doesn't exists in '${resourcePath}'") - endif() - - endif() - - set(nrc_mode ${TARGET_NRC_MODE_${targetName}}) - if (${nrc_mode} STREQUAL "NRC_PACKED") - set(resPath ${sourceDir}/res) - set(DEST_RESDIR ${CMAKE_CURRENT_BINARY_DIR}/resgen) - - # Create 'res' directory for packed resources - # In the same location as executable - if (WIN32) - set(resRelative "res") - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/${resRelative}) - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # For macOS bundles, resource dir is created in 'macOSBundle' - set(resRelative "../resources") - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(resRelative "res") - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory $/${resRelative}) - else() - message(FATAL_ERROR "Unknown system") - endif() - - getSubDirectories(${resPath} resPackDirs) - - # Copy all resource packs - foreach(resSubDir ${resPackDirs}) - add_custom_command(TARGET ${bundleName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${DEST_RESDIR}/${resSubDir}.res $/${resRelative}) - endforeach() - - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(getDirectDepends path _ret) - - if (${path}_DIRECTDEPENDS) - set(${_ret} ${${path}_DIRECTDEPENDS} PARENT_SCOPE) - - else() - set(${_ret} "" PARENT_SCOPE) - - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(appendIncludeDependency targetName depend) - - if ("${${targetName}_INCLUDEDEPENDS}" STREQUAL "") - set(${targetName}_INCLUDEDEPENDS "${depend}" CACHE INTERNAL "") - else() - list (FIND ${targetName}_INCLUDEDEPENDS ${depend} index) - if (${index} EQUAL -1) - set(${targetName}_INCLUDEDEPENDS "${${targetName}_INCLUDEDEPENDS};${depend}" CACHE INTERNAL "") - endif () - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(getRecursiveTargetIncludes targetName dependList) - - foreach(depend ${dependList}) - - get_filename_component(dependName ${depend} NAME) - if (TARGET ${dependName}) - appendIncludeDependency(${targetName} ${CMAKE_SRC_PATH}/${depend}) - getDirectDepends(${depend} childDependList) - - elseif (EXISTS ${CMAKE_INC_PATH}/${depend}) - appendIncludeDependency(${targetName} ${CMAKE_INC_PATH}/${depend}) - getDirectDepends(${depend} childDependList) - - else() - # May exists binaries in 'lib' without include files - set(childDependList "") - - endif() - - if (childDependList) - getRecursiveTargetIncludes(${targetName} "${childDependList}") - endif() - - endforeach() - -endfunction() - -#------------------------------------------------------------------------------ - -function(targetDependsIncludeDirectories targetName firstLevelDepends) - - set(${targetName}_INCLUDEDEPENDS "" CACHE INTERNAL "") - getRecursiveTargetIncludes(${targetName} "${firstLevelDepends}") - - if (NOT "${${targetName}_INCLUDEDEPENDS}" STREQUAL "") - target_include_directories(${targetName} PUBLIC "${${targetName}_INCLUDEDEPENDS}") - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(processTarget targetName targetType dependList) - message(STATUS "- ${targetName}: Starting") - - # Get Files - set(${targetName}_SRCFILES "" CACHE INTERNAL "") - set(${targetName}_SRCSUBDIRS "" CACHE INTERNAL "") - getRecursiveSourceFiles(${targetName} ${CMAKE_CURRENT_SOURCE_DIR} "src") - set(srcFiles ${${targetName}_SRCFILES}) - set(srcSubDirs ${${targetName}_SRCSUBDIRS}) - - getResourceFiles(${targetName} ${targetType} ${CMAKE_CURRENT_SOURCE_DIR} resFiles resIncludeDir) - - # TARGET Build - if (targetType MATCHES STATIC_LIB) - add_library(${targetName} STATIC ${srcFiles} ${resFiles}) - elseif (targetType MATCHES WIN_EXE) - add_executable(${targetName} WIN32 ${srcFiles} ${resFiles}) - elseif (targetType MATCHES WIN_CONSOLE) - add_executable(${targetName} ${srcFiles} ${resFiles}) - elseif (targetType MATCHES WIN_DLL) - add_library(${targetName} SHARED ${srcFiles} ${resFiles}) - elseif (targetType MATCHES APPLE_BUNDLE) - add_executable(${targetName} MACOSX_BUNDLE ${srcFiles} ${resFiles}) - elseif (targetType MATCHES APPLE_CONSOLE) - add_executable(${targetName} ${srcFiles} ${resFiles}) - elseif (targetType MATCHES LINUX_EXE) - add_executable(${targetName} ${srcFiles} ${resFiles}) - elseif (targetType MATCHES LINUX_BUNDLE) - add_executable(${targetName} ${srcFiles} ${resFiles}) - else() - message(FATAL_ERROR "Unknown target type") - endif() - - # IDE Properties for TARGET - if (IDE_PROPERTIES) - set_target_properties(${targetName} PROPERTIES ${IDE_PROPERTIES}) - endif() - - # Resource packs - installResourcePacks(${targetName} ${targetType} ${CMAKE_CURRENT_SOURCE_DIR}) - - # Target Definitions - set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS $<$:CMAKE_DEBUG>) - set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS $<$:CMAKE_RELEASE>) - set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS $<$:CMAKE_RELEASEWITHASSERT>) - - if (WIN32) - # Visual Studio 2005/2008 doesn't have - if(MSVC_VERSION EQUAL 1500 OR MSVC_VERSION LESS 1500) - target_include_directories(${targetName} PUBLIC ${CMAKE_PRJ_PATH}/depend) - endif() - - # Platform toolset macro - set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS VS_PLATFORM=${VS_TOOLSET_NUMBER}) - - # Disable linker '4099' "pdb" warnings - # Disable linker '4098' mixed (static/dynamic) runtime library warnings - set_target_properties(${targetName} PROPERTIES LINK_FLAGS "/ignore:4099 /ignore:4098") - - endif() - - # GTK Include directories - if (${CMAKE_TOOLKIT} MATCHES "GTK3") - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/gtk3) - # Use the package PkgConfig to detect GTK+ headers/library files - find_package(PkgConfig REQUIRED) - pkg_check_modules(GTK3 REQUIRED gtk+-3.0) - target_include_directories(${targetName} PUBLIC ${GTK3_INCLUDE_DIRS}) - set_target_properties(${targetName} PROPERTIES COMPILE_FLAGS "-D__GTK3_TOOLKIT__") - endif() - endif() - - # TARGET local directory include - target_include_directories(${targetName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - - # TARGET local subdirectories includes - foreach (srcSubDir ${srcSubDirs}) - target_include_directories(${targetName} PUBLIC ${srcSubDir}) - endforeach() - - # Include dir for target generated resources - if (resIncludeDir) - target_include_directories(${targetName} PUBLIC ${resIncludeDir}) - endif() - - if (dependList) - foreach(dependency ${dependList}) - get_filename_component(dependencyName ${dependency} NAME) - if (TARGET ${dependencyName}) - add_dependencies(${targetName} ${dependencyName}) - endif() - endforeach() - - # Recursive directory includes - targetDependsIncludeDirectories(${targetName} "${dependList}") - endif() - - message(STATUS "- ${targetName}: Completed ") -endfunction() - -#------------------------------------------------------------------------------ - -function(processStaticLib libName dependList) - processTarget("${libName}" "STATIC_LIB" "${dependList}") - - # In Linux, static libs must link with other libs - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - targetLinkWithLibraries(${libName} "${dependencies}") - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(setDotNetProps targetName dotnetDependList dotnetFramework) - set(DOTNET_LIBS System ${dotnetDependList}) - set_target_properties(${targetName} PROPERTIES VS_DOTNET_REFERENCES "${DOTNET_LIBS}") - - # C++/Cli is not compatible with '/MT' runtime library - target_compile_options(${targetName} PUBLIC "$<$:/MDd>") - target_compile_options(${targetName} PUBLIC "$<$:/MD>") - target_compile_options(${targetName} PUBLIC "$<$:/MD>") - - # DOTNET Framework version - set_target_properties(${targetName} PROPERTIES DOTNET_TARGET_FRAMEWORK_VERSION v${dotnetFramework}) - -endfunction() - -#------------------------------------------------------------------------------ - -function(windowsBundle bundleName bundleType dependList) - processTarget("${bundleName}" "${bundleType}" "${dependList}") -endfunction() - -#------------------------------------------------------------------------------ - -function(bundleProp bundleName property value) - # Fails in XCode 3.2, 4 - # /bin/bash -c "plutil -replace NSHumanReadableCopyright -string 2019\ NAppGUI .../Info.plist" - # unrecognized option: -replace - if(${XCODE_VERSION} VERSION_GREATER "5.99") - add_custom_command(TARGET ${bundleName} POST_BUILD COMMAND /bin/bash -c \"plutil -replace ${property} -string "${value}" $/../Info.plist\") - endif() -endfunction() - -#------------------------------------------------------------------------------ - -function(macOSBundle bundleName dependList) - - processTarget("${bundleName}" APPLE_BUNDLE "${dependList}") - - # Info.plist configure - # Proyect provides its own Info.plist? - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) - set_target_properties(${bundleName} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) - # Use default template - else() - set_target_properties(${bundleName} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_PRJ_PATH}/templates/Info.plist) - endif() - - # Overwrite some properties - bundleProp(${bundleName} NSHumanReadableCopyright "${CURRENT_YEAR} ${PACK_VENDOR}") - bundleProp(${bundleName} CFBundleVersion "${PACK_VERSION}") - - target_link_libraries(${bundleName} ${COCOA_LIB}) - -endfunction() - -#------------------------------------------------------------------------------ - -function(linuxBundle bundleName dependList) - processTarget("${bundleName}" LINUX_BUNDLE "${dependList}") - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) - set_target_properties(${bundleName} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}") -endfunction() - -#------------------------------------------------------------------------------ - -function(appendLinkDependency targetName depend) - - if ("${${targetName}_LINKDEPENDS}" STREQUAL "") - set(${targetName}_LINKDEPENDS "${depend}" CACHE INTERNAL "") - else() - #list (FIND ${targetName}_LINKDEPENDS ${depend} index) - #if (${index} EQUAL -1) - set(${targetName}_LINKDEPENDS "${${targetName}_LINKDEPENDS};${depend}" CACHE INTERNAL "") - #endif () - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(appendBinaryLinkDependency targetName depend) - - if ("${${targetName}_LINKDEPENDS}" STREQUAL "") - set(${targetName}_LINKDEPENDS "${depend}" CACHE INTERNAL "") - # In Linux (GCC) we need the entire chain of binary dependencies (don't delete duplicates) - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(${targetName}_LINKDEPENDS "${${targetName}_LINKDEPENDS};${depend}" CACHE INTERNAL "") - else() - list (FIND ${targetName}_LINKDEPENDS ${depend} index) - if (${index} EQUAL -1) - set(${targetName}_LINKDEPENDS "${${targetName}_LINKDEPENDS};${depend}" CACHE INTERNAL "") - endif () - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(binaryTarget targetName _ret) - - if (NOT NAPPGUI_COMPILER_TOOLSET) - message(FATAL_ERROR "NAPPGUI_COMPILER_TOOLSET Not Set") - endif() - - if (NOT NAPPGUI_ARCH) - message(FATAL_ERROR "NAPPGUI_ARCH Not Set") - endif() - - if (NOT NAPPGUI_LIB_PREFIX) - set(NAPPGUI_LIB_PREFIX "") - endif() - - if (NOT NAPPGUI_LIB_SUFFIX) - message(FATAL_ERROR "NAPPGUI_LIB_SUFFIX Not Set") - endif() - - set(BINARY_DIR ${CMAKE_LIB_PATH}/${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}) - if (EXISTS ${BINARY_DIR}) - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(${_ret} ${BINARY_DIR}/${CMAKE_BUILD_CONFIG}/${NAPPGUI_LIB_PREFIX}${targetName}${NAPPGUI_LIB_SUFFIX} PARENT_SCOPE) - else() - set(${_ret} ${BINARY_DIR}/${CMAKE_CFG_INTDIR}/${NAPPGUI_LIB_PREFIX}${targetName}${NAPPGUI_LIB_SUFFIX} PARENT_SCOPE) - endif() - else() - set(${_ret} "" PARENT_SCOPE) - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(getRecursiveTargetLinks targetName dependList) - - foreach(depend ${dependList}) - get_filename_component(dependName ${depend} NAME) - - # Dependency is a source project - if (TARGET ${dependName}) - get_target_property(TARGET_TYPE ${dependName} TYPE) - if (${TARGET_TYPE} STREQUAL "STATIC_LIBRARY") - appendLinkDependency(${targetName} ${dependName}) - getDirectDepends(${depend} childDependList) - endif () - - else() - # Check if dependency is a binary - get_filename_component(libDir ${depend} DIRECTORY) - get_filename_component(libName ${depend} NAME) - set(libBinaryPath ${CMAKE_LIB_PATH}/${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}/Debug/${libDir}/${NAPPGUI_LIB_PREFIX}${libName}${NAPPGUI_LIB_SUFFIX}) - - if (EXISTS ${libBinaryPath}) - binaryTarget(${depend} binaryName) - appendBinaryLinkDependency(${targetName} ${binaryName}) - getDirectDepends(${depend} childDependList) - - else() - message(FALTAL_ERROR "'${depend}' Unknown dependency") - - endif() - - endif() - - if (childDependList) - getRecursiveTargetLinks(${targetName} "${childDependList}") - endif() - - endforeach() - -endfunction() - -#------------------------------------------------------------------------------ - -function(existsDepend targetName depend _ret) - list (FIND ${targetName}_LINKDEPENDS ${depend} _index) - if (${_index} GREATER -1) - set(${_ret} ${_index} PARENT_SCOPE) - else() - binaryTarget(${depend} binaryName) - if (NOT "${binaryName}" STREQUAL "") - list (FIND ${targetName}_LINKDEPENDS ${binaryName} _index) - set(${_ret} ${_index} PARENT_SCOPE) - else() - set(${_ret} "-1" PARENT_SCOPE) - endif() - endif() -endfunction() - -#------------------------------------------------------------------------------ - -function(targetDependOnLib targetName libName _ret) - - set(${_ret} "NO" PARENT_SCOPE) - - if (${targetName} MATCHES "${libName}") - set(${_ret} "YES" PARENT_SCOPE) - return() - endif() - - foreach(lib in ${${targetName}_LINKDEPENDS}) - - if (${lib} MATCHES "${libName}") - set(${_ret} "YES" PARENT_SCOPE) - return() - endif() - - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - - if (${lib} MATCHES ".*lib${libName}.a") - set(${_ret} "YES" PARENT_SCOPE) - return() - endif() - - endif() - - endforeach() - -endfunction() - -#------------------------------------------------------------------------------ - -function(targetLinkWithLibraries targetName firstLevelDepends) - - set(${targetName}_LINKDEPENDS "" CACHE INTERNAL "") - getRecursiveTargetLinks(${targetName} "${firstLevelDepends}") - - if (NOT "${${targetName}_LINKDEPENDS}" STREQUAL "") - target_link_libraries(${targetName} ${${targetName}_LINKDEPENDS}) - endif() - - # Target should link with pthread - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - targetDependOnLib(${targetName} "osbs" _depends) - if (${_depends} STREQUAL "YES") - target_link_libraries(${targetName} pthread) - endif() - endif() - - # Target should link with GTK3 - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - if (${CMAKE_TOOLKIT} MATCHES "GTK3") - targetDependOnLib(${targetName} "draw2d" _depends) - if (${_depends} STREQUAL "YES") - # Use the package PkgConfig to detect GTK+ headers/library files - find_package(PkgConfig REQUIRED) - pkg_check_modules(GTK3 REQUIRED gtk+-3.0) - target_link_libraries(${targetName} ${GTK3_LIBRARIES}) - endif() - endif() - endif() - - # Target should link with libCurl - if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - targetDependOnLib(${targetName} "inet" _depends) - if (${_depends} STREQUAL "YES") - find_package(CURL) - if (${CURL_FOUND}) - target_link_libraries(${targetName} ${CURL_LIBRARY}) - else() - message(ERROR "- libCURL is required. Try 'sudo apt-get install libcurl4-openssl-dev'") - endif() - endif() - endif() - - -endfunction() - -#------------------------------------------------------------------------------ - -function(readPackFile) - - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/res/pack.txt) - file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/res/pack.txt PackContents) - foreach(NameAndValue ${PackContents}) - # Strip leading spaces - string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue}) - # Find variable name - string(REGEX MATCH "^[^=]+" Name ${NameAndValue}) - # Find the value - string(REPLACE "${Name}=" "" Value ${NameAndValue}) - # Set the variable - set(PACK_${Name} "${Value}" PARENT_SCOPE) - endforeach() - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(installerScript targetName platform generator config) - set(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/CPack-${targetName}-${config}.cmake) - file(WRITE ${SCRIPT} "# CPack script for ${targetName} project\n") - file(APPEND ${SCRIPT} "# Automatic generated by NAppGUI\n") - file(APPEND ${SCRIPT} "# You can configure the installer from /res/pack.txt\n") - file(APPEND ${SCRIPT} "set(CPACK_GENERATOR \"${generator}\")\n") - file(APPEND ${SCRIPT} "set(CPACK_INSTALLED_DIRECTORIES \"${CMAKE_CURRENT_BINARY_DIR}/${config};.\")\n") - file(APPEND ${SCRIPT} "set(CPACK_SYSTEM_NAME \"${platform}_${NAPPGUI_ARCH}\")\n") - file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_NAME \"${targetName}\")\n") - file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_VENDOR \"${PACK_VENDOR}\")\n") - file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_VERSION \"${PACK_VERSION}\")\n") - file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_DESCRIPTION \"${PACK_DESC}\")\n") - file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_FILE_NAME \"\${CPACK_PACKAGE_NAME}\")\n") - #file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_FILE_NAME \"\${CPACK_PACKAGE_NAME}-\${CPACK_PACKAGE_VERSION}-\${CPACK_SYSTEM_NAME}\")\n") - file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY \"\${PACK_VENDOR}/\${CPACK_PACKAGE_NAME}-${NAPPGUI_ARCH}\")\n") - - if (${generator} MATCHES "NSIS") - - file(APPEND ${SCRIPT} "\n") - file(APPEND ${SCRIPT} "# NSIS generator specific options\n") - file(APPEND ${SCRIPT} "set(CPACK_NSIS_PACKAGE_NAME \"\${CPACK_PACKAGE_FILE_NAME}\")\n") - file(APPEND ${SCRIPT} "set(CPACK_NSIS_DISPLAY_NAME \"\${CPACK_PACKAGE_NAME} (${NAPPGUI_ARCH})\")\n") - file(APPEND ${SCRIPT} "set(CPACK_NSIS_MUI_ICON \"${CMAKE_CURRENT_SOURCE_DIR}/res\\\\logo256.ico\")\n") - file(APPEND ${SCRIPT} "set(CPACK_NSIS_MUI_UNIICON \"${CMAKE_CURRENT_SOURCE_DIR}/res\\\\logo256.ico\")\n") - file(APPEND ${SCRIPT} "set(CPACK_PACKAGE_ICON \"${CMAKE_CURRENT_SOURCE_DIR}/res\\\\banner.bmp\")\n") - file(APPEND ${SCRIPT} "set(CPACK_RESOURCE_FILE_LICENSE \"${CMAKE_CURRENT_SOURCE_DIR}/res/license.txt\")\n") - - if (${NAPPGUI_ARCH} MATCHES "x64") - file(APPEND ${SCRIPT} "set(CPACK_NSIS_INSTALL_ROOT \"\$PROGRAMFILES64\\\\\${CPACK_PACKAGE_VENDOR}\\\\\${CPACK_PACKAGE_NAME}\")\n") - else() - file(APPEND ${SCRIPT} "set(CPACK_NSIS_INSTALL_ROOT \"\$PROGRAMFILES\\\\\${CPACK_PACKAGE_VENDOR}\\\\\${CPACK_PACKAGE_NAME}\")\n") - endif() - - file(APPEND ${SCRIPT} "set(CPACK_NSIS_INSTALLED_ICON_NAME \"\${CPACK_PACKAGE_NAME}.exe\")\n") - file(APPEND ${SCRIPT} "set(CPACK_NSIS_MENU_LINKS \"\${CPACK_PACKAGE_NAME}.exe\" \"\${CPACK_PACKAGE_NAME} (${NAPPGUI_ARCH})\")\n") - file(APPEND ${SCRIPT} "set(CPACK_NSIS_DEFINES \"!define MUI_STARTMENUPAGE_DEFAULTFOLDER \\\\\${CPACK_PACKAGE_VENDOR}\\\\\${CPACK_PACKAGE_NAME}\")\n") - - elseif (${generator} MATCHES "DragNDrop") - file(APPEND ${SCRIPT} "set(CPACK_DMG_VOLUME_NAME \"\${CPACK_PACKAGE_NAME}\")\n") - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/license.txt ${CMAKE_CURRENT_BINARY_DIR}/$) - - elseif (${generator} MATCHES "TGZ") - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/res/license.txt ${CMAKE_CURRENT_BINARY_DIR}/$) - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(processInstaller targetName) - if (CMAKE_PACKAGE_PATH) - - if (NOT EXISTS ${CMAKE_PACKAGE_PATH}/Debug) - file(MAKE_DIRECTORY ${CMAKE_PACKAGE_PATH}/Debug) - endif() - - if (NOT EXISTS ${CMAKE_PACKAGE_PATH}/Release) - file(MAKE_DIRECTORY ${CMAKE_PACKAGE_PATH}/Release) - endif() - - if (NOT EXISTS ${CMAKE_PACKAGE_PATH}/ReleaseWithAssert) - file(MAKE_DIRECTORY ${CMAKE_PACKAGE_PATH}/ReleaseWithAssert) - endif() - - if (WIN32) - installerScript(${targetName} "win" ${CMAKE_PACKAGE_GEN} "Debug") - installerScript(${targetName} "win" ${CMAKE_PACKAGE_GEN} "Release") - installerScript(${targetName} "win" ${CMAKE_PACKAGE_GEN} "ReleaseWithAssert") - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND cd ${CMAKE_PACKAGE_PATH}/$ & cpack --config ${CMAKE_CURRENT_BINARY_DIR}/CPack-${targetName}-$.cmake) - - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - installerScript(${targetName} "macos" ${CMAKE_PACKAGE_GEN} "Debug") - installerScript(${targetName} "macos" ${CMAKE_PACKAGE_GEN} "Release") - installerScript(${targetName} "macos" ${CMAKE_PACKAGE_GEN} "ReleaseWithAssert") - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND /bin/bash -c \"cd ${CMAKE_PACKAGE_PATH}/$ && ${CPACK_COMMAND} --config ${CMAKE_CURRENT_BINARY_DIR}/CPack-${targetName}-$.cmake\") - - else() - installerScript(${targetName} "linux" ${CMAKE_PACKAGE_GEN} "Debug") - installerScript(${targetName} "linux" ${CMAKE_PACKAGE_GEN} "Release") - installerScript(${targetName} "linux" ${CMAKE_PACKAGE_GEN} "ReleaseWithAssert") - add_custom_command(TARGET ${targetName} POST_BUILD COMMAND /bin/bash -c \"cd ${CMAKE_PACKAGE_PATH}/$ && ${CPACK_COMMAND} --config ${CMAKE_CURRENT_BINARY_DIR}/CPack-${targetName}-$.cmake\") - - endif() - else() - message("- ${targetName}: set CMAKE_PACKAGE_PATH to create packages") - endif() -endfunction() - -#------------------------------------------------------------------------------ - -function(processDesktopApp appName dependList) - - readPackFile() - set(dependencies "osapp") - list(APPEND dependencies "${dependList}") - if (WIN32) - windowsBundle(${appName} WIN_EXE "${dependencies}") - set_target_properties(${appName} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS") - set_target_properties(${appName} PROPERTIES LINK_FLAGS_RELASE "/SUBSYSTEM:WINDOWS") - set_target_properties(${appName} PROPERTIES LINK_FLAGS_RELASEWITHASSERT "/SUBSYSTEM:WINDOWS") - - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - macOSBundle(${appName} "${dependencies}") - - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - linuxBundle(${appName} "${dependencies}") - - else() - message("Unknown platform") - - endif() - - targetLinkWithLibraries(${appName} "${dependencies}") - - if (${CMAKE_PACKAGE}) - processInstaller(${appName}) - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(macOSCommand appName dependList) - processTarget("${appName}" APPLE_CONSOLE "${dependList}") - target_link_libraries(${appName} ${COCOA_LIB}) -endfunction() - -#------------------------------------------------------------------------------ - -function(linuxCommand appName dependList) - processTarget("${appName}" LINUX_EXE "${dependList}") -endfunction() - -#------------------------------------------------------------------------------ - -function(processCommandApp appName dependList) - - #set(dependencies "core") - set(dependencies "") - list(APPEND dependencies "${dependList}") - - if (WIN32) - windowsBundle(${appName} WIN_CONSOLE "${dependencies}") - set_target_properties(${appName} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") - set_target_properties(${appName} PROPERTIES LINK_FLAGS_RELASE "/SUBSYSTEM:CONSOLE") - set_target_properties(${appName} PROPERTIES LINK_FLAGS_RELEASEWITHASSERT "/SUBSYSTEM:CONSOLE") - - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - macOSCommand("${appName}" "${dependencies}") - - elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - linuxCommand("${appName}" "${dependencies}") - - else() - message(ERROR "- ${appName} Unknown system") - - endif() - - targetLinkWithLibraries(${appName} "${dependencies}") - -endfunction() - -#------------------------------------------------------------------------------ - -function(addTarget targetName targetPath nrcMode) - - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${targetPath}) - set(TARGET_NRC_MODE_${targetName} ${nrcMode} CACHE INTERNAL "") - add_subdirectory(${targetPath}) - - else() - message(WARNING "${targetPath} doesn't exists.") - - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(setTargetFilter targetName targetPath) - - get_filename_component(filter ${targetPath} PATH) - - if (filter) - set_target_properties(${targetName} PROPERTIES FOLDER ${filter}) - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(staticLib libPath dependencies nrcMode) - - # Library location - set(libSourcePath ${CMAKE_CURRENT_SOURCE_DIR}/${libPath}) - get_filename_component(libDir ${libPath} PATH) - get_filename_component(libName ${libPath} NAME) - set(libBinaryPath ${CMAKE_LIB_PATH}/${NAPPGUI_COMPILER_TOOLSET}_${NAPPGUI_ARCH}/Debug/${libDir}/${NAPPGUI_LIB_PREFIX}${libName}${NAPPGUI_LIB_SUFFIX}) - set(${libPath}_DIRECTDEPENDS "${dependencies}" CACHE INTERNAL "") - - # Library exists as binary - if (EXISTS ${libBinaryPath}) - message(STATUS "- ${libName}: Detected binary file") - - else() - # New Library (doesn't exists yet) - if (NOT EXISTS ${libSourcePath}) - - set(libPathName ${libSourcePath}/${libName}) - string(TOUPPER ${libName} libNameUpper) - - # New directory - file(MAKE_DIRECTORY ${libPath}) - file(MAKE_DIRECTORY ${libPath}/res) - - # lib.hxx file - file(WRITE ${libPathName}.hxx "/* ${libName} */\n\n") - file(APPEND ${libPathName}.hxx "#ifndef __${libNameUpper}_HXX__\n") - file(APPEND ${libPathName}.hxx "#define __${libNameUpper}_HXX__\n\n") - - foreach(dependency ${dependencies}) - file(APPEND ${libPathName}.hxx "#include \"${dependency}.hxx\"\n") - endforeach() - - file(APPEND ${libPathName}.hxx "\n") - file(APPEND ${libPathName}.hxx "/* TODO: Define data types here */\n\n") - file(APPEND ${libPathName}.hxx "#endif\n") - - # lib.h file - file(WRITE ${libPathName}.h "/* ${libName} */\n\n") - file(APPEND ${libPathName}.h "#include \"${libName}.hxx\"\n\n") - file(APPEND ${libPathName}.h "__EXTERN_C\n\n") - file(APPEND ${libPathName}.h "void ${libName}_start(void);\n\n") - file(APPEND ${libPathName}.h "void ${libName}_finish(void);\n\n") - file(APPEND ${libPathName}.h "__END_C\n") - - # lib.c file - file(WRITE ${libPathName}.c "/* ${libName} */\n\n") - file(APPEND ${libPathName}.c "#include \"${libName}.h\"\n\n") - file(APPEND ${libPathName}.c "/*---------------------------------------------------------------------------*/\n\n") - file(APPEND ${libPathName}.c "void ${libName}_start(void)\n") - file(APPEND ${libPathName}.c "{\n") - file(APPEND ${libPathName}.c " /*TODO: Implement library initialization code here */\n") - file(APPEND ${libPathName}.c "}\n\n") - file(APPEND ${libPathName}.c "/*---------------------------------------------------------------------------*/\n\n") - file(APPEND ${libPathName}.c "void ${libName}_finish(void)\n") - file(APPEND ${libPathName}.c "{\n") - file(APPEND ${libPathName}.c " /*TODO: Implement library ending code here */\n") - file(APPEND ${libPathName}.c "}\n\n") - - message(STATUS "- ${libName}: Created new project") - endif() - - # CMakeLists.txt create/update - file(WRITE ${libSourcePath}/CMakeLists.txt "processStaticLib(${libName} \"${dependencies}\")") - - # Configure (from target dir) - addTarget(${libName} ${libPath} ${nrcMode}) - - # Filter (folder in IDE) - setTargetFilter(${libName} ${libPath}) - - endif() - -endfunction() - -#------------------------------------------------------------------------------ - -function(commandApp appPath dependencies nrcMode) - - set(appFullPath ${CMAKE_CURRENT_SOURCE_DIR}/${appPath}) - get_filename_component(appName ${appPath} NAME) - - if (NOT EXISTS ${appFullPath}) - set(resPath ${appFullPath}/res) - file(MAKE_DIRECTORY ${appFullPath}) - file(MAKE_DIRECTORY ${resPath}) - - # main.c - string(TOLOWER ${appName} appNameLower) - file(COPY ${CMAKE_PRJ_PATH}/templates/cmdmain.c DESTINATION ${appFullPath}) - file(RENAME ${appFullPath}/cmdmain.c ${appFullPath}/${appNameLower}.c) - - message(STATUS "- ${appName}: Created new project") - endif() - - # CMakeLists.txt create/update - file(WRITE ${appFullPath}/CMakeLists.txt "processCommandApp(${appName} \"${dependencies}\")") - - # Configure (from target dir) - addTarget(${appName} ${appPath} ${nrcMode}) - - # Filter (folder in IDE) - setTargetFilter(${appName} ${appPath}) - -endfunction() - -#------------------------------------------------------------------------------ - -function(desktopApp appName appPath dependencies nrcMode) - - set(appFullPath ${CMAKE_CURRENT_SOURCE_DIR}/${appPath}) - - if (NOT EXISTS ${appFullPath}) - set(resPath ${appFullPath}/res) - file(MAKE_DIRECTORY ${appFullPath}) - file(MAKE_DIRECTORY ${resPath}) - - # logo - file(COPY ${CMAKE_PRJ_PATH}/templates/logo.icns DESTINATION ${resPath}) - file(COPY ${CMAKE_PRJ_PATH}/templates/logo256.ico DESTINATION ${resPath}) - file(COPY ${CMAKE_PRJ_PATH}/templates/logo48.ico DESTINATION ${resPath}) - file(COPY ${CMAKE_PRJ_PATH}/templates/banner.bmp DESTINATION ${resPath}) - - # license - file(COPY ${CMAKE_PRJ_PATH}/templates/license.txt DESTINATION ${resPath}) - - # pack.txt - file(WRITE ${resPath}/pack.txt "VENDOR=NAppGUI\n") - file(APPEND ${resPath}/pack.txt "VERSION=1.0\n") - file(APPEND ${resPath}/pack.txt "DESC=Write here the application description\n") - - # main.c - file(COPY ${CMAKE_PRJ_PATH}/templates/main.c DESTINATION ${appFullPath}) - string(TOLOWER ${appName} appNameLower) - file(RENAME ${appFullPath}/main.c ${appFullPath}/${appNameLower}.c) - - message(STATUS "- ${appName}: Created new project") - endif() - - # CMakeLists.txt create/update - file(WRITE ${appFullPath}/CMakeLists.txt "processDesktopApp(${appName} \"${dependencies}\")") - - # Configure (from target dir) - addTarget(${appName} ${appPath} ${nrcMode}) - - # Filter (folder in IDE) - setTargetFilter(${appName} ${appPath}) - -endfunction() - diff --git a/prj/CMakeGCCheckVersion.txt b/prj/CMakeGCCheckVersion.cmake similarity index 100% rename from prj/CMakeGCCheckVersion.txt rename to prj/CMakeGCCheckVersion.cmake diff --git a/prj/CMakeGlobals.txt b/prj/CMakeGlobals.cmake similarity index 66% rename from prj/CMakeGlobals.txt rename to prj/CMakeGlobals.cmake index 143d794..c6cee9a 100644 --- a/prj/CMakeGlobals.txt +++ b/prj/CMakeGlobals.cmake @@ -28,20 +28,30 @@ message (STATUS "${CMAKE_GENERATOR}") #------------------------------------------------------------------------------ set(CMAKE_CONFIGURATION_TYPES "Debug;Release;ReleaseWithAssert" CACHE INTERNAL "Configuration Types" FORCE) +# foreach(config ${CMAKE_CONFIGURATION_TYPES}) +# string(TOUPPER ${config} configUpper) +# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${configUpper} "${CMAKE_BINARY_DIR}/${config}/lib") +# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${configUpper} "${CMAKE_BINARY_DIR}/${config}/bin") +# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${configUpper} "${CMAKE_BINARY_DIR}/${config}/bin") +# endforeach() + +# RELEASEWITHASSERT inherits from RELEASE set(CMAKE_CXX_FLAGS_RELEASEWITHASSERT ${CMAKE_CXX_FLAGS_RELEASE}) set(CMAKE_C_FLAGS_RELEASEWITHASSERT ${CMAKE_C_FLAGS_RELEASE}) set(CMAKE_EXE_LINKER_FLAGS_RELEASEWITHASSERT ${CMAKE_EXE_LINKER_FLAGS_RELEASE}) # Global variables #------------------------------------------------------------------------------ -set(PUBLIC_HEADER_EXTENSION "*.h;*.hxx;*.hpp") +set(PUBLIC_HEADER_EXTENSION "*.h;*.hxx;*.hpp;*.def") set(HEADER_EXTENSION "${PUBLIC_HEADER_EXTENSION};*.inl;*.ixx;*.ipp") set(SRC_EXTENSION "${HEADER_EXTENSION};*.c;*.cpp") -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") set(SRC_EXTENSION "${SRC_EXTENSION};*.m") endif() set(RES_EXTENSION "*.png" "*.jpg" "*.gif" "*.msg" "*.*") +set(NAPPGUI_CACHE_SOURCE_DIRECTORIES "" CACHE INTERNAL "") +set(NAPPGUI_CACHE_TARGETS "" CACHE INTERNAL "") # Global options #------------------------------------------------------------------------------ @@ -49,3 +59,13 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) get_filename_component(CPACK_COMMAND ${CMAKE_COMMAND} PATH) set(CPACK_COMMAND ${CPACK_COMMAND}/cpack) +# Policies +#------------------------------------------------------------------------------ + +# https://cmake.org/cmake/help/latest/policy/CMP0068.html +# RPATH settings on macOS do not affect install_name. +# CMake 3.9 and newer remove any effect the following settings may have on the +# install_name of a target on macOS +if(${CMAKE_VERSION} VERSION_GREATER "3.8.999") + cmake_policy(SET CMP0068 NEW) +endif() diff --git a/prj/CMakeNAppGUI.txt b/prj/CMakeNAppGUI.cmake similarity index 59% rename from prj/CMakeNAppGUI.txt rename to prj/CMakeNAppGUI.cmake index 5ed22cf..73748ec 100644 --- a/prj/CMakeNAppGUI.txt +++ b/prj/CMakeNAppGUI.cmake @@ -14,6 +14,10 @@ set(CMAKE_PRJ_PATH ${CMAKE_PRJ_PATH}/prj) get_filename_component(CMAKE_LIB_PATH ${CMAKE_CURRENT_LIST_DIR} PATH) set(CMAKE_LIB_PATH ${CMAKE_LIB_PATH}/lib) +# 'bin' path +get_filename_component(CMAKE_BIN_PATH ${CMAKE_CURRENT_LIST_DIR} PATH) +set(CMAKE_BIN_PATH ${CMAKE_BIN_PATH}/bin) + # 'src' path get_filename_component(CMAKE_SRC_PATH ${CMAKE_CURRENT_LIST_DIR} PATH) set(CMAKE_SRC_PATH ${CMAKE_SRC_PATH}/src) @@ -21,22 +25,22 @@ set(CMAKE_SRC_PATH ${CMAKE_SRC_PATH}/src) set(DIRECTX_SDK_FIND FALSE CACHE INTERNAL "") # Scripts -include(${CMAKE_PRJ_PATH}/CMakeSDKVersion.txt) -include(${CMAKE_PRJ_PATH}/CMakeGlobals.txt) -include(${CMAKE_PRJ_PATH}/CMakeVSWarnings.txt) -include(${CMAKE_PRJ_PATH}/CMakeXCWarnings.txt) -include(${CMAKE_PRJ_PATH}/CMakeVSCheckVersion.txt) -include(${CMAKE_PRJ_PATH}/CMakeXCCheckVersion.txt) -include(${CMAKE_PRJ_PATH}/CMakeGCCheckVersion.txt) -include(${CMAKE_PRJ_PATH}/CMakeCompilers.txt) -include(${CMAKE_PRJ_PATH}/CMakeFunctions.txt) +include(${CMAKE_PRJ_PATH}/CMakeSDKVersion.cmake) +include(${CMAKE_PRJ_PATH}/CMakeGlobals.cmake) +include(${CMAKE_PRJ_PATH}/CMakeVSWarnings.cmake) +include(${CMAKE_PRJ_PATH}/CMakeXCWarnings.cmake) +include(${CMAKE_PRJ_PATH}/CMakeVSCheckVersion.cmake) +include(${CMAKE_PRJ_PATH}/CMakeXCCheckVersion.cmake) +include(${CMAKE_PRJ_PATH}/CMakeGCCheckVersion.cmake) +include(${CMAKE_PRJ_PATH}/CMakeCompilers.cmake) +include(${CMAKE_PRJ_PATH}/CMakeFunctions.cmake) # nrc 'NAppGUI Resource Compiler' command if (WIN32) set(CMAKE_NRC ${CMAKE_PRJ_PATH}/script/win/${NAPPGUI_ARCH}/nrc.exe) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") set(CMAKE_NRC ${CMAKE_PRJ_PATH}/script/osx/${NAPPGUI_HOST}/nrc) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(CMAKE_NRC ${CMAKE_PRJ_PATH}/script/linux/${NAPPGUI_HOST}/nrc) else() message(FATAL_ERROR "CMAKE_NRC Not Set") diff --git a/prj/CMakeSDKVersion.cmake b/prj/CMakeSDKVersion.cmake new file mode 100644 index 0000000..318a005 --- /dev/null +++ b/prj/CMakeSDKVersion.cmake @@ -0,0 +1,33 @@ +# SDK version +# This file is part of NAppGUI-SDK project +# See README.txt and LICENSE.txt + +set(NAPPGUI_MAJOR 1) +set(NAPPGUI_MINOR 3) +set(NAPPGUI_REVISION 0) + +# Build version +#------------------------------------------------------------------------------ +# This is a 'Release' distribution +set (VERSION_FILE ${CMAKE_PRJ_PATH}/build.txt) +if (EXISTS "${VERSION_FILE}") + set(RELEASE_DISTRIBUTION YES) + file(READ ${VERSION_FILE} NAPPGUI_BUILD) + string(REPLACE "\r\n" "" NAPPGUI_BUILD ${NAPPGUI_BUILD}) + string(REPLACE "\n" "" NAPPGUI_BUILD ${NAPPGUI_BUILD}) + +# This a 'Development' version +else() + + find_package(Subversion) + if (SUBVERSION_FOUND) + Subversion_WC_INFO(${CMAKE_CURRENT_LIST_DIR} SVN_NAPPGUI) + set(NAPPGUI_BUILD ${SVN_NAPPGUI_WC_REVISION}) + endif() + +endif() + +if (NOT NAPPGUI_BUILD) + message("- Unknown NAppGUI Revision") + set(NAPPGUI_BUILD "XXXX") +endif() diff --git a/prj/CMakeSDKVersion.txt b/prj/CMakeSDKVersion.txt deleted file mode 100644 index c62db15..0000000 --- a/prj/CMakeSDKVersion.txt +++ /dev/null @@ -1,50 +0,0 @@ -# SDK version -# This file is part of NAppGUI-SDK project -# See README.txt and LICENSE.txt - -set(NAPPGUI_MAJOR 1) -set(NAPPGUI_MINOR 2) -set(NAPPGUI_REVISION 4) - -# Build version -#------------------------------------------------------------------------------ -# This is a 'Release' distribution -set (VERSION_FILE ${CMAKE_PRJ_PATH}/build.txt) -if (EXISTS "${VERSION_FILE}") - set(RELEASE_DISTRIBUTION YES) - file(READ ${VERSION_FILE} NAPPGUI_BUILD) - string(REPLACE "\r\n" "" NAPPGUI_BUILD ${NAPPGUI_BUILD}) - string(REPLACE "\n" "" NAPPGUI_BUILD ${NAPPGUI_BUILD}) - -# This a 'Development' version -else() - - set(SVNVERSION "svnversion") - - # Xcode 11 doesn't install 'svn' - # https://stackoverflow.com/questions/60869347/mac-command-line-tools-11-4-no-longer-has-svn - # We use 'brew install svn' - if(XCODE_VERSION VERSION_GREATER 10.99) - set(SVNVERSION "/usr/local/bin/svnversion") - endif() - - execute_process(COMMAND "${SVNVERSION}" "-n" WORKING_DIRECTORY ${CMAKE_PRJ_PATH} OUTPUT_VARIABLE SVN_VERSION ERROR_VARIABLE SVN_ERROR) - if (NOT ${SVN_VERSION} STREQUAL "") - string(FIND ${SVN_VERSION} ":" SVN_POS) - if (NOT ${SVN_POS} EQUAL -1) - math(EXPR SVN_POS "${SVN_POS} + 1") - string(SUBSTRING ${SVN_VERSION} ${SVN_POS} -1 SVN_VERSION) - endif() - - string(REPLACE "M" "" SVN_VERSION ${SVN_VERSION}) - string(REPLACE "S" "" SVN_VERSION ${SVN_VERSION}) - string(REPLACE "P" "" SVN_VERSION ${SVN_VERSION}) - set(NAPPGUI_BUILD ${SVN_VERSION}) - - else() - message("- Unknown NAppGUI Revision") - set(NAPPGUI_BUILD "") - - endif() - -endif() diff --git a/prj/CMakeVSCheckVersion.txt b/prj/CMakeVSCheckVersion.cmake similarity index 93% rename from prj/CMakeVSCheckVersion.txt rename to prj/CMakeVSCheckVersion.cmake index f3274d7..f87ab7b 100644 --- a/prj/CMakeVSCheckVersion.txt +++ b/prj/CMakeVSCheckVersion.cmake @@ -30,8 +30,8 @@ macro(checkVisualStudioVersion) # 1600 = 10.0 Visual Studio 2010 (v100 toolset) # 1500 = 9.0 Visual Studio 2008 (v90 toolset) # 1400 = 8.0 Visual Studio 2005 (v80 toolset) - # 1310 = 7.1 Visual Studio .NET 2003 - # 1300 = 7.0 Visual Studio .NET 2002 + # 1310 = 7.1 Visual Studio .NET 2003 + # 1300 = 7.0 Visual Studio .NET 2002 # 1200 = 6.0 Visual Studio 6.0 # @@ -56,9 +56,7 @@ macro(checkVisualStudioVersion) set(CMAKE_VS_PLATFORM_TOOLSET "v90") else() # Plaform Toolset Macro - if (Z${CMAKE_VS_PLATFORM_TOOLSET}Z STREQUAL "ZZ") - set(VS_TOOLSET_NUMBER 1430) - elseif (${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v143") + if (${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v143") set(VS_TOOLSET_NUMBER 1430) elseif (${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v142") set(VS_TOOLSET_NUMBER 1420) @@ -88,6 +86,6 @@ macro(checkVisualStudioVersion) message(FATAL_ERROR "Unsupported VS Platform Toolset (${CMAKE_VS_PLATFORM_TOOLSET})") endif() endif() - + endmacro() diff --git a/prj/CMakeVSWarnings.txt b/prj/CMakeVSWarnings.cmake similarity index 97% rename from prj/CMakeVSWarnings.txt rename to prj/CMakeVSWarnings.cmake index 9a786af..66ac2c3 100644 --- a/prj/CMakeVSWarnings.txt +++ b/prj/CMakeVSWarnings.cmake @@ -6,7 +6,7 @@ # https://msdn.microsoft.com/en-us/library/23k5d385(v=vs.140).aspx # # 'Manual' activation of compiler warning disabled by default in -W4 -# We don't use -Wall for compile problems in VS2017 +# We don't use -Wall for compile problems in VS2017 # https://developercommunity.visualstudio.com/content/problem/174539/objbaseh-error-when-compiling-with-permissive-and.html # #------------------------------------------------------------------------------ @@ -19,18 +19,18 @@ set(AdditionalDefinitions "/wd4625" "/wd4626" - # Additional warning over W4 + # Additional warning over W4 # (level 4) enumerator 'identifier' in a switch of enum 'enumeration' is not explicitly handled by a case label. - "/w44061" + "/w44061" # (level 4) enumerator 'identifier' in a switch of enum 'enumeration' is not handled - "/w44062" + "/w44062" # (level 3) 'operator/operation': unsafe conversion from 'type of expression' to 'type required' - "/w44191" + "/w44191" # (level 4) 'identifier': conversion from 'type1' to 'type2', possible loss of data - "/w44242" + "/w44242" # (level 4) 'operator': conversion from 'type1' to 'type2', possible loss of data "/w44254" @@ -84,7 +84,7 @@ set(AdditionalDefinitions "/w44365" # (level 3) layout of class has changed from a previous version of the compiler due to better packing - "/w44370" + "/w44370" # (level 3) layout of class may have changed from a previous version of the compiler due to better packing of member 'member' "/w44371" @@ -105,7 +105,7 @@ set(AdditionalDefinitions "/w44437" # (level 3) top level '__unaligned' is not implemented in this context - "/w44444" + "/w44444" # (level 4) a forward declaration of an unscoped enumeration must have an underlying type (int assumed) "/w44471" @@ -147,10 +147,10 @@ set(AdditionalDefinitions "/w44574" # (level 3) 'symbol1' has already been initialized by another union member in the initializer list, 'symbol2' - "/w44608" + "/w44608" # (level 3) #pragma warning: there is no warning number 'number' - "/w44619" + "/w44619" # (level 4) 'derived class': default constructor could not be generated because a base class default constructor is inaccessible "/w44623" @@ -193,7 +193,7 @@ set(AdditionalDefinitions # We consider it as Compiler optimization # (level 4) 'bytes' bytes padding added after construct 'member_name' - # "/w44820" + # "/w44820" # (level 2) conversion from 'type1' to 'type2' is sign-extended. This may cause unexpected runtime behavior "/w44826" diff --git a/prj/CMakeXCCheckVersion.txt b/prj/CMakeXCCheckVersion.cmake similarity index 87% rename from prj/CMakeXCCheckVersion.txt rename to prj/CMakeXCCheckVersion.cmake index 0a51d7d..4cddfda 100644 --- a/prj/CMakeXCCheckVersion.txt +++ b/prj/CMakeXCCheckVersion.cmake @@ -16,7 +16,17 @@ endfunction() # Get macOS name from SDK #------------------------------------------------------------------------------ function(osxSDKName sdkVersion _ret) - if (${sdkVersion} STREQUAL "12.0") + if (${sdkVersion} STREQUAL "13.1") + set(${_ret} "Ventura" PARENT_SCOPE) + elseif (${sdkVersion} STREQUAL "13.0") + set(${_ret} "Ventura" PARENT_SCOPE) + elseif (${sdkVersion} STREQUAL "12.4") + set(${_ret} "Monterey" PARENT_SCOPE) + elseif (${sdkVersion} STREQUAL "12.3") + set(${_ret} "Monterey" PARENT_SCOPE) + elseif (${sdkVersion} STREQUAL "12.2") + set(${_ret} "Monterey" PARENT_SCOPE) + elseif (${sdkVersion} STREQUAL "12.0") set(${_ret} "Monterey" PARENT_SCOPE) elseif (${sdkVersion} STREQUAL "11.5") set(${_ret} "Big Sur" PARENT_SCOPE) @@ -77,14 +87,24 @@ macro(checkXcodeVersion) message(FATAL_ERROR "Unknown Apple CMAKE_SYSTEM_NAME.") endif() + # Xcode 14 + if(XCODE_VERSION VERSION_GREATER 13.99) + checkClangCompiler() + set(BASE_OSX_SDK 13.0) + set(CMAKE_DEPLOYMENT_TARGET "13.0" CACHE STRING "Minimun macOS version required") + set_property(CACHE CMAKE_DEPLOYMENT_TARGET PROPERTY STRINGS "13.1;13.0;12.4;12.3;12.2;12.0;11.5;11.4;11.3;11.2;11.1;11.0;10.15;10.14;10.13") + set(CMAKE_ARCHITECTURE "x86_64" CACHE STRING "Processor architecture") + set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS "x86_64;arm64") + # Xcode 13 - if(XCODE_VERSION VERSION_GREATER 12.99) + elseif(XCODE_VERSION VERSION_GREATER 12.99) checkClangCompiler() - set(BASE_OSX_SDK 12.0) - set(CMAKE_DEPLOYMENT_TARGET "12.0" CACHE STRING "Minimun macOS version required") - set_property(CACHE CMAKE_DEPLOYMENT_TARGET PROPERTY STRINGS "12.0;11.5;11.4;11.3;11.2;11.1;11.0;10.15;10.14;10.13;10.12;10.11;10.10;10.9") + set(BASE_OSX_SDK 12.3) + set(CMAKE_DEPLOYMENT_TARGET "12.3" CACHE STRING "Minimun macOS version required") + set_property(CACHE CMAKE_DEPLOYMENT_TARGET PROPERTY STRINGS "12.3;12.2;12.0;11.5;11.4;11.3;11.2;11.1;11.0;10.15;10.14;10.13") set(CMAKE_ARCHITECTURE "x86_64" CACHE STRING "Processor architecture") set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS "x86_64;arm64") + # Xcode 12 elseif(XCODE_VERSION VERSION_GREATER 11.99) checkClangCompiler() @@ -100,10 +120,11 @@ macro(checkXcodeVersion) else() set(BASE_OSX_SDK 11.0) set(CMAKE_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimun macOS version required") - set_property(CACHE CMAKE_DEPLOYMENT_TARGET PROPERTY STRINGS "11.3;11.2;11.1;11.0;10.15;10.14;10.13;10.12;10.11;10.10;10.9") + set_property(CACHE CMAKE_DEPLOYMENT_TARGET PROPERTY STRINGS "11.5;11.4;11.3;11.2;11.1;11.0;10.15;10.14;10.13;10.12;10.11;10.10;10.9") set(CMAKE_ARCHITECTURE "x86_64" CACHE STRING "Processor architecture") set_property(CACHE CMAKE_ARCHITECTURE PROPERTY STRINGS "x86_64;arm64") endif() + # Xcode 11 elseif(XCODE_VERSION VERSION_GREATER 10.99) checkClangCompiler() @@ -124,7 +145,7 @@ macro(checkXcodeVersion) # Xcode 9 elseif(XCODE_VERSION VERSION_GREATER 8.99) - checkClangCompiler() + checkClangCompiler() set(BASE_OSX_SDK 10.13) set(CMAKE_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimun macOS version required") set_property(CACHE CMAKE_DEPLOYMENT_TARGET PROPERTY STRINGS "10.13;10.12;10.11;10.10;10.9") @@ -202,4 +223,3 @@ macro(checkXcodeVersion) endif() endmacro() - diff --git a/prj/CMakeXCWarnings.cmake b/prj/CMakeXCWarnings.cmake new file mode 100644 index 0000000..1ba8c5e --- /dev/null +++ b/prj/CMakeXCWarnings.cmake @@ -0,0 +1,170 @@ +# CMake Xcode Warnings config +# This file is part of NAppGUI-SDK project +# See README.txt and LICENSE.txt + +# MacOS GCC Configuration +#------------------------------------------------------------------------------ +macro(configureMacOSGcc) + set(IDE_PROPERTIES + # GCC Code generation + XCODE_ATTRIBUTE_GCC_FAST_OBJC_DISPATCH "YES" + XCODE_ATTRIBUTE_GCC_AUTO_VECTORIZATION "YES" + XCODE_ATTRIBUTE_GCC_OBJC_CALL_CXX_CDTORS "YES" + XCODE_ATTRIBUTE_GCC_ENABLE_SSE3_EXTENSIONS "YES" + XCODE_ATTRIBUTE_GCC_ENABLE_SSE41_EXTENSIONS "YES" + XCODE_ATTRIBUTE_GCC_ENABLE_SSE42_EXTENSIONS "YES" + XCODE_ATTRIBUTE_GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS "YES" + XCODE_ATTRIBUTE_GCC_MODEL_TUNING "None" + + # GCC Language + XCODE_ATTRIBUTE_GCC_CHAR_IS_UNSIGNED_CHAR "YES" + XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS "NO" + XCODE_ATTRIBUTE_GCC_ENABLE_CPP_RTTI "NO" + XCODE_ATTRIBUTE_GCC_ENABLE_EXCEPTIONS "NO" + XCODE_ATTRIBUTE_GCC_ENABLE_OBJC_EXCEPTIONS "NO" + + # GCC Warnings + XCODE_ATTRIBUTE_GCC_WARN_CHECK_SWITCH_STATEMENTS "YES" + XCODE_ATTRIBUTE_GCC_WARN_FOUR_CHARACTER_CONSTANTS "YES" + + # Library control singletons use global destructors + # Avoid the Warning + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_GLOBAL_CONSTRUCTORS "NO" + + XCODE_ATTRIBUTE_GCC_WARN_SHADOW "YES" + XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION "YES" + XCODE_ATTRIBUTE_GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL "YES" + XCODE_ATTRIBUTE_GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES" + XCODE_ATTRIBUTE_GCC_WARN_MISSING_PARENTHESES "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_PROTOTYPES "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "NO" + XCODE_ATTRIBUTE_GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR "NO" + XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES" + XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES" + XCODE_ATTRIBUTE_GCC_WARN_PEDANTIC "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_POINTER_SIGNEDNESS "YES" + XCODE_ATTRIBUTE_GCC_WARN_PROTOTYPE_CONVERSION "NO" + XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES" + XCODE_ATTRIBUTE_GCC_WARN_STRICT_SELECTOR_MATCH "NO" + XCODE_ATTRIBUTE_GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS "YES" + XCODE_ATTRIBUTE_GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS "NO" + XCODE_ATTRIBUTE_GCC_TREAT_WARNINGS_AS_ERRORS "NO" + XCODE_ATTRIBUTE_GCC_WARN_TYPECHECK_CALLS_TO_PRINTF "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNDECLARED_SELECTOR "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNKNOWN_PRAGMAS "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_LABEL "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_PARAMETER "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO "YES" + # Avoid warnings when C90 is used + XCODE_ATTRIBUTE_WARNING_CFLAGS "-Wno-long-long -Wno-overlength-strings") + + # C/C++ Compiler Flags + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -Wno-uninitialized") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -Wno-uninitialized") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-strict-aliasing") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-strict-aliasing") + set(CMAKE_C_FLAGS_RELEASEWITHASSERT "${CMAKE_C_FLAGS_RELEASEWITHASSERT} -Wno-strict-aliasing") + set(CMAKE_CXX_FLAGS_RELEASEWITHASSERT "${CMAKE_CXX_FLAGS_RELEASEWITHASSERT} -Wno-strict-aliasing") +endmacro() + +# MacOS Clang Configuration +#------------------------------------------------------------------------------ +macro(configureMacOSClang) + set(IDE_PROPERTIES + + # Code generation + XCODE_ATTRIBUTE_GCC_NO_COMMON_BLOCKS "YES" + + # Preprocessing + XCODE_ATTRIBUTE_ENABLE_STRICT_OBJC_MSGSEND "YES" + + # Architectures + XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "YES" + + # Warning policies + XCODE_ATTRIBUTE_GCC_WARN_PEDANTIC "YES" + + # Warning All Languages + XCODE_ATTRIBUTE_CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING "YES" + XCODE_ATTRIBUTE_GCC_WARN_CHECK_SWITCH_STATEMENTS "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS "YES" + XCODE_ATTRIBUTE_CLANG_WARN_DOCUMENTATION_COMMENTS "NO" + XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES" + XCODE_ATTRIBUTE_GCC_WARN_FOUR_CHARACTER_CONSTANTS "YES" + XCODE_ATTRIBUTE_GCC_WARN_SHADOW "YES" + XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES" + XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES" + XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION "YES" + XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES" + XCODE_ATTRIBUTE_CLANG_WARN_FLOAT_CONVERSION "YES" + XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES" + XCODE_ATTRIBUTE_CLANG_WARN_NON_LITERAL_NULL_CONVERSION "YES" + XCODE_ATTRIBUTE_CLANG_WARN_IMPLICIT_SIGN_CONVERSION "YES" + XCODE_ATTRIBUTE_CLANG_WARN_INFINITE_RECURSION "YES" + XCODE_ATTRIBUTE_GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES" + XCODE_ATTRIBUTE_GCC_WARN_MISSING_PARENTHESES "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_PROTOTYPES "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "NO" + XCODE_ATTRIBUTE_CLANG_WARN_ASSIGN_ENUM "YES" + XCODE_ATTRIBUTE_GCC_WARN_ABOUT_POINTER_SIGNEDNESS "YES" + XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES" + XCODE_ATTRIBUTE_CLANG_WARN_STRICT_PROTOTYPES "YES" + XCODE_ATTRIBUTE_CLANG_WARN_COMMA "YES" + XCODE_ATTRIBUTE_CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION "YES" + XCODE_ATTRIBUTE_GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS "NO" + XCODE_ATTRIBUTE_GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS "YES" + XCODE_ATTRIBUTE_GCC_WARN_TYPECHECK_CALLS_TO_PRINTF "YES" + XCODE_ATTRIBUTE_CLANG_WARN_UNGUARDED_AVAILABILITY "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNKNOWN_PRAGMAS "YES" + XCODE_ATTRIBUTE_CLANG_WARN_UNREACHABLE_CODE "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_LABEL "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_PARAMETER "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES" + + # Warning C++ + XCODE_ATTRIBUTE_CLANG_WARN_RANGE_LOOP_ANALYSIS "YES" + XCODE_ATTRIBUTE_CLANG_WARN_SUSPICIOUS_MOVE "YES" + + # Warning Objective-C + XCODE_ATTRIBUTE_CLANG_WARN__DUPLICATE_METHOD_MATCH "YES" + XCODE_ATTRIBUTE_GCC_WARN_UNDECLARED_SELECTOR "YES") + + + # Avoid warnings when C90 is used + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wno-long-long -Wno-overlength-strings") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-long-long -Wno-overlength-strings") + set(CMAKE_C_FLAGS_RELEASEWITHASSERT "${CMAKE_C_FLAGS_RELEASEWITHASSERT} -Wno-long-long -Wno-overlength-strings") + + # Avoid Linker warnings in user distributions + # (Debug symbols DWARF) + if (RELEASE_DISTRIBUTION) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -w") + endif() + + # C/C++ Compiler Flags + if(${XCODE_VERSION} VERSION_GREATER "7.99.99") + + set(IDE_PROPERTIES ${IDE_PROPERTIES} + XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_WEAK "YES") + + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-undefined-var-template") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-undefined-var-template") + set(CMAKE_C_FLAGS_RELEASEWITHASSERT "${CMAKE_C_FLAGS_RELEASEWITHASSERT}") + set(CMAKE_CXX_FLAGS_RELEASEWITHASSERT "${CMAKE_CXX_FLAGS_RELEASEWITHASSERT} -Wno-undefined-var-template") + endif() + +endmacro() diff --git a/prj/CMakeXCWarnings.txt b/prj/CMakeXCWarnings.txt deleted file mode 100644 index 1e67d58..0000000 --- a/prj/CMakeXCWarnings.txt +++ /dev/null @@ -1,165 +0,0 @@ -# CMake Xcode Warnings config -# This file is part of NAppGUI-SDK project -# See README.txt and LICENSE.txt - -# MacOS GCC Configuration -#------------------------------------------------------------------------------ -macro(configureMacOSGcc) - set(IDE_PROPERTIES - # GCC Code generation - XCODE_ATTRIBUTE_GCC_FAST_OBJC_DISPATCH "YES" - XCODE_ATTRIBUTE_GCC_AUTO_VECTORIZATION "YES" - XCODE_ATTRIBUTE_GCC_OBJC_CALL_CXX_CDTORS "YES" - XCODE_ATTRIBUTE_GCC_ENABLE_SSE3_EXTENSIONS "YES" - XCODE_ATTRIBUTE_GCC_ENABLE_SSE41_EXTENSIONS "YES" - XCODE_ATTRIBUTE_GCC_ENABLE_SSE42_EXTENSIONS "YES" - XCODE_ATTRIBUTE_GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS "YES" - XCODE_ATTRIBUTE_GCC_MODEL_TUNING "None" - - # GCC Language - XCODE_ATTRIBUTE_GCC_CHAR_IS_UNSIGNED_CHAR "YES" - XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD "c99" - XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS "NO" - XCODE_ATTRIBUTE_GCC_ENABLE_CPP_RTTI "NO" - XCODE_ATTRIBUTE_GCC_ENABLE_EXCEPTIONS "NO" - XCODE_ATTRIBUTE_GCC_ENABLE_OBJC_EXCEPTIONS "NO" - - # GCC Warnings - XCODE_ATTRIBUTE_GCC_WARN_CHECK_SWITCH_STATEMENTS "YES" - XCODE_ATTRIBUTE_GCC_WARN_FOUR_CHARACTER_CONSTANTS "YES" - - # Library control singletons use global destructors - # Avoid the Warning - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_GLOBAL_CONSTRUCTORS "NO" - - XCODE_ATTRIBUTE_GCC_WARN_SHADOW "YES" - XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION "YES" - XCODE_ATTRIBUTE_GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL "YES" - XCODE_ATTRIBUTE_GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES" - XCODE_ATTRIBUTE_GCC_WARN_MISSING_PARENTHESES "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_PROTOTYPES "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "NO" - XCODE_ATTRIBUTE_GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR "NO" - XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES" - XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES" - XCODE_ATTRIBUTE_GCC_WARN_PEDANTIC "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_POINTER_SIGNEDNESS "YES" - XCODE_ATTRIBUTE_GCC_WARN_PROTOTYPE_CONVERSION "NO" - XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES" - XCODE_ATTRIBUTE_GCC_WARN_STRICT_SELECTOR_MATCH "NO" - XCODE_ATTRIBUTE_GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS "YES" - XCODE_ATTRIBUTE_GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS "NO" - XCODE_ATTRIBUTE_GCC_TREAT_WARNINGS_AS_ERRORS "NO" - XCODE_ATTRIBUTE_GCC_WARN_TYPECHECK_CALLS_TO_PRINTF "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNDECLARED_SELECTOR "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNKNOWN_PRAGMAS "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_LABEL "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_PARAMETER "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO "YES" - XCODE_ATTRIBUTE_WARNING_CFLAGS "-Wno-overlength-strings -Wno-long-long") - - # C/C++ Compiler Flags - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -Wno-uninitialized") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -Wno-uninitialized") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-strict-aliasing") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-strict-aliasing") - set(CMAKE_C_FLAGS_RELEASEWITHASSERT "${CMAKE_C_FLAGS_RELEASEWITHASSERT} -Wno-strict-aliasing") - set(CMAKE_CXX_FLAGS_RELEASEWITHASSERT "${CMAKE_CXX_FLAGS_RELEASEWITHASSERT} -Wno-strict-aliasing") -endmacro() - -# MacOS Clang Configuration -#------------------------------------------------------------------------------ -macro(configureMacOSClang) - set(IDE_PROPERTIES - - # Code generation - #XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD "c99" - XCODE_ATTRIBUTE_GCC_NO_COMMON_BLOCKS "YES" - - # Preprocessing - XCODE_ATTRIBUTE_ENABLE_STRICT_OBJC_MSGSEND "YES" - - # Architectures - XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "YES" - - # Warning policies - XCODE_ATTRIBUTE_GCC_WARN_PEDANTIC "YES" - - # Warning All Languages - XCODE_ATTRIBUTE_CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING "YES" - XCODE_ATTRIBUTE_GCC_WARN_CHECK_SWITCH_STATEMENTS "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS "YES" - XCODE_ATTRIBUTE_CLANG_WARN_DOCUMENTATION_COMMENTS "NO" - XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES" - XCODE_ATTRIBUTE_GCC_WARN_FOUR_CHARACTER_CONSTANTS "YES" - XCODE_ATTRIBUTE_GCC_WARN_SHADOW "YES" - XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES" - XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES" - XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION "YES" - XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES" - XCODE_ATTRIBUTE_CLANG_WARN_FLOAT_CONVERSION "YES" - XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES" - XCODE_ATTRIBUTE_CLANG_WARN_NON_LITERAL_NULL_CONVERSION "YES" - XCODE_ATTRIBUTE_CLANG_WARN_IMPLICIT_SIGN_CONVERSION "YES" - XCODE_ATTRIBUTE_CLANG_WARN_INFINITE_RECURSION "YES" - XCODE_ATTRIBUTE_GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES" - XCODE_ATTRIBUTE_GCC_WARN_MISSING_PARENTHESES "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_PROTOTYPES "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "NO" - XCODE_ATTRIBUTE_CLANG_WARN_ASSIGN_ENUM "YES" - XCODE_ATTRIBUTE_GCC_WARN_ABOUT_POINTER_SIGNEDNESS "YES" - XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES" - XCODE_ATTRIBUTE_CLANG_WARN_STRICT_PROTOTYPES "YES" - XCODE_ATTRIBUTE_CLANG_WARN_COMMA "YES" - XCODE_ATTRIBUTE_CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION "YES" - XCODE_ATTRIBUTE_GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS "NO" - XCODE_ATTRIBUTE_GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS "YES" - XCODE_ATTRIBUTE_GCC_WARN_TYPECHECK_CALLS_TO_PRINTF "YES" - XCODE_ATTRIBUTE_CLANG_WARN_UNGUARDED_AVAILABILITY "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNKNOWN_PRAGMAS "YES" - XCODE_ATTRIBUTE_CLANG_WARN_UNREACHABLE_CODE "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_LABEL "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_PARAMETER "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES" - - # Warning C++ - XCODE_ATTRIBUTE_CLANG_WARN_RANGE_LOOP_ANALYSIS "YES" - XCODE_ATTRIBUTE_CLANG_WARN_SUSPICIOUS_MOVE "YES" - - # Warning Objective-C - XCODE_ATTRIBUTE_CLANG_WARN__DUPLICATE_METHOD_MATCH "YES" - XCODE_ATTRIBUTE_GCC_WARN_UNDECLARED_SELECTOR "YES") - - # Avoid Linker warnings in user distributions - # (Debug symbols DWARF) - if (RELEASE_DISTRIBUTION) - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -w") - endif() - - # C/C++ Compiler Flags - if(${XCODE_VERSION} VERSION_GREATER "7.99.99") - - set(IDE_PROPERTIES ${IDE_PROPERTIES} - XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_WEAK "YES") - - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-undefined-var-template") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-undefined-var-template") - set(CMAKE_C_FLAGS_RELEASEWITHASSERT "${CMAKE_C_FLAGS_RELEASEWITHASSERT}") - set(CMAKE_CXX_FLAGS_RELEASEWITHASSERT "${CMAKE_CXX_FLAGS_RELEASEWITHASSERT} -Wno-undefined-var-template") - endif() - -endmacro() diff --git a/prj/build.txt b/prj/build.txt index 54afd31..1e3e300 100644 --- a/prj/build.txt +++ b/prj/build.txt @@ -1 +1 @@ -3888 +4146 diff --git a/prj/script/linux/aarch64/nrc b/prj/script/linux/arm64/nrc old mode 100755 new mode 100644 similarity index 100% rename from prj/script/linux/aarch64/nrc rename to prj/script/linux/arm64/nrc diff --git a/prj/templates/banner.bmp b/prj/templates/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/prj/templates/banner.bmp and /dev/null differ diff --git a/prj/templates/license.txt b/prj/templates/license.txt deleted file mode 100644 index a2531e1..0000000 --- a/prj/templates/license.txt +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2015 Francisco Garcia Collado - -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. \ No newline at end of file diff --git a/prj/templates/main.c b/prj/templates/main.c index 64832e8..5628571 100644 --- a/prj/templates/main.c +++ b/prj/templates/main.c @@ -60,7 +60,7 @@ static App *i_create(void) { App *app = heap_new0(App); Panel *panel = i_panel(app); - app->window = window_create(ekWNSTD); + app->window = window_create(ekWINDOW_STD); window_panel(app->window, panel); window_title(app->window, "Hello, World!"); window_origin(app->window, v2df(500, 200)); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f3a6c0..4709c73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,37 +6,36 @@ project(NAppGUI) # NAppGUI Build Scripts get_filename_component(ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR} PATH) -include(${ROOT_PATH}/prj/CMakeNAppGUI.txt) +include(${ROOT_PATH}/prj/CMakeNAppGUI.cmake) -# Libraries -staticLib("sewer" "" NRC_NONE) -staticLib("osbs" "sewer" NRC_NONE) -staticLib("core" "osbs" NRC_NONE) -staticLib("geom2d" "core" NRC_NONE) -staticLib("draw2d" "geom2d" NRC_NONE) -staticLib("osgui" "draw2d" NRC_NONE) -staticLib("gui" "draw2d" NRC_EMBEDDED) -staticLib("osapp" "osgui;gui" NRC_NONE) -staticLib("inet" "core" NRC_NONE) -staticLib("utils/nlib" "core" NRC_NONE) -staticLib("demo/casino" "draw2d" NRC_EMBEDDED) - -# Exes -commandApp("utils/nrc" "utils/nlib" NRC_NONE) -desktopApp("HelloWorld" "demo/hello" "" NRC_NONE) -desktopApp("HelloCpp" "demo/hellocpp" "" NRC_NONE) -desktopApp("Die" "demo/die" "demo/casino" NRC_EMBEDDED) -desktopApp("Dice" "demo/dice" "demo/casino" NRC_EMBEDDED) -desktopApp("Bricks" "demo/bricks" "" NRC_EMBEDDED) -desktopApp("Fractals" "demo/fractals" "" NRC_EMBEDDED) -desktopApp("Bode" "demo/bode" "" NRC_PACKED) -desktopApp("Products" "demo/products" "inet" NRC_PACKED) -desktopApp("GuiHello" "howto/guihello" "" NRC_EMBEDDED) -desktopApp("DrawHello" "howto/drawhello" "" NRC_EMBEDDED) -desktopApp("Col2dHello" "howto/col2dhello" "" NRC_EMBEDDED) -desktopApp("DrawImg" "howto/drawimg" "" NRC_EMBEDDED) -desktopApp("UrlImg" "howto/urlimg" "inet" NRC_EMBEDDED) +# Static libraries +staticLib("sewer" "sewer" "" NRC_NONE) +staticLib("osbs" "osbs" "sewer" NRC_NONE) +staticLib("core" "core" "osbs" NRC_NONE) +staticLib("geom2d" "geom2d" "core" NRC_NONE) +staticLib("draw2d" "draw2d" "geom2d" NRC_NONE) +staticLib("osgui" "osgui" "draw2d" NRC_NONE) +staticLib("gui" "gui" "draw2d" NRC_EMBEDDED) +staticLib("inet" "inet" "core" NRC_NONE) +staticLib("osapp" "osapp" "osgui;gui" NRC_NONE) +staticLib("casino" "demo/casino" "draw2d" NRC_EMBEDDED) +# Executables +desktopApp("Bode" "demo/bode" "osapp" NRC_EMBEDDED) +desktopApp("Bricks" "demo/bricks" "osapp" NRC_EMBEDDED) +desktopApp("Die" "demo/die" "osapp;casino" NRC_EMBEDDED) +desktopApp("Dice" "demo/dice" "osapp;casino" NRC_EMBEDDED) +desktopApp("Fractals" "demo/fractals" "osapp" NRC_EMBEDDED) +desktopApp("HelloWorld" "demo/hello" "osapp" NRC_EMBEDDED) +desktopApp("HelloCpp" "demo/hellocpp" "osapp" NRC_EMBEDDED) +desktopApp("Products" "demo/products" "osapp;inet" NRC_PACKED) +desktopApp("Col2dHello" "howto/col2dhello" "osapp" NRC_EMBEDDED) +desktopApp("DrawBig" "howto/drawbig" "osapp" NRC_EMBEDDED) +desktopApp("DrawHello" "howto/drawhello" "osapp" NRC_EMBEDDED) +desktopApp("DrawImg" "howto/drawimg" "osapp" NRC_EMBEDDED) +desktopApp("GuiHello" "howto/guihello" "osapp" NRC_EMBEDDED) +desktopApp("UrlImg" "howto/urlimg" "osapp;inet" NRC_EMBEDDED) # Your projects here! +generateSolution() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a5bad4d..d15ac7e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1 +1,2 @@ -processStaticLib(core "osbs") \ No newline at end of file +processStaticLib(core "osbs" "") +processDynamicLib(core_d "osbs_d" "") diff --git a/src/core/array.c b/src/core/array.c index 66dc7ba..59933d6 100644 --- a/src/core/array.c +++ b/src/core/array.c @@ -10,8 +10,7 @@ /* Array data structure */ -#include "core.inl" -#include "blib.inl" +#include "blib.h" #include "bmem.h" #include "cassert.h" #include "heap.h" @@ -456,10 +455,10 @@ byte_t *array_all(const Array *array) byte_t *array_insert(Array *array, const uint32_t pos, const uint32_t n) { - register uint32_t celem, cpos; + uint32_t celem, cpos; cassert_no_null(array); celem = array->elems; - cpos = pos == UINT32_MAX ? celem : pos; + cpos = (pos == UINT32_MAX) ? celem : pos; cassert_msg(cpos <= array->elems, "Array invalid index"); cassert(n > 0); diff --git a/src/core/array.h b/src/core/array.h index 6be21d8..2e8d3bd 100644 --- a/src/core/array.h +++ b/src/core/array.h @@ -14,74 +14,74 @@ __EXTERN_C -Array *array_create(const uint16_t esize, const char_t *type); +_core_api Array *array_create(const uint16_t esize, const char_t *type); -Array *array_copy(const Array *array, FPtr_scopy func_copy, const char_t *type); +_core_api Array *array_copy(const Array *array, FPtr_scopy func_copy, const char_t *type); -Array *array_copy_ptr(const Array *array, FPtr_copy func_copy, const char_t *type); +_core_api Array *array_copy_ptr(const Array *array, FPtr_copy func_copy, const char_t *type); -Array *array_read(Stream *stream, const uint16_t esize, FPtr_read_init func_read_init, const char_t *type); +_core_api Array *array_read(Stream *stream, const uint16_t esize, FPtr_read_init func_read_init, const char_t *type); -Array *array_read_ptr(Stream *stream, FPtr_read func_read, const char_t *type); +_core_api Array *array_read_ptr(Stream *stream, FPtr_read func_read, const char_t *type); -void array_destroy(Array **array, FPtr_remove func_remove, const char_t *type); +_core_api void array_destroy(Array **array, FPtr_remove func_remove, const char_t *type); -void array_destopt(Array **array, FPtr_remove func_remove, const char_t *type); +_core_api void array_destopt(Array **array, FPtr_remove func_remove, const char_t *type); -void array_destroy_ptr(Array **array, FPtr_destroy func_destroy, const char_t *type); +_core_api void array_destroy_ptr(Array **array, FPtr_destroy func_destroy, const char_t *type); -void array_destopt_ptr(Array **array, FPtr_destroy func_destroy, const char_t *type); +_core_api void array_destopt_ptr(Array **array, FPtr_destroy func_destroy, const char_t *type); -void array_clear(Array *array, FPtr_remove func_remove); +_core_api void array_clear(Array *array, FPtr_remove func_remove); -void array_clear_ptr(Array *array, FPtr_destroy func_destroy); +_core_api void array_clear_ptr(Array *array, FPtr_destroy func_destroy); -void array_write(Stream *stream, const Array *array, FPtr_write func_write); +_core_api void array_write(Stream *stream, const Array *array, FPtr_write func_write); -void array_write_ptr(Stream *stream, const Array *array, FPtr_write func_write); +_core_api void array_write_ptr(Stream *stream, const Array *array, FPtr_write func_write); -uint32_t array_size(const Array *array); +_core_api uint32_t array_size(const Array *array); -uint32_t array_esize(const Array *array); +_core_api uint32_t array_esize(const Array *array); -byte_t *array_get(const Array *array, const uint32_t pos); +_core_api byte_t *array_get(const Array *array, const uint32_t pos); -byte_t *array_get_last(const Array *array); +_core_api byte_t *array_get_last(const Array *array); -byte_t *array_all(const Array *array); +_core_api byte_t *array_all(const Array *array); -byte_t *array_insert(Array *array, const uint32_t pos, const uint32_t n); +_core_api byte_t *array_insert(Array *array, const uint32_t pos, const uint32_t n); -byte_t *array_insert0(Array *array, const uint32_t pos, const uint32_t n); +_core_api byte_t *array_insert0(Array *array, const uint32_t pos, const uint32_t n); -void array_join(Array *dest, const Array *src, FPtr_scopy func_copy); +_core_api void array_join(Array *dest, const Array *src, FPtr_scopy func_copy); -void array_join_ptr(Array *dest, const Array *src, FPtr_copy func_copy); +_core_api void array_join_ptr(Array *dest, const Array *src, FPtr_copy func_copy); -void array_delete(Array *array, const uint32_t pos, const uint32_t n, FPtr_remove func_remove); +_core_api void array_delete(Array *array, const uint32_t pos, const uint32_t n, FPtr_remove func_remove); -void array_delete_ptr(Array *array, const uint32_t pos, const uint32_t n, FPtr_destroy func_destroy); +_core_api void array_delete_ptr(Array *array, const uint32_t pos, const uint32_t n, FPtr_destroy func_destroy); -void array_pop(Array *array, FPtr_remove func_remove); +_core_api void array_pop(Array *array, FPtr_remove func_remove); -void array_pop_ptr(Array *array, FPtr_destroy func_destroy); +_core_api void array_pop_ptr(Array *array, FPtr_destroy func_destroy); -void array_sort(Array *array, FPtr_compare func_compare); +_core_api void array_sort(Array *array, FPtr_compare func_compare); -void array_sort_ex(Array *array, FPtr_compare_ex func_compare, void *data); +_core_api void array_sort_ex(Array *array, FPtr_compare_ex func_compare, void *data); -void array_sort_ptr(Array *array, FPtr_compare func_compare); +_core_api void array_sort_ptr(Array *array, FPtr_compare func_compare); -void array_sort_ptr_ex(Array *array, FPtr_compare_ex func_compare, void *data); +_core_api void array_sort_ptr_ex(Array *array, FPtr_compare_ex func_compare, void *data); -uint32_t array_find_ptr(const Array *array, const void *elem); +_core_api uint32_t array_find_ptr(const Array *array, const void *elem); -byte_t *array_search(const Array *array, FPtr_compare func_compare, const void *key, uint32_t *pos); +_core_api byte_t *array_search(const Array *array, FPtr_compare func_compare, const void *key, uint32_t *pos); -byte_t *array_search_ptr(const Array *array, FPtr_compare func_compare, const void *key, uint32_t *pos); +_core_api byte_t *array_search_ptr(const Array *array, FPtr_compare func_compare, const void *key, uint32_t *pos); -byte_t *array_bsearch(const Array *array, FPtr_compare func_compare, const void *key, uint32_t *pos); +_core_api byte_t *array_bsearch(const Array *array, FPtr_compare func_compare, const void *key, uint32_t *pos); -byte_t *array_bsearch_ptr(const Array *array, FPtr_compare func_compare, const void *key, uint32_t *pos); +_core_api byte_t *array_bsearch_ptr(const Array *array, FPtr_compare func_compare, const void *key, uint32_t *pos); __END_C diff --git a/src/core/arrpt.hpp b/src/core/arrpt.hpp index 49359a7..a59d50d 100644 --- a/src/core/arrpt.hpp +++ b/src/core/arrpt.hpp @@ -102,20 +102,12 @@ struct ArrP2 /*---------------------------------------------------------------------------*/ -template -static const char_t* i_arrpttype(void) -{ - static char_t dtype[64]; - bstd_sprintf(dtype, sizeof(dtype), "ArrPt<%s>", typeid(type).name()); - return dtype; -} - -/*---------------------------------------------------------------------------*/ - template ArrPt* ArrPt::create(void) { - return (ArrPt*)array_create(sizeof(type*), i_arrpttype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrPt<%s>", typeid(type).name()); + return (ArrPt*)array_create(sizeof(type*), dtype); } /*---------------------------------------------------------------------------*/ @@ -123,7 +115,9 @@ ArrPt* ArrPt::create(void) template ArrPt* ArrPt::copy(const ArrPt *array, type*(*func_copy)(const type*)) { - return (ArrPt*)array_copy_ptr((Array*)array, (FPtr_copy)func_copy, i_arrpttype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrPt<%s>", typeid(type).name()); + return (ArrPt*)array_copy_ptr((Array*)array, (FPtr_copy)func_copy, dtype); } /*---------------------------------------------------------------------------*/ @@ -131,7 +125,9 @@ ArrPt* ArrPt::copy(const ArrPt *array, type*(*func_copy)(const template ArrPt* ArrPt::read(Stream *stm, type*(*func_read)(Stream*)) { - return (ArrPt*)array_read_ptr(stm, (FPtr_read)func_read, i_arrpttype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrPt<%s>", typeid(type).name()); + return (ArrPt*)array_read_ptr(stm, (FPtr_read)func_read, dtype); } /*---------------------------------------------------------------------------*/ @@ -139,7 +135,9 @@ ArrPt* ArrPt::read(Stream *stm, type*(*func_read)(Stream*)) template void ArrPt::destroy(ArrPt **array, void(*func_destroy)(type**)) { - array_destroy_ptr((Array**)array, (FPtr_destroy)func_destroy, i_arrpttype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrPt<%s>", typeid(type).name()); + array_destroy_ptr((Array**)array, (FPtr_destroy)func_destroy, dtype); } /*---------------------------------------------------------------------------*/ @@ -147,7 +145,9 @@ void ArrPt::destroy(ArrPt **array, void(*func_destroy)(type**)) template void ArrPt::destopt(ArrPt **array, void(*func_destroy)(type**)) { - array_destopt_ptr((Array**)array, (FPtr_destroy)func_destroy, i_arrpttype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrPt<%s>", typeid(type).name()); + array_destopt_ptr((Array**)array, (FPtr_destroy)func_destroy, dtype); } /*---------------------------------------------------------------------------*/ diff --git a/src/core/arrst.hpp b/src/core/arrst.hpp index 7017917..c73230a 100644 --- a/src/core/arrst.hpp +++ b/src/core/arrst.hpp @@ -108,20 +108,12 @@ struct ArrS2 /*---------------------------------------------------------------------------*/ -template -static const char_t* i_arrtype(void) -{ - static char_t dtype[64]; - bstd_sprintf(dtype, sizeof(dtype), "ArrSt<%s>", typeid(type).name()); - return dtype; -} - -/*---------------------------------------------------------------------------*/ - template ArrSt* ArrSt::create(void) { - return (ArrSt*)array_create(sizeof(type), i_arrtype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrSt<%s>", typeid(type).name()); + return (ArrSt*)array_create(sizeof(type), dtype); } /*---------------------------------------------------------------------------*/ @@ -129,7 +121,9 @@ ArrSt* ArrSt::create(void) template ArrSt* ArrSt::copy(const ArrSt *array, void(*func_copy)(type*, const type)) { - return (ArrSt*)array_copy((Array*)array, (FPtr_scopy)func_copy, i_arrtype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrSt<%s>", typeid(type).name()); + return (ArrSt*)array_copy((Array*)array, (FPtr_scopy)func_copy, dtype); } /*---------------------------------------------------------------------------*/ @@ -137,7 +131,9 @@ ArrSt* ArrSt::copy(const ArrSt *array, void(*func_copy)(type*, template ArrSt* ArrSt::read(Stream *stm, void(*func_read)(Stream*, type*)) { - return (ArrSt*)array_read(stm, sizeof(type), (FPtr_read_init)func_read, i_arrtype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrSt<%s>", typeid(type).name()); + return (ArrSt*)array_read(stm, sizeof(type), (FPtr_read_init)func_read, dtype); } /*---------------------------------------------------------------------------*/ @@ -145,7 +141,9 @@ ArrSt* ArrSt::read(Stream *stm, void(*func_read)(Stream*, type*)) template void ArrSt::destroy(ArrSt **array, void(*func_remove)(type*)) { - array_destroy((Array**)array, (FPtr_remove)func_remove, i_arrtype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrSt<%s>", typeid(type).name()); + array_destroy((Array**)array, (FPtr_remove)func_remove, dtype); } /*---------------------------------------------------------------------------*/ @@ -153,7 +151,9 @@ void ArrSt::destroy(ArrSt **array, void(*func_remove)(type*)) template void ArrSt::destopt(ArrSt **array, void(*func_remove)(type*)) { - array_destopt((Array**)array, (FPtr_remove)func_remove, i_arrtype()); + char_t dtype[64]; + bstd_sprintf(dtype, sizeof(dtype), "ArrSt<%s>", typeid(type).name()); + array_destopt((Array**)array, (FPtr_remove)func_remove, dtype); } /*---------------------------------------------------------------------------*/ diff --git a/src/core/bhash.c b/src/core/bhash.c index 029733d..c1535bf 100644 --- a/src/core/bhash.c +++ b/src/core/bhash.c @@ -97,9 +97,3 @@ uint32_t bhash_append_real32(const uint32_t hash, const real32_t value) { return i_incremental_hash((const byte_t*)&value, sizeof(real32_t), hash); } - - - - - - diff --git a/src/core/bhash.h b/src/core/bhash.h index 8f51bc9..7940227 100644 --- a/src/core/bhash.h +++ b/src/core/bhash.h @@ -14,11 +14,11 @@ __EXTERN_C -uint32_t bhash_from_block(const byte_t *data, const uint32_t size); +_core_api uint32_t bhash_from_block(const byte_t *data, const uint32_t size); -uint32_t bhash_append_uint32(const uint32_t hash, const uint32_t value); +_core_api uint32_t bhash_append_uint32(const uint32_t hash, const uint32_t value); -uint32_t bhash_append_real32(const uint32_t hash, const real32_t value); +_core_api uint32_t bhash_append_real32(const uint32_t hash, const real32_t value); __END_C diff --git a/src/core/buffer.h b/src/core/buffer.h index 0cc9c21..ac10a60 100644 --- a/src/core/buffer.h +++ b/src/core/buffer.h @@ -15,17 +15,17 @@ __EXTERN_C -Buffer *buffer_create(const uint32_t size); +_core_api Buffer *buffer_create(const uint32_t size); -Buffer *buffer_with_data(const byte_t *data, const uint32_t size); +_core_api Buffer *buffer_with_data(const byte_t *data, const uint32_t size); -void buffer_destroy(Buffer **buffer); +_core_api void buffer_destroy(Buffer **buffer); -uint32_t buffer_size(const Buffer *buffer); +_core_api uint32_t buffer_size(const Buffer *buffer); -byte_t *buffer_data(Buffer *buffer); +_core_api byte_t *buffer_data(Buffer *buffer); -const byte_t *buffer_const(const Buffer *buffer); +_core_api const byte_t *buffer_const(const Buffer *buffer); __END_C diff --git a/src/core/clock.c b/src/core/clock.c index 0a24395..386e7e0 100644 --- a/src/core/clock.c +++ b/src/core/clock.c @@ -10,7 +10,6 @@ /* Clock (Frame counter) */ -#include "core.inl" #include "clock.h" #include "btime.h" #include "cassert.h" diff --git a/src/core/clock.h b/src/core/clock.h index f8e7be0..f6201fa 100644 --- a/src/core/clock.h +++ b/src/core/clock.h @@ -15,14 +15,14 @@ __EXTERN_C -Clock *clock_create(const real64_t interval); +_core_api Clock *clock_create(const real64_t interval); -void clock_destroy(Clock **clk); +_core_api void clock_destroy(Clock **clk); -bool_t clock_frame(Clock *clk, real64_t *prev_frame, real64_t *curr_frame); +_core_api bool_t clock_frame(Clock *clk, real64_t *prev_frame, real64_t *curr_frame); -void clock_reset(Clock *clk); +_core_api void clock_reset(Clock *clk); -real64_t clock_elapsed(const Clock *clk); +_core_api real64_t clock_elapsed(const Clock *clk); __END_C diff --git a/src/core/core.cpp b/src/core/core.cpp index e991565..fb575d7 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -12,41 +12,24 @@ #include "osbs.h" #include "core.h" -#include "core.inl" #include "heap.inl" #include "dbind.inl" #include "stream.inl" #include "bmem.h" +#include "blib.h" #include "bproc.h" -#include "bstd.h" #include "cassert.h" -#include "heap.h" #include "log.h" +static uint32_t i_NUM_USERS = 0; + /*---------------------------------------------------------------------------*/ -class Core +static void i_core_atexit(void) { -public: - static uint32_t NUM_USERS; - - //Core() - //{ - // log_printf("Starting Core"); - //} - - ~Core() - { - if (NUM_USERS != 0) - { - core_finish(); - //log_printf("Error! core is not properly closed (%d)\n", NUM_USERS); - } - } -}; - -static Core i_CORE; -uint32_t Core::NUM_USERS = 0; + if (i_NUM_USERS != 0) + log_printf("Error! core is not properly closed (%d)\n", i_NUM_USERS); +} /*---------------------------------------------------------------------------*/ @@ -69,23 +52,25 @@ static void i_assert_to_log(void *item, const uint32_t group, const char_t *capt void core_start(void) { - if (i_CORE.NUM_USERS == 0) + if (i_NUM_USERS == 0) { osbs_start(); _heap_start(); _stm_start(); _dbind_start(); cassert_set_func(NULL, i_assert_to_log); - i_CORE.NUM_USERS = 1; - #if defined (__APPLE__) || defined (__LINUX__) + blib_atexit(i_core_atexit); + + i_NUM_USERS = 1; + #if defined (__APPLE__) || defined (__LINUX__) cassert(sizeof(EventHandler) == 2 * sizeof(void*)); - #else + #else cassert(sizeof(EventHandler) == sizeof(void*)); - #endif + #endif } else { - i_CORE.NUM_USERS += 1; + i_NUM_USERS += 1; } } @@ -93,10 +78,10 @@ void core_start(void) void core_finish(void) { - cassert(i_CORE.NUM_USERS > 0); - if (i_CORE.NUM_USERS == 1) + cassert(i_NUM_USERS > 0); + if (i_NUM_USERS == 1) { - i_CORE.NUM_USERS = 0; + i_NUM_USERS = 0; _dbind_finish(); _stm_finish(); _heap_finish(); @@ -104,6 +89,6 @@ void core_finish(void) } else { - i_CORE.NUM_USERS -= 1; + i_NUM_USERS -= 1; } } diff --git a/src/core/core.def b/src/core/core.def new file mode 100644 index 0000000..ecfbcec --- /dev/null +++ b/src/core/core.def @@ -0,0 +1,21 @@ +/* Core library import/export */ + +#if defined(CORE_IMPORT) + #if defined(__GNUC__) + #define _core_api + #elif defined(_MSC_VER) + #define _core_api __declspec(dllimport) + #else + #error Unknown compiler + #endif +#elif defined(NAPPGUI_SHARED_LIB) + #if defined(__GNUC__) + #define _core_api __attribute__((visibility("default"))) + #elif defined(_MSC_VER) + #define _core_api __declspec(dllexport) + #else + #error Unknown compiler + #endif +#else + #define _core_api +#endif diff --git a/src/core/core.h b/src/core/core.h index cc09588..6600113 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -15,8 +15,8 @@ __EXTERN_C -void core_start(void); +_core_api void core_start(void); -void core_finish(void); +_core_api void core_finish(void); __END_C diff --git a/src/core/core.hxx b/src/core/core.hxx index ded11a9..bcf6454 100644 --- a/src/core/core.hxx +++ b/src/core/core.hxx @@ -15,6 +15,7 @@ #define __CORE_HXX__ #include "osbs.hxx" +#include "core.def" typedef enum _core_event_t { @@ -168,7 +169,7 @@ typedef enum _token_t ekTLESS, /* < */ ekTGREAT, /* > */ - ekTCOMMA, /* , */ + ekTCOMMA, /* , */ ekTPERIOD, /* . */ ekTSCOLON, /* ; */ ekTCOLON, /* : */ @@ -179,7 +180,7 @@ typedef enum _token_t ekTCLOSBRAC, /* ] */ ekTOPENCURL, /* { */ ekTCLOSCURL, /* } */ - + ekTPLUS, /* + */ ekTMINUS, /* - */ ekTASTERK, /* * */ @@ -216,20 +217,21 @@ typedef enum _token_t } ltoken_t; -typedef struct _array_t Array; typedef struct _buffer_t Buffer; -typedef struct _keybuf_t KeyBuf; -typedef struct _clock_t Clock; -typedef struct _event_t Event; -typedef struct _listener_t Listener; +typedef struct _string_t String; +typedef struct _stream_t Stream; +typedef struct _array_t Array; typedef struct _rbtree_t RBTree; -typedef const char_t* ResId; -typedef struct _respack ResPack; typedef struct _regex RegEx; -typedef struct _stream_t Stream; -typedef struct _string_t String; +typedef struct _event_t Event; +typedef struct _keybuf_t KeyBuf; +typedef struct _listener_t Listener; typedef struct _direntry_t DirEntry; typedef struct _evfiledir_t EvFileDir; +typedef struct _respack ResPack; +typedef const char_t* ResId; +typedef struct _clock_t Clock; +typedef struct _object_t Object; #define HEAPARR "::arr" #define ARRST "ArrSt::" @@ -268,6 +270,11 @@ struct _buffer_t char data[512]; }; +struct _object_t +{ + uint32_t count; +}; + struct _string_t { uint32_t size; @@ -328,7 +335,7 @@ DeclPt(ResPack); struct IListener { protected: - Listener *listen(IListener *obj, void(IListener::*handler)(Event*)); + _core_api Listener *listen(IListener *obj, void(IListener::*handler)(Event*)); }; typedef void(IListener::*EventHandler)(Event*); diff --git a/src/core/core.ixx b/src/core/core.ixx index 36924b6..1e2ac6f 100644 --- a/src/core/core.ixx +++ b/src/core/core.ixx @@ -15,46 +15,9 @@ #include "core.hxx" -typedef enum _dtype_t -{ - ekDTYPE_BOOL, - ekDTYPE_INT8, - ekDTYPE_INT16, - ekDTYPE_INT32, - ekDTYPE_INT64, - ekDTYPE_UINT8, - ekDTYPE_UINT16, - ekDTYPE_UINT32, - ekDTYPE_UINT64, - ekDTYPE_REAL32, - ekDTYPE_REAL64, - ekDTYPE_ENUM, - ekDTYPE_STRING, - ekDTYPE_STRING_PTR, - ekDTYPE_ARRAY, - ekDTYPE_ARRPTR, - ekDTYPE_OBJECT, - ekDTYPE_OBJECT_PTR, - ekDTYPE_OBJECT_OPAQUE, - ekDTYPE_UNKNOWN -} dtype_t; - -typedef struct _object_t Object; typedef struct _nfa_t NFA; typedef struct _evassert_t EvAssert; typedef struct _lexscn_t LexScn; -typedef struct _dbind_t DBind; -typedef struct _stbind_t StBind; -typedef struct _enumbind_t EnumBind; -typedef struct _enumvbind_t EnumVBind; - -typedef void*(*FPtr_data)(const byte_t *data, const uint32_t size); -#define FUNC_CHECK_DATA(func, type)\ - (void)((type*(*)(const byte_t*, const uint32_t))func == func) - -typedef Buffer*(*FPtr_buffer)(const void *obj); -#define FUNC_CHECK_BUFFER(func, type)\ - (void)((Buffer*(*)(const type*))func == func) typedef void*(*FPtr_retain)(const void *item); #define FUNC_CHECK_RETAIN(func, type)\ @@ -64,15 +27,6 @@ typedef void(*FPtr_release)(void **item); #define FUNC_CHECK_RELEASE(func, type)\ (void)((void(*)(type**))func == func) -typedef void*(*FPtr_create_from_data)(const byte_t *data, const uint32_t size); -#define FUNC_CHECK_CREATE_FROM_DATA(func, type)\ - (void)((type*(*)(const byte_t*, const uint32_t))func == func) - -struct _object_t -{ - uint32_t retain_count; -}; - struct _evassert_t { uint32_t group; diff --git a/src/core/coreall.h b/src/core/coreall.h index 3cd90ff..87934cf 100644 --- a/src/core/coreall.h +++ b/src/core/coreall.h @@ -8,36 +8,18 @@ * */ -/* All-in-one core headers include */ +/* Core library all-in-one headers include */ -/* sewer */ -#include "cassert.h" -#include "types.h" -#include "ptr.h" -#include "unicode.h" +#include "osbsall.h" -/* osbs */ -#include "osbs.h" -#include "bfile.h" -#include "bmath.h" -#include "bmem.h" -#include "bmutex.h" -#include "bproc.h" -#include "bthread.h" -#include "btime.h" -#include "bsocket.h" -#include "bstd.h" -#include "log.h" - -/* core */ #include "core.h" #include "arrpt.h" #include "arrst.h" #include "bhash.h" #include "buffer.h" +#include "clock.h" #include "date.h" #include "dbind.h" -#include "clock.h" #include "event.h" #include "heap.h" #include "hfile.h" diff --git a/src/core/coreh.hxx b/src/core/coreh.hxx new file mode 100644 index 0000000..61dcb7e --- /dev/null +++ b/src/core/coreh.hxx @@ -0,0 +1,57 @@ +/* + * NAppGUI Cross-platform C SDK + * 2015-2022 Francisco Garcia Collado + * MIT Licence + * https://nappgui.com/en/legal/license.html + * + * File: coreh.hxx + * + */ + +/* Undocumented (hidden) Core library types */ + +#ifndef __COREH_HXX__ +#define __COREH_HXX__ + +#include "core.hxx" + +typedef enum _dtype_t +{ + ekDTYPE_BOOL, + ekDTYPE_INT8, + ekDTYPE_INT16, + ekDTYPE_INT32, + ekDTYPE_INT64, + ekDTYPE_UINT8, + ekDTYPE_UINT16, + ekDTYPE_UINT32, + ekDTYPE_UINT64, + ekDTYPE_REAL32, + ekDTYPE_REAL64, + ekDTYPE_ENUM, + ekDTYPE_STRING, + ekDTYPE_STRING_PTR, + ekDTYPE_ARRAY, + ekDTYPE_ARRPTR, + ekDTYPE_OBJECT, + ekDTYPE_OBJECT_PTR, + ekDTYPE_OBJECT_OPAQUE, + ekDTYPE_UNKNOWN +} dtype_t; + +typedef struct _dbind_t DBind; +typedef struct _stbind_t StBind; + +typedef void*(*FPtr_data)(const byte_t *data, const uint32_t size); +#define FUNC_CHECK_DATA(func, type)\ + (void)((type*(*)(const byte_t*, const uint32_t))func == func) + +typedef Buffer*(*FPtr_buffer)(const void *obj); +#define FUNC_CHECK_BUFFER(func, type)\ + (void)((Buffer*(*)(const type*))func == func) + +typedef void*(*FPtr_create_from_data)(const byte_t *data, const uint32_t size); +#define FUNC_CHECK_CREATE_FROM_DATA(func, type)\ + (void)((type*(*)(const byte_t*, const uint32_t))func == func) + +#endif \ No newline at end of file diff --git a/src/core/date.c b/src/core/date.c index a5ddf3d..846d7e2 100644 --- a/src/core/date.c +++ b/src/core/date.c @@ -34,7 +34,7 @@ static Date i_add_micros(const Date *date, int64_t micros) { uint64_t dmicros = btime_to_micro(date); Date ndate; - + if (micros > 0) dmicros += (uint64_t)micros; else @@ -122,7 +122,7 @@ bool_t date_between(const Date *date, const Date *from, const Date *to) int f = date_cmp(date, from); int t = date_cmp(date, to); - // 'from' is more recent date --> swap + /* 'from' is more recent date --> swap */ if (c < 0) { int s = f; diff --git a/src/core/date.h b/src/core/date.h index 55c367f..cb5a4e8 100644 --- a/src/core/date.h +++ b/src/core/date.h @@ -15,32 +15,32 @@ __EXTERN_C -Date date_system(void); +_core_api Date date_system(void); -Date date_add_seconds(const Date *date, int32_t seconds); +_core_api Date date_add_seconds(const Date *date, int32_t seconds); -Date date_add_minutes(const Date *date, int32_t minutes); +_core_api Date date_add_minutes(const Date *date, int32_t minutes); -Date date_add_hours(const Date *date, int32_t hours); +_core_api Date date_add_hours(const Date *date, int32_t hours); -Date date_add_days(const Date *date, int32_t days); +_core_api Date date_add_days(const Date *date, int32_t days); -int16_t date_year(void); +_core_api int16_t date_year(void); -int date_cmp(const Date *date1, const Date *date2); +_core_api int date_cmp(const Date *date1, const Date *date2); -bool_t date_between(const Date *date, const Date *from, const Date *to); +_core_api bool_t date_between(const Date *date, const Date *from, const Date *to); -bool_t date_is_null(const Date *date); +_core_api bool_t date_is_null(const Date *date); -String *date_DD_MM_YYYY_HH_MM_SS(const Date *date); +_core_api String *date_DD_MM_YYYY_HH_MM_SS(const Date *date); -String *date_YYYY_MM_DD_HH_MM_SS(const Date *date); +_core_api String *date_YYYY_MM_DD_HH_MM_SS(const Date *date); -const char_t *date_month_en(const month_t month); +_core_api const char_t *date_month_en(const month_t month); -const char_t *date_month_es(const month_t month); +_core_api const char_t *date_month_es(const month_t month); -extern Date kDATE_NULL; +_core_api extern Date kDATE_NULL; __END_C diff --git a/src/core/dbind.c b/src/core/dbind.c index 4672407..52bf26e 100644 --- a/src/core/dbind.c +++ b/src/core/dbind.c @@ -11,6 +11,7 @@ /* Data bindings */ #include "dbind.h" +#include "dbindh.h" #include "dbind.inl" #include "tfilter.inl" #include "arrpt.h" @@ -26,10 +27,12 @@ #include "stream.h" #include "strings.h" -typedef union i_attr_t i_Attr; -typedef struct i_databind_t i_DataBind; +typedef union _attribs_t Attribs; +typedef struct _enumbind_t EnumBind; +typedef struct _enumvbind_t EnumVBind; +typedef struct _databind_t DataBind; -union i_attr_t +union _attribs_t { struct _bool_ { @@ -99,7 +102,7 @@ struct _dbind_t String *name; uint16_t offset; uint16_t size; - i_Attr attr; + Attribs attr; }; struct _stbind_t @@ -128,7 +131,7 @@ struct _enumbind_t ArrSt(EnumVBind) *values; }; -struct i_databind_t +struct _databind_t { ArrPt(StBind) *stbinds; ArrPt(EnumBind) *ebinds; @@ -141,52 +144,11 @@ DeclPt(EnumBind); DeclSt(DBind); DeclPt(StBind); -//struct StBindData{ StBind elem[1024];};struct ArrStStBind{ uint32_t reserved; uint32_t size; uint16_t elem_sizeof; struct StBindData *content;}; struct ArrStStBind;inline struct ArrStStBind* arrst_StBind_create(const uint16_t esize){ return (struct ArrStStBind*)array_create(esize, (const char_t*)("ArrSt::""StBind"));}inline struct ArrStStBind* arrst_StBind_copy(const struct ArrStStBind *array, void(func_copy)(StBind*, const StBind*)){ return (struct ArrStStBind*)array_copy((Array*)array, (FPtr_scopy)func_copy, (const char_t*)("ArrSt::""StBind"));}inline struct ArrStStBind* arrst_StBind_read(Stream *stream, const uint16_t esize, void(func_read)(Stream*, StBind*)){ return (struct ArrStStBind*)array_read(stream, esize, (FPtr_read_init)func_read, (const char_t*)("ArrSt::""StBind"));}inline void arrst_StBind_destroy(struct ArrStStBind **array, void(func_remove)(StBind*)){ array_destroy((Array**)array, (FPtr_remove)func_remove, (const char_t*)("ArrSt::""StBind"));}inline void arrst_StBind_destopt(struct ArrStStBind **array, void(func_remove)(StBind*)){ array_destopt((Array**)array, (FPtr_remove)func_remove, (const char_t*)("ArrSt::""StBind"));}inline void arrst_StBind_clear(struct ArrStStBind *array, void(func_remove)(StBind*)){ array_clear((Array*)array, (FPtr_remove)func_remove);}inline void arrst_StBind_write(Stream *stream, const struct ArrStStBind *array, void(func_write)(Stream*, const StBind*)){ array_write(stream, (const Array*)array, (FPtr_write)func_write);}inline uint32_t arrst_StBind_size(const struct ArrStStBind *array){ return array_size((const Array*)array);}inline StBind *arrst_StBind_get(struct ArrStStBind *array, const uint32_t pos){ return (StBind*)array_get((Array*)array, pos);}inline const StBind *arrst_StBind_get_const(const struct ArrStStBind *array, const uint32_t pos){ return (const StBind*)array_get((Array*)array, pos);}inline StBind *arrst_StBind_last(struct ArrStStBind *array){ return (StBind*)array_get_last((Array*)array);}inline const StBind *arrst_StBind_last_const(const struct ArrStStBind *array){ return (const StBind*)array_get_last((const Array*)array);}inline StBind *arrst_StBind_all(struct ArrStStBind *array){ return (StBind*)array_all((Array*)array);}inline const StBind *arrst_StBind_all_const(const struct ArrStStBind *array){ return (const StBind*)array_all((Array*)array);}inline StBind *arrst_StBind_insert(struct ArrStStBind *array, const uint32_t pos, const uint32_t n){ return (StBind*)array_insert((Array*)array, pos, n);}inline StBind *arrst_StBind_insert0(struct ArrStStBind *array, const uint32_t pos, const uint32_t n){ return (StBind*)array_insert0((Array*)array, pos, n);}inline void arrst_StBind_join(struct ArrStStBind *dest, const struct ArrStStBind *src, void(func_copy)(StBind*, const StBind*)){ array_join((Array*)dest, (const Array*)src, (FPtr_scopy)func_copy);}inline void arrst_StBind_delete(struct ArrStStBind *array, const uint32_t pos, void(func_remove)(StBind*)){ array_delete((Array*)array, pos, 1, (FPtr_remove)func_remove);}inline void arrst_StBind_pop(struct ArrStStBind *array, void(func_remove)(StBind*)){ array_pop((Array*)array, (FPtr_remove)func_remove);}inline void arrst_StBind_sort(struct ArrStStBind *array, int(func_compare)(const StBind*, const StBind*)){ array_sort((Array*)array, (FPtr_compare)func_compare);}inline void arrst_StBind_sort_ex(struct ArrStStBind *array, FPtr_compare_ex func_compare, void *data){ array_sort_ex((Array*)array, func_compare, data);}inline StBind* arrst_StBind_search(struct ArrStStBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (StBind*)array_search((Array*)array, func_compare, key, pos);}inline const StBind* arrst_StBind_search_const(const struct ArrStStBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (const StBind*)array_search((Array*)array, func_compare, key, pos);}inline StBind* arrst_StBind_bsearch(struct ArrStStBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (StBind*)array_bsearch((Array*)array, func_compare, key, pos);}inline const StBind* arrst_StBind_bsearch_const(const struct ArrStStBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (const StBind*)array_bsearch((Array*)array, func_compare, key, pos);}inline void arrst_StBind_end(void); -//struct DBindData{ DBind elem[1024];}; -//struct ArrStDBind{ uint32_t reserved; uint32_t size; uint16_t elem_sizeof; struct DBindData *content;}; -//struct ArrStDBind; -//inline struct ArrStDBind* arrst_DBind_create(const uint16_t esize) -//{ return (struct ArrStDBind*)array_create(esize, (const char_t*)("ArrSt::""DBind"));} -//inline struct ArrStDBind* arrst_DBind_copy(const struct ArrStDBind *array, void(func_copy)(DBind*, const DBind*)) -//{ return (struct ArrStDBind*)array_copy((Array*)array, (FPtr_scopy)func_copy, (const char_t*)("ArrSt::""DBind"));} -//inline struct ArrStDBind* arrst_DBind_read(Stream *stream, const uint16_t esize, void(func_read)(Stream*, DBind*)) -//{ return (struct ArrStDBind*)array_read(stream, esize, (FPtr_read_init)func_read, (const char_t*)("ArrSt::""DBind"));} -//inline void arrst_DBind_destroy(struct ArrStDBind **array, void(func_remove)(DBind*)) -//{ array_destroy((Array**)array, (FPtr_remove)func_remove, (const char_t*)("ArrSt::""DBind"));} -//inline void arrst_DBind_destopt(struct ArrStDBind **array, void(func_remove)(DBind*)) -//{ array_destopt((Array**)array, (FPtr_remove)func_remove, (const char_t*)("ArrSt::""DBind"));} -//inline void arrst_DBind_clear(struct ArrStDBind *array, void(func_remove)(DBind*)) -//{ array_clear((Array*)array, (FPtr_remove)func_remove);} -//inline void arrst_DBind_write(Stream *stream, const struct ArrStDBind *array, void(func_write)(Stream*, const DBind*)) -//{ array_write(stream, (const Array*)array, (FPtr_write)func_write);} -//inline uint32_t arrst_DBind_size(const struct ArrStDBind *array) -//{ return array_size((const Array*)array);} -//inline DBind *arrst_DBind_get(struct ArrStDBind *array, const uint32_t pos) -//{ return (DBind*)array_get((Array*)array, pos);} -//inline const DBind *arrst_DBind_get_const(const struct ArrStDBind *array, const uint32_t pos) -//{ return (const DBind*)array_get((Array*)array, pos);} -//inline DBind *arrst_DBind_last(struct ArrStDBind *array) -//{ return (DBind*)array_get_last((Array*)array);} -//inline const DBind *arrst_DBind_last_const(const struct ArrStDBind *array) -//{ return (const DBind*)array_get_last((const Array*)array);} -// -//DBind *arrst_DBind_all(struct ArrStDBind *array);inline DBind *arrst_DBind_all(struct ArrStDBind *array){return (DBind*)array_all((Array*)array);} -// -// -// -//inline const DBind *arrst_DBind_all_const(const struct ArrStDBind *array) -//{ return (const DBind*)array_all((Array*)array);} -//inline DBind *arrst_DBind_insert(struct ArrStDBind *array, const uint32_t pos, const uint32_t n) -//{ return (DBind*)array_insert((Array*)array, pos, n);} -//inline DBind *arrst_DBind_insert0(struct ArrStDBind *array, const uint32_t pos, const uint32_t n) -//{ return (DBind*)array_insert0((Array*)array, pos, n);}inline void arrst_DBind_join(struct ArrStDBind *dest, const struct ArrStDBind *src, void(func_copy)(DBind*, const DBind*)){ array_join((Array*)dest, (const Array*)src, (FPtr_scopy)func_copy);}inline void arrst_DBind_delete(struct ArrStDBind *array, const uint32_t pos, void(func_remove)(DBind*)){ array_delete((Array*)array, pos, 1, (FPtr_remove)func_remove);}inline void arrst_DBind_pop(struct ArrStDBind *array, void(func_remove)(DBind*)){ array_pop((Array*)array, (FPtr_remove)func_remove);}inline void arrst_DBind_sort(struct ArrStDBind *array, int(func_compare)(const DBind*, const DBind*)){ array_sort((Array*)array, (FPtr_compare)func_compare);}inline void arrst_DBind_sort_ex(struct ArrStDBind *array, FPtr_compare_ex func_compare, void *data){ array_sort_ex((Array*)array, func_compare, data);}inline DBind* arrst_DBind_search(struct ArrStDBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (DBind*)array_search((Array*)array, func_compare, key, pos);}inline const DBind* arrst_DBind_search_const(const struct ArrStDBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (const DBind*)array_search((Array*)array, func_compare, key, pos);}inline DBind* arrst_DBind_bsearch(struct ArrStDBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (DBind*)array_bsearch((Array*)array, func_compare, key, pos);}inline const DBind* arrst_DBind_bsearch_const(const struct ArrStDBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (const DBind*)array_bsearch((Array*)array, func_compare, key, pos);}inline void arrst_DBind_end(void); -//struct EnumVBindData{ EnumVBind elem[1024];};struct ArrStEnumVBind{ uint32_t reserved; uint32_t size; uint16_t elem_sizeof; struct EnumVBindData *content;}; struct ArrStEnumVBind;inline struct ArrStEnumVBind* arrst_EnumVBind_create(const uint16_t esize){ return (struct ArrStEnumVBind*)array_create(esize, (const char_t*)("ArrSt::""EnumVBind"));}inline struct ArrStEnumVBind* arrst_EnumVBind_copy(const struct ArrStEnumVBind *array, void(func_copy)(EnumVBind*, const EnumVBind*)){ return (struct ArrStEnumVBind*)array_copy((Array*)array, (FPtr_scopy)func_copy, (const char_t*)("ArrSt::""EnumVBind"));}inline struct ArrStEnumVBind* arrst_EnumVBind_read(Stream *stream, const uint16_t esize, void(func_read)(Stream*, EnumVBind*)){ return (struct ArrStEnumVBind*)array_read(stream, esize, (FPtr_read_init)func_read, (const char_t*)("ArrSt::""EnumVBind"));}inline void arrst_EnumVBind_destroy(struct ArrStEnumVBind **array, void(func_remove)(EnumVBind*)){ array_destroy((Array**)array, (FPtr_remove)func_remove, (const char_t*)("ArrSt::""EnumVBind"));}inline void arrst_EnumVBind_destopt(struct ArrStEnumVBind **array, void(func_remove)(EnumVBind*)){ array_destopt((Array**)array, (FPtr_remove)func_remove, (const char_t*)("ArrSt::""EnumVBind"));}inline void arrst_EnumVBind_clear(struct ArrStEnumVBind *array, void(func_remove)(EnumVBind*)){ array_clear((Array*)array, (FPtr_remove)func_remove);}inline void arrst_EnumVBind_write(Stream *stream, const struct ArrStEnumVBind *array, void(func_write)(Stream*, const EnumVBind*)){ array_write(stream, (const Array*)array, (FPtr_write)func_write);}inline uint32_t arrst_EnumVBind_size(const struct ArrStEnumVBind *array){ return array_size((const Array*)array);}inline EnumVBind *arrst_EnumVBind_get(struct ArrStEnumVBind *array, const uint32_t pos){ return (EnumVBind*)array_get((Array*)array, pos);}inline const EnumVBind *arrst_EnumVBind_get_const(const struct ArrStEnumVBind *array, const uint32_t pos){ return (const EnumVBind*)array_get((Array*)array, pos);}inline EnumVBind *arrst_EnumVBind_last(struct ArrStEnumVBind *array){ return (EnumVBind*)array_get_last((Array*)array);}inline const EnumVBind *arrst_EnumVBind_last_const(const struct ArrStEnumVBind *array){ return (const EnumVBind*)array_get_last((const Array*)array);}inline EnumVBind *arrst_EnumVBind_all(struct ArrStEnumVBind *array){ return (EnumVBind*)array_all((Array*)array);}inline const EnumVBind *arrst_EnumVBind_all_const(const struct ArrStEnumVBind *array){ return (const EnumVBind*)array_all((Array*)array);}inline EnumVBind *arrst_EnumVBind_insert(struct ArrStEnumVBind *array, const uint32_t pos, const uint32_t n){ return (EnumVBind*)array_insert((Array*)array, pos, n);}inline EnumVBind *arrst_EnumVBind_insert0(struct ArrStEnumVBind *array, const uint32_t pos, const uint32_t n){ return (EnumVBind*)array_insert0((Array*)array, pos, n);}inline void arrst_EnumVBind_join(struct ArrStEnumVBind *dest, const struct ArrStEnumVBind *src, void(func_copy)(EnumVBind*, const EnumVBind*)){ array_join((Array*)dest, (const Array*)src, (FPtr_scopy)func_copy);}inline void arrst_EnumVBind_delete(struct ArrStEnumVBind *array, const uint32_t pos, void(func_remove)(EnumVBind*)){ array_delete((Array*)array, pos, 1, (FPtr_remove)func_remove);}inline void arrst_EnumVBind_pop(struct ArrStEnumVBind *array, void(func_remove)(EnumVBind*)){ array_pop((Array*)array, (FPtr_remove)func_remove);}inline void arrst_EnumVBind_sort(struct ArrStEnumVBind *array, int(func_compare)(const EnumVBind*, const EnumVBind*)){ array_sort((Array*)array, (FPtr_compare)func_compare);}inline void arrst_EnumVBind_sort_ex(struct ArrStEnumVBind *array, FPtr_compare_ex func_compare, void *data){ array_sort_ex((Array*)array, func_compare, data);}inline EnumVBind* arrst_EnumVBind_search(struct ArrStEnumVBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (EnumVBind*)array_search((Array*)array, func_compare, key, pos);}inline const EnumVBind* arrst_EnumVBind_search_const(const struct ArrStEnumVBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (const EnumVBind*)array_search((Array*)array, func_compare, key, pos);}inline EnumVBind* arrst_EnumVBind_bsearch(struct ArrStEnumVBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (EnumVBind*)array_bsearch((Array*)array, func_compare, key, pos);}inline const EnumVBind* arrst_EnumVBind_bsearch_const(const struct ArrStEnumVBind *array, FPtr_compare func_compare, const void *key, uint32_t *pos){ return (const EnumVBind*)array_bsearch((Array*)array, func_compare, key, pos);}inline void arrst_EnumVBind_end(void); - static void i_remove_object(byte_t *data, const StBind *stbind, const uint16_t size); static void i_destroy_object(byte_t **data, const StBind *stbind, const uint16_t size); static void i_write_value(Stream *stm, DBind *dbind, dtype_t type, const char_t *subtype, const void *data); static bool_t i_read_value(Stream *stm, DBind *dbind, dtype_t type, const char_t *subtype, void *data); -static i_DataBind i_DATABIND = { 0, 0 }; +static DataBind i_DATABIND = { 0, 0 }; /*---------------------------------------------------------------------------*/ @@ -582,7 +544,7 @@ static dtype_t i_data_type(const char_t *mtype, String **subtype, uint16_t *size return ekDTYPE_ARRPTR; } - + { uint32_t n = str_len_c(mtype); if (mtype[n - 1] == '*') @@ -820,7 +782,7 @@ static void i_add_member(StBind *stbind, const char_t *mname, const char_t *mtyp member->attr.arrayt.dtype = i_data_type(tc(subtype), NULL, NULL); member->attr.arrayt.stbind = NULL; member->attr.arrayt.ebind = NULL; - + switch (member->attr.arrayt.dtype) { /* Allowed array types */ case ekDTYPE_BOOL: @@ -863,7 +825,7 @@ static void i_add_member(StBind *stbind, const char_t *mname, const char_t *mtyp member->attr.arrayt.dtype = i_data_type(tc(subtype), NULL, NULL); member->attr.arrayt.stbind = NULL; member->attr.arrayt.ebind = NULL; - + switch (member->attr.arrayt.dtype) { /* Allowed pointer array types */ case ekDTYPE_OBJECT: @@ -926,11 +888,11 @@ static void i_add_member(StBind *stbind, const char_t *mname, const char_t *mtyp /*---------------------------------------------------------------------------*/ void dbind_imp( - const char_t *type, - const uint16_t size, - const char_t *mname, - const char_t *mtype, - const uint16_t moffset, + const char_t *type, + const uint16_t size, + const char_t *mname, + const char_t *mtype, + const uint16_t moffset, const uint16_t msize) { uint32_t index = 0; @@ -977,15 +939,6 @@ static __INLINE EnumVBind *i_enum_vbind(EnumBind *ebind, const char_t *name) /*---------------------------------------------------------------------------*/ -//static int i_cmp_ebind(const EnumVBind *ebind1, const EnumVBind *ebind2) -//{ -// cassert_no_null(ebind1); -// cassert_no_null(ebind2); -// return (int)ebind1->value - (int)ebind2->value; -//} - -/*---------------------------------------------------------------------------*/ - void dbind_enum_imp(const char_t *type, const char_t *name, const enum_t value, const char_t *alias) { EnumBind *ebind = i_enum_bind(type); @@ -1007,8 +960,6 @@ void dbind_enum_imp(const char_t *type, const char_t *name, const enum_t value, str_upd(&evalue->alias, tc(evalue->name)); else str_upd(&evalue->alias, alias); - - //arrst_sort(ebind->values, i_cmp_ebind, EnumVBind); } /*---------------------------------------------------------------------------*/ @@ -1040,6 +991,34 @@ void dbind_opaque_imp( /*---------------------------------------------------------------------------*/ +void dbind_opaque_destroy(const char_t *object_type) +{ + if (i_DATABIND.stbinds != NULL) + { + arrpt_foreach(stbind, i_DATABIND.stbinds, StBind) + if (stbind->members != NULL) + { + arrst_foreach(member, stbind->members, DBind) + if (member->type == ekDTYPE_OBJECT_OPAQUE) + { + if (member->attr.object.def != NULL) + { + cassert_no_null(member->attr.object.stbind); + if (str_equ(member->attr.object.stbind->type, object_type) == TRUE) + { + cassert_no_nullf(member->attr.object.stbind->func_destroy); + member->attr.object.stbind->func_destroy(&member->attr.object.def); + } + } + } + arrst_end(); + } + arrpt_end(); + } +} + +/*---------------------------------------------------------------------------*/ + static void i_init_object(byte_t *data, const StBind *stbind, const uint16_t size) { cassert_no_null(stbind); @@ -1104,47 +1083,47 @@ static void i_init_object(byte_t *data, const StBind *stbind, const uint16_t siz break; case ekDTYPE_INT8: - *(int8_t*)(data + member->offset) = _dbind_int8(member, (int8_t)member->attr.intt.def); + *(int8_t*)(data + member->offset) = dbind_int8(member, (int8_t)member->attr.intt.def); break; case ekDTYPE_INT16: - *(int16_t*)(data + member->offset) = _dbind_int16(member, (int16_t)member->attr.intt.def); + *(int16_t*)(data + member->offset) = dbind_int16(member, (int16_t)member->attr.intt.def); break; case ekDTYPE_INT32: - *(int32_t*)(data + member->offset) = _dbind_int32(member, (int32_t)member->attr.intt.def); + *(int32_t*)(data + member->offset) = dbind_int32(member, (int32_t)member->attr.intt.def); break; case ekDTYPE_INT64: - *(int64_t*)(data + member->offset) = _dbind_int64(member, (int64_t)member->attr.intt.def); + *(int64_t*)(data + member->offset) = dbind_int64(member, (int64_t)member->attr.intt.def); break; case ekDTYPE_UINT8: - *(uint8_t*)(data + member->offset) = _dbind_uint8(member, (uint8_t)member->attr.intt.def); + *(uint8_t*)(data + member->offset) = dbind_uint8(member, (uint8_t)member->attr.intt.def); break; case ekDTYPE_UINT16: - *(uint16_t*)(data + member->offset) = _dbind_uint16(member, (uint16_t)member->attr.intt.def); + *(uint16_t*)(data + member->offset) = dbind_uint16(member, (uint16_t)member->attr.intt.def); break; case ekDTYPE_UINT32: - *(uint32_t*)(data + member->offset) = _dbind_uint32(member, (uint32_t)member->attr.intt.def); + *(uint32_t*)(data + member->offset) = dbind_uint32(member, (uint32_t)member->attr.intt.def); break; case ekDTYPE_UINT64: - *(uint64_t*)(data + member->offset) = _dbind_uint64(member, (uint64_t)member->attr.intt.def); + *(uint64_t*)(data + member->offset) = dbind_uint64(member, (uint64_t)member->attr.intt.def); break; case ekDTYPE_ENUM: *(enum_t*)(data + member->offset) = member->attr.enumt.def; break; - + case ekDTYPE_REAL32: - *(real32_t*)(data + member->offset) = _dbind_real32(member, member->attr.real32t.def); + *(real32_t*)(data + member->offset) = dbind_real32(member, member->attr.real32t.def); break; case ekDTYPE_REAL64: - *(real64_t*)(data + member->offset) = _dbind_real64(member, member->attr.real64t.def); + *(real64_t*)(data + member->offset) = dbind_real64(member, member->attr.real64t.def); break; case ekDTYPE_UNKNOWN: @@ -1245,7 +1224,8 @@ byte_t *dbind_create_imp(const char_t *type) case ekDTYPE_OBJECT_OPAQUE: case ekDTYPE_UNKNOWN: cassert_msg(FALSE, "Dbind: Unexpected type in constructor."); - cassert_default(); + break; + cassert_default(); } str_destopt(&subtype); @@ -1373,7 +1353,7 @@ static void i_destroy_arrpt(Array **array, const char_t *type) uint16_t size; dtype_t dtype = i_data_type(type, &subtype, &size); char_t atype[128] = ARRPT; - + switch (dtype) { case ekDTYPE_OBJECT: { @@ -1606,6 +1586,8 @@ void dbind_destroy_imp(byte_t **data, const char_t *type) case ekDTYPE_OBJECT_OPAQUE: case ekDTYPE_UNKNOWN: cassert_msg(FALSE, "Dbind: Unexpected type in destructor."); + break; + cassert_default(); } @@ -1764,7 +1746,7 @@ static bool_t i_read_value(Stream *stm, DBind *dbind, dtype_t type, const char_t if (dbind != NULL) { real32_t value = stm_read_r32(stm); - *((real32_t*)data) = _dbind_real32(dbind, value); + *((real32_t*)data) = dbind_real32(dbind, value); } else { @@ -1776,7 +1758,7 @@ static bool_t i_read_value(Stream *stm, DBind *dbind, dtype_t type, const char_t if (dbind != NULL) { real64_t value = stm_read_r64(stm); - *((real64_t*)data) = _dbind_real64(dbind, value); + *((real64_t*)data) = dbind_real64(dbind, value); } else { @@ -1877,7 +1859,7 @@ static void *i_create_type(Stream *stm, const char_t *type) } else { - // Destroy the array + /* Destroy the array */ cassert_msg(FALSE, "Not implemented"); } break; @@ -1896,7 +1878,7 @@ static void *i_create_type(Stream *stm, const char_t *type) } else { - // Destroy the array + /* Destroy the array */ cassert_msg(FALSE, "Not implemented"); } break; @@ -2077,7 +2059,7 @@ static void i_write_arrpt(Stream *stm, const Array *array, const char_t *type) const byte_t *data = array_all(array); uint32_t i, n = array_size(array); String *subtype = NULL; - dtype_t atype = _dbind_type(type, &subtype, NULL); + dtype_t atype = dbind_data_type(type, &subtype, NULL); const char_t *stype = subtype != NULL ? tc(subtype) : NULL; stm_write_u32(stm, n); if (atype == ekDTYPE_STRING) @@ -2149,8 +2131,11 @@ static void i_write_value(Stream *stm, DBind *dbind, dtype_t type, const char_t stm_write_r64(stm, *(real64_t*)data); break; case ekDTYPE_ENUM: - stm_write_enum(stm, *(enum_t*)data, enum_t); + { + enum_t edata = *(enum_t*)data; + stm_write_enum(stm, edata, enum_t); break; + } case ekDTYPE_STRING: case ekDTYPE_STRING_PTR: str_write(stm, *(String**)data); @@ -2540,71 +2525,107 @@ void dbind_suffix_imp(const char_t *type, const char_t *mname, const char_t *suf /*---------------------------------------------------------------------------*/ -dtype_t _dbind_type(const char_t *type, String **subtype, uint16_t *size) +dtype_t dbind_data_type(const char_t *type, String **subtype, uint16_t *size) { return i_data_type(type, subtype, size); } /*---------------------------------------------------------------------------*/ -uint16_t _dbind_struct_size(const char_t *type) +const StBind* dbind_stbind(const char_t *type) { - dtype_t dtype; - uint16_t size; - dtype = i_data_type(type, NULL, &size); - cassert_unref(dtype == ekDTYPE_OBJECT, dtype); - return size; + return i_find_stbind(type, NULL); } /*---------------------------------------------------------------------------*/ -bool_t _dbind_struct(const char_t *type, uint16_t *size, uint32_t *nmembers) +const char_t* dbind_stbind_type(const StBind *stbind) { - StBind *stbind = i_find_stbind(type, NULL); - if (stbind == NULL) - return FALSE; + cassert_no_null(stbind); + return tc(stbind->type); +} + +/*---------------------------------------------------------------------------*/ + +uint16_t dbind_stbind_sizeof(const StBind *stbind) +{ + cassert_no_null(stbind); + return stbind->size; +} + +/*---------------------------------------------------------------------------*/ - ptr_assign(size, stbind->size); - ptr_assign(nmembers, arrst_size(stbind->members, DBind)); - return TRUE; +uint32_t dbind_stbind_count(const StBind *stbind) +{ + cassert_no_null(stbind); + return arrst_size(stbind->members, DBind); } /*---------------------------------------------------------------------------*/ -bool_t _dbind_member_i(const char_t *type, const uint32_t i, const char_t **name, uint16_t *offset, dtype_t *mtype, const char_t **subtype) +const DBind* dbind_stbind_member(const StBind *stbind, const uint32_t i) { - StBind *stbind = NULL; - DBind *member = NULL; - cassert_no_null(name); - cassert_no_null(offset); - cassert_no_null(mtype); - cassert_no_null(subtype); + cassert_no_null(stbind); + return arrst_get(stbind->members, i, DBind); +} - stbind = i_find_stbind(type, NULL); - if (stbind == NULL) - return FALSE; +/*---------------------------------------------------------------------------*/ - member = arrst_get(stbind->members, i, DBind); - if (member == NULL) - return FALSE; +const DBind* dbind_stbind_find(const StBind *stbind, const char_t *name) +{ + cassert_no_null(stbind); + return i_find_by_name(stbind->members, name); +} + +/*---------------------------------------------------------------------------*/ + +void dbind_stbind_opaque(const StBind *stbind, const byte_t *data, const uint32_t size, void **obj) +{ + /* Create an opaque object from data */ + cassert_no_null(stbind); + cassert_no_null(obj); + cassert(stbind->members == NULL); + if (*obj != NULL) + { + cassert_no_nullf(stbind->func_destroy); + stbind->func_destroy(obj); + } - *name = tc(member->name); - *offset = member->offset; - *mtype = member->type; - *subtype = i_subtype_str(member); - return TRUE; + if (stbind->func_data != NULL) + { + *obj = stbind->func_data(data, size); + } + else if (stbind->func_read != NULL) + { + Stream *stm = stm_from_block(data, size); + *obj = stbind->func_read(stm); + stm_close(&stm); + } } /*---------------------------------------------------------------------------*/ -DBind *_dbind_member(const char_t *type, const char_t *name) +void dbind_stbind_opaque_upd(const StBind *stbind, void *new_obj, void **obj) { - return i_member(type, name); + cassert_no_null(stbind); + cassert(stbind->members == NULL); + cassert_no_null(obj); + if (*obj != NULL) + { + cassert_no_nullf(stbind->func_destroy); + stbind->func_destroy(obj); + } + + if (new_obj != NULL) + { + cassert_no_nullf(stbind->func_copy); + *obj = stbind->func_copy(new_obj); + } } /*---------------------------------------------------------------------------*/ -dtype_t _dbind_member_type(const DBind *dbind) +dtype_t dbind_type(const DBind *dbind) { cassert_no_null(dbind); return dbind->type; @@ -2612,7 +2633,15 @@ dtype_t _dbind_member_type(const DBind *dbind) /*---------------------------------------------------------------------------*/ -uint16_t _dbind_member_offset(const DBind *dbind) +const char_t *dbind_name(const DBind *dbind) +{ + cassert_no_null(dbind); + return tc(dbind->name); +} + +/*---------------------------------------------------------------------------*/ + +uint16_t dbind_offset(const DBind *dbind) { cassert_no_null(dbind); return dbind->offset; @@ -2620,7 +2649,7 @@ uint16_t _dbind_member_offset(const DBind *dbind) /*---------------------------------------------------------------------------*/ -uint16_t _dbind_member_size(const DBind *dbind) +uint16_t dbind_sizeof(const DBind *dbind) { cassert_no_null(dbind); return dbind->size; @@ -2628,7 +2657,7 @@ uint16_t _dbind_member_size(const DBind *dbind) /*---------------------------------------------------------------------------*/ -const char_t *_dbind_member_subtype(const DBind *dbind) +const char_t *dbind_subtype(const DBind *dbind) { cassert_no_null(dbind); return i_subtype_str(dbind); @@ -2636,19 +2665,15 @@ const char_t *_dbind_member_subtype(const DBind *dbind) /*---------------------------------------------------------------------------*/ -void _dbind_member_get(const DBind *dbind, uint16_t *offset, dtype_t *mtype, uint16_t *msize, const char_t **subtype) +const StBind* dbind_get_stbind(const DBind *dbind) { cassert_no_null(dbind); - ptr_assign(offset, dbind->offset); - ptr_assign(mtype, dbind->type); - ptr_assign(msize, dbind->size); - if (subtype != NULL) - *subtype = i_subtype_str(dbind); + return dbind->stbind; } /*---------------------------------------------------------------------------*/ -const char_t *_dbind_real32_format(const DBind *dbind) +const char_t *dbind_real32_format(const DBind *dbind) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_REAL32); @@ -2657,7 +2682,7 @@ const char_t *_dbind_real32_format(const DBind *dbind) /*---------------------------------------------------------------------------*/ -const char_t *_dbind_real64_format(const DBind *dbind) +const char_t *dbind_real64_format(const DBind *dbind) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_REAL64); @@ -2666,7 +2691,7 @@ const char_t *_dbind_real64_format(const DBind *dbind) /*---------------------------------------------------------------------------*/ -void _dbind_real32_range(const DBind *dbind, real32_t *min, real32_t *max) +void dbind_real32_range(const DBind *dbind, real32_t *min, real32_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_REAL32); @@ -2678,7 +2703,7 @@ void _dbind_real32_range(const DBind *dbind, real32_t *min, real32_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_real64_range(const DBind *dbind, real64_t *min, real64_t *max) +void dbind_real64_range(const DBind *dbind, real64_t *min, real64_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_REAL64); @@ -2690,7 +2715,7 @@ void _dbind_real64_range(const DBind *dbind, real64_t *min, real64_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_int8_range(const DBind *dbind, int8_t *min, int8_t *max) +void dbind_int8_range(const DBind *dbind, int8_t *min, int8_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_INT8); @@ -2704,7 +2729,7 @@ void _dbind_int8_range(const DBind *dbind, int8_t *min, int8_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_int16_range(const DBind *dbind, int16_t *min, int16_t *max) +void dbind_int16_range(const DBind *dbind, int16_t *min, int16_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_INT16); @@ -2718,7 +2743,7 @@ void _dbind_int16_range(const DBind *dbind, int16_t *min, int16_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_int32_range(const DBind *dbind, int32_t *min, int32_t *max) +void dbind_int32_range(const DBind *dbind, int32_t *min, int32_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_INT32); @@ -2732,7 +2757,7 @@ void _dbind_int32_range(const DBind *dbind, int32_t *min, int32_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_int64_range(const DBind *dbind, int64_t *min, int64_t *max) +void dbind_int64_range(const DBind *dbind, int64_t *min, int64_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_INT64); @@ -2746,7 +2771,7 @@ void _dbind_int64_range(const DBind *dbind, int64_t *min, int64_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_uint8_range(const DBind *dbind, uint8_t *min, uint8_t *max) +void dbind_uint8_range(const DBind *dbind, uint8_t *min, uint8_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_UINT8); @@ -2760,7 +2785,7 @@ void _dbind_uint8_range(const DBind *dbind, uint8_t *min, uint8_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_uint16_range(const DBind *dbind, uint16_t *min, uint16_t *max) +void dbind_uint16_range(const DBind *dbind, uint16_t *min, uint16_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_UINT16); @@ -2774,7 +2799,7 @@ void _dbind_uint16_range(const DBind *dbind, uint16_t *min, uint16_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_uint32_range(const DBind *dbind, uint32_t *min, uint32_t *max) +void dbind_uint32_range(const DBind *dbind, uint32_t *min, uint32_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_UINT32); @@ -2788,7 +2813,7 @@ void _dbind_uint32_range(const DBind *dbind, uint32_t *min, uint32_t *max) /*---------------------------------------------------------------------------*/ -void _dbind_uint64_range(const DBind *dbind, uint64_t *min, uint64_t *max) +void dbind_uint64_range(const DBind *dbind, uint64_t *min, uint64_t *max) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_UINT64); @@ -2802,124 +2827,201 @@ void _dbind_uint64_range(const DBind *dbind, uint64_t *min, uint64_t *max) /*---------------------------------------------------------------------------*/ -StBind* _dbind_stbind(const char_t *type) +real32_t dbind_real32(const DBind *dbind, const real32_t value) { - return i_find_stbind(type, NULL); + cassert_no_null(dbind); + cassert(dbind->type == ekDTYPE_REAL32); + if (value != REAL32_MAX) + { + real32_t v = bmath_clampf(value, dbind->attr.real32t.min, dbind->attr.real32t.max); + return bmath_round_stepf(v, dbind->attr.real32t.prec); + } + + return value; } /*---------------------------------------------------------------------------*/ -StBind* _dbind_get_stbind(const DBind *dbind) +real64_t dbind_real64(const DBind *dbind, const real64_t value) { cassert_no_null(dbind); - return dbind->stbind; + cassert(dbind->type == ekDTYPE_REAL64); + if (value != REAL64_MAX) + { + real64_t v = bmath_clampd(value, dbind->attr.real64t.min, dbind->attr.real64t.max); + return bmath_round_stepd(v, dbind->attr.real64t.prec); + } + + return value; } /*---------------------------------------------------------------------------*/ -const char_t* _dbind_stbind_type(const StBind *stbind) +static __INLINE int64_t i_int(const DBind* dbind, const dtype_t type, const int64_t value, const int64_t min, const int64_t max) { - cassert_no_null(stbind); - return tc(stbind->type); + cassert_no_null(dbind); + cassert_unref(dbind->type == type, type); + cassert(dbind->attr.intt.min >= min); + cassert(dbind->attr.intt.max <= max); + if (value < dbind->attr.intt.min) + return dbind->attr.intt.min; + else if (value > dbind->attr.intt.max) + return dbind->attr.intt.max; + else + return value; } /*---------------------------------------------------------------------------*/ -uint16_t _dbind_stbind_size(const StBind *stbind) +int8_t dbind_int8(const DBind* dbind, const int8_t value) { - cassert_no_null(stbind); - return stbind->size; + return (int8_t)i_int(dbind, ekDTYPE_INT8, (int64_t)value, INT8_MIN, INT8_MAX); } /*---------------------------------------------------------------------------*/ -uint32_t _dbind_stbind_members(const StBind *stbind) +int16_t dbind_int16(const DBind* dbind, const int16_t value) { - cassert_no_null(stbind); - return arrst_size(stbind->members, DBind); + return (int16_t)i_int(dbind, ekDTYPE_INT16, (int64_t)value, INT16_MIN, INT16_MAX); } /*---------------------------------------------------------------------------*/ -void _dbind_stbind_member_i(const StBind *stbind, const uint32_t i, const char_t **name, uint16_t *offset, dtype_t *mtype, const char_t **subtype) +int32_t dbind_int32(const DBind* dbind, const int32_t value) { - DBind *member = NULL; - cassert_no_null(stbind); - member = arrst_get(stbind->members, i, DBind); + return (int32_t)i_int(dbind, ekDTYPE_INT32, (int64_t)value, INT32_MIN, INT32_MAX); +} - if (name != NULL) - *name = tc(member->name); +/*---------------------------------------------------------------------------*/ - if (offset != NULL) - *offset = member->offset; +int64_t dbind_int64(const DBind* dbind, const int64_t value) +{ + return (int64_t)i_int(dbind, ekDTYPE_INT64, (int64_t)value, INT64_MIN, INT64_MAX); +} - if (mtype != NULL) - *mtype = member->type; +/*---------------------------------------------------------------------------*/ - if (subtype != NULL) - *subtype = i_subtype_str(member); +uint8_t dbind_uint8(const DBind* dbind, const uint8_t value) +{ + return (uint8_t)i_int(dbind, ekDTYPE_UINT8, (int64_t)value, 0, UINT8_MAX); } /*---------------------------------------------------------------------------*/ -void _dbind_opaque(const char_t *type, const byte_t *data, const uint32_t size, void **obj) +uint16_t dbind_uint16(const DBind* dbind, const uint16_t value) { - StBind *stbind = i_find_stbind(type, NULL); - if (stbind != NULL) - { - cassert_no_null(obj); - cassert(stbind->members == NULL); - if (*obj != NULL) - { - cassert_no_nullf(stbind->func_destroy); - stbind->func_destroy(obj); - } + return (uint16_t)i_int(dbind, ekDTYPE_UINT16, (int64_t)value, 0, UINT16_MAX); +} - if (stbind->func_data != NULL) - { - *obj = stbind->func_data(data, size); - } - else if (stbind->func_read != NULL) - { - Stream *stm = stm_from_block(data, size); - *obj = stbind->func_read(stm); - stm_close(&stm); - } - } +/*---------------------------------------------------------------------------*/ + +uint32_t dbind_uint32(const DBind* dbind, const uint32_t value) +{ + return (uint32_t)i_int(dbind, ekDTYPE_UINT32, (int64_t)value, 0, UINT32_MAX); } /*---------------------------------------------------------------------------*/ -static void i_upd_opaque(StBind *stbind, void *new_obj, void **obj) +uint64_t dbind_uint64(const DBind* dbind, const uint64_t value) { - cassert_no_null(stbind); - cassert_no_null(obj); - cassert(stbind->members == NULL); - if (*obj != NULL) - { - cassert_no_nullf(stbind->func_destroy); - stbind->func_destroy(obj); - } + return (uint64_t)i_int(dbind, ekDTYPE_UINT64, (int64_t)value, 0, INT64_MAX); +} - if (new_obj != NULL) - { - cassert_no_nullf(stbind->func_copy); - *obj = stbind->func_copy(new_obj); - } +/*---------------------------------------------------------------------------*/ + +real32_t dbind_incr_real32(const DBind *dbind, const real32_t value, const bool_t pos) +{ + real32_t v = 0; + real32_t sc = pos ? 1.f : -1.f; + cassert_no_null(dbind); + cassert(dbind->type == ekDTYPE_REAL32); + v = bmath_clampf(value + sc * dbind->attr.real32t.incr, dbind->attr.real32t.min, dbind->attr.real32t.max); + return bmath_round_stepf(v, dbind->attr.real32t.prec); } /*---------------------------------------------------------------------------*/ -void _dbind_opaque_upd(const char_t *type, void *new_obj, void **obj) +real64_t dbind_incr_real64(const DBind *dbind, const real64_t value, const bool_t pos) { - StBind *stbind = i_find_stbind(type, NULL); - if (stbind != NULL) - i_upd_opaque(stbind, new_obj, obj); + real64_t v = 0; + real64_t sc = pos ? 1. : -1.; + cassert_no_null(dbind); + cassert(dbind->type == ekDTYPE_REAL64); + v = bmath_clampd(value + sc * dbind->attr.real64t.incr, dbind->attr.real64t.min, dbind->attr.real64t.max); + return bmath_round_stepd(v, dbind->attr.real64t.prec); +} + +/*---------------------------------------------------------------------------*/ + +static __INLINE int64_t i_incr_int(const DBind *dbind, const int64_t value, const bool_t pos) +{ + int64_t v = pos ? value + dbind->attr.intt.incr : value - dbind->attr.intt.incr; + if (v > dbind->attr.intt.max) + return dbind->attr.intt.max; + else if (v < dbind->attr.intt.min) + return dbind->attr.intt.min; + return v; +} + +/*---------------------------------------------------------------------------*/ + +int8_t dbind_incr_int8(const DBind *dbind, const int8_t value, const bool_t pos) +{ + return (int8_t)i_incr_int(dbind, (int64_t)value, pos); +} + +/*---------------------------------------------------------------------------*/ + +int16_t dbind_incr_int16(const DBind *dbind, const int16_t value, const bool_t pos) +{ + return (int16_t)i_incr_int(dbind, (int64_t)value, pos); +} + +/*---------------------------------------------------------------------------*/ + +int32_t dbind_incr_int32(const DBind *dbind, const int32_t value, const bool_t pos) +{ + return (int32_t)i_incr_int(dbind, (int64_t)value, pos); +} + +/*---------------------------------------------------------------------------*/ + +int64_t dbind_incr_int64(const DBind *dbind, const int64_t value, const bool_t pos) +{ + return (int64_t)i_incr_int(dbind, (int64_t)value, pos); +} + +/*---------------------------------------------------------------------------*/ + +uint8_t dbind_incr_uint8(const DBind *dbind, const uint8_t value, const bool_t pos) +{ + return (uint8_t)i_incr_int(dbind, (int64_t)value, pos); } /*---------------------------------------------------------------------------*/ -bool_t _dbind_filter_string(DBind *dbind, const char_t *src, char_t *dest, const uint32_t size) +uint16_t dbind_incr_uint16(const DBind *dbind, const uint16_t value, const bool_t pos) +{ + return (uint16_t)i_incr_int(dbind, (int64_t)value, pos); +} + +/*---------------------------------------------------------------------------*/ + +uint32_t dbind_incr_uint32(const DBind *dbind, const uint32_t value, const bool_t pos) +{ + return (uint32_t)i_incr_int(dbind, (int64_t)value, pos); +} + +/*---------------------------------------------------------------------------*/ + +uint64_t dbind_incr_uint64(const DBind *dbind, const uint64_t value, const bool_t pos) +{ + return (uint64_t)i_incr_int(dbind, (int64_t)value, pos); +} + +/*---------------------------------------------------------------------------*/ + +bool_t dbind_string_filter(const DBind *dbind, const char_t *src, char_t *dest, const uint32_t size) { cassert_no_null(dbind); switch (dbind->type) { @@ -2964,7 +3066,7 @@ bool_t _dbind_filter_string(DBind *dbind, const char_t *src, char_t *dest, const /*---------------------------------------------------------------------------*/ -real32_t _dbind_string_to_real32(DBind *dbind, const real32_t value, const char_t *src) +real32_t dbind_string_to_real32(const DBind *dbind, const real32_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_REAL32); @@ -2985,7 +3087,7 @@ real32_t _dbind_string_to_real32(DBind *dbind, const real32_t value, const char_ /*---------------------------------------------------------------------------*/ -real64_t _dbind_string_to_real64(DBind *dbind, const real64_t value, const char_t *src) +real64_t dbind_string_to_real64(const DBind *dbind, const real64_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_REAL64); @@ -3006,7 +3108,7 @@ real64_t _dbind_string_to_real64(DBind *dbind, const real64_t value, const char_ /*---------------------------------------------------------------------------*/ -int8_t _dbind_string_to_int8(DBind *dbind, const int8_t value, const char_t *src) +int8_t dbind_string_to_int8(const DBind *dbind, const int8_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_INT8); @@ -3032,7 +3134,7 @@ int8_t _dbind_string_to_int8(DBind *dbind, const int8_t value, const char_t *src /*---------------------------------------------------------------------------*/ -int16_t _dbind_string_to_int16(DBind *dbind, const int16_t value, const char_t *src) +int16_t dbind_string_to_int16(const DBind *dbind, const int16_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_INT16); @@ -3058,7 +3160,7 @@ int16_t _dbind_string_to_int16(DBind *dbind, const int16_t value, const char_t * /*---------------------------------------------------------------------------*/ -int32_t _dbind_string_to_int32(DBind *dbind, const int32_t value, const char_t *src) +int32_t dbind_string_to_int32(const DBind *dbind, const int32_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_INT32); @@ -3084,7 +3186,7 @@ int32_t _dbind_string_to_int32(DBind *dbind, const int32_t value, const char_t * /*---------------------------------------------------------------------------*/ -int64_t _dbind_string_to_int64(DBind *dbind, const int64_t value, const char_t *src) +int64_t dbind_string_to_int64(const DBind *dbind, const int64_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_INT64); @@ -3110,7 +3212,7 @@ int64_t _dbind_string_to_int64(DBind *dbind, const int64_t value, const char_t * /*---------------------------------------------------------------------------*/ -uint8_t _dbind_string_to_uint8(DBind *dbind, const uint8_t value, const char_t *src) +uint8_t dbind_string_to_uint8(const DBind *dbind, const uint8_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_UINT8); @@ -3136,7 +3238,7 @@ uint8_t _dbind_string_to_uint8(DBind *dbind, const uint8_t value, const char_t * /*---------------------------------------------------------------------------*/ -uint16_t _dbind_string_to_uint16(DBind *dbind, const uint16_t value, const char_t *src) +uint16_t dbind_string_to_uint16(const DBind *dbind, const uint16_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_UINT16); @@ -3162,7 +3264,7 @@ uint16_t _dbind_string_to_uint16(DBind *dbind, const uint16_t value, const char_ /*---------------------------------------------------------------------------*/ -uint32_t _dbind_string_to_uint32(DBind *dbind, const uint32_t value, const char_t *src) +uint32_t dbind_string_to_uint32(const DBind *dbind, const uint32_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_UINT32); @@ -3188,7 +3290,7 @@ uint32_t _dbind_string_to_uint32(DBind *dbind, const uint32_t value, const char_ /*---------------------------------------------------------------------------*/ -uint64_t _dbind_string_to_uint64(DBind *dbind, const uint64_t value, const char_t *src) +uint64_t dbind_string_to_uint64(const DBind *dbind, const uint64_t value, const char_t *src) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_UINT64); @@ -3214,205 +3316,11 @@ uint64_t _dbind_string_to_uint64(DBind *dbind, const uint64_t value, const char_ /*---------------------------------------------------------------------------*/ -real32_t _dbind_real32(DBind *dbind, const real32_t value) -{ - cassert_no_null(dbind); - cassert(dbind->type == ekDTYPE_REAL32); - if (value != REAL32_MAX) - { - real32_t v = bmath_clampf(value, dbind->attr.real32t.min, dbind->attr.real32t.max); - return bmath_round_stepf(v, dbind->attr.real32t.prec); - } - - return value; -} - -/*---------------------------------------------------------------------------*/ - -real64_t _dbind_real64(DBind *dbind, const real64_t value) -{ - cassert_no_null(dbind); - cassert(dbind->type == ekDTYPE_REAL64); - if (value != REAL64_MAX) - { - real64_t v = bmath_clampd(value, dbind->attr.real64t.min, dbind->attr.real64t.max); - return bmath_round_stepd(v, dbind->attr.real64t.prec); - } - - return value; -} - -/*---------------------------------------------------------------------------*/ - -static __INLINE int64_t i_int(const DBind* dbind, const dtype_t type, const int64_t value, const int64_t min, const int64_t max) -{ - cassert_no_null(dbind); - cassert_unref(dbind->type == type, type); - cassert_unref(dbind->attr.intt.min >= min, min); - cassert_unref(dbind->attr.intt.max <= max, max); - if (value < dbind->attr.intt.min) - return dbind->attr.intt.min; - else if (value > dbind->attr.intt.max) - return dbind->attr.intt.max; - else - return value; -} - -/*---------------------------------------------------------------------------*/ - -int8_t _dbind_int8(const DBind* dbind, const int8_t value) -{ - return (int8_t)i_int(dbind, ekDTYPE_INT8, (int64_t)value, INT8_MIN, INT8_MAX); -} - -/*---------------------------------------------------------------------------*/ - -int16_t _dbind_int16(const DBind* dbind, const int16_t value) -{ - return (int16_t)i_int(dbind, ekDTYPE_INT16, (int64_t)value, INT16_MIN, INT16_MAX); -} - -/*---------------------------------------------------------------------------*/ - -int32_t _dbind_int32(const DBind* dbind, const int32_t value) -{ - return (int32_t)i_int(dbind, ekDTYPE_INT32, (int64_t)value, INT32_MIN, INT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -int64_t _dbind_int64(const DBind* dbind, const int64_t value) -{ - return (int64_t)i_int(dbind, ekDTYPE_INT64, (int64_t)value, INT64_MIN, INT64_MAX); -} - -/*---------------------------------------------------------------------------*/ - -uint8_t _dbind_uint8(const DBind* dbind, const uint8_t value) -{ - return (uint8_t)i_int(dbind, ekDTYPE_UINT8, (int64_t)value, 0, UINT8_MAX); -} - -/*---------------------------------------------------------------------------*/ - -uint16_t _dbind_uint16(const DBind* dbind, const uint16_t value) -{ - return (uint16_t)i_int(dbind, ekDTYPE_UINT16, (int64_t)value, 0, UINT16_MAX); -} - -/*---------------------------------------------------------------------------*/ - -uint32_t _dbind_uint32(const DBind* dbind, const uint32_t value) -{ - return (uint32_t)i_int(dbind, ekDTYPE_UINT32, (int64_t)value, 0, UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -uint64_t _dbind_uint64(const DBind* dbind, const uint64_t value) -{ - return (uint64_t)i_int(dbind, ekDTYPE_UINT64, (int64_t)value, 0, INT64_MAX); -} - -/*---------------------------------------------------------------------------*/ - -real32_t _dbind_incr_real32(DBind *dbind, const real32_t value, const bool_t pos) -{ - real32_t v = 0; - real32_t sc = pos ? 1.f : -1.f; - cassert_no_null(dbind); - cassert(dbind->type == ekDTYPE_REAL32); - v = bmath_clampf(value + sc * dbind->attr.real32t.incr, dbind->attr.real32t.min, dbind->attr.real32t.max); - return bmath_round_stepf(v, dbind->attr.real32t.prec); -} - -/*---------------------------------------------------------------------------*/ - -real64_t _dbind_incr_real64(DBind *dbind, const real64_t value, const bool_t pos) -{ - real64_t v = 0; - real64_t sc = pos ? 1. : -1.; - cassert_no_null(dbind); - cassert(dbind->type == ekDTYPE_REAL64); - v = bmath_clampd(value + sc * dbind->attr.real64t.incr, dbind->attr.real64t.min, dbind->attr.real64t.max); - return bmath_round_stepd(v, dbind->attr.real64t.prec); -} - -/*---------------------------------------------------------------------------*/ - -static __INLINE int64_t i_incr_int(DBind *dbind, const int64_t value, const bool_t pos) -{ - int64_t v = pos ? value + dbind->attr.intt.incr : value - dbind->attr.intt.incr; - if (v > dbind->attr.intt.max) - return dbind->attr.intt.max; - else if (v < dbind->attr.intt.min) - return dbind->attr.intt.min; - return v; -} - -/*---------------------------------------------------------------------------*/ - -int8_t _dbind_incr_int8(DBind *dbind, const int8_t value, const bool_t pos) -{ - return (int8_t)i_incr_int(dbind, (int64_t)value, pos); -} - -/*---------------------------------------------------------------------------*/ - -int16_t _dbind_incr_int16(DBind *dbind, const int16_t value, const bool_t pos) -{ - return (int16_t)i_incr_int(dbind, (int64_t)value, pos); -} - -/*---------------------------------------------------------------------------*/ - -int32_t _dbind_incr_int32(DBind *dbind, const int32_t value, const bool_t pos) -{ - return (int32_t)i_incr_int(dbind, (int64_t)value, pos); -} - -/*---------------------------------------------------------------------------*/ - -int64_t _dbind_incr_int64(DBind *dbind, const int64_t value, const bool_t pos) -{ - return (int64_t)i_incr_int(dbind, (int64_t)value, pos); -} - -/*---------------------------------------------------------------------------*/ - -uint8_t _dbind_incr_uint8(DBind *dbind, const uint8_t value, const bool_t pos) -{ - return (uint8_t)i_incr_int(dbind, (int64_t)value, pos); -} - -/*---------------------------------------------------------------------------*/ - -uint16_t _dbind_incr_uint16(DBind *dbind, const uint16_t value, const bool_t pos) -{ - return (uint16_t)i_incr_int(dbind, (int64_t)value, pos); -} - -/*---------------------------------------------------------------------------*/ - -uint32_t _dbind_incr_uint32(DBind *dbind, const uint32_t value, const bool_t pos) -{ - return (uint32_t)i_incr_int(dbind, (int64_t)value, pos); -} - -/*---------------------------------------------------------------------------*/ - -uint64_t _dbind_incr_uint64(DBind *dbind, const uint64_t value, const bool_t pos) -{ - return (uint64_t)i_incr_int(dbind, (int64_t)value, pos); -} - -/*---------------------------------------------------------------------------*/ - -void* _dbind_default_opaque(DBind *dbind) +void* dbind_opaque_default(const DBind *dbind) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_OBJECT_OPAQUE); - return dbind->attr.object.def; + return dbind->attr.object.def; } /*---------------------------------------------------------------------------*/ @@ -3452,7 +3360,7 @@ static bool_t i_is_basic_type(const dtype_t type) /*---------------------------------------------------------------------------*/ -bool_t _dbind_type_is_number(const dtype_t type) +static bool_t i_is_number(const dtype_t type) { switch (type) { case ekDTYPE_INT8: @@ -3487,41 +3395,7 @@ bool_t _dbind_type_is_number(const dtype_t type) /*---------------------------------------------------------------------------*/ -bool_t _dbind_type_is_integer(const dtype_t type) -{ - switch (type) { - case ekDTYPE_INT8: - case ekDTYPE_INT16: - case ekDTYPE_INT32: - case ekDTYPE_INT64: - case ekDTYPE_UINT8: - case ekDTYPE_UINT16: - case ekDTYPE_UINT32: - case ekDTYPE_UINT64: - return TRUE; - case ekDTYPE_BOOL: - case ekDTYPE_REAL32: - case ekDTYPE_REAL64: - case ekDTYPE_ENUM: - case ekDTYPE_STRING: - case ekDTYPE_STRING_PTR: - case ekDTYPE_ARRAY: - case ekDTYPE_ARRPTR: - case ekDTYPE_OBJECT: - case ekDTYPE_OBJECT_PTR: - case ekDTYPE_OBJECT_OPAQUE: - return FALSE; - - case ekDTYPE_UNKNOWN: - cassert_default(); - } - - return FALSE; -} - -/*---------------------------------------------------------------------------*/ - -bool_t _dbind_is_basic_type(const DBind* dbind) +bool_t dbind_is_basic_type(const DBind* dbind) { cassert_no_null(dbind); return i_is_basic_type(dbind->type); @@ -3529,47 +3403,54 @@ bool_t _dbind_is_basic_type(const DBind* dbind) /*---------------------------------------------------------------------------*/ -bool_t _dbind_is_number_type(const DBind *dbind) +bool_t dbind_is_number_type(const DBind *dbind) { cassert_no_null(dbind); - return _dbind_type_is_number(dbind->type); + return i_is_number(dbind->type); } /*---------------------------------------------------------------------------*/ -bool_t _dbind_is_enum_type(const DBind *dbind) +uint32_t dbind_enum_count(const DBind *dbind) { cassert_no_null(dbind); - return (bool_t)(dbind->type == ekDTYPE_ENUM); + cassert(dbind->type == ekDTYPE_ENUM); + return arrst_size(dbind->attr.enumt.ebind->values, EnumVBind); } /*---------------------------------------------------------------------------*/ -uint32_t _dbind_enum_size(const DBind *dbind) +enum_t dbind_enum_value(const DBind *dbind, const uint32_t index) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_ENUM); - return arrst_size(dbind->attr.enumt.ebind->values, EnumVBind); + if (index < arrst_size(dbind->attr.enumt.ebind->values, EnumVBind)) + { + const EnumVBind *ebind = arrst_get(dbind->attr.enumt.ebind->values, index, EnumVBind); + return ebind->value; + } + + return ENUM_MAX(enum_t); } /*---------------------------------------------------------------------------*/ -enum_t _dbind_enum_value(const DBind *dbind, const uint32_t index) +const char_t *dbind_enum_alias(const DBind *dbind, const uint32_t index) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_ENUM); if (index < arrst_size(dbind->attr.enumt.ebind->values, EnumVBind)) { const EnumVBind *ebind = arrst_get(dbind->attr.enumt.ebind->values, index, EnumVBind); - return ebind->value; + return tc(ebind->alias); } - return ENUM_MAX(enum_t); + return ""; } /*---------------------------------------------------------------------------*/ -uint32_t _dbind_enum_index(const DBind *dbind, const enum_t value) +uint32_t dbind_enum_index(const DBind *dbind, const enum_t value) { cassert_no_null(dbind); cassert(dbind->type == ekDTYPE_ENUM); @@ -3579,18 +3460,3 @@ uint32_t _dbind_enum_index(const DBind *dbind, const enum_t value) arrst_end(); return UINT32_MAX; } - -/*---------------------------------------------------------------------------*/ - -const char_t *_dbind_enum_alias(const DBind *dbind, const uint32_t index) -{ - cassert_no_null(dbind); - cassert(dbind->type == ekDTYPE_ENUM); - if (index < arrst_size(dbind->attr.enumt.ebind->values, EnumVBind)) - { - const EnumVBind *ebind = arrst_get(dbind->attr.enumt.ebind->values, index, EnumVBind); - return tc(ebind->alias); - } - - return ""; -} diff --git a/src/core/dbind.h b/src/core/dbind.h index dcc5284..7b4ff8c 100644 --- a/src/core/dbind.h +++ b/src/core/dbind.h @@ -15,33 +15,33 @@ __EXTERN_C -void dbind_imp(const char_t *type, const uint16_t size, const char_t *mname, const char_t *mtype, const uint16_t moffset, const uint16_t msize); +_core_api void dbind_imp(const char_t *type, const uint16_t size, const char_t *mname, const char_t *mtype, const uint16_t moffset, const uint16_t msize); -void dbind_enum_imp(const char_t *type, const char_t *name, const enum_t value, const char_t *alias); +_core_api void dbind_enum_imp(const char_t *type, const char_t *name, const enum_t value, const char_t *alias); -byte_t *dbind_create_imp(const char_t *type); +_core_api byte_t *dbind_create_imp(const char_t *type); -void dbind_init_imp(byte_t *data, const char_t *type); +_core_api void dbind_init_imp(byte_t *data, const char_t *type); -void dbind_remove_imp(byte_t *data, const char_t *type); +_core_api void dbind_remove_imp(byte_t *data, const char_t *type); -void dbind_destroy_imp(byte_t **data, const char_t *type); +_core_api void dbind_destroy_imp(byte_t **data, const char_t *type); -void dbind_destopt_imp(byte_t **data, const char_t *type); +_core_api void dbind_destopt_imp(byte_t **data, const char_t *type); -void *dbind_read_imp(Stream *stm, const char_t *type); +_core_api void *dbind_read_imp(Stream *stm, const char_t *type); -void dbind_write_imp(Stream *stm, const void *data, const char_t *type); +_core_api void dbind_write_imp(Stream *stm, const void *data, const char_t *type); -void dbind_default_imp(const char_t *type, const char_t *mname, const void *value); +_core_api void dbind_default_imp(const char_t *type, const char_t *mname, const void *value); -void dbind_range_imp(const char_t *type, const char_t *mname, const void *min, const void *max); +_core_api void dbind_range_imp(const char_t *type, const char_t *mname, const void *min, const void *max); -void dbind_precision_imp(const char_t *type, const char_t *mname, const void *prec); +_core_api void dbind_precision_imp(const char_t *type, const char_t *mname, const void *prec); -void dbind_increment_imp(const char_t *type, const char_t *mname, const void *incr); +_core_api void dbind_increment_imp(const char_t *type, const char_t *mname, const void *incr); -void dbind_suffix_imp(const char_t *type, const char_t *mname, const char_t *suffix); +_core_api void dbind_suffix_imp(const char_t *type, const char_t *mname, const char_t *suffix); __END_C diff --git a/src/core/dbind.inl b/src/core/dbind.inl index 52103e7..415c8cd 100644 --- a/src/core/dbind.inl +++ b/src/core/dbind.inl @@ -18,169 +18,4 @@ void _dbind_start(void); void _dbind_finish(void); -void dbind_opaque_imp(const char_t *type, FPtr_data func_data, FPtr_buffer func_buffer, FPtr_copy func_copy, FPtr_read func_read, FPtr_write func_write, FPtr_destroy func_destroy); - -dtype_t _dbind_type(const char_t *type, String **subtype, uint16_t *size); - -uint16_t _dbind_struct_size(const char_t *type); - -bool_t _dbind_struct(const char_t *type, uint16_t *size, uint32_t *nmembers); - -bool_t _dbind_member_i(const char_t *type, const uint32_t i, const char_t **name, uint16_t *offset, dtype_t *mtype, const char_t **subtype); - -DBind* _dbind_member(const char_t *type, const char_t *name); - -dtype_t _dbind_member_type(const DBind *dbind); - -uint16_t _dbind_member_offset(const DBind *dbind); - -uint16_t _dbind_member_size(const DBind *dbind); - -const char_t *_dbind_member_subtype(const DBind *dbind); - -void _dbind_member_get(const DBind *dbind, uint16_t *offset, dtype_t *mtype, uint16_t *msize, const char_t **subtype); - -const char_t *_dbind_real32_format(const DBind *dbind); - -const char_t *_dbind_real64_format(const DBind *dbind); - -void _dbind_real32_range(const DBind *dbind, real32_t *min, real32_t *max); - -void _dbind_real64_range(const DBind *dbind, real64_t *min, real64_t *max); - -void _dbind_int8_range(const DBind *dbind, int8_t *min, int8_t *max); - -void _dbind_int16_range(const DBind *dbind, int16_t *min, int16_t *max); - -void _dbind_int32_range(const DBind *dbind, int32_t *min, int32_t *max); - -void _dbind_int64_range(const DBind *dbind, int64_t *min, int64_t *max); - -void _dbind_uint8_range(const DBind *dbind, uint8_t *min, uint8_t *max); - -void _dbind_uint16_range(const DBind *dbind, uint16_t *min, uint16_t *max); - -void _dbind_uint32_range(const DBind *dbind, uint32_t *min, uint32_t *max); - -void _dbind_uint64_range(const DBind *dbind, uint64_t *min, uint64_t *max); - -StBind* _dbind_stbind(const char_t *type); - -StBind* _dbind_get_stbind(const DBind *dbind); - -const char_t* _dbind_stbind_type(const StBind *stbind); - -uint16_t _dbind_stbind_size(const StBind *stbind); - -uint32_t _dbind_stbind_members(const StBind *stbind); - -void _dbind_stbind_member_i(const StBind *stbind, const uint32_t i, const char_t **name, uint16_t *offset, dtype_t *mtype, const char_t **subtype); - -void _dbind_opaque(const char_t *type, const byte_t *data, const uint32_t size, void **obj); - -void _dbind_opaque_upd(const char_t *type, void *new_obj, void **obj); - -bool_t _dbind_filter_string(DBind *dbind, const char_t *src, char_t *dest, const uint32_t size); - -real32_t _dbind_string_to_real32(DBind *dbind, const real32_t value, const char_t *src); - -real64_t _dbind_string_to_real64(DBind *dbind, const real64_t value, const char_t *src); - -int8_t _dbind_string_to_int8(DBind *dbind, const int8_t value, const char_t *src); - -int16_t _dbind_string_to_int16(DBind *dbind, const int16_t value, const char_t *src); - -int32_t _dbind_string_to_int32(DBind *dbind, const int32_t value, const char_t *src); - -int64_t _dbind_string_to_int64(DBind *dbind, const int64_t value, const char_t *src); - -uint8_t _dbind_string_to_uint8(DBind *dbind, const uint8_t value, const char_t *src); - -uint16_t _dbind_string_to_uint16(DBind *dbind, const uint16_t value, const char_t *src); - -uint32_t _dbind_string_to_uint32(DBind *dbind, const uint32_t value, const char_t *src); - -uint64_t _dbind_string_to_uint64(DBind *dbind, const uint64_t value, const char_t *src); - -real32_t _dbind_real32(DBind *dbind, const real32_t value); - -real64_t _dbind_real64(DBind *dbind, const real64_t value); - -int8_t _dbind_int8(const DBind *dbind, const int8_t value); - -int16_t _dbind_int16(const DBind* dbind, const int16_t value); - -int32_t _dbind_int32(const DBind* dbind, const int32_t value); - -int64_t _dbind_int64(const DBind* dbind, const int64_t value); - -uint8_t _dbind_uint8(const DBind* dbind, const uint8_t value); - -uint16_t _dbind_uint16(const DBind* dbind, const uint16_t value); - -uint32_t _dbind_uint32(const DBind* dbind, const uint32_t value); - -uint64_t _dbind_uint64(const DBind* dbind, const uint64_t value); - -real32_t _dbind_incr_real32(DBind *dbind, const real32_t value, const bool_t pos); - -real64_t _dbind_incr_real64(DBind *dbind, const real64_t value, const bool_t pos); - -int8_t _dbind_incr_int8(DBind *dbind, const int8_t value, const bool_t pos); - -int16_t _dbind_incr_int16(DBind *dbind, const int16_t value, const bool_t pos); - -int32_t _dbind_incr_int32(DBind *dbind, const int32_t value, const bool_t pos); - -int64_t _dbind_incr_int64(DBind *dbind, const int64_t value, const bool_t pos); - -uint8_t _dbind_incr_uint8(DBind *dbind, const uint8_t value, const bool_t pos); - -uint16_t _dbind_incr_uint16(DBind *dbind, const uint16_t value, const bool_t pos); - -uint32_t _dbind_incr_uint32(DBind *dbind, const uint32_t value, const bool_t pos); - -uint64_t _dbind_incr_uint64(DBind *dbind, const uint64_t value, const bool_t pos); - -void* _dbind_default_opaque(DBind *dbind); - -bool_t _dbind_type_is_number(const dtype_t type); - -bool_t _dbind_type_is_integer(const dtype_t type); - -bool_t _dbind_is_basic_type(const DBind* dbind); - -bool_t _dbind_is_number_type(const DBind *dbind); - -bool_t _dbind_is_enum_type(const DBind *dbind); - -uint32_t _dbind_enum_size(const DBind *dbind); - -enum_t _dbind_enum_value(const DBind *dbind, const uint32_t index); - -uint32_t _dbind_enum_index(const DBind *dbind, const enum_t value); - -const char_t *_dbind_enum_alias(const DBind *dbind, const uint32_t index); - __END_C - -#define dbind_opaque(type, func_data, func_buffer, func_copy, func_read, func_write, func_destroy)\ - (\ - FUNC_CHECK_DATA(func_data, type),\ - FUNC_CHECK_BUFFER(func_buffer, type),\ - FUNC_CHECK_COPY(func_copy, type),\ - FUNC_CHECK_READ(func_read, type),\ - FUNC_CHECK_WRITE(func_write, type),\ - FUNC_CHECK_DESTROY(func_destroy, type),\ - dbind_opaque_imp(\ - (const char_t*)#type,\ - (FPtr_data)func_data,\ - (FPtr_buffer)func_buffer,\ - (FPtr_copy)func_copy,\ - (FPtr_read)func_read,\ - (FPtr_write)func_write,\ - (FPtr_destroy)func_destroy)\ - ) - - - diff --git a/src/core/dbindh.h b/src/core/dbindh.h new file mode 100644 index 0000000..6ea426e --- /dev/null +++ b/src/core/dbindh.h @@ -0,0 +1,177 @@ +/* + * NAppGUI Cross-platform C SDK + * 2015-2022 Francisco Garcia Collado + * MIT Licence + * https://nappgui.com/en/legal/license.html + * + * File: dbindh.h + * + */ + +/* +* Undocumented (hidden) API to use DBind database +* +* StBind = Data binding with struct type +* DBind = Data binding with struct member +* +*/ + +#include "coreh.hxx" + +__EXTERN_C + +_core_api void dbind_opaque_imp(const char_t *type, FPtr_data func_data, FPtr_buffer func_buffer, FPtr_copy func_copy, FPtr_read func_read, FPtr_write func_write, FPtr_destroy func_destroy); + +_core_api void dbind_opaque_destroy(const char_t *object_type); + +_core_api dtype_t dbind_data_type(const char_t *type, String **subtype, uint16_t *size); + + +_core_api const StBind* dbind_stbind(const char_t *type); + +_core_api const char_t* dbind_stbind_type(const StBind *stbind); + +_core_api uint16_t dbind_stbind_sizeof(const StBind *stbind); + +_core_api uint32_t dbind_stbind_count(const StBind *stbind); + +_core_api const DBind* dbind_stbind_member(const StBind *stbind, const uint32_t i); + +_core_api const DBind* dbind_stbind_find(const StBind *stbind, const char_t *name); + +_core_api void dbind_stbind_opaque(const StBind *stbind, const byte_t *data, const uint32_t size, void **obj); + +_core_api void dbind_stbind_opaque_upd(const StBind *stbind, void *new_obj, void **obj); + + +_core_api dtype_t dbind_type(const DBind *dbind); + +_core_api const char_t *dbind_name(const DBind *dbind); + +_core_api uint16_t dbind_offset(const DBind *dbind); + +_core_api uint16_t dbind_sizeof(const DBind *dbind); + +_core_api const char_t *dbind_subtype(const DBind *dbind); + +_core_api const StBind* dbind_get_stbind(const DBind *dbind); + +_core_api const char_t *dbind_real32_format(const DBind *dbind); + +_core_api const char_t *dbind_real64_format(const DBind *dbind); + +_core_api void dbind_real32_range(const DBind *dbind, real32_t *min, real32_t *max); + +_core_api void dbind_real64_range(const DBind *dbind, real64_t *min, real64_t *max); + +_core_api void dbind_int8_range(const DBind *dbind, int8_t *min, int8_t *max); + +_core_api void dbind_int16_range(const DBind *dbind, int16_t *min, int16_t *max); + +_core_api void dbind_int32_range(const DBind *dbind, int32_t *min, int32_t *max); + +_core_api void dbind_int64_range(const DBind *dbind, int64_t *min, int64_t *max); + +_core_api void dbind_uint8_range(const DBind *dbind, uint8_t *min, uint8_t *max); + +_core_api void dbind_uint16_range(const DBind *dbind, uint16_t *min, uint16_t *max); + +_core_api void dbind_uint32_range(const DBind *dbind, uint32_t *min, uint32_t *max); + +_core_api void dbind_uint64_range(const DBind *dbind, uint64_t *min, uint64_t *max); + +_core_api real32_t dbind_real32(const DBind *dbind, const real32_t value); + +_core_api real64_t dbind_real64(const DBind *dbind, const real64_t value); + +_core_api int8_t dbind_int8(const DBind *dbind, const int8_t value); + +_core_api int16_t dbind_int16(const DBind* dbind, const int16_t value); + +_core_api int32_t dbind_int32(const DBind* dbind, const int32_t value); + +_core_api int64_t dbind_int64(const DBind* dbind, const int64_t value); + +_core_api uint8_t dbind_uint8(const DBind* dbind, const uint8_t value); + +_core_api uint16_t dbind_uint16(const DBind* dbind, const uint16_t value); + +_core_api uint32_t dbind_uint32(const DBind* dbind, const uint32_t value); + +_core_api uint64_t dbind_uint64(const DBind* dbind, const uint64_t value); + +_core_api real32_t dbind_incr_real32(const DBind *dbind, const real32_t value, const bool_t pos); + +_core_api real64_t dbind_incr_real64(const DBind *dbind, const real64_t value, const bool_t pos); + +_core_api int8_t dbind_incr_int8(const DBind *dbind, const int8_t value, const bool_t pos); + +_core_api int16_t dbind_incr_int16(const DBind *dbind, const int16_t value, const bool_t pos); + +_core_api int32_t dbind_incr_int32(const DBind *dbind, const int32_t value, const bool_t pos); + +_core_api int64_t dbind_incr_int64(const DBind *dbind, const int64_t value, const bool_t pos); + +_core_api uint8_t dbind_incr_uint8(const DBind *dbind, const uint8_t value, const bool_t pos); + +_core_api uint16_t dbind_incr_uint16(const DBind *dbind, const uint16_t value, const bool_t pos); + +_core_api uint32_t dbind_incr_uint32(const DBind *dbind, const uint32_t value, const bool_t pos); + +_core_api uint64_t dbind_incr_uint64(const DBind *dbind, const uint64_t value, const bool_t pos); + +_core_api bool_t dbind_string_filter(const DBind *dbind, const char_t *src, char_t *dest, const uint32_t size); + +_core_api real32_t dbind_string_to_real32(const DBind *dbind, const real32_t value, const char_t *src); + +_core_api real64_t dbind_string_to_real64(const DBind *dbind, const real64_t value, const char_t *src); + +_core_api int8_t dbind_string_to_int8(const DBind *dbind, const int8_t value, const char_t *src); + +_core_api int16_t dbind_string_to_int16(const DBind *dbind, const int16_t value, const char_t *src); + +_core_api int32_t dbind_string_to_int32(const DBind *dbind, const int32_t value, const char_t *src); + +_core_api int64_t dbind_string_to_int64(const DBind *dbind, const int64_t value, const char_t *src); + +_core_api uint8_t dbind_string_to_uint8(const DBind *dbind, const uint8_t value, const char_t *src); + +_core_api uint16_t dbind_string_to_uint16(const DBind *dbind, const uint16_t value, const char_t *src); + +_core_api uint32_t dbind_string_to_uint32(const DBind *dbind, const uint32_t value, const char_t *src); + +_core_api uint64_t dbind_string_to_uint64(const DBind *dbind, const uint64_t value, const char_t *src); + +_core_api void* dbind_opaque_default(const DBind *dbind); + +_core_api bool_t dbind_is_basic_type(const DBind* dbind); + +_core_api bool_t dbind_is_number_type(const DBind *dbind); + +_core_api uint32_t dbind_enum_count(const DBind *dbind); + +_core_api enum_t dbind_enum_value(const DBind *dbind, const uint32_t index); + +_core_api const char_t *dbind_enum_alias(const DBind *dbind, const uint32_t index); + +_core_api uint32_t dbind_enum_index(const DBind *dbind, const enum_t value); + +__END_C + +#define dbind_opaque(type, func_data, func_buffer, func_copy, func_read, func_write, func_destroy)\ + (\ + FUNC_CHECK_DATA(func_data, type),\ + FUNC_CHECK_BUFFER(func_buffer, type),\ + FUNC_CHECK_COPY(func_copy, type),\ + FUNC_CHECK_READ(func_read, type),\ + FUNC_CHECK_WRITE(func_write, type),\ + FUNC_CHECK_DESTROY(func_destroy, type),\ + dbind_opaque_imp(\ + (const char_t*)#type,\ + (FPtr_data)func_data,\ + (FPtr_buffer)func_buffer,\ + (FPtr_copy)func_copy,\ + (FPtr_read)func_read,\ + (FPtr_write)func_write,\ + (FPtr_destroy)func_destroy)\ + ) diff --git a/src/core/event.cpp b/src/core/event.cpp index 6748815..c5a2801 100644 --- a/src/core/event.cpp +++ b/src/core/event.cpp @@ -80,14 +80,6 @@ Listener *listener_imp(void *object, FPtr_event_handler func_event_handler) /*---------------------------------------------------------------------------*/ -Listener *listener_copy(const Listener *listener) -{ - cassert_no_null(listener); - return i_create_listener(listener->object, NULL/*listener->func_release*/, listener->func_event_handler, listener->member_event_handler); -} - -/*---------------------------------------------------------------------------*/ - void listener_destroy(Listener **listener) { cassert_no_null(listener); @@ -109,7 +101,7 @@ void listener_update(Listener **listener, Listener *new_listener) /*---------------------------------------------------------------------------*/ -void listener_retain(Listener *listener, FPtr_retain func_retain, FPtr_release func_release) +void _listener_retain(Listener *listener, FPtr_retain func_retain, FPtr_release func_release) { cassert_no_null(listener); cassert_no_nullf(func_retain); diff --git a/src/core/event.h b/src/core/event.h index 22e9ba4..0533983 100644 --- a/src/core/event.h +++ b/src/core/event.h @@ -15,23 +15,23 @@ __EXTERN_C -Listener *listener_imp(void *object, FPtr_event_handler func_event_handler); +_core_api Listener *listener_imp(void *object, FPtr_event_handler func_event_handler); -void listener_destroy(Listener **listener); +_core_api void listener_destroy(Listener **listener); -void listener_update(Listener **listener, Listener *new_listener); +_core_api void listener_update(Listener **listener, Listener *new_listener); -void listener_event_imp(Listener *listener, const uint32_t type, void *sender, void *params, void *result, const char_t *sender_type, const char_t *params_type, const char_t *result_type); +_core_api void listener_event_imp(Listener *listener, const uint32_t type, void *sender, void *params, void *result, const char_t *sender_type, const char_t *params_type, const char_t *result_type); -void listener_pass_event_imp(Listener *listener, Event *event, void *sender, const char_t *sender_type); +_core_api void listener_pass_event_imp(Listener *listener, Event *event, void *sender, const char_t *sender_type); -uint32_t event_type(const Event *event); +_core_api uint32_t event_type(const Event *event); -void *event_sender_imp(Event *event, const char_t *type); +_core_api void *event_sender_imp(Event *event, const char_t *type); -void *event_params_imp(Event *event, const char_t *type); +_core_api void *event_params_imp(Event *event, const char_t *type); -void *event_result_imp(Event *event, const char_t *type); +_core_api void *event_result_imp(Event *event, const char_t *type); __END_C diff --git a/src/core/event.inl b/src/core/event.inl index 8d12cc9..0f3dc75 100644 --- a/src/core/event.inl +++ b/src/core/event.inl @@ -14,8 +14,6 @@ __EXTERN_C -Listener *listener_copy(const Listener *listener); - -void listener_retain(Listener *listener, FPtr_retain func_retain, FPtr_release func_release); +void _listener_retain(Listener *listener, FPtr_retain func_retain, FPtr_release func_release); __END_C diff --git a/src/core/heap.c b/src/core/heap.c index 60177b6..17c54c7 100644 --- a/src/core/heap.c +++ b/src/core/heap.c @@ -12,8 +12,8 @@ #include "heap.h" #include "heap.inl" -#include "blib.inl" -#include "osbs.inl" +#include "blib.h" +#include "osbs.h" #include "bmem.h" #include "bmutex.h" #include "bthread.h" @@ -143,9 +143,9 @@ static void i_new_page(const uint32_t page_size, i_Page **current_page, uint32_t static void i_init_memory(i_Memory *memory, const uint32_t page_size) { - cassert_no_null(memory); + cassert_no_null(memory); /* Page size is power of 2 */ - cassert((page_size != 0) && (page_size & (page_size - 1)) == 0); + cassert((page_size != 0) && (page_size & (page_size - 1)) == 0); bmem_zero(memory, i_Memory); memory->main_thread_id = bthread_current_id(); memory->mutex = bmutex_create(); @@ -189,7 +189,7 @@ static byte_t* i_malloc(i_Memory *memory, const uint32_t size, const uint32_t al cassert_no_null(memory); cassert_no_null(memory->current_page); - // Block can be stored by paged allocator + /* Block can be stored by paged allocator */ if (__TRUE_EXPECTED(size + align + sizeof(i_Page) + sizeof(void*) < memory->page_size)) { register uint32_t mod = memory->current_page->offset % align; @@ -220,7 +220,7 @@ static byte_t* i_malloc(i_Memory *memory, const uint32_t size, const uint32_t al } cassert_fatal((mem != NULL) && ((intptr_t)mem % (intptr_t)align) == 0); - return mem; + return mem; } /*---------------------------------------------------------------------------*/ @@ -228,7 +228,7 @@ static byte_t* i_malloc(i_Memory *memory, const uint32_t size, const uint32_t al static void i_free(i_Memory *memory, byte_t *mem, const uint32_t size, const uint32_t align) { cassert_no_null(memory); - + /* Block filled with waste */ #if defined (__ASSERTS__) bmem_set1(mem, size, 0x3F); @@ -266,7 +266,7 @@ static void i_free(i_Memory *memory, byte_t *mem, const uint32_t size, const uin { cassert(page->next == NULL); i_init_page(page); - } + } } } /* Block was stored using an own block */ @@ -286,7 +286,7 @@ static byte_t* i_realloc(i_Memory *memory, byte_t *prev_mem, const uint32_t size cassert_no_null(memory->current_page); /* Some of new/previous block can be/is stored in paged allocator */ - if (__TRUE_EXPECTED((prev_size + align + sizeof(i_Page) + sizeof(void*) < memory->page_size) + if (__TRUE_EXPECTED((prev_size + align + sizeof(i_Page) + sizeof(void*) < memory->page_size) || (size + align + sizeof(i_Page) + sizeof(void*) < memory->page_size))) { register uint32_t min_size; @@ -303,7 +303,7 @@ static byte_t* i_realloc(i_Memory *memory, byte_t *prev_mem, const uint32_t size } cassert_fatal((mem != NULL) && ((intptr_t)mem % (intptr_t)align) == 0); - return mem; + return mem; } /*---------------------------------------------------------------------------*/ @@ -353,8 +353,8 @@ void _heap_finish(void) } #endif - if (i_MEMORY.num_allocs != i_MEMORY.num_deallocs - || i_MEMORY.total_bytes_allocated != i_MEMORY.total_bytes_deallocated + if (i_MEMORY.num_allocs != i_MEMORY.num_deallocs + || i_MEMORY.total_bytes_allocated != i_MEMORY.total_bytes_deallocated || i_MEMORY.bytes_allocated > 0) { log_printf("[FAIL] Heap Global Memory Leaks!!!"); @@ -379,7 +379,7 @@ void _heap_finish(void) if (i_MEMORY.great_pages_alloc > 0) log_printf(" %u pages greater than %u bytes", i_MEMORY.great_pages_alloc, i_MEMORY.page_size); log_printf("============================"); - + #if defined(__MEMORY_AUDITOR__) if (i_HEAP_VERBOSE == TRUE) { @@ -404,7 +404,7 @@ void _heap_finish(void) log_printf("Config: Release"); #endif } - + i_remove_memory(&i_MEMORY); } @@ -433,24 +433,19 @@ void _heap_page_size(const uint32_t size) i_PAGESIZE = 1024; } -/*---------------------------------------------------------------------------*/ - -void _heap_verbose(const bool_t verbose) -{ - i_HEAP_VERBOSE = verbose; -} - #if defined (__MEMORY_AUDITOR__) /*---------------------------------------------------------------------------*/ -//static void i_dump_objects(void) -//{ -// register uint32_t i; -// log_printf("Num objects: %d", i_MEMORY.num_objects); -// for (i = 0; i < i_MEMORY.num_objects; ++i) -// log_printf("%s %d %d", i_MEMORY.objects[i].name, i_MEMORY.objects[i].num_allocs, i_MEMORY.objects[i].num_deallocs); -//} +/* +static void i_dump_objects(void) +{ + register uint32_t i; + log_printf("Num objects: %d", i_MEMORY.num_objects); + for (i = 0; i < i_MEMORY.num_objects; ++i) + log_printf("%s %d %d", i_MEMORY.objects[i].name, i_MEMORY.objects[i].num_allocs, i_MEMORY.objects[i].num_deallocs); +} + */ /*---------------------------------------------------------------------------*/ @@ -556,10 +551,9 @@ static __INLINE byte_t *i_malloc_imp(const uint32_t size, const uint32_t align, void heap_start_mt(void) { - //cassert(bthread_current_id() == i_MEMORY.main_thread_id); bmutex_lock(i_MEMORY.mutex); i_MEMORY.mtcount += 1; - _osbs_mutex(i_MEMORY.mutex); + osbs_memory_mt(i_MEMORY.mutex); bmutex_unlock(i_MEMORY.mutex); } @@ -567,17 +561,37 @@ void heap_start_mt(void) void heap_end_mt(void) { - //cassert(bthread_current_id() == i_MEMORY.main_thread_id); bmutex_lock(i_MEMORY.mutex); cassert(i_MEMORY.mtcount > 0); i_MEMORY.mtcount -= 1; if (i_MEMORY.mtcount == 0) - _osbs_mutex(NULL); + osbs_memory_mt(NULL); bmutex_unlock(i_MEMORY.mutex); } /*---------------------------------------------------------------------------*/ +void heap_verbose(const bool_t verbose) +{ + i_HEAP_VERBOSE = verbose; +} + +/*---------------------------------------------------------------------------*/ + +void heap_stats(const bool_t stats) +{ + i_HEAP_STATS = stats; +} + +/*---------------------------------------------------------------------------*/ + +bool_t heap_leaks(void) +{ + return i_HEAP_LEAKS; +} + +/*---------------------------------------------------------------------------*/ + byte_t *heap_malloc_imp(const uint32_t size, const char_t *name, const bool_t equal_sized) { return i_malloc_imp(size, sizeof(void*), name, equal_sized); @@ -623,7 +637,7 @@ static __INLINE byte_t *i_realloc_imp(byte_t *mem, const uint32_t size, const ui if (new_size > size) { - i_MEMORY.bytes_allocated += new_size - size; + i_MEMORY.bytes_allocated += new_size - size; if (i_MEMORY.bytes_allocated > i_MEMORY.max_bytes_allocated) i_MEMORY.max_bytes_allocated = i_MEMORY.bytes_allocated; } @@ -779,17 +793,3 @@ void heap_auditor_delete(const char_t *name) unref(name); #endif } - -/*---------------------------------------------------------------------------*/ - -void heap_stats(const bool_t stats) -{ - i_HEAP_STATS = stats; -} - -/*---------------------------------------------------------------------------*/ - -bool_t heap_leaks(void) -{ - return i_HEAP_LEAKS; -} diff --git a/src/core/heap.h b/src/core/heap.h index 7da7a3c..9ede71a 100644 --- a/src/core/heap.h +++ b/src/core/heap.h @@ -15,31 +15,33 @@ __EXTERN_C -void heap_start_mt(void); +_core_api void heap_start_mt(void); -void heap_end_mt(void); +_core_api void heap_end_mt(void); -byte_t *heap_malloc_imp(const uint32_t size, const char_t *name, const bool_t equal_sized); +_core_api void heap_verbose(const bool_t verbose); -byte_t *heap_calloc_imp(const uint32_t size, const char_t *name, const bool_t equal_sized); +_core_api void heap_stats(const bool_t stats); -byte_t *heap_realloc(byte_t *mem, const uint32_t size, const uint32_t new_size, const char_t *name); +_core_api bool_t heap_leaks(void); -byte_t *heap_aligned_malloc_imp(const uint32_t size, const uint32_t align, const char_t *name, const bool_t equal_sized); +_core_api byte_t *heap_malloc_imp(const uint32_t size, const char_t *name, const bool_t equal_sized); -byte_t *heap_aligned_calloc_imp(const uint32_t size, const uint32_t align, const char_t *name, const bool_t equal_sized); +_core_api byte_t *heap_calloc_imp(const uint32_t size, const char_t *name, const bool_t equal_sized); -byte_t *heap_aligned_realloc(byte_t *mem, const uint32_t size, const uint32_t new_size, const uint32_t align, const char_t *name); +_core_api byte_t *heap_realloc(byte_t *mem, const uint32_t size, const uint32_t new_size, const char_t *name); -void heap_free(byte_t **mem, const uint32_t size, const char_t *name); +_core_api byte_t *heap_aligned_malloc_imp(const uint32_t size, const uint32_t align, const char_t *name, const bool_t equal_sized); -void heap_auditor_add(const char_t *name); +_core_api byte_t *heap_aligned_calloc_imp(const uint32_t size, const uint32_t align, const char_t *name, const bool_t equal_sized); -void heap_auditor_delete(const char_t *name); +_core_api byte_t *heap_aligned_realloc(byte_t *mem, const uint32_t size, const uint32_t new_size, const uint32_t align, const char_t *name); -void heap_stats(const bool_t stats); +_core_api void heap_free(byte_t **mem, const uint32_t size, const char_t *name); -bool_t heap_leaks(void); +_core_api void heap_auditor_add(const char_t *name); + +_core_api void heap_auditor_delete(const char_t *name); __END_C diff --git a/src/core/heap.inl b/src/core/heap.inl index 63ff994..cb3e446 100644 --- a/src/core/heap.inl +++ b/src/core/heap.inl @@ -20,8 +20,6 @@ void _heap_finish(void); void _heap_page_size(const uint32_t size); -void _heap_verbose(const bool_t verbose); - __END_C diff --git a/src/core/hfile.c b/src/core/hfile.c index 4493dfb..4e36031 100644 --- a/src/core/hfile.c +++ b/src/core/hfile.c @@ -11,7 +11,7 @@ /* High-level operations in files and directories */ #include "hfile.h" -#include "hfile.inl" +#include "hfileh.h" #include "arrst.h" #include "bfile.h" #include "bstd.h" @@ -75,7 +75,7 @@ bool_t hfile_dir_create(const char_t *pathname, ferror_t *error) break; } - i -= 1; + i -= 1; } while (i < size) @@ -259,12 +259,12 @@ bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recurs n1 = arrst_size(dir1, DirEntry); n2 = arrst_size(dir2, DirEntry); - // Two dirs with entries + /* Two dirs with entries */ while (i1 < n1 && i2 < n2 && ok) { int cmp = str_cmp(files1[i1].name, tc(files2[i2].name)); - // Entry with the same name in both dirs + /* Entry with the same name in both dirs */ if (cmp == 0) { if (i_except(tc(files1[i1].name), except, except_size) == FALSE) @@ -280,10 +280,10 @@ bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recurs str_destroy(&path2); } } - // This is a file + /* This is a file */ else { - // Source file is more recent --> Copy + /* Source file is more recent --> Copy */ if (date_cmp(&files1[i1].date, &files2[i2].date) > 0) { String *path = str_cpath("%s/%s", src, tc(files1[i1].name)); @@ -297,7 +297,7 @@ bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recurs i2 += 1; } - // Entry exists in src, but not in dest + /* Entry exists in src, but not in dest */ else if (cmp < 0) { if (i_except(tc(files1[i1].name), except, except_size) == FALSE) @@ -315,7 +315,7 @@ bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recurs str_destroy(&path2); } } - // This is a file + /* This is a file */ else { String *path = str_cpath("%s/%s", src, tc(files1[i1].name)); @@ -327,7 +327,7 @@ bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recurs i1 += 1; } - // Entry exists in dest, but not in src + /* Entry exists in dest, but not in src */ else { if (remove_in_dest == TRUE && i_except(tc(files2[i2].name), except, except_size) == FALSE) @@ -346,7 +346,7 @@ bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recurs } } - // Remaining entries in src + /* Remaining entries in src */ while (i1 < n1 && ok) { if (i_except(tc(files1[i1].name), except, except_size) == FALSE) @@ -356,13 +356,13 @@ bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recurs if (recursive == TRUE) { String *path1 = str_cpath("%s/%s", src, tc(files1[i1].name)); - String *path2 = str_cpath("%s/%s", src, tc(files2[i2].name)); + String *path2 = str_cpath("%s/%s", dest, tc(files1[i1].name)); ok = hfile_dir_sync(tc(path1), tc(path2), recursive, remove_in_dest, except, except_size, error); str_destroy(&path1); str_destroy(&path2); } } - // This is a file + /* This is a file */ else { String *path = str_cpath("%s/%s", src, tc(files1[i1].name)); @@ -374,7 +374,7 @@ bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recurs i1 += 1; } - // Remaining entries in dest + /* Remaining entries in dest */ while (i2 < n2 && remove_in_dest && ok) { if (i_except(tc(files2[i2].name), except, except_size) == FALSE) @@ -441,7 +441,7 @@ static bool_t i_read_entire_file(const char_t *pathname, byte_t *file_data, cons File *file = NULL; uint32_t bytes_readed; bool_t readed = FALSE; - + file = bfile_open(pathname, ekREAD, error); if (__FALSE_EXPECTED(file == NULL)) return FALSE; @@ -633,7 +633,7 @@ static bool_t i_process_whole_directory(Listener *listener, const char_t *pathna Dir *dir = bfile_dir_open(pathname, error); if (__TRUE_EXPECTED(dir != NULL)) - { + { bool_t continue_process = TRUE; char_t filename[512]; file_type_t file_type; @@ -688,7 +688,7 @@ static bool_t i_process_whole_directory(Listener *listener, const char_t *pathna params.filename = filename; params.pathname = tc(fullname); params.depth = depth_level; - listener_event(listener, ekEENTRY, NULL, ¶ms, &enter_subdir, void, EvFileDir, bool_t); + listener_event(listener, ekEENTRY, NULL, ¶ms, &enter_subdir, void, EvFileDir, bool_t); if (enter_subdir == TRUE) { continue_process = i_process_whole_directory(listener, tc(fullname), flags, depth_level + 1, error); @@ -725,14 +725,14 @@ bool_t hfile_dir_loop(const char_t *pathname, Listener *listener, const bool_t s ferror_t ferror = ekFOK; if (subdirs == TRUE) BIT_SET(flags, i_ekDIR_ENTRY); - + if (hiddens == TRUE) { BIT_SET(flags, i_ekHIDDEN_FILES); if (subdirs == TRUE) BIT_SET(flags, i_ekHIDDEN_SUBDIRS); } - + i_process_whole_directory(listener, pathname, flags, 0, &ferror); ptr_assign(error, ferror); listener_destroy(&listener); diff --git a/src/core/hfile.h b/src/core/hfile.h index 1a43381..b5e6fdd 100644 --- a/src/core/hfile.h +++ b/src/core/hfile.h @@ -15,40 +15,40 @@ __EXTERN_C -bool_t hfile_dir(const char_t *pathname); +_core_api bool_t hfile_dir(const char_t *pathname); -bool_t hfile_dir_create(const char_t *pathname, ferror_t *error); +_core_api bool_t hfile_dir_create(const char_t *pathname, ferror_t *error); -bool_t hfile_dir_destroy(const char_t *pathname, ferror_t *error); +_core_api bool_t hfile_dir_destroy(const char_t *pathname, ferror_t *error); -ArrSt(DirEntry) *hfile_dir_list(const char_t *pathname, const bool_t subdirs, ferror_t *error); +_core_api ArrSt(DirEntry) *hfile_dir_list(const char_t *pathname, const bool_t subdirs, ferror_t *error); -void hfile_dir_entry_remove(DirEntry *entry); +_core_api void hfile_dir_entry_remove(DirEntry *entry); -Date hfile_date(const char_t *pathname, const bool_t recursive); +_core_api Date hfile_date(const char_t *pathname, const bool_t recursive); -bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recursive, const bool_t remove_in_dest, const char_t **except, const uint32_t except_size, ferror_t *error); +_core_api bool_t hfile_dir_sync(const char_t *src, const char_t *dest, const bool_t recursive, const bool_t remove_in_dest, const char_t **except, const uint32_t except_size, ferror_t *error); -bool_t hfile_exists(const char_t *pathname, file_type_t *file_type); +_core_api bool_t hfile_exists(const char_t *pathname, file_type_t *file_type); -bool_t hfile_is_uptodate(const char_t *src, const char_t *dest); +_core_api bool_t hfile_is_uptodate(const char_t *src, const char_t *dest); -bool_t hfile_copy(const char_t *from, const char_t *to, ferror_t *error); +_core_api bool_t hfile_copy(const char_t *from, const char_t *to, ferror_t *error); -Buffer *hfile_buffer(const char_t *pathname, ferror_t *error); +_core_api Buffer *hfile_buffer(const char_t *pathname, ferror_t *error); -String *hfile_string(const char_t *pathname, ferror_t *error); +_core_api String *hfile_string(const char_t *pathname, ferror_t *error); -Stream *hfile_stream(const char_t *pathname, ferror_t *error); +_core_api Stream *hfile_stream(const char_t *pathname, ferror_t *error); -bool_t hfile_from_string(const char_t *pathname, const String *str, ferror_t *error); +_core_api bool_t hfile_from_string(const char_t *pathname, const String *str, ferror_t *error); -bool_t hfile_from_data(const char_t *pathname, const byte_t *data, const uint32_t size, ferror_t *error); +_core_api bool_t hfile_from_data(const char_t *pathname, const byte_t *data, const uint32_t size, ferror_t *error); -bool_t hfile_dir_loop(const char_t *pathname, Listener *listener, const bool_t subdirs, const bool_t hiddens, ferror_t *error); +_core_api bool_t hfile_dir_loop(const char_t *pathname, Listener *listener, const bool_t subdirs, const bool_t hiddens, ferror_t *error); -String *hfile_appdata(const char_t *filename); +_core_api String *hfile_appdata(const char_t *filename); -String *hfile_home_dir(const char_t *path); +_core_api String *hfile_home_dir(const char_t *path); __END_C diff --git a/src/core/hfile.inl b/src/core/hfile.inl deleted file mode 100644 index 3a1452f..0000000 --- a/src/core/hfile.inl +++ /dev/null @@ -1,27 +0,0 @@ -/* - * NAppGUI Cross-platform C SDK - * 2015-2022 Francisco Garcia Collado - * MIT Licence - * https://nappgui.com/en/legal/license.html - * - * File: hfile.inl - * - */ - -/* High-level file operations */ - -#include "core.hxx" - -__EXTERN_C - -String *hfile_exename(void); - -String *hfile_home_dir(const char_t *path); - -String *hfile_build_dir(const char_t *dir, const char_t *target); - -String *hfile_src_dir(const char_t *file); - -String *hfile_root_dir(const char_t *file); - -__END_C diff --git a/src/core/hfileh.h b/src/core/hfileh.h new file mode 100644 index 0000000..e7f4274 --- /dev/null +++ b/src/core/hfileh.h @@ -0,0 +1,25 @@ +/* + * NAppGUI Cross-platform C SDK + * 2015-2022 Francisco Garcia Collado + * MIT Licence + * https://nappgui.com/en/legal/license.html + * + * File: hfileh.h + * + */ + +/* Undocumented (hidden) API about files and directories */ + +#include "coreh.hxx" + +__EXTERN_C + +_core_api String *hfile_exename(void); + +_core_api String *hfile_build_dir(const char_t *dir, const char_t *target); + +_core_api String *hfile_src_dir(const char_t *file); + +_core_api String *hfile_root_dir(const char_t *file); + +__END_C diff --git a/src/core/keybuf.h b/src/core/keybuf.h index 6dbe904..c9a18ef 100644 --- a/src/core/keybuf.h +++ b/src/core/keybuf.h @@ -15,20 +15,20 @@ __EXTERN_C -KeyBuf *keybuf_create(void); +_core_api KeyBuf *keybuf_create(void); -void keybuf_destroy(KeyBuf **buffer); +_core_api void keybuf_destroy(KeyBuf **buffer); -void keybuf_OnUp(KeyBuf *buffer, const vkey_t key); +_core_api void keybuf_OnUp(KeyBuf *buffer, const vkey_t key); -void keybuf_OnDown(KeyBuf *buffer, const vkey_t key); +_core_api void keybuf_OnDown(KeyBuf *buffer, const vkey_t key); -void keybuf_clear(KeyBuf *buffer); +_core_api void keybuf_clear(KeyBuf *buffer); -bool_t keybuf_pressed(const KeyBuf *buffer, const vkey_t key); +_core_api bool_t keybuf_pressed(const KeyBuf *buffer, const vkey_t key); -const char_t* keybuf_str(const vkey_t key); +_core_api const char_t* keybuf_str(const vkey_t key); -void keybuf_dump(const KeyBuf *buffer); +_core_api void keybuf_dump(const KeyBuf *buffer); __END_C diff --git a/src/core/lex.c b/src/core/lex.c index 5ca44fd..c3530c9 100644 --- a/src/core/lex.c +++ b/src/core/lex.c @@ -26,7 +26,7 @@ typedef struct _lexopts_t LexOpts; typedef enum _state_t -{ +{ stSTART, stSPACES, stSLASH, @@ -48,7 +48,7 @@ typedef enum _state_t stEXP, stEXP1, stEND -} state_t; +} gui_state_t; struct _lexopts_t { @@ -72,7 +72,7 @@ struct _lexscn_t /*---------------------------------------------------------------------------*/ -LexScn *lexscn_create(void) +LexScn *_lexscn_create(void) { LexScn *lex = heap_new0(LexScn); lex->lexsize = 256; @@ -82,7 +82,7 @@ LexScn *lexscn_create(void) /*---------------------------------------------------------------------------*/ -void lexscn_destroy(LexScn **lex) +void _lexscn_destroy(LexScn **lex) { cassert_no_null(lex); cassert_no_null(*lex); @@ -92,7 +92,7 @@ void lexscn_destroy(LexScn **lex) /*---------------------------------------------------------------------------*/ -void lexscn_spaces(LexScn *lex, const bool_t activate) +void _lexscn_spaces(LexScn *lex, const bool_t activate) { cassert_no_null(lex); lex->opts.spaces = activate; @@ -100,7 +100,7 @@ void lexscn_spaces(LexScn *lex, const bool_t activate) /*---------------------------------------------------------------------------*/ -void lexscn_newlines(LexScn *lex, const bool_t activate) +void _lexscn_newlines(LexScn *lex, const bool_t activate) { cassert_no_null(lex); lex->opts.newlines = activate; @@ -108,7 +108,7 @@ void lexscn_newlines(LexScn *lex, const bool_t activate) /*---------------------------------------------------------------------------*/ -void lexscn_escapes(LexScn *lex, const bool_t activate) +void _lexscn_escapes(LexScn *lex, const bool_t activate) { cassert_no_null(lex); lex->opts.escapes = activate; @@ -116,7 +116,7 @@ void lexscn_escapes(LexScn *lex, const bool_t activate) /*---------------------------------------------------------------------------*/ -void lexscn_comments(LexScn *lex, const bool_t activate) +void _lexscn_comments(LexScn *lex, const bool_t activate) { cassert_no_null(lex); lex->opts.comments = activate; @@ -124,24 +124,13 @@ void lexscn_comments(LexScn *lex, const bool_t activate) /*---------------------------------------------------------------------------*/ -//void lexscn_start(LexScn *lex, Stream *stm); -//void lexscn_start(LexScn *lex, Stream *stm) -//{ -// cassert_no_null(lex); -// lex->col = 1; -// lex->row = 1; -// lex->stm = stm; -//} - -/*---------------------------------------------------------------------------*/ - static uint32_t i_get_char(LexScn *lex, Stream *stm) { uint32_t col = stm_col(stm); uint32_t row = stm_col(stm); uint32_t code = stm_read_char(stm); cassert_no_null(lex); - + if (__TRUE_EXPECTED(code != UINT32_MAX)) { lex->pcol = col; @@ -187,7 +176,7 @@ static void i_add_lexeme(LexScn *lex, const uint32_t code) /*---------------------------------------------------------------------------*/ -static state_t i_START(const uint32_t code, ltoken_t *token) +static gui_state_t i_START(const uint32_t code, ltoken_t *token) { cassert_no_null(token); switch (code) { @@ -307,7 +296,7 @@ static state_t i_START(const uint32_t code, ltoken_t *token) /*---------------------------------------------------------------------------*/ -static state_t i_SPACES(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_SPACES(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code == ' ' || code == '\t' || code == '\v' || code == '\f' || code == '\r') return stSPACES; @@ -319,7 +308,7 @@ static state_t i_SPACES(const uint32_t code, ltoken_t *token, uint8_t *charst) /*---------------------------------------------------------------------------*/ -static state_t i_SLASH(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_SLASH(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code == '/') return stSL_COMMENT; @@ -333,7 +322,7 @@ static state_t i_SLASH(const uint32_t code, ltoken_t *token, uint8_t *charst) /*---------------------------------------------------------------------------*/ -static state_t i_SL_COMMENT(const uint32_t code, ltoken_t *token) +static gui_state_t i_SL_COMMENT(const uint32_t code, ltoken_t *token) { if (code == '\n') { @@ -345,7 +334,7 @@ static state_t i_SL_COMMENT(const uint32_t code, ltoken_t *token) /*---------------------------------------------------------------------------*/ -static state_t i_ML_COMMENT(const uint32_t code) +static gui_state_t i_ML_COMMENT(const uint32_t code) { if (code == '*') return stML_COMMENT2; @@ -354,7 +343,7 @@ static state_t i_ML_COMMENT(const uint32_t code) /*---------------------------------------------------------------------------*/ -static state_t i_ML_COMMENT2(const uint32_t code, ltoken_t *token) +static gui_state_t i_ML_COMMENT2(const uint32_t code, ltoken_t *token) { if (code == '/') { @@ -370,7 +359,7 @@ static state_t i_ML_COMMENT2(const uint32_t code, ltoken_t *token) /*---------------------------------------------------------------------------*/ -static state_t i_PERIOD(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_PERIOD(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code >= '0' && code <= '9') return stREAL; @@ -382,7 +371,7 @@ static state_t i_PERIOD(const uint32_t code, ltoken_t *token, uint8_t *charst) /*---------------------------------------------------------------------------*/ -static state_t i_IDENTIFIER(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_IDENTIFIER(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code >= 'a' && code <= 'z') return stIDENTIFIER; @@ -400,7 +389,7 @@ static state_t i_IDENTIFIER(const uint32_t code, ltoken_t *token, uint8_t *chars /*---------------------------------------------------------------------------*/ -static state_t i_STRING(const uint32_t code, const bool_t escapes, ltoken_t *token, uint8_t *charst) +static gui_state_t i_STRING(const uint32_t code, const bool_t escapes, ltoken_t *token, uint8_t *charst) { if (code == '\\') { @@ -419,7 +408,7 @@ static state_t i_STRING(const uint32_t code, const bool_t escapes, ltoken_t *tok /*---------------------------------------------------------------------------*/ -static state_t i_STRING_ESCAPE(uint32_t *code, const bool_t escapes, uint32_t *ci, char_t *c, uint8_t *charst) +static gui_state_t i_STRING_ESCAPE(uint32_t *code, const bool_t escapes, uint32_t *ci, char_t *c, uint8_t *charst) { if (escapes == FALSE) { @@ -472,7 +461,7 @@ static state_t i_STRING_ESCAPE(uint32_t *code, const bool_t escapes, uint32_t *c return stSTRING; } - // Octal char + /* Octal char */ if (*code >= '0' && *code <= '7') { cassert(*ci == 0); @@ -482,7 +471,7 @@ static state_t i_STRING_ESCAPE(uint32_t *code, const bool_t escapes, uint32_t *c return stSTRING_OCTAL; } - // Hex char + /* Hex char */ if (*code == 'x') { cassert(*ci == 0); @@ -490,7 +479,7 @@ static state_t i_STRING_ESCAPE(uint32_t *code, const bool_t escapes, uint32_t *c return stSTRING_HEX; } - // Unicode BMP + /* Unicode BMP */ if (*code == 'u') { cassert(*ci == 0); @@ -498,7 +487,7 @@ static state_t i_STRING_ESCAPE(uint32_t *code, const bool_t escapes, uint32_t *c return stSTRING_UNICODE4; } - // Unicode 32bits + /* Unicode 32bits */ if (*code == 'U') { cassert(*ci == 0); @@ -506,7 +495,7 @@ static state_t i_STRING_ESCAPE(uint32_t *code, const bool_t escapes, uint32_t *c return stSTRING_UNICODE8; } - // Ignored escape sequence + /* Ignored escape sequence */ cassert(*ci == 0); *charst = DISCARD_CHAR; return stSTRING; @@ -514,7 +503,7 @@ static state_t i_STRING_ESCAPE(uint32_t *code, const bool_t escapes, uint32_t *c /*---------------------------------------------------------------------------*/ -static state_t i_STRING_OCTAL(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *charst) +static gui_state_t i_STRING_OCTAL(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *charst) { if (*code >= '0' && *code <= '7') { @@ -542,7 +531,7 @@ static state_t i_STRING_OCTAL(uint32_t *code, uint32_t *ci, char_t *c, uint8_t * /*---------------------------------------------------------------------------*/ -static state_t i_STRING_HEX(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *charst) +static gui_state_t i_STRING_HEX(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *charst) { if ((*code >= 'a' && *code <= 'f') || (*code >= 'A' && *code <= 'F')) { @@ -563,7 +552,7 @@ static state_t i_STRING_HEX(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *ch } } - // '\xhh' with 0 or 1 hex char --> discart + /* '\xhh' with 0 or 1 hex char --> discart */ *ci = 0; *charst = DISCARD_CHAR; return stSTRING; @@ -571,7 +560,7 @@ static state_t i_STRING_HEX(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *ch /*---------------------------------------------------------------------------*/ -static state_t i_STRING_UNICODE4(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *charst) +static gui_state_t i_STRING_UNICODE4(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *charst) { if ((*code >= 'a' && *code <= 'f') || (*code >= 'A' && *code <= 'F')) { @@ -592,14 +581,14 @@ static state_t i_STRING_UNICODE4(uint32_t *code, uint32_t *ci, char_t *c, uint8_ } } - // '\uhhhh' with 0, 1, 2 or 3 hex char --> discart + /* '\uhhhh' with 0, 1, 2 or 3 hex char --> discart */ *charst = DISCARD_CHAR; return stSTRING; } /*---------------------------------------------------------------------------*/ -static state_t i_STRING_UNICODE8(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *charst) +static gui_state_t i_STRING_UNICODE8(uint32_t *code, uint32_t *ci, char_t *c, uint8_t *charst) { if ((*code >= 'a' && *code <= 'f') || (*code >= 'A' && *code <= 'F')) { @@ -620,14 +609,14 @@ static state_t i_STRING_UNICODE8(uint32_t *code, uint32_t *ci, char_t *c, uint8_ } } - // '\Uhhhhhhhh' with (0-7) hex char --> discart + /* '\Uhhhhhhhh' with (0-7) hex char --> discart */ *charst = DISCARD_CHAR; return stSTRING; } /*---------------------------------------------------------------------------*/ -static state_t i_ZERO(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_ZERO(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code == 'x' || code == 'X') return stHEX; @@ -643,7 +632,7 @@ static state_t i_ZERO(const uint32_t code, ltoken_t *token, uint8_t *charst) /*---------------------------------------------------------------------------*/ -static state_t i_INT(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_INT(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code >= '0' && code <= '9') return stINT; @@ -664,7 +653,7 @@ static state_t i_INT(const uint32_t code, ltoken_t *token, uint8_t *charst) /*---------------------------------------------------------------------------*/ -static state_t i_HEX(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_HEX(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code >= '0' && code <= '9') return stHEX; @@ -690,7 +679,7 @@ static state_t i_HEX(const uint32_t code, ltoken_t *token, uint8_t *charst) /*---------------------------------------------------------------------------*/ -static state_t i_REAL(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_REAL(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code >= '0' && code <= '9') return stREAL; @@ -713,7 +702,7 @@ static state_t i_REAL(const uint32_t code, ltoken_t *token, uint8_t *charst) /*---------------------------------------------------------------------------*/ -static state_t i_EXP(const uint32_t code, ltoken_t *token) +static gui_state_t i_EXP(const uint32_t code, ltoken_t *token) { if (code >= '0' && code <= '9') return stEXP1; @@ -727,7 +716,7 @@ static state_t i_EXP(const uint32_t code, ltoken_t *token) /*---------------------------------------------------------------------------*/ -static state_t i_EXP1(const uint32_t code, ltoken_t *token, uint8_t *charst) +static gui_state_t i_EXP1(const uint32_t code, ltoken_t *token, uint8_t *charst) { if (code >= '0' && code <= '9') return stEXP1; @@ -750,20 +739,7 @@ static state_t i_EXP1(const uint32_t code, ltoken_t *token, uint8_t *charst) /*---------------------------------------------------------------------------*/ -//void lexscn_jump_bom(LexScn *lex, Stream *stm); -//void lexscn_jump_bom(LexScn *lex, Stream *stm) -//{ -// uint32_t code = i_get_char(lex, stm); -// -// while (code == 0xFEFF) -// code = i_get_char(lex, stm); -// -// i_store_char(lex, stm, code); -//} - -/*---------------------------------------------------------------------------*/ - -ltoken_t lexscn_token(LexScn *lex, Stream *stm) +ltoken_t _lexscn_token(LexScn *lex, Stream *stm) { ltoken_t token = ENUM_MAX(ltoken_t); @@ -771,7 +747,7 @@ ltoken_t lexscn_token(LexScn *lex, Stream *stm) uint32_t code = 0; uint32_t ci = 0; char_t c[10]; - state_t state = stSTART; + gui_state_t state = stSTART; cassert_no_null(lex); lex->tcol = stm_col(stm); lex->trow = stm_row(stm); @@ -862,7 +838,7 @@ ltoken_t lexscn_token(LexScn *lex, Stream *stm) i_add_lexeme(lex, code); else if (charst == STORE_CHAR) i_store_char(lex, stm, code); - else + else { cassert(charst == DISCARD_CHAR); } if (state == stEND) @@ -899,7 +875,7 @@ ltoken_t lexscn_token(LexScn *lex, Stream *stm) /*---------------------------------------------------------------------------*/ -uint32_t lexscn_row(const LexScn *lex) +uint32_t _lexscn_row(const LexScn *lex) { cassert_no_null(lex); return lex->trow; @@ -907,7 +883,7 @@ uint32_t lexscn_row(const LexScn *lex) /*---------------------------------------------------------------------------*/ -uint32_t lexscn_col(const LexScn *lex) +uint32_t _lexscn_col(const LexScn *lex) { cassert_no_null(lex); return lex->tcol; @@ -915,7 +891,7 @@ uint32_t lexscn_col(const LexScn *lex) /*---------------------------------------------------------------------------*/ -const char_t *lexscn_lexeme(const LexScn *lex, uint32_t *size) +const char_t *_lexscn_lexeme(const LexScn *lex, uint32_t *size) { cassert_no_null(lex); ptr_assign(size, lex->lexi); @@ -924,7 +900,7 @@ const char_t *lexscn_lexeme(const LexScn *lex, uint32_t *size) /*---------------------------------------------------------------------------*/ -const char_t *lexscn_string(const ltoken_t token) +const char_t *_lexscn_string(const ltoken_t token) { switch (token) { case ekTSLCOM: @@ -957,7 +933,7 @@ const char_t *lexscn_string(const ltoken_t token) case ekTOPENCURL: return "{"; case ekTCLOSCURL: - return "}"; + return "}"; case ekTPLUS: return "+"; case ekTMINUS: @@ -1019,115 +995,3 @@ const char_t *lexscn_string(const ltoken_t token) return "--"; } - -/*---------------------------------------------------------------------------*/ - -//void lexscn_jump(LexScn *lex, Stream *stm, const ltoken_t token); -//void lexscn_jump(LexScn *lex, Stream *stm, const ltoken_t token) -//{ -// ltoken_t tok = lexscn_token(lex, stm); -// if (tok != token) -// stm_corrupt(stm); -//} - -/*---------------------------------------------------------------------------*/ - -//const char_t *lexscn_read_line(LexScn *lex); -//const char_t *lexscn_read_line(LexScn *lex) -//{ -// uint32_t code = 0; -// cassert_no_null(lex); -// -// for(;;) -// { -// code = i_get_code(lex, lex->stm); -// if (code == ' ' || code == '\t' || code == '\v' || code == '\f' || code == '\r') -// continue; -// else -// break; -// } -// -// lex->tcol = lex->col; -// lex->trow = lex->row; -// lex->lexi = 0; -// -// while(code != '\n' && code != 0) -// { -// i_add_lexeme(lex, code); -// code = i_get_code(lex, lex->stm); -// } -// -// lex->lexeme[lex->lexi] = '\0'; -// return lex->lexeme; -//} - -/*---------------------------------------------------------------------------*/ - -//uint32_t lexscn_read_u32(LexScn *lex, Stream *stm); -//uint32_t lexscn_read_u32(LexScn *lex, Stream *stm) -//{ -// ltoken_t tok = lexscn_token(lex, stm); -// -// if (tok == ekTINTEGER) -// return str_to_u32(lexscn_lexeme(lex, NULL), 10, NULL); -// -// stm_corrupt(stm); -// return 0; -//} - -/*---------------------------------------------------------------------------*/ - -//real32_t lexscn_read_r32(LexScn *lex, Stream *stm); -//real32_t lexscn_read_r32(LexScn *lex, Stream *stm) -//{ -// bool_t minus = FALSE; -// ltoken_t tok = lexscn_token(lex, stm); -// -// if (tok == ekTMINUS) -// { -// minus = TRUE; -// tok = lexscn_token(lex, stm); -// } -// -// if (tok == ekTINTEGER || tok == ekTREAL) -// { -// real32_t number = str_to_r32(lexscn_lexeme(lex, NULL), NULL); -// -// if (minus == TRUE) -// return - number; -// else -// return number; -// } -// -// stm_corrupt(stm); -// return 0; -//} - -/*---------------------------------------------------------------------------*/ - -//real64_t lexscn_read_r64(LexScn *lex, Stream *stm); -//real64_t lexscn_read_r64(LexScn *lex, Stream *stm) -//{ -// bool_t minus = FALSE; -// ltoken_t tok = lexscn_token(lex, stm); -// -// if (tok == ekTMINUS) -// { -// minus = TRUE; -// tok = lexscn_token(lex, stm); -// } -// -// if (tok == ekTINTEGER || tok == ekTREAL) -// { -// real64_t number = str_to_r64(lexscn_lexeme(lex, NULL), NULL); -// -// if (minus == TRUE) -// return - number; -// else -// return number; -// } -// -// stm_corrupt(stm); -// return 0; -//} - diff --git a/src/core/lex.inl b/src/core/lex.inl index 85e85fe..7b8974a 100644 --- a/src/core/lex.inl +++ b/src/core/lex.inl @@ -14,26 +14,26 @@ __EXTERN_C -LexScn *lexscn_create(void); +LexScn *_lexscn_create(void); -void lexscn_destroy(LexScn **lex); +void _lexscn_destroy(LexScn **lex); -void lexscn_spaces(LexScn *lex, const bool_t activate); +void _lexscn_spaces(LexScn *lex, const bool_t activate); -void lexscn_newlines(LexScn *lex, const bool_t activate); +void _lexscn_newlines(LexScn *lex, const bool_t activate); -void lexscn_escapes(LexScn *lex, const bool_t activate); +void _lexscn_escapes(LexScn *lex, const bool_t activate); -void lexscn_comments(LexScn *lex, const bool_t activate); +void _lexscn_comments(LexScn *lex, const bool_t activate); -ltoken_t lexscn_token(LexScn *lex, Stream *stm); +ltoken_t _lexscn_token(LexScn *lex, Stream *stm); -uint32_t lexscn_row(const LexScn *lex); +uint32_t _lexscn_row(const LexScn *lex); -uint32_t lexscn_col(const LexScn *lex); +uint32_t _lexscn_col(const LexScn *lex); -const char_t *lexscn_lexeme(const LexScn *lex, uint32_t *size); +const char_t *_lexscn_lexeme(const LexScn *lex, uint32_t *size); -const char_t *lexscn_string(const ltoken_t token); +const char_t *_lexscn_string(const ltoken_t token); __END_C diff --git a/src/core/nfa.c b/src/core/nfa.c index ca592a6..8153cda 100644 --- a/src/core/nfa.c +++ b/src/core/nfa.c @@ -196,7 +196,7 @@ static bool_t i_check_nfa(const NFA *nfa) /*---------------------------------------------------------------------------*/ -NFA *nfa_string(const char_t *str) +NFA *_nfa_string(const char_t *str) { NFA *nfa = heap_new0(NFA); register uint32_t codepoint = unicode_to_u32(str, ekUTF8); @@ -223,7 +223,7 @@ NFA *nfa_string(const char_t *str) /*---------------------------------------------------------------------------*/ -void nfa_destroy(NFA **nfa) +void _nfa_destroy(NFA **nfa) { cassert_no_null(nfa); cassert_no_null(*nfa); @@ -707,7 +707,7 @@ static NFA *i_infix_to_NFA(const ArrSt(NToken) *tokens) nfa1 = arrpt_last(stack, NFA); i_nfa_union(nfa1, nfa2); cassert(i_check_nfa(nfa1) == TRUE); - nfa_destroy(&nfa2); + _nfa_destroy(&nfa2); break; } @@ -719,7 +719,7 @@ static NFA *i_infix_to_NFA(const ArrSt(NToken) *tokens) nfa1 = arrpt_last(stack, NFA); i_nfa_concat(nfa1, nfa2); cassert(i_check_nfa(nfa1) == TRUE); - nfa_destroy(&nfa2); + _nfa_destroy(&nfa2); break; } @@ -746,7 +746,7 @@ static NFA *i_infix_to_NFA(const ArrSt(NToken) *tokens) /*---------------------------------------------------------------------------*/ -NFA *nfa_regex(const char_t *regex, const bool_t verbose) +NFA *_nfa_regex(const char_t *regex, const bool_t verbose) { ArrSt(NToken) *tokens = i_tokens_unix_regex(regex); NFA *nfa = NULL; @@ -835,7 +835,7 @@ static void i_add_closure(const ArrSt(Trans) *ttable, ArrSt(uint32_t) *states, c /*---------------------------------------------------------------------------*/ -void nfa_start(NFA *nfa) +void _nfa_start(NFA *nfa) { cassert_no_null(nfa); if (nfa->current == NULL) @@ -854,7 +854,7 @@ void nfa_start(NFA *nfa) /*---------------------------------------------------------------------------*/ -bool_t nfa_next(NFA *nfa, const uint32_t codepoint) +bool_t _nfa_next(NFA *nfa, const uint32_t codepoint) { cassert_no_null(nfa); arrst_clear(nfa->temp, NULL, uint32_t); @@ -870,7 +870,7 @@ bool_t nfa_next(NFA *nfa, const uint32_t codepoint) /*---------------------------------------------------------------------------*/ -bool_t nfa_accept(NFA *nfa) +bool_t _nfa_accept(NFA *nfa) { register uint32_t accept; cassert_no_null(nfa); diff --git a/src/core/nfa.inl b/src/core/nfa.inl index 9148a82..d84375c 100644 --- a/src/core/nfa.inl +++ b/src/core/nfa.inl @@ -14,17 +14,17 @@ __EXTERN_C -NFA *nfa_string(const char_t *str); +NFA *_nfa_string(const char_t *str); -NFA *nfa_regex(const char_t *regex, const bool_t verbose); +NFA *_nfa_regex(const char_t *regex, const bool_t verbose); -void nfa_destroy(NFA **nfa); +void _nfa_destroy(NFA **nfa); -void nfa_start(NFA *nfa); +void _nfa_start(NFA *nfa); -bool_t nfa_next(NFA *nfa, const uint32_t codepoint); +bool_t _nfa_next(NFA *nfa, const uint32_t codepoint); -bool_t nfa_accept(NFA *nfa); +bool_t _nfa_accept(NFA *nfa); __END_C diff --git a/src/core/obj.c b/src/core/obj.c index 40b0e72..4b316e2 100644 --- a/src/core/obj.c +++ b/src/core/obj.c @@ -10,7 +10,7 @@ /* Generic object utilities */ -#include "obj.inl" +#include "objh.h" #include "event.inl" #include "event.h" #include "cassert.h" @@ -21,7 +21,7 @@ void obj_init(Object *object) { cassert_no_null(object); - object->retain_count = 0; + object->count = 0; } /*---------------------------------------------------------------------------*/ @@ -29,7 +29,7 @@ void obj_init(Object *object) byte_t *obj_new_imp(const uint32_t size, const char_t *type) { Object *object = (Object*)heap_malloc(size, type); - object->retain_count = 0; + object->count = 0; return (byte_t*)object; } @@ -38,7 +38,7 @@ byte_t *obj_new_imp(const uint32_t size, const char_t *type) byte_t *obj_new0_imp(const uint32_t size, const char_t *type) { Object *object = (Object*)heap_calloc(size, type); - object->retain_count = 0; + object->count = 0; return (byte_t*)object; } @@ -47,7 +47,7 @@ byte_t *obj_new0_imp(const uint32_t size, const char_t *type) void *obj_retain_imp(const void *object) { cassert_no_null(object); - ((Object*)object)->retain_count += 1; + ((Object*)object)->count += 1; return (void*)object; } @@ -56,24 +56,16 @@ void *obj_retain_imp(const void *object) void *obj_retain_optional_imp(const void *object) { if (object != NULL) - ((Object*)object)->retain_count += 1; + ((Object*)object)->count += 1; return (void*)object; } /*---------------------------------------------------------------------------*/ -uint32_t obj_retain_count_imp(const void *object) -{ - cassert_no_null(object); - return ((Object*)object)->retain_count; -} - -/*---------------------------------------------------------------------------*/ - void obj_remove(Object *object) { cassert_no_null(object); - cassert(object->retain_count == 0); + cassert(object->count == 0); } /*---------------------------------------------------------------------------*/ @@ -82,8 +74,8 @@ void obj_release_imp(void **object) { cassert_no_null(object); cassert_no_null(*object); - cassert(((Object*)(*object))->retain_count > 0); - ((Object*)(*object))->retain_count -= 1; + cassert(((Object*)(*object))->count > 0); + ((Object*)(*object))->count -= 1; *object = NULL; } @@ -94,8 +86,8 @@ void obj_release_optional_imp(void **object) cassert_no_null(object); if (*object != NULL) { - cassert(((Object*)(*object))->retain_count > 0); - ((Object*)(*object))->retain_count -= 1; + cassert(((Object*)(*object))->count > 0); + ((Object*)(*object))->count -= 1; *object = NULL; } } @@ -108,7 +100,7 @@ void obj_delete_imp(byte_t **object, const uint32_t size, const char_t *type) cassert_no_null(object); obj = (Object*)(*object); cassert_no_null(obj); - cassert(obj->retain_count == 0); + cassert(obj->count == 0); heap_free(object, size, type); } @@ -117,7 +109,7 @@ void obj_delete_imp(byte_t **object, const uint32_t size, const char_t *type) Listener *obj_listener_imp(void *object, FPtr_event_handler func_event_handler) { Listener *listener = listener_imp(object, func_event_handler); - listener_retain(listener, obj_retain_imp, obj_release_imp); + _listener_retain(listener, obj_retain_imp, obj_release_imp); return listener; } diff --git a/src/core/obj.inl b/src/core/objh.h similarity index 56% rename from src/core/obj.inl rename to src/core/objh.h index d27a4c9..e8f4764 100644 --- a/src/core/obj.inl +++ b/src/core/objh.h @@ -4,47 +4,38 @@ * MIT Licence * https://nappgui.com/en/legal/license.html * - * File: obj.inl + * File: objh.h * */ -/* Generic object utilities */ +/* Undocumented (hidden) API about generic object utilities */ -#include "core.ixx" +#include "core.hxx" __EXTERN_C -void obj_init(Object *object); +_core_api void obj_init(Object *object); -byte_t *obj_new_imp(const uint32_t size, const char_t *type); +_core_api byte_t *obj_new_imp(const uint32_t size, const char_t *type); -byte_t *obj_new0_imp(const uint32_t size, const char_t *type); +_core_api byte_t *obj_new0_imp(const uint32_t size, const char_t *type); -void *obj_retain_imp(const void *object); +_core_api void *obj_retain_imp(const void *object); -void *obj_retain_optional_imp(const void *object); +_core_api void *obj_retain_optional_imp(const void *object); -uint32_t obj_retain_count_imp(const void *object); +_core_api void obj_remove(Object *object); -void obj_remove(Object *object); +_core_api void obj_release_imp(void **object); -void obj_release_imp(void **object); +_core_api void obj_release_optional_imp(void **object); -void obj_release_optional_imp(void **object); +_core_api void obj_delete_imp(byte_t **object, const uint32_t size, const char_t *type); -void obj_delete_imp(byte_t **object, const uint32_t size, const char_t *type); - -Listener *obj_listener_imp(void *object, FPtr_event_handler func_event_handler); +_core_api Listener *obj_listener_imp(void *object, FPtr_event_handler func_event_handler); __END_C -/*#define obj_malloc(size, type)\ - (type*)obj_malloc_imp((size)) - -#define obj_calloc(size, type)\ - (type*)obj_calloc_imp((size)) -*/ - #define obj_new(type)\ (type*)obj_new_imp(sizeof(type), #type) @@ -59,10 +50,6 @@ __END_C ((void)((type*)(object) == (object)),\ (type*)obj_retain_optional_imp((void*)(object))) -#define obj_retain_count(object, type)\ - ((void)((type*)(object) == (object)),\ - obj_retain_count_imp((void*)(object))) - #define obj_release(object, type)\ ((void)((type**)(object) == (object)),\ obj_release_imp((void**)(object))) @@ -75,13 +62,6 @@ __END_C ((void)((const type**)(object) == (object)),\ obj_release_optional_imp((void**)(object))) -/* -#define obj_destroy(object, size, type)\ - ((void)((type**)(object) == (object)),\ - obj_destroy_imp((void**)(object), (size))) - -*/ - #define obj_delete(object, type)\ ((void)((type**)(object) == (object)),\ obj_delete_imp((byte_t**)(object), sizeof(type), (const char_t*)#type)) diff --git a/src/core/rbtree.c b/src/core/rbtree.c index 95188af..f7fcbbd 100644 --- a/src/core/rbtree.c +++ b/src/core/rbtree.c @@ -10,7 +10,6 @@ /* Red - Black trees */ -#include "core.inl" #include "rbtree.h" #include "bmem.h" #include "cassert.h" @@ -33,7 +32,7 @@ struct i_node_t i_Node *lnode; i_Node *rnode; }; - + #define i_NODE_DATA(node)\ ((void)((i_Node*)node == node),\ ((byte_t*)node + sizeof(i_Node))) @@ -62,7 +61,7 @@ static i_Node *i_create_node(const uint16_t esize, const uint16_t ksize) i_Node *node = (i_Node*)heap_malloc(sizeof32(i_Node) + esize + ksize, "RBNode"); node->type = i_RED_NODE; node->lnode = NULL; - node->rnode = NULL; + node->rnode = NULL; return node; } @@ -76,10 +75,10 @@ static __INLINE void i_dealloc_node(i_Node **node, const uint16_t esize, const u /*---------------------------------------------------------------------------*/ static __INLINE void i_destroy_node_data( - i_Node *node, + i_Node *node, __DEBUG_PARAMC(const uint16_t esize) - const uint16_t ksize, - FPtr_remove func_remove, + const uint16_t ksize, + FPtr_remove func_remove, FPtr_destroy func_destroy, FPtr_destroy func_destroy_key) { @@ -103,7 +102,7 @@ static __INLINE void i_destroy_node_data( void **data = (void**)(i_NODE_DATA(node) + ksize); #if defined (__ASSERTS__) cassert(esize == sizeof(void*)); - #endif + #endif func_destroy(data); } } @@ -111,10 +110,10 @@ static __INLINE void i_destroy_node_data( /*---------------------------------------------------------------------------*/ static void i_destroy_node( - i_Node **node, - const uint16_t esize, - const uint16_t ksize, - FPtr_remove func_remove, + i_Node **node, + const uint16_t esize, + const uint16_t ksize, + FPtr_remove func_remove, FPtr_destroy func_destroy, FPtr_destroy func_destroy_key) { @@ -153,7 +152,7 @@ RBTree *rbtree_create(FPtr_compare func_compare, const uint16_t esize, const uin tree->func_compare = func_compare; tree->elems = 0; tree->esize = esize; - tree->ksize = ksize > 0 ? ksize + ksize % sizeof(void*) : ksize; // Node element alignment + tree->ksize = ksize > 0 ? ksize + ksize % sizeof(void*) : ksize; /* Node element alignment */ tree->root = NULL; tree->it.path_size = 0; tree->it.path_alloc = 8; @@ -378,7 +377,7 @@ static bool_t i_inorder_next(i_Iterator *it) cassert(it->path_size <= it->path_alloc); cnode = cnode->lnode; it->path[it->path_size] = cnode; - it->path_size += 1; + it->path_size += 1; } return TRUE; @@ -391,7 +390,7 @@ static bool_t i_inorder_next(i_Iterator *it) it->path_size -= 1; parent = it->path[it->path_size - 1]; cassert_no_null(parent); - + if (parent->lnode == cnode) return TRUE; else @@ -421,7 +420,7 @@ static bool_t i_inorder_prev(i_Iterator *it) cassert(it->path_size <= it->path_alloc); cnode = cnode->rnode; it->path[it->path_size] = cnode; - it->path_size += 1; + it->path_size += 1; } return TRUE; @@ -434,7 +433,7 @@ static bool_t i_inorder_prev(i_Iterator *it) it->path_size -= 1; parent = it->path[it->path_size - 1]; cassert_no_null(parent); - + if (parent->rnode == cnode) return TRUE; else @@ -451,8 +450,8 @@ static bool_t i_inorder_prev(i_Iterator *it) static __INLINE void i_rotate_left(i_Node *node, i_Node *parent, i_Node **root) { - i_Node *rnode; - cassert_no_null(node); + i_Node *rnode; + cassert_no_null(node); rnode = node->rnode; cassert_no_null(rnode); node->rnode = rnode->lnode; @@ -483,7 +482,7 @@ static __INLINE void i_rotate_left(i_Node *node, i_Node *parent, i_Node **root) static __INLINE void i_rotate_right(i_Node *node, i_Node *parent, i_Node **root) { i_Node *lnode; - cassert_no_null(node); + cassert_no_null(node); lnode = node->lnode; cassert_no_null(lnode); node->lnode = lnode->rnode; @@ -519,13 +518,13 @@ static void i_restructure_after_insert(i_Iterator *it, i_Node **root) i = it->path_size; while (i > 0) - { + { i_Node *cnode = it->path[i - 1]; cassert_no_null(cnode); cassert(cnode->type == i_RED_NODE); - + if (i > 1) - { + { i_Node *parent = it->path[i - 2]; cassert_no_null(parent); if (parent->type == i_RED_NODE) @@ -619,7 +618,7 @@ static void i_restructure_after_insert(i_Iterator *it, i_Node **root) /*---------------------------------------------------------------------------*/ static i_Node *i_insert_node( - i_Node **root, + i_Node **root, const uint32_t elems, const void *key, const bool_t isptr, @@ -710,7 +709,7 @@ byte_t *rbtree_insert(RBTree *tree, const void *key, FPtr_copy func_key_copy) bool_t rbtree_insert_ptr(RBTree *tree, void *ptr) { i_Node *new_node = i_insert_node(&tree->root, tree->elems, ptr, TRUE, tree->func_compare, &tree->it, tree->ksize, tree->esize); - tree->it.path_size = 0; + tree->it.path_size = 0; if (new_node != NULL) { tree->elems += 1; @@ -737,7 +736,7 @@ static void i_restructure_after_delete(i_Iterator *it, i_Node **root) i = it->path_size; while (i > 1) - { + { i_Node *cnode = it->path[i - 1]; if (cnode == NULL || cnode->type == i_BLACK_NODE) { @@ -775,7 +774,7 @@ static void i_restructure_after_delete(i_Iterator *it, i_Node **root) cassert(i > 0); i -= 1; } - else + else { i_Node *grand = NULL; /*! */ @@ -785,7 +784,7 @@ static void i_restructure_after_delete(i_Iterator *it, i_Node **root) cassert(brother->lnode->type == i_RED_NODE); brother->lnode->type = i_BLACK_NODE; brother->type = i_RED_NODE; - i_rotate_right(brother, parent, root); + i_rotate_right(brother, parent, root); brother = parent->rnode; cassert_no_null(brother); } @@ -833,7 +832,7 @@ static void i_restructure_after_delete(i_Iterator *it, i_Node **root) cassert(i > 0); i -= 1; } - else + else { i_Node *grand = NULL; @@ -844,7 +843,7 @@ static void i_restructure_after_delete(i_Iterator *it, i_Node **root) cassert(brother->rnode->type == i_RED_NODE); brother->rnode->type = i_BLACK_NODE; brother->type = i_RED_NODE; - i_rotate_left(brother, parent, root); + i_rotate_left(brother, parent, root); brother = parent->lnode; cassert_no_null(brother); } @@ -855,7 +854,7 @@ static void i_restructure_after_delete(i_Iterator *it, i_Node **root) cassert(brother->lnode->type == i_RED_NODE); brother->type = parent->type; brother->lnode->type = i_BLACK_NODE; - parent->type = i_BLACK_NODE; + parent->type = i_BLACK_NODE; grand = (i > 2) ? it->path[i - 3] : NULL; i_rotate_right(parent, grand, root); i = 1; @@ -876,9 +875,9 @@ static void i_restructure_after_delete(i_Iterator *it, i_Node **root) /*---------------------------------------------------------------------------*/ static bool_t i_delete_element( - i_Node **root, + i_Node **root, const uint32_t elems, - const void *key, + const void *key, const bool_t isptr, FPtr_compare func_compare, i_Iterator *it, @@ -924,7 +923,7 @@ static bool_t i_delete_element( register i_Node *parent; register i_Node *child; - parent = it->path[it->path_size - 2]; + parent = it->path[it->path_size - 2]; cassert_no_null(parent); if (deleted_node->lnode != NULL) @@ -961,7 +960,7 @@ static bool_t i_delete_element( it->path[0] = deleted_node->lnode; } else if (deleted_node->rnode != NULL) - { + { *root = deleted_node->rnode; it->path[0] = deleted_node->rnode; } @@ -1083,7 +1082,7 @@ byte_t *rbtree_next(RBTree *tree) /*---------------------------------------------------------------------------*/ byte_t *rbtree_prev(RBTree *tree) -{ +{ cassert_no_null(tree); if (i_inorder_prev(&tree->it) == TRUE) return i_NODE_DATA(tree->it.path[tree->it.path_size - 1]) + tree->ksize; @@ -1127,7 +1126,7 @@ byte_t *rbtree_next_ptr(RBTree *tree) /*---------------------------------------------------------------------------*/ byte_t *rbtree_prev_ptr(RBTree *tree) -{ +{ cassert_no_null(tree); if (i_inorder_prev(&tree->it) == TRUE) return *(byte_t**)(i_NODE_DATA(tree->it.path[tree->it.path_size - 1]) + tree->ksize); @@ -1155,9 +1154,9 @@ const char_t *rbtree_get_key(const RBTree *tree) /*---------------------------------------------------------------------------*/ static void i_check_in_depth( - const i_Node *node, - uint32_t path_accum, - uint32_t black_path_accum, + const i_Node *node, + uint32_t path_accum, + uint32_t black_path_accum, uint32_t *black_depth, uint32_t *min_depth, uint32_t *max_depth) @@ -1221,7 +1220,7 @@ bool_t rbtree_check(const RBTree *tree) cassert(tree->root->type == i_BLACK_NODE); i_check_in_depth(tree->root, 0, 0, &black_depth, &min_depth, &max_depth); - { + { uint32_t max_theoric_depth = i_log2(tree->elems + 1); max_theoric_depth <<= 1; cassert(max_depth < max_theoric_depth); diff --git a/src/core/rbtree.h b/src/core/rbtree.h index ab07f39..ad0b9c2 100644 --- a/src/core/rbtree.h +++ b/src/core/rbtree.h @@ -14,43 +14,43 @@ __EXTERN_C -RBTree *rbtree_create(FPtr_compare func_compare, const uint16_t esize, const uint16_t ksize, const char_t *type); +_core_api RBTree *rbtree_create(FPtr_compare func_compare, const uint16_t esize, const uint16_t ksize, const char_t *type); -void rbtree_destroy(RBTree **tree, FPtr_remove func_remove, FPtr_destroy func_destroy_key, const char_t *type); +_core_api void rbtree_destroy(RBTree **tree, FPtr_remove func_remove, FPtr_destroy func_destroy_key, const char_t *type); -void rbtree_destroy_ptr(RBTree **tree, FPtr_destroy func_destroy, FPtr_destroy func_destroy_key, const char_t *type); +_core_api void rbtree_destroy_ptr(RBTree **tree, FPtr_destroy func_destroy, FPtr_destroy func_destroy_key, const char_t *type); -uint32_t rbtree_size(const RBTree *tree); +_core_api uint32_t rbtree_size(const RBTree *tree); -byte_t *rbtree_get(const RBTree *tree, const void *key, const bool_t isptr); +_core_api byte_t *rbtree_get(const RBTree *tree, const void *key, const bool_t isptr); -byte_t *rbtree_insert(RBTree *tree, const void *key, FPtr_copy func_key_copy); +_core_api byte_t *rbtree_insert(RBTree *tree, const void *key, FPtr_copy func_key_copy); -bool_t rbtree_insert_ptr(RBTree *tree, void *ptr); +_core_api bool_t rbtree_insert_ptr(RBTree *tree, void *ptr); -bool_t rbtree_delete(RBTree *tree, const void *key, FPtr_remove func_remove, FPtr_destroy func_destroy_key); +_core_api bool_t rbtree_delete(RBTree *tree, const void *key, FPtr_remove func_remove, FPtr_destroy func_destroy_key); -bool_t rbtree_delete_ptr(RBTree *tree, const void *key, FPtr_destroy func_destroy, FPtr_destroy func_destroy_key); +_core_api bool_t rbtree_delete_ptr(RBTree *tree, const void *key, FPtr_destroy func_destroy, FPtr_destroy func_destroy_key); -byte_t *rbtree_first(RBTree *tree); +_core_api byte_t *rbtree_first(RBTree *tree); -byte_t *rbtree_last(RBTree *tree); +_core_api byte_t *rbtree_last(RBTree *tree); -byte_t *rbtree_next(RBTree *tree); +_core_api byte_t *rbtree_next(RBTree *tree); -byte_t *rbtree_prev(RBTree *tree); +_core_api byte_t *rbtree_prev(RBTree *tree); -byte_t *rbtree_first_ptr(RBTree *tree); +_core_api byte_t *rbtree_first_ptr(RBTree *tree); -byte_t *rbtree_last_ptr(RBTree *tree); +_core_api byte_t *rbtree_last_ptr(RBTree *tree); -byte_t *rbtree_next_ptr(RBTree *tree); +_core_api byte_t *rbtree_next_ptr(RBTree *tree); -byte_t *rbtree_prev_ptr(RBTree *tree); +_core_api byte_t *rbtree_prev_ptr(RBTree *tree); -const char_t *rbtree_get_key(const RBTree *tree); +_core_api const char_t *rbtree_get_key(const RBTree *tree); -bool_t rbtree_check(const RBTree *tree); +_core_api bool_t rbtree_check(const RBTree *tree); __END_C diff --git a/src/core/regex.c b/src/core/regex.c index 7e75d14..e9a5c1d 100644 --- a/src/core/regex.c +++ b/src/core/regex.c @@ -14,36 +14,38 @@ #include "nfa.inl" #include "unicode.h" -//RegEx *regex = regex_create("000_OCR_OK_01_.*\\.png"); -//bool_t ok1 = regex_match(regex, "000_OCR_OK_01_001.png"); -//bool_t ok2 = regex_match(regex, "000_OCR_OK_01_001spng"); -//bool_t ok3 = regex_match(regex, "000_OCR_OK_01_003.png"); -//bool_t ok4 = regex_match(regex, "000_OCR_OK_01_004.png"); -//bool_t ok5 = regex_match(regex, "000_OCR_OK_01_005.png"); -//bool_t ok6 = regex_match(regex, "000_OCR_OK_01_006.png"); -//bool_t ok7 = regex_match(regex, "000_OCR_OK_01_007.png"); -//bool_t ok8 = regex_match(regex, "000_OCR_OK_01_008.png"); -//bool_t ok9 = regex_match(regex, "000_OCR_OK_01_009.png"); -//bool_t okA = regex_match(regex, "001_OCR_OK_01_009.png"); -//bool_t okB = regex_match(regex, "002_OCR_OK_01_009.png"); -//bool_t okC = regex_match(regex, "003_OCR_OK_01_009.png"); -//bool_t okD = regex_match(regex, "004_OCR_OK_01_009.png"); -//bool_t okE = regex_match(regex, "005_OCR_OK_01_009.png"); -//bool_t okF = regex_match(regex, "006_OCR_OK_01_009.png"); -//regex_destroy(®ex); +/* +RegEx *regex = regex_create("000_OCR_OK_01_.*\\.png"); +bool_t ok1 = regex_match(regex, "000_OCR_OK_01_001.png"); +bool_t ok2 = regex_match(regex, "000_OCR_OK_01_001spng"); +bool_t ok3 = regex_match(regex, "000_OCR_OK_01_003.png"); +bool_t ok4 = regex_match(regex, "000_OCR_OK_01_004.png"); +bool_t ok5 = regex_match(regex, "000_OCR_OK_01_005.png"); +bool_t ok6 = regex_match(regex, "000_OCR_OK_01_006.png"); +bool_t ok7 = regex_match(regex, "000_OCR_OK_01_007.png"); +bool_t ok8 = regex_match(regex, "000_OCR_OK_01_008.png"); +bool_t ok9 = regex_match(regex, "000_OCR_OK_01_009.png"); +bool_t okA = regex_match(regex, "001_OCR_OK_01_009.png"); +bool_t okB = regex_match(regex, "002_OCR_OK_01_009.png"); +bool_t okC = regex_match(regex, "003_OCR_OK_01_009.png"); +bool_t okD = regex_match(regex, "004_OCR_OK_01_009.png"); +bool_t okE = regex_match(regex, "005_OCR_OK_01_009.png"); +bool_t okF = regex_match(regex, "006_OCR_OK_01_009.png"); +regex_destroy(®ex); + */ /*---------------------------------------------------------------------------*/ RegEx *regex_create(const char_t *pattern) { - return (RegEx*)nfa_regex(pattern, FALSE); + return (RegEx*)_nfa_regex(pattern, FALSE); } /*---------------------------------------------------------------------------*/ void regex_destroy(RegEx **regex) { - nfa_destroy((NFA**)regex); + _nfa_destroy((NFA**)regex); } /*---------------------------------------------------------------------------*/ @@ -51,16 +53,16 @@ void regex_destroy(RegEx **regex) bool_t regex_match(const RegEx *regex, const char_t *str) { uint32_t codepoint; - nfa_start((NFA*)regex); + _nfa_start((NFA*)regex); codepoint = unicode_to_u32(str, ekUTF8); while(codepoint != 0) { - if (nfa_next((NFA*)regex, codepoint) == FALSE) + if (_nfa_next((NFA*)regex, codepoint) == FALSE) return FALSE; str = unicode_next(str, ekUTF8); codepoint = unicode_to_u32(str, ekUTF8); } - return nfa_accept((NFA*)regex); + return _nfa_accept((NFA*)regex); } diff --git a/src/core/regex.h b/src/core/regex.h index dbc34dd..33ba9f0 100644 --- a/src/core/regex.h +++ b/src/core/regex.h @@ -15,10 +15,10 @@ __EXTERN_C -RegEx *regex_create(const char_t *pattern); +_core_api RegEx *regex_create(const char_t *pattern); -void regex_destroy(RegEx **regex); +_core_api void regex_destroy(RegEx **regex); -bool_t regex_match(const RegEx *regex, const char_t *str); +_core_api bool_t regex_match(const RegEx *regex, const char_t *str); __END_C diff --git a/src/core/respack.c b/src/core/respack.c index af9f7b2..5dca36d 100644 --- a/src/core/respack.c +++ b/src/core/respack.c @@ -12,12 +12,10 @@ #include "respack.h" #include "respackh.h" -#include "respack.inl" #include "arrpt.h" #include "arrst.h" #include "bfile.h" #include "buffer.h" -#include "core.inl" #include "cassert.h" #include "heap.h" #include "hfile.h" diff --git a/src/core/respack.h b/src/core/respack.h index 2fa7e0e..e4bf233 100644 --- a/src/core/respack.h +++ b/src/core/respack.h @@ -15,10 +15,10 @@ __EXTERN_C -void respack_destroy(ResPack **pack); +_core_api void respack_destroy(ResPack **pack); -const char_t *respack_text(const ResPack *pack, const ResId id); +_core_api const char_t *respack_text(const ResPack *pack, const ResId id); -const byte_t *respack_file(const ResPack *pack, const ResId id, uint32_t *size); +_core_api const byte_t *respack_file(const ResPack *pack, const ResId id, uint32_t *size); __END_C diff --git a/src/core/respack.inl b/src/core/respack.inl deleted file mode 100644 index f3684e5..0000000 --- a/src/core/respack.inl +++ /dev/null @@ -1,39 +0,0 @@ -/* - * NAppGUI Cross-platform C SDK - * 2015-2022 Francisco Garcia Collado - * MIT Licence - * https://nappgui.com/en/legal/license.html - * - * File: respack.inl - * - */ - -/* Resource Packages */ - -#include "core.ixx" - -__EXTERN_C - -void *respack_object_imp(const ResPack *pack, const ResId id, FPtr_create_from_data func_create, FPtr_destroy func_destroy); - -const char_t *respack_atext(const ArrPt(ResPack) *packs, const ResId id, bool_t *is_resid); - -const byte_t *respack_afile(const ArrPt(ResPack) *packs, const ResId id, uint32_t *size, bool_t *is_resid); - -void *respack_aobj_imp(const ArrPt(ResPack) *packs, const ResId id, FPtr_create_from_data func_create, FPtr_destroy func_destroy, bool_t *is_resid); - - -__END_C - -#define respack_object(pack, id, func_create, func_destroy, type)\ - ((void)\ - FUNC_CHECK_CREATE_FROM_DATA(func_create, type),\ - FUNC_CHECK_DESTROY(func_destroy, type),\ - (type*)respack_object_imp(pack, id, (FPtr_create_from_data)func_create, (FPtr_destroy)func_destroy)) - -#define respack_aobj(packs, id, func_create, func_destroy, is_resid, type)\ - ((void)\ - FUNC_CHECK_CREATE_FROM_DATA(func_create, type),\ - FUNC_CHECK_DESTROY(func_destroy, type),\ - (type*)respack_aobj_imp(packs, id, (FPtr_create_from_data)func_create, (FPtr_destroy)func_destroy, is_resid)) - \ No newline at end of file diff --git a/src/core/respackh.h b/src/core/respackh.h index 08010fc..ef787d9 100644 --- a/src/core/respackh.h +++ b/src/core/respackh.h @@ -8,20 +8,38 @@ * */ -/* Resource Packages */ +/* Undocumented (hidden) API about resource packages */ -#include "core.hxx" +#include "coreh.hxx" __EXTERN_C -ResPack *respack_embedded(const char_t *name); +_core_api ResPack *respack_embedded(const char_t *name); -ResPack *respack_packed(const char_t *name, const char_t *locale); +_core_api ResPack *respack_packed(const char_t *name, const char_t *locale); -void respack_add_msg(ResPack *pack, const char_t *msg); +_core_api void respack_add_msg(ResPack *pack, const char_t *msg); -void respack_add_cdata(ResPack *pack, const uint32_t type, const byte_t *data, const uint32_t data_size); +_core_api void respack_add_cdata(ResPack *pack, const uint32_t type, const byte_t *data, const uint32_t data_size); + +_core_api void *respack_object_imp(const ResPack *pack, const ResId id, FPtr_create_from_data func_create, FPtr_destroy func_destroy); + +_core_api void *respack_aobj_imp(const ArrPt(ResPack) *packs, const ResId id, FPtr_create_from_data func_create, FPtr_destroy func_destroy, bool_t *is_resid); + +_core_api const char_t *respack_atext(const ArrPt(ResPack) *packs, const ResId id, bool_t *is_resid); + +_core_api const byte_t *respack_afile(const ArrPt(ResPack) *packs, const ResId id, uint32_t *size, bool_t *is_resid); __END_C - \ No newline at end of file +#define respack_object(pack, id, func_create, func_destroy, type)\ + ((void)\ + FUNC_CHECK_CREATE_FROM_DATA(func_create, type),\ + FUNC_CHECK_DESTROY(func_destroy, type),\ + (type*)respack_object_imp(pack, id, (FPtr_create_from_data)func_create, (FPtr_destroy)func_destroy)) + +#define respack_aobj(packs, id, func_create, func_destroy, is_resid, type)\ + ((void)\ + FUNC_CHECK_CREATE_FROM_DATA(func_create, type),\ + FUNC_CHECK_DESTROY(func_destroy, type),\ + (type*)respack_aobj_imp(packs, id, (FPtr_create_from_data)func_create, (FPtr_destroy)func_destroy, is_resid)) diff --git a/src/core/stream.c b/src/core/stream.c index 7decff5..2f24031 100644 --- a/src/core/stream.c +++ b/src/core/stream.c @@ -13,7 +13,6 @@ #include "stream.h" #include "stream.inl" #include "lex.inl" -#include "core.inl" #include "bfile.h" #include "bmem.h" #include "bstd.h" @@ -106,7 +105,7 @@ struct _stream_t i_Buffer *output; i_Buffer *input; i_Channel channel; - + LexScn *lex; uint32_t col; uint32_t row; @@ -125,7 +124,6 @@ typedef void(*i_FPtr_cache)(Stream*, const uint32_t size); static void i_to_mem_fill_cache(Stream*, const uint32_t size); static void i_from_mem_fill_cache(Stream*, const uint32_t size); static void i_file_fill_cache(Stream*, const uint32_t size); -//static void i_sock_fill_cache(Stream*, const uint32_t size); static void i_stdin_fill_cache(Stream*, const uint32_t size); typedef void(*i_FPtr_write)(Stream*, const byte_t *data, const uint32_t size); @@ -276,7 +274,7 @@ void stm_close(Stream **stm) i_remove_buffer(&(*stm)->textline, "StreamTextLine"); i_remove_buffer(&(*stm)->restore, "StreamRestore"); i_close_channel(&(*stm)->channel, (*stm)->type); - ptr_destopt(lexscn_destroy, &(*stm)->lex, LexScn); + ptr_destopt(_lexscn_destroy, &(*stm)->lex, LexScn); heap_delete(stm, Stream); } @@ -564,6 +562,14 @@ void stm_set_read_utf(Stream *stm, const unicode_t format) /*---------------------------------------------------------------------------*/ +bool_t stm_is_memory(const Stream *stm) +{ + cassert_no_null(stm); + return (bool_t)(stm->type == i_ekTOMEMORY || stm->type == i_ekFROMMEMORY); +} + +/*---------------------------------------------------------------------------*/ + uint64_t stm_bytes_written(const Stream *stm) { cassert_no_null(stm); @@ -599,7 +605,7 @@ uint32_t stm_row(const Stream *stm) uint32_t stm_token_col(const Stream *stm) { cassert_no_null(stm); - return lexscn_col(stm->lex); + return _lexscn_col(stm->lex); } /*---------------------------------------------------------------------------*/ @@ -607,7 +613,7 @@ uint32_t stm_token_col(const Stream *stm) uint32_t stm_token_row(const Stream *stm) { cassert_no_null(stm); - return lexscn_row(stm->lex); + return _lexscn_row(stm->lex); } /*---------------------------------------------------------------------------*/ @@ -615,7 +621,7 @@ uint32_t stm_token_row(const Stream *stm) const char_t *stm_token_lexeme(const Stream *stm, uint32_t *size) { cassert_no_null(stm); - return lexscn_lexeme(stm->lex, size); + return _lexscn_lexeme(stm->lex, size); } /*---------------------------------------------------------------------------*/ @@ -625,7 +631,7 @@ void stm_token_escapes(Stream *stm, const bool_t active_escapes) cassert_no_null(stm); stm->escapes = active_escapes; if (stm->lex != NULL) - lexscn_escapes(stm->lex, stm->escapes); + _lexscn_escapes(stm->lex, stm->escapes); } /*---------------------------------------------------------------------------*/ @@ -635,7 +641,7 @@ void stm_token_spaces(Stream *stm, const bool_t active_spaces) cassert_no_null(stm); stm->spaces = active_spaces; if (stm->lex != NULL) - lexscn_spaces(stm->lex, stm->spaces); + _lexscn_spaces(stm->lex, stm->spaces); } /*---------------------------------------------------------------------------*/ @@ -645,7 +651,7 @@ void stm_token_comments(Stream *stm, const bool_t active_comments) cassert_no_null(stm); stm->comments = active_comments; if (stm->lex != NULL) - lexscn_comments(stm->lex, stm->comments); + _lexscn_comments(stm->lex, stm->comments); } /*---------------------------------------------------------------------------*/ @@ -815,7 +821,7 @@ static void i_grow_buffer(i_Buffer *output, const uint32_t size, const uint32_t data = heap_malloc(new_size, memname); - // Exists non-readed data in buffer, we have to preserve + /* Exists non-readed data in buffer, we have to preserve */ if (output->data != NULL) { const byte_t *sdata = output->data + output->roffset; @@ -861,12 +867,12 @@ static void i_need_buffer_space(Stream *stm, i_Buffer *output, const uint32_t si } else if (stm->type == i_ekSOCKET) { - // Sockets all allways write cache-flushed + /* Sockets all allways write cache-flushed */ cassert(output->woffset == 0); - } + } else { - // For channel buffers --> flush to free space in cache + /* For channel buffers --> flush to free space in cache */ cassert_no_nullf(i_FUNC_WRITE[stm->type]); cassert(output->roffset == 0); i_FUNC_WRITE[stm->type](stm, output->data, output->woffset); @@ -881,28 +887,28 @@ static void i_write(Stream *stm, const byte_t *data, const uint32_t size, const register i_Buffer *output; cassert_no_null(stm); cassert(size > 0); - + if (!IS_OK(stm->state)) return; output = stm->output; if (output != NULL) { - // No space in buffer + /* No space in buffer */ if (output->woffset + size > output->size) i_need_buffer_space(stm, stm->output, size); - // No space in buffer after request - // So big for cache --> Direct writting to channel + /* No space in buffer after request + So big for cache --> Direct writting to channel */ if (output->woffset + size > output->size) { - cassert(reverse == FALSE); // So big for endianness + cassert(reverse == FALSE); /* So big for endianness */ cassert_no_nullf(i_FUNC_WRITE[stm->type]); cassert(output->roffset == 0); - cassert(output->woffset == 0); // Has been flushed + cassert(output->woffset == 0); /* Has been flushed */ i_FUNC_WRITE[stm->type](stm, data, size); } - // Write in cache + /* Write in cache */ else { byte_t *dest = output->data + output->woffset; @@ -924,20 +930,20 @@ static void i_write(Stream *stm, const byte_t *data, const uint32_t size, const } else { - // Ups! reverse no endianness?? + /* Ups! reverse no endianness?? */ cassert(size <= 8); bmem_rev(dest, size); } } - - // For sockets --> flush cache allways + + /* For sockets --> flush cache allways */ if (stm->type == i_ekSOCKET) { cassert_no_nullf(i_FUNC_WRITE[stm->type]); cassert(output->roffset == 0); i_FUNC_WRITE[stm->type](stm, output->data, output->woffset); output->woffset = 0; - } + } } stm->write_offset += size; @@ -1354,11 +1360,11 @@ static uint32_t i_read(Stream *stm, byte_t *data, const uint32_t size, const boo register byte_t *src = stm->restore.data + stm->restore.roffset; if (read_restore > size) read_restore = size; - - // data = NULL for jump + + /* data = NULL for jump */ if (data != NULL) bmem_copy(data, src, read_restore); - + readed += read_restore; stm->restore.roffset += read_restore; } @@ -1367,7 +1373,7 @@ static uint32_t i_read(Stream *stm, byte_t *data, const uint32_t size, const boo if (stm->type == i_ekSOCKET) { register uint32_t remain = size - readed; - + if (data != NULL) { i_read_from_socket(stm, data + readed, remain); @@ -1378,14 +1384,14 @@ static uint32_t i_read(Stream *stm, byte_t *data, const uint32_t size, const boo byte_t waste[512]; uint32_t i, n = remain / sizeof(waste); uint32_t last = remain % sizeof(waste); - + for (i = 0; i < n; ++i) i_read_from_socket(stm, waste, sizeof(waste)); if (last > 0) i_read_from_socket(stm, waste, last); } - + readed += remain; } else @@ -1399,7 +1405,7 @@ static uint32_t i_read(Stream *stm, byte_t *data, const uint32_t size, const boo } /* Fill data buffer */ - // readed = 0 -- readed already from 'restore' buffer */ + /* readed = 0 -- readed already from 'restore' buffer */ for (; readed < size; ) { register uint32_t remain = size - readed; @@ -1418,7 +1424,7 @@ static uint32_t i_read(Stream *stm, byte_t *data, const uint32_t size, const boo if (remain < available) available = remain; - // data = NULL for jump + /* data = NULL for jump */ if (data != NULL) bmem_copy(data + readed, input->data + input->roffset, available); @@ -1426,7 +1432,7 @@ static uint32_t i_read(Stream *stm, byte_t *data, const uint32_t size, const boo readed += available; } } - + if (data != NULL && reverse == TRUE) { if (size == 2) @@ -1634,12 +1640,12 @@ uint32_t stm_read_char(Stream *stm) { stm->col += 1; } - + return code; } else { - //BIT_SET(stm->state, CORRUPTION_BIT); + /* BIT_SET(stm->state, CORRUPTION_BIT); */ return UINT32_MAX; } } @@ -1747,13 +1753,13 @@ ltoken_t stm_read_token(Stream *stm) cassert_no_null(stm); if (stm->lex == NULL) { - stm->lex = lexscn_create(); - lexscn_escapes(stm->lex, stm->escapes); - lexscn_spaces(stm->lex, stm->spaces); - lexscn_comments(stm->lex, stm->comments); + stm->lex = _lexscn_create(); + _lexscn_escapes(stm->lex, stm->escapes); + _lexscn_spaces(stm->lex, stm->spaces); + _lexscn_comments(stm->lex, stm->comments); } - return lexscn_token(stm->lex, stm); + return _lexscn_token(stm->lex, stm); } /*---------------------------------------------------------------------------*/ @@ -1925,30 +1931,6 @@ real64_t stm_read_r64_tok(Stream *stm) /*---------------------------------------------------------------------------*/ -//const char_t *stm_read_delim(Stream *stm, const uint32_t codepoint); -//const char_t *stm_read_delim(Stream *stm, const uint32_t codepoint) -//{ -// i_Buffer *line; -// uint32_t code = 0; -// cassert_no_null(stm); -// if (!IS_OK(stm->state)) -// return ""; -// -// line = &stm->textline; -// line->roffset = 0; -// code = stm_read_char(stm); -// while (code != codepoint) -// { -// i_char_to_cache(stm, code); -// code = stm_read_char(stm); -// } -// -// i_char_to_cache(stm, 0); -// return (const char_t*)line->data; -//} - -/*---------------------------------------------------------------------------*/ - bool_t stm_read_bool(Stream *stm) { bool_t v = FALSE; @@ -2129,8 +2111,8 @@ void _stm_restore(Stream *stm, const byte_t *data, const uint32_t size) { byte_t *dest = NULL; cassert_no_null(stm); - - // No space in buffer + + /* No space in buffer */ if (stm->restore.woffset + size > stm->restore.size) i_grow_buffer(&stm->restore, size, 64, "StreamRestore"); @@ -2154,32 +2136,3 @@ void _stm_restore_row(Stream *stm, const uint32_t row) cassert_no_null(stm); stm->row = row; } - -/*---------------------------------------------------------------------------*/ - -bool_t _stm_memory(const Stream *stm) -{ - cassert_no_null(stm); - return (bool_t)(stm->type == i_ekTOMEMORY || stm->type == i_ekFROMMEMORY); -} - -/*---------------------------------------------------------------------------*/ - -uint32_t _stm_get_roffset(const Stream *stm) -{ - cassert_no_null(stm); - cassert(stm->type == i_ekTOMEMORY || stm->type == i_ekFROMMEMORY); - return stm->buffer1.roffset; -} - -/*---------------------------------------------------------------------------*/ - -void _stm_set_roffset(Stream *stm, const uint32_t offset) -{ - uint32_t roffset; - cassert_no_null(stm); - cassert(stm->type == i_ekTOMEMORY || stm->type == i_ekFROMMEMORY); - roffset = stm->buffer1.roffset; - stm->buffer1.roffset = offset; - stm->read_offset -= (offset - roffset); -} diff --git a/src/core/stream.h b/src/core/stream.h index 76a5a8d..65a9b29 100644 --- a/src/core/stream.h +++ b/src/core/stream.h @@ -15,182 +15,183 @@ __EXTERN_C -Stream *stm_from_block(const byte_t *data, const uint32_t size); +_core_api Stream *stm_from_block(const byte_t *data, const uint32_t size); -Stream *stm_memory(const uint32_t size); +_core_api Stream *stm_memory(const uint32_t size); -Stream *stm_from_file(const char_t *pathname, ferror_t *error); +_core_api Stream *stm_from_file(const char_t *pathname, ferror_t *error); -Stream *stm_to_file(const char_t *pathname, ferror_t *error); +_core_api Stream *stm_to_file(const char_t *pathname, ferror_t *error); -Stream *stm_append_file(const char_t *pathname, ferror_t *error); +_core_api Stream *stm_append_file(const char_t *pathname, ferror_t *error); -Stream *stm_socket(Socket *socket); +_core_api Stream *stm_socket(Socket *socket); -void stm_close(Stream **stm); +_core_api void stm_close(Stream **stm); -endian_t stm_get_write_endian(const Stream *stm); +_core_api endian_t stm_get_write_endian(const Stream *stm); -endian_t stm_get_read_endian(const Stream *stm); +_core_api endian_t stm_get_read_endian(const Stream *stm); -void stm_set_write_endian(Stream *stm, const endian_t endian); +_core_api void stm_set_write_endian(Stream *stm, const endian_t endian); -void stm_set_read_endian(Stream *stm, const endian_t endian); +_core_api void stm_set_read_endian(Stream *stm, const endian_t endian); -unicode_t stm_get_write_utf(const Stream *stm); +_core_api unicode_t stm_get_write_utf(const Stream *stm); -unicode_t stm_get_read_utf(const Stream *stm); +_core_api unicode_t stm_get_read_utf(const Stream *stm); -void stm_set_write_utf(Stream *stm, const unicode_t format); +_core_api void stm_set_write_utf(Stream *stm, const unicode_t format); -void stm_set_read_utf(Stream *stm, const unicode_t format); +_core_api void stm_set_read_utf(Stream *stm, const unicode_t format); -uint64_t stm_bytes_written(const Stream *stm); +_core_api bool_t stm_is_memory(const Stream *stm); -uint64_t stm_bytes_readed(const Stream *stm); +_core_api uint64_t stm_bytes_written(const Stream *stm); -uint32_t stm_col(const Stream *stm); +_core_api uint64_t stm_bytes_readed(const Stream *stm); -uint32_t stm_row(const Stream *stm); +_core_api uint32_t stm_col(const Stream *stm); -uint32_t stm_token_col(const Stream *stm); +_core_api uint32_t stm_row(const Stream *stm); -uint32_t stm_token_row(const Stream *stm); +_core_api uint32_t stm_token_col(const Stream *stm); -const char_t *stm_token_lexeme(const Stream *stm, uint32_t *size); +_core_api uint32_t stm_token_row(const Stream *stm); -void stm_token_escapes(Stream *stm, const bool_t active_escapes); +_core_api const char_t *stm_token_lexeme(const Stream *stm, uint32_t *size); -void stm_token_spaces(Stream *stm, const bool_t active_spaces); +_core_api void stm_token_escapes(Stream *stm, const bool_t active_escapes); -void stm_token_comments(Stream *stm, const bool_t active_comments); +_core_api void stm_token_spaces(Stream *stm, const bool_t active_spaces); -sstate_t stm_state(const Stream *stm); +_core_api void stm_token_comments(Stream *stm, const bool_t active_comments); -ferror_t stm_file_err(const Stream *stm); +_core_api sstate_t stm_state(const Stream *stm); -serror_t stm_sock_err(const Stream *stm); +_core_api ferror_t stm_file_err(const Stream *stm); -void stm_corrupt(Stream *stm); +_core_api serror_t stm_sock_err(const Stream *stm); -String *stm_str(const Stream *stm); +_core_api void stm_corrupt(Stream *stm); -const byte_t *stm_buffer(const Stream *stm); +_core_api String *stm_str(const Stream *stm); -uint32_t stm_buffer_size(const Stream *stm); +_core_api const byte_t *stm_buffer(const Stream *stm); +_core_api uint32_t stm_buffer_size(const Stream *stm); -void stm_write(Stream *stm, const byte_t *data, const uint32_t size); -void stm_write_char(Stream *stm, const uint32_t codepoint); +_core_api void stm_write(Stream *stm, const byte_t *data, const uint32_t size); -uint32_t stm_printf(Stream *stm, const char_t *format, ...) __PRINTF(2, 3); +_core_api void stm_write_char(Stream *stm, const uint32_t codepoint); -uint32_t stm_writef(Stream *stm, const char_t *str); +_core_api uint32_t stm_printf(Stream *stm, const char_t *format, ...) __PRINTF(2, 3); -void stm_write_bool(Stream *stm, const bool_t value); +_core_api uint32_t stm_writef(Stream *stm, const char_t *str); -void stm_write_i8(Stream *stm, const int8_t value); +_core_api void stm_write_bool(Stream *stm, const bool_t value); -void stm_write_i16(Stream *stm, const int16_t value); +_core_api void stm_write_i8(Stream *stm, const int8_t value); -void stm_write_i32(Stream *stm, const int32_t value); +_core_api void stm_write_i16(Stream *stm, const int16_t value); -void stm_write_i64(Stream *stm, const int64_t value); +_core_api void stm_write_i32(Stream *stm, const int32_t value); -void stm_write_u8(Stream *stm, const uint8_t value); +_core_api void stm_write_i64(Stream *stm, const int64_t value); -void stm_write_u16(Stream *stm, const uint16_t value); +_core_api void stm_write_u8(Stream *stm, const uint8_t value); -void stm_write_u32(Stream *stm, const uint32_t value); +_core_api void stm_write_u16(Stream *stm, const uint16_t value); -void stm_write_u64(Stream *stm, const uint64_t value); +_core_api void stm_write_u32(Stream *stm, const uint32_t value); -void stm_write_r32(Stream *stm, const real32_t value); +_core_api void stm_write_u64(Stream *stm, const uint64_t value); -void stm_write_r64(Stream *stm, const real64_t value); +_core_api void stm_write_r32(Stream *stm, const real32_t value); +_core_api void stm_write_r64(Stream *stm, const real64_t value); -uint32_t stm_read(Stream *stm, byte_t *data, const uint32_t size); -uint32_t stm_read_char(Stream *stm); +_core_api uint32_t stm_read(Stream *stm, byte_t *data, const uint32_t size); -const char_t *stm_read_chars(Stream *stm, const uint32_t n); +_core_api uint32_t stm_read_char(Stream *stm); -const char_t *stm_read_line(Stream *stm); +_core_api const char_t *stm_read_chars(Stream *stm, const uint32_t n); -const char_t *stm_read_trim(Stream *stm); +_core_api const char_t *stm_read_line(Stream *stm); -ltoken_t stm_read_token(Stream *stm); +_core_api const char_t *stm_read_trim(Stream *stm); -int8_t stm_read_i8_tok(Stream *stm); +_core_api ltoken_t stm_read_token(Stream *stm); -int16_t stm_read_i16_tok(Stream *stm); +_core_api int8_t stm_read_i8_tok(Stream *stm); -int32_t stm_read_i32_tok(Stream *stm); +_core_api int16_t stm_read_i16_tok(Stream *stm); -int64_t stm_read_i64_tok(Stream *stm); +_core_api int32_t stm_read_i32_tok(Stream *stm); -uint8_t stm_read_u8_tok(Stream *stm); +_core_api int64_t stm_read_i64_tok(Stream *stm); -uint16_t stm_read_u16_tok(Stream *stm); +_core_api uint8_t stm_read_u8_tok(Stream *stm); -uint32_t stm_read_u32_tok(Stream *stm); +_core_api uint16_t stm_read_u16_tok(Stream *stm); -uint64_t stm_read_u64_tok(Stream *stm); +_core_api uint32_t stm_read_u32_tok(Stream *stm); -real32_t stm_read_r32_tok(Stream *stm); +_core_api uint64_t stm_read_u64_tok(Stream *stm); -real64_t stm_read_r64_tok(Stream *stm); +_core_api real32_t stm_read_r32_tok(Stream *stm); +_core_api real64_t stm_read_r64_tok(Stream *stm); -bool_t stm_read_bool(Stream *stm); -int8_t stm_read_i8(Stream *stm); +_core_api bool_t stm_read_bool(Stream *stm); -int16_t stm_read_i16(Stream *stm); +_core_api int8_t stm_read_i8(Stream *stm); -int32_t stm_read_i32(Stream *stm); +_core_api int16_t stm_read_i16(Stream *stm); -int64_t stm_read_i64(Stream *stm); +_core_api int32_t stm_read_i32(Stream *stm); -uint8_t stm_read_u8(Stream *stm); +_core_api int64_t stm_read_i64(Stream *stm); -uint16_t stm_read_u16(Stream *stm); +_core_api uint8_t stm_read_u8(Stream *stm); -uint32_t stm_read_u32(Stream *stm); +_core_api uint16_t stm_read_u16(Stream *stm); -uint64_t stm_read_u64(Stream *stm); +_core_api uint32_t stm_read_u32(Stream *stm); -real32_t stm_read_r32(Stream *stm); +_core_api uint64_t stm_read_u64(Stream *stm); -real64_t stm_read_r64(Stream *stm); +_core_api real32_t stm_read_r32(Stream *stm); +_core_api real64_t stm_read_r64(Stream *stm); -void stm_skip(Stream *stm, const uint32_t size); -void stm_skip_bom(Stream *stm); +_core_api void stm_skip(Stream *stm, const uint32_t size); -void stm_skip_token(Stream *stm, const ltoken_t token); +_core_api void stm_skip_bom(Stream *stm); -void stm_flush(Stream *stm); +_core_api void stm_skip_token(Stream *stm, const ltoken_t token); -void stm_pipe(Stream *from, Stream *to, const uint32_t n); +_core_api void stm_flush(Stream *stm); +_core_api void stm_pipe(Stream *from, Stream *to, const uint32_t n); -extern Stream *kSTDIN; +_core_api extern Stream *kSTDIN; -extern Stream *kSTDOUT; +_core_api extern Stream *kSTDOUT; -extern Stream *kSTDERR; +_core_api extern Stream *kSTDERR; -extern Stream *kDEVNULL; +_core_api extern Stream *kDEVNULL; __END_C #define stm_write_enum(stm, value, type)\ - stm_write_i32(stm, (const int32_t)value) + stm_write_i32(stm, (int32_t)value) #define stm_read_enum(stm, type)\ (type)stm_read_i32(stm) diff --git a/src/core/stream.inl b/src/core/stream.inl index 3deeaa8..490ffeb 100644 --- a/src/core/stream.inl +++ b/src/core/stream.inl @@ -24,11 +24,5 @@ void _stm_restore_col(Stream *stm, const uint32_t col); void _stm_restore_row(Stream *stm, const uint32_t row); -bool_t _stm_memory(const Stream *stm); - -uint32_t _stm_get_roffset(const Stream *stm); - -void _stm_set_roffset(Stream *stm, const uint32_t offset); - __END_C diff --git a/src/core/strings.c b/src/core/strings.c index 2440a54..66aabf5 100644 --- a/src/core/strings.c +++ b/src/core/strings.c @@ -12,8 +12,7 @@ #include "strings.h" #include "arrpt.h" -#include "core.inl" -#include "blib.inl" +#include "blib.h" #include "bmem.h" #include "bstd.h" #include "cassert.h" @@ -354,12 +353,12 @@ static void i_replace(String **str, const char_t *replace, const char_t *with) uint32_t count = 0; /* number of replacements */ uint32_t len_new = 0; /* length of new string */ String *lstr = NULL; - + cassert_no_null(str); cassert_no_null(*str); cassert_no_null(replace); cassert_no_null(with); - + len_inp = blib_strlen(i_DATA(*str)); if (len_inp == 0) return; @@ -367,7 +366,7 @@ static void i_replace(String **str, const char_t *replace, const char_t *with) len_rep = blib_strlen(replace); if (len_rep == 0) return; - + /* Count the number of replacements needed */ { const char_t *src = NULL; /* the next insert point */ @@ -395,7 +394,7 @@ static void i_replace(String **str, const char_t *replace, const char_t *with) len_new += 1; lstr = i_create_string(len_new, NULL); - /* First time through the loop, all the variable are set correctly from here on. + /* First time through the loop, all the variable are set correctly from here on. src points to the end of the result string ins points to the next occurrence of rep in orig orig points to the remainder of orig after "end of rep" @@ -426,10 +425,10 @@ static void i_replace(String **str, const char_t *replace, const char_t *with) src += len_front + len_rep; /* move to next "end of replacement" */ } - + str_copy_c(dest, len_new, src); } - + str_destroy(str); *str = lstr; } @@ -659,18 +658,6 @@ bool_t str_is_sufix(const char_t *str, const char_t *sufix) /*---------------------------------------------------------------------------*/ -//compare_t str_dcompare(const String **str1, const String **str2); -//compare_t str_dcompare(const String **str1, const String **str2) -//{ -// cassert_no_null(str1); -// cassert_no_null(str2); -// cassert_no_null(*str1); -// cassert_no_null(*str2); -// return bstr_cmp((const byte_t*)i_DATA(*str1), (const byte_t*)i_DATA(*str2)); -//} - -/*---------------------------------------------------------------------------*/ - int str_scmp(const String *str1, const String *str2) { cassert_no_null(str1); @@ -793,40 +780,6 @@ bool_t str_equ_end(const char_t *str, const char_t *end) /*---------------------------------------------------------------------------*/ -//bool_t str_equals_c_ignore_case(const char_t *str1, const char_t *str2); -//bool_t str_equals_c_ignore_case(const char_t *str1, const char_t *str2) -//{ -// register char_t c1, c2; -// for (;; ++str1, ++str2) -// { -// c1 = *str1; -// c2 = *str1; -// -// if (c1 == '\0' || c2 == '\0') -// return (c1 == c2) ? TRUE : FALSE; -// -// if (c1 >= 'A' && c1 <= 'Z') -// c1 += 32; -// if (c2 >= 'A' && c2 <= 'Z') -// c2 += 32; -// -// if (c1 != c2) -// return FALSE; -// } -//} - -/*---------------------------------------------------------------------------*/ - -//bool_t str_equ_cn(const char_t *str1, const char_t *str2, const uint32_t n); -//bool_t str_equ_cn(const char_t *str1, const char_t *str2, const uint32_t n) -//{ -// cassert(bmem_size((const byte_t*)str1) >= n); -// cassert(bmem_size((const byte_t*)str2) >= n); -// return bstr_cmp_n((const byte_t*)str1, (const byte_t*)str2, n) == ekEQUALS; -//} - -/*---------------------------------------------------------------------------*/ - void str_upper(String *str) { register char_t *data = NULL, *end_data = NULL; @@ -1019,7 +972,7 @@ void str_split_pathname(const char_t *pathname, String **path, String **file) *file = str_c(pathname); } } - + /*---------------------------------------------------------------------------*/ void str_split_pathext(const char_t *pathname, String **path, String **file, String **ext) @@ -1044,7 +997,6 @@ void str_split_pathext(const char_t *pathname, String **path, String **file, Str fileext = str_filext(filename); if (fileext != NULL) { - //fileext -= 1; if (file != NULL) *file = str_cn(filename, (uint32_t)(fileext - filename - 1)); @@ -1107,37 +1059,38 @@ static __INLINE bool_t i_ok(const char_t *str, const bool_t allow_minus) unref(allow_minus); return TRUE; -// if (errno == ERANGE) -// { -// return FALSE; -// } -// else -// { -// while (*str == ' ') -// str += 1; -// -// if (*str == '-') -// { -// if (allow_minus == FALSE) -// return FALSE; -// str += 1; -// } -// -// while (*str == ' ') -// str += 1; -// -// while (*str != '\0' && !(*str == ' ' || *str == '\t' || *str == '\n' || *str == '\v' || *str == '\f' || *str == '\r')) -// { -// if (*str < '0' || *str > '9') -// { -// return FALSE; -// } -// -// str += 1; -// } -// -// return TRUE; -// } +/* if (errno == ERANGE) + { + return FALSE; + } + else + { + while (*str == ' ') + str += 1; + + if (*str == '-') + { + if (allow_minus == FALSE) + return FALSE; + str += 1; + } + + while (*str == ' ') + str += 1; + + while (*str != '\0' && !(*str == ' ' || *str == '\t' || *str == '\n' || *str == '\v' || *str == '\f' || *str == '\r')) + { + if (*str < '0' || *str > '9') + { + return FALSE; + } + + str += 1; + } + + return TRUE; + } + */ } /*---------------------------------------------------------------------------*/ diff --git a/src/core/strings.h b/src/core/strings.h index 6055d74..94f9002 100644 --- a/src/core/strings.h +++ b/src/core/strings.h @@ -14,134 +14,134 @@ __EXTERN_C -const char_t *tc(const String *str); +_core_api const char_t *tc(const String *str); -char_t *tcc(String *str); +_core_api char_t *tcc(String *str); -String *str_c(const char_t *str); +_core_api String *str_c(const char_t *str); -String *str_cn(const char_t *str, const uint32_t n); +_core_api String *str_cn(const char_t *str, const uint32_t n); -String *str_trim(const char_t *str); +_core_api String *str_trim(const char_t *str); -String *str_trim_n(const char_t *str, const uint32_t n); +_core_api String *str_trim_n(const char_t *str, const uint32_t n); -String *str_copy(const String *str); +_core_api String *str_copy(const String *str); -String *str_printf(const char_t *format, ...) __PRINTF(1, 2); +_core_api String *str_printf(const char_t *format, ...) __PRINTF(1, 2); -String *str_path(const platform_t platform, const char_t *format, ...) __PRINTF(2, 3); +_core_api String *str_path(const platform_t platform, const char_t *format, ...) __PRINTF(2, 3); -String *str_cpath(const char_t *format, ...) __PRINTF(1, 2); +_core_api String *str_cpath(const char_t *format, ...) __PRINTF(1, 2); -String *str_relpath(const char_t *path1, const char_t *path2); +_core_api String *str_relpath(const char_t *path1, const char_t *path2); -String *str_repl(const char_t *str, ...); +_core_api String *str_repl(const char_t *str, ...); -String *str_reserve(const uint32_t n); +_core_api String *str_reserve(const uint32_t n); -String *str_fill(const uint32_t n, const char_t c); +_core_api String *str_fill(const uint32_t n, const char_t c); -String *str_read(Stream *stream); +_core_api String *str_read(Stream *stream); -void str_write(Stream *stream, const String *str); +_core_api void str_write(Stream *stream, const String *str); -void str_writef(Stream *stream, const String *str); +_core_api void str_writef(Stream *stream, const String *str); -void str_copy_c(char_t *dest, const uint32_t size, const char_t *src); +_core_api void str_copy_c(char_t *dest, const uint32_t size, const char_t *src); -void str_copy_cn(char_t *dest, const uint32_t size, const char_t *src, const uint32_t n); +_core_api void str_copy_cn(char_t *dest, const uint32_t size, const char_t *src, const uint32_t n); -void str_cat(String **dest, const char_t *src); +_core_api void str_cat(String **dest, const char_t *src); -void str_cat_c(char_t *dest, const uint32_t size, const char_t *src); +_core_api void str_cat_c(char_t *dest, const uint32_t size, const char_t *src); -void str_upd(String **str, const char_t *new_str); +_core_api void str_upd(String **str, const char_t *new_str); -void str_destroy(String **str); +_core_api void str_destroy(String **str); -void str_destopt(String **str); +_core_api void str_destopt(String **str); -uint32_t str_len(const String *str); +_core_api uint32_t str_len(const String *str); -uint32_t str_len_c(const char_t *str); +_core_api uint32_t str_len_c(const char_t *str); -uint32_t str_nchars(const String *str); +_core_api uint32_t str_nchars(const String *str); -uint32_t str_prefix(const char_t *str1, const char_t *str2); +_core_api uint32_t str_prefix(const char_t *str1, const char_t *str2); -bool_t str_is_prefix(const char_t *str, const char_t *prefix); +_core_api bool_t str_is_prefix(const char_t *str, const char_t *prefix); -bool_t str_is_sufix(const char_t *str, const char_t *sufix); +_core_api bool_t str_is_sufix(const char_t *str, const char_t *sufix); -int str_scmp(const String *str1, const String *str2); +_core_api int str_scmp(const String *str1, const String *str2); -int str_cmp(const String *str1, const char_t *str2); +_core_api int str_cmp(const String *str1, const char_t *str2); -int str_cmp_c(const char_t *str1, const char_t *str2); +_core_api int str_cmp_c(const char_t *str1, const char_t *str2); -int str_cmp_cn(const char_t *str1, const char_t *str2, const uint32_t n); +_core_api int str_cmp_cn(const char_t *str1, const char_t *str2, const uint32_t n); -bool_t str_empty(const String *str); +_core_api bool_t str_empty(const String *str); -bool_t str_empty_c(const char_t *str); +_core_api bool_t str_empty_c(const char_t *str); -bool_t str_equ(const String *str1, const char_t *str2); +_core_api bool_t str_equ(const String *str1, const char_t *str2); -bool_t str_equ_c(const char_t *str1, const char_t *str2); +_core_api bool_t str_equ_c(const char_t *str1, const char_t *str2); -bool_t str_equ_cn(const char_t *str1, const char_t *str2, const uint32_t n); +_core_api bool_t str_equ_cn(const char_t *str1, const char_t *str2, const uint32_t n); -bool_t str_equ_nocase(const char_t *str1, const char_t *str2); +_core_api bool_t str_equ_nocase(const char_t *str1, const char_t *str2); -bool_t str_equ_end(const char_t *str, const char_t *end); +_core_api bool_t str_equ_end(const char_t *str, const char_t *end); -void str_upper(String *str); +_core_api void str_upper(String *str); -void str_lower(String *str); +_core_api void str_lower(String *str); -void str_upper_c(char_t *dest, const uint32_t size, const char_t *str); +_core_api void str_upper_c(char_t *dest, const uint32_t size, const char_t *str); -void str_lower_c(char_t *dest, const uint32_t size, const char_t *str); +_core_api void str_lower_c(char_t *dest, const uint32_t size, const char_t *str); -void str_subs(String *str, const char_t replace, const char_t with); +_core_api void str_subs(String *str, const char_t replace, const char_t with); -void str_repl_c(char_t *str, const char_t *replace, const char_t *with); +_core_api void str_repl_c(char_t *str, const char_t *replace, const char_t *with); -const char_t *str_str(const char_t *str, const char_t *substr); +_core_api const char_t *str_str(const char_t *str, const char_t *substr); -bool_t str_split(const char_t *str, const char_t *substr, String **left, String **right); +_core_api bool_t str_split(const char_t *str, const char_t *substr, String **left, String **right); -bool_t str_split_trim(const char_t *str, const char_t *substr, String **left, String **right); +_core_api bool_t str_split_trim(const char_t *str, const char_t *substr, String **left, String **right); -void str_split_pathname(const char_t *pathname, String **path, String **file); +_core_api void str_split_pathname(const char_t *pathname, String **path, String **file); -void str_split_pathext(const char_t *pathname, String **path, String **file, String **ext); +_core_api void str_split_pathext(const char_t *pathname, String **path, String **file, String **ext); -const char_t *str_filename(const char_t *pathname); +_core_api const char_t *str_filename(const char_t *pathname); -const char_t *str_filext(const char_t *pathname); +_core_api const char_t *str_filext(const char_t *pathname); -uint32_t str_find(const ArrPt(String) *array, const char_t *str); +_core_api uint32_t str_find(const ArrPt(String) *array, const char_t *str); -int8_t str_to_i8(const char_t *str, const uint32_t base, bool_t *error); +_core_api int8_t str_to_i8(const char_t *str, const uint32_t base, bool_t *error); -int16_t str_to_i16(const char_t *str, const uint32_t base, bool_t *error); +_core_api int16_t str_to_i16(const char_t *str, const uint32_t base, bool_t *error); -int32_t str_to_i32(const char_t *str, const uint32_t base, bool_t *error); +_core_api int32_t str_to_i32(const char_t *str, const uint32_t base, bool_t *error); -int64_t str_to_i64(const char_t *str, const uint32_t base, bool_t *error); +_core_api int64_t str_to_i64(const char_t *str, const uint32_t base, bool_t *error); -uint8_t str_to_u8(const char_t *str, const uint32_t base, bool_t *error); +_core_api uint8_t str_to_u8(const char_t *str, const uint32_t base, bool_t *error); -uint16_t str_to_u16(const char_t *str, const uint32_t base, bool_t *error); +_core_api uint16_t str_to_u16(const char_t *str, const uint32_t base, bool_t *error); -uint32_t str_to_u32(const char_t *str, const uint32_t base, bool_t *error); +_core_api uint32_t str_to_u32(const char_t *str, const uint32_t base, bool_t *error); -uint64_t str_to_u64(const char_t *str, const uint32_t base, bool_t *error); +_core_api uint64_t str_to_u64(const char_t *str, const uint32_t base, bool_t *error); -real32_t str_to_r32(const char_t *str, bool_t *error); +_core_api real32_t str_to_r32(const char_t *str, bool_t *error); -real64_t str_to_r64(const char_t *str, bool_t *error); +_core_api real64_t str_to_r64(const char_t *str, bool_t *error); __END_C diff --git a/src/core/tfilter.c b/src/core/tfilter.c index 047a30a..54e3f3b 100644 --- a/src/core/tfilter.c +++ b/src/core/tfilter.c @@ -20,7 +20,7 @@ typedef enum _state_t stZERO, stINTEGER, stREAL -} state_t; +} gui_state_t; /*---------------------------------------------------------------------------*/ @@ -29,7 +29,7 @@ void tfilter_number(const char_t *src, char_t *dest, const uint32_t size, const uint32_t csize, i = 0; uint32_t codepoint = unicode_to_u32b(src, ekUTF8, &csize); uint32_t decimals = 0; - state_t state = stSTART; + gui_state_t state = stSTART; bool_t valid = FALSE; while (codepoint != 0) { diff --git a/src/demo/bode/CMakeLists.txt b/src/demo/bode/CMakeLists.txt index 8b74d1d..b4ca125 100644 --- a/src/demo/bode/CMakeLists.txt +++ b/src/demo/bode/CMakeLists.txt @@ -1 +1 @@ -processDesktopApp(Bode "") \ No newline at end of file +processDesktopApp(Bode "osapp" "") diff --git a/src/demo/bode/bdplot.c b/src/demo/bode/bdplot.c index 5318c68..a8dc93d 100644 --- a/src/demo/bode/bdplot.c +++ b/src/demo/bode/bdplot.c @@ -217,20 +217,20 @@ static void i_x_steps(const Graph *graph, const R2Df *rect, const real32_t x_inc num_x_cuts = bmath_floorf(num_x_cuts); if (num_x_cuts == 0.f) num_x_cuts = 1.f; - + *x_increment = (graph->box.max.x - graph->box.min.x) / num_x_cuts; *x_increment = bmath_round_stepf(*x_increment, x_increment_step); if (*x_increment == .0f) *x_increment = x_increment_step; cassert(*x_increment >= x_increment_step); - + *min_x_value = bmath_round_stepf(graph->box.min.x, *x_increment); - + if (*min_x_value < graph->box.min.x) *min_x_value += *x_increment; - + cassert(*min_x_value >= graph->box.min.x); - + num_steps = (graph->box.max.x - *min_x_value) / *x_increment; *num_x_steps = (uint32_t)bmath_floorf(num_steps); } @@ -250,7 +250,7 @@ static void i_y_steps(const Graph *graph, const R2Df *rect, const real32_t y_inc num_y_cuts = bmath_floorf(num_y_cuts); if (num_y_cuts == 0.f) num_y_cuts = 1.f; - + *y_increment = (graph->box.max.y - graph->box.min.y) / num_y_cuts; *y_increment = bmath_round_stepf(*y_increment, y_increment_step); if (*y_increment == .0f) @@ -258,12 +258,12 @@ static void i_y_steps(const Graph *graph, const R2Df *rect, const real32_t y_inc cassert(*y_increment >= y_increment_step); *min_y_value = bmath_round_stepf(graph->box.min.y, *y_increment); - + if (*min_y_value < graph->box.min.y) *min_y_value += *y_increment; - + cassert(*min_y_value >= graph->box.min.y); - + num_steps = (graph->box.max.y - *min_y_value) / *y_increment; *num_y_steps = (uint32_t)bmath_floorf(num_steps); } @@ -296,14 +296,14 @@ static bool_t i_xy_from_canvas(const Graph *graph, const R2Df *rect, const real3 break; } } - - // p->x == v2d[0].x + + /* p->x == v2d[0].x */ if (index == 0) { p->y = graph->points[0].y; return TRUE; } - // v2d[index-1].x < p->x < v2d[index].x + /* v2d[index-1].x < p->x < v2d[index].x */ else if (index < graph->n - 1) { register real32_t x0 = graph->points[index-1].x; @@ -313,7 +313,7 @@ static bool_t i_xy_from_canvas(const Graph *graph, const R2Df *rect, const real3 p->y = y0 + (p->x - x0) * ((y1 - y0) / (x1 - x0)); return TRUE; } - // p->x is out of graph limits + /* p->x is out of graph limits */ else { return FALSE; @@ -334,11 +334,11 @@ static bool_t i_xy_to_canvas(const Graph *graph, const R2Df *rect, const V2Df *p norm.x = (p->x - graph->box.min.x) / (graph->box.max.x - graph->box.min.x); if (norm.x < 0.f || norm.x > 1.f) return FALSE; - + norm.y = (p->y - graph->box.min.y) / (graph->box.max.y - graph->box.min.y); if (norm.y < 0.f || norm.y > 1.f) return FALSE; - + canvas_p->x = rect->pos.x + norm.x * rect->size.width; canvas_p->y = rect->pos.y + norm.y * rect->size.height; return TRUE; @@ -356,7 +356,7 @@ static bool_t i_x_to_canvas(const Graph *graph, const R2Df *rect, const real32_t norm = (x - graph->box.min.x) / (graph->box.max.x - graph->box.min.x); if (norm < 0.f || norm > 1.f) return FALSE; - + *canvas_x = rect->pos.x + norm * rect->size.width; return TRUE; } @@ -373,7 +373,7 @@ static bool_t i_y_to_canvas(const Graph *graph, const R2Df *rect, const real32_t norm = (y - graph->box.min.y) / (graph->box.max.y - graph->box.min.y); if (norm < 0.f || norm > 1.f) return FALSE; - + *canvas_y = rect->pos.y + norm * rect->size.height; return TRUE; } @@ -424,7 +424,7 @@ static bool_t i_eval_inverse(const Graph *graph, const real32_t y, real32_t *x) return TRUE; } } - + return FALSE; } @@ -510,7 +510,7 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ draw_line_color(ctx, plot->colaxis2); draw_line_dash(ctx, pattern, 2); - + graph_x = min_db_grid_x_value; p0.y = iframe.pos.y; p1.y = iframe.pos.y + iframe.size.height - 10.f; @@ -527,17 +527,17 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_x += x_db_grid_increment; } - + if (db_canvas_point.x != REAL32_MAX) { p0.x = p1.x = db_canvas_point.x; p1.y = iframe.pos.y + iframe.size.height; draw_line(ctx, p0.x, p0.y, p1.x, p1.y); } - + graph_y = min_db_grid_y_value; p0.x = iframe.pos.x + 10.f; p1.x = iframe.pos.x + iframe.size.width; @@ -554,10 +554,10 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_y += y_db_grid_increment; } - + draw_line_dash(ctx, NULL, 0); } @@ -603,7 +603,7 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ draw_line_color(ctx, plot->colgrap22); draw_line(ctx, p0.x, p0.y, p1.x, p1.y); - // Vertical -180Āŗ cutting edge + /* Vertical -180Āŗ cutting edge */ if (i_eval_inverse(&plot->graph.phase, -180.f, &x_180) == TRUE) { real32_t canvas_x = 0; @@ -641,7 +641,7 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ draw_text_align(ctx, align, ekBOTTOM); draw_text(ctx, text, db_canvas_point.x, height - db_canvas_point.y); } - + if (phase_canvas_point.x != REAL32_MAX) { char_t text[16]; @@ -656,14 +656,13 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ /* Axes */ { - //Font font; real32_t graph_x, graph_y; V2Df p0, p1; register uint32_t i; - + draw_line_color(ctx, plot->colaxis1); draw_text_color(ctx, plot->colaxis1); - + { V2Df pa0, pa1, pa2, pa3; pa0.x = iframe.pos.x; @@ -678,7 +677,7 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ draw_line(ctx, pa0.x, pa0.y, pa2.x, pa2.y); draw_line(ctx, pa1.x, pa1.y, pa3.x, pa3.y); } - + if (db_canvas_point.x != REAL32_MAX) { char_t text[16]; @@ -688,7 +687,7 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ bstd_sprintf(text, sizeof(text), "%.3f", db_point.x); draw_text_align(ctx, align, ekTOP); } - + graph_x = min_db_grid_x_value; p0.y = height - iframe.pos.y; p1.y = height - (iframe.pos.y + 10.f); @@ -710,15 +709,15 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_x += x_db_grid_increment; } - + graph_y = min_db_grid_y_value; p0.x = iframe.pos.x; p1.x = iframe.pos.x + 10.f; draw_text_align(ctx, ekRIGHT, ekCENTER); - + for (i = 0; i <= num_db_grid_y_steps; ++i) { real32_t canvas_y = 0.f; @@ -737,15 +736,15 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_y += y_db_grid_increment; } - + graph_y = min_phase_grid_y_value; p0.x = iframe.pos.x + iframe.size.width; p1.x = p0.x - 10.f; draw_text_align(ctx, ekLEFT, ekCENTER); - + for (i = 0; i <= num_phase_grid_y_steps; ++i) { real32_t canvas_y = 0.f; @@ -762,12 +761,11 @@ void plot_draw_graph1(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_y += y_phase_grid_increment; } } - //if (width > 230.f) { V2Df text_pos; text_pos.x = LMARGIN; @@ -817,10 +815,10 @@ void plot_draw_graph2(Plot *plot, DCtx *ctx, const real32_t width, const real32_ V2Df p0, p1; real32_t pattern[2] = {2.f, 2.f}; register uint32_t i; - + draw_line_color(ctx, plot->colaxis2); draw_line_dash(ctx, pattern, 2); - + graph_x = min_simu_grid_x_value; p0.y = iframe.pos.y; p1.y = iframe.pos.y + iframe.size.height - 10.f; @@ -837,17 +835,17 @@ void plot_draw_graph2(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_x += x_simu_grid_increment; } - + if (simu_canvas_point.x != REAL32_MAX) { p0.x = p1.x = simu_canvas_point.x; p1.y = iframe.pos.y + iframe.size.height; draw_line(ctx, p0.x, p0.y, p1.x, p1.y); } - + graph_y = min_simu_grid_y_value; p0.x = iframe.pos.x + 10.f; p1.x = iframe.pos.x + iframe.size.width; @@ -864,10 +862,10 @@ void plot_draw_graph2(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_y += y_simu_grid_increment; } - + draw_line_dash(ctx, NULL, 0); } @@ -899,10 +897,10 @@ void plot_draw_graph2(Plot *plot, DCtx *ctx, const real32_t width, const real32_ real32_t graph_x, graph_y; V2Df p0, p1; register uint32_t i; - + draw_line_color(ctx, plot->colaxis1); draw_text_color(ctx, plot->colaxis1); - + { V2Df pa0, pa1, pa2, pa3; pa0.x = iframe.pos.x; @@ -932,7 +930,7 @@ void plot_draw_graph2(Plot *plot, DCtx *ctx, const real32_t width, const real32_ draw_line(ctx, pa0.x, pa0.y, pa2.x, pa2.y); draw_line(ctx, pa1.x, pa1.y, pa3.x, pa3.y); } - + if (simu_canvas_point.x != REAL32_MAX) { char_t text[16]; @@ -965,7 +963,7 @@ void plot_draw_graph2(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_x += x_simu_grid_increment; } @@ -973,7 +971,7 @@ void plot_draw_graph2(Plot *plot, DCtx *ctx, const real32_t width, const real32_ p0.x = iframe.pos.x; p1.x = iframe.pos.x + 10.f; draw_text_align(ctx, ekRIGHT, ekCENTER); - + for (i = 0; i <= num_simu_grid_y_steps; ++i) { real32_t canvas_y = 0.f; @@ -992,7 +990,7 @@ void plot_draw_graph2(Plot *plot, DCtx *ctx, const real32_t width, const real32_ { cassert(FALSE); } - + graph_y += y_simu_grid_increment; } } diff --git a/src/demo/bode/bdview.c b/src/demo/bode/bdview.c index 462b14c..85ef152 100644 --- a/src/demo/bode/bdview.c +++ b/src/demo/bode/bdview.c @@ -163,7 +163,7 @@ static void i_slider_K(Layout *layout, const char_t *title, const uint32_t row) label_text(label, title); edit_align(edit, ekRIGHT); layout_label(layout, label, 0, row); - layout_slider(layout, slider, 1, row); + layout_slider(layout, slider, 1, row); layout_edit(layout, edit, 2, row); } @@ -201,7 +201,7 @@ static Layout* i_right(Ctrl *ctrl) View* view2 = view_create(); layout_view(layout, view1, 0, 0); layout_view(layout, view2, 0, 1); - layout_layout(layout, layout1, 0, 2); + layout_layout(layout, layout1, 0, 2); layout_vmargin(layout, 0, 2); layout_vmargin(layout, 1, 5); layout_vexpand2(layout, 0, 1, .5f); @@ -219,7 +219,7 @@ static Panel *i_panel(Ctrl *ctrl) Layout *layout1 = i_left(ctrl); Layout* layout2 = i_right(ctrl); layout_layout(layout, layout1, 0, 0); - layout_layout(layout, layout2, 1, 0); + layout_layout(layout, layout2, 1, 0); layout_hmargin(layout, 0, 5); layout_hexpand(layout, 1); layout_margin(layout, 10); @@ -238,7 +238,7 @@ static Panel *i_panel(Ctrl *ctrl) Window* bdview_create(Ctrl *ctrl) { Panel *panel = i_panel(ctrl); - Window *window = window_create(ekWNSRES); + Window *window = window_create(ekWINDOW_STDRES); window_panel(window, panel); window_title(window, "Bode plot"); return window; diff --git a/src/demo/bode/res/banner.bmp b/src/demo/bode/res/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/src/demo/bode/res/banner.bmp and /dev/null differ diff --git a/src/demo/bode/res/license.txt b/src/demo/bode/res/license.txt deleted file mode 100644 index 0aba933..0000000 --- a/src/demo/bode/res/license.txt +++ /dev/null @@ -1,5 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode diff --git a/src/demo/bode/res/pack.txt b/src/demo/bode/res/pack.txt deleted file mode 100644 index 48d0a29..0000000 --- a/src/demo/bode/res/pack.txt +++ /dev/null @@ -1,3 +0,0 @@ -VENDOR=NAppGUI -VERSION=1.0 -DESC=Bode plot diagram diff --git a/src/demo/bricks/CMakeLists.txt b/src/demo/bricks/CMakeLists.txt index 7be82cf..6bd19c6 100644 --- a/src/demo/bricks/CMakeLists.txt +++ b/src/demo/bricks/CMakeLists.txt @@ -1 +1 @@ -processDesktopApp(Bricks "") \ No newline at end of file +processDesktopApp(Bricks "osapp" "") diff --git a/src/demo/bricks/bricks.c b/src/demo/bricks/bricks.c index d9250e1..2011006 100644 --- a/src/demo/bricks/bricks.c +++ b/src/demo/bricks/bricks.c @@ -53,7 +53,7 @@ static const uint32_t i_NUM_ROWS = 4; /*---------------------------------------------------------------------------*/ static void i_OnDraw(App *app, Event *e) -{ +{ const EvDraw *params = event_params(e, EvDraw); uint32_t i = 0; @@ -72,7 +72,7 @@ static void i_OnDraw(App *app, Event *e) draw_rect(params->ctx, ekFILLSK, x, y, width, height); } } - + { real32_t x = (app->player_pos - app->brick_width) * params->width; real32_t y = (1 - i_BRICK_HEIGHT - i_BRICK_SEPARATION) * params->height; @@ -119,11 +119,11 @@ static void i_OnStart(App *app, Event *e) Label *label = label_create(); Button *button = button_push(); view_size(view, s2df(258, 344)); - view_OnDraw(view, listener(app, i_OnDraw, App)); + view_OnDraw(view, listener(app, i_OnDraw, App)); slider_OnMoved(slider, listener(app, i_OnSlider, App)); label_text(label, "Use the slider!"); button_text(button, "Start"); - button_OnClick(button, listener(app, i_OnStart, App)); + button_OnClick(button, listener(app, i_OnStart, App)); layout_view(layout, view, 0, 0); layout_slider(layout, slider, 0, 1); layout_label(layout, label, 0, 2); @@ -146,7 +146,7 @@ static void i_init_game(App *app) real32_t hoffset; Brick *brick = NULL; uint32_t j, i; - + app->color[0] = color_rgb(255, 0, 0); app->color[1] = color_rgb(0, 255, 0); app->color[2] = color_rgb(0, 0, 255); @@ -161,7 +161,7 @@ static void i_init_game(App *app) for (j = 0; j < i_NUM_ROWS; ++j) { real32_t woffset = i_BRICK_SEPARATION; - + for (i = 0; i < i_BRICKS_PER_ROW; ++i) { brick->x = woffset; @@ -171,10 +171,10 @@ static void i_init_game(App *app) woffset += app->brick_width + i_BRICK_SEPARATION; brick++; } - + hoffset += i_BRICK_HEIGHT + i_BRICK_SEPARATION; } - + app->player_pos = slider_get_value(app->slider); app->ball_x = .5f; app->ball_y = .5f; @@ -199,7 +199,7 @@ static App *i_create(void) { App *app = heap_new0(App); Panel *panel = i_panel(app); - app->window = window_create(ekWNSRES); + app->window = window_create(ekWINDOW_STDRES); window_panel(app->window, panel); window_origin(app->window, v2df(200, 200)); window_title(app->window, "Bricks - A 2D Game"); @@ -241,22 +241,22 @@ static void i_update(App *app, const real64_t prtime, const real64_t ctime) real32_t step = (real32_t)(ctime - prtime); bool_t collide; uint32_t i; - - // Update ball position + + /* Update ball position */ app->ball_x += step * app->ball_speed * app->ball_dir.x; app->ball_y += step * app->ball_speed * app->ball_dir.y; - - // Collision with limits + + /* Collision with limits */ if (app->ball_x + i_BALL_RADIUS >= 1.f && app->ball_dir.x >= 0.f) app->ball_dir.x = - app->ball_dir.x; - + if (app->ball_x - i_BALL_RADIUS <= 0.f && app->ball_dir.x <= 0.f) app->ball_dir.x = - app->ball_dir.x; if (app->ball_y - i_BALL_RADIUS <= 0.f && app->ball_dir.y <= 0.f) app->ball_dir.y = - app->ball_dir.y; - - // Collision with bricks + + /* Collision with bricks */ collide = FALSE; for (i = 0; i < NUM_BRICKS; ++i) { @@ -277,7 +277,7 @@ static void i_update(App *app, const real64_t prtime, const real64_t ctime) } } - // Collision with player + /* Collision with player */ { Brick player; player.x = app->player_pos - app->brick_width; @@ -290,7 +290,7 @@ static void i_update(App *app, const real64_t prtime, const real64_t ctime) } } - // Game Over + /* Game Over */ if (app->ball_y + i_BALL_RADIUS >= 1.f) { i_init_game(app); diff --git a/src/demo/bricks/res/banner.bmp b/src/demo/bricks/res/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/src/demo/bricks/res/banner.bmp and /dev/null differ diff --git a/src/demo/bricks/res/license.txt b/src/demo/bricks/res/license.txt deleted file mode 100644 index 0aba933..0000000 --- a/src/demo/bricks/res/license.txt +++ /dev/null @@ -1,5 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode diff --git a/src/demo/bricks/res/pack.txt b/src/demo/bricks/res/pack.txt deleted file mode 100644 index ae4d04a..0000000 --- a/src/demo/bricks/res/pack.txt +++ /dev/null @@ -1,3 +0,0 @@ -VENDOR=NAppGUI -VERSION=1.0 -DESC=Write here the application description diff --git a/src/demo/casino/CMakeLists.txt b/src/demo/casino/CMakeLists.txt index d54ef66..e3f8ee9 100644 --- a/src/demo/casino/CMakeLists.txt +++ b/src/demo/casino/CMakeLists.txt @@ -1 +1,2 @@ -processStaticLib(casino "draw2d") \ No newline at end of file +processStaticLib(casino "draw2d" "") +processDynamicLib(casino_d "draw2d" "") diff --git a/src/demo/casino/casino.def b/src/demo/casino/casino.def new file mode 100644 index 0000000..31d92ba --- /dev/null +++ b/src/demo/casino/casino.def @@ -0,0 +1,21 @@ +/* casino library import/export */ + +#if defined(CASINO_IMPORT) + #if defined(__GNUC__) + #define _casino_api + #elif defined(_MSC_VER) + #define _casino_api __declspec(dllimport) + #else + #error Unknown compiler + #endif +#elif defined(NAPPGUI_SHARED_LIB) + #if defined(__GNUC__) + #define _casino_api __attribute__((visibility("default"))) + #elif defined(_MSC_VER) + #define _casino_api __declspec(dllexport) + #else + #error Unknown compiler + #endif +#else + #define _casino_api +#endif diff --git a/src/demo/casino/casino.h b/src/demo/casino/casino.h index 70b5cd9..b5afba5 100644 --- a/src/demo/casino/casino.h +++ b/src/demo/casino/casino.h @@ -14,8 +14,8 @@ __EXTERN_C -void casino_start(void); +_casino_api void casino_start(void); -void casino_finish(void); +_casino_api void casino_finish(void); __END_C diff --git a/src/demo/casino/casino.hxx b/src/demo/casino/casino.hxx index 02f53d4..025b2a1 100644 --- a/src/demo/casino/casino.hxx +++ b/src/demo/casino/casino.hxx @@ -14,6 +14,7 @@ #define __CASINO_HXX__ #include "draw2d.hxx" +#include "casino.def" /* TODO: Define data types here */ diff --git a/src/demo/casino/ddraw.c b/src/demo/casino/ddraw.c index f1dba0d..ee27047 100644 --- a/src/demo/casino/ddraw.c +++ b/src/demo/casino/ddraw.c @@ -16,6 +16,9 @@ /*---------------------------------------------------------------------------*/ static const real32_t i_MAX_PADDING = 0.2f; +const real32_t kDEF_PADDING = .15f; +const real32_t kDEF_CORNER = .15f; +const real32_t kDEF_RADIUS = .35f; /*---------------------------------------------------------------------------*/ @@ -27,7 +30,7 @@ void die_draw(DCtx *ctx, const real32_t x, const real32_t y, const real32_t widt real32_t rc, rr; real32_t p1, p2, p3; - dsize = width < height ? width : height; + dsize = width < height ? width : height; dsize -= bmath_floorf(2.f * dsize * padding * i_MAX_PADDING); dx = x + .5f * (width - dsize); dy = y + .5f * (height - dsize); diff --git a/src/demo/casino/ddraw.h b/src/demo/casino/ddraw.h index d26db44..176c70b 100644 --- a/src/demo/casino/ddraw.h +++ b/src/demo/casino/ddraw.h @@ -12,13 +12,19 @@ #include "casino.hxx" -void die_draw( - DCtx *ctx, - const real32_t x, - const real32_t y, - const real32_t width, - const real32_t height, - const real32_t padding, - const real32_t corner, - const real32_t radius, - const uint32_t face); +_casino_api void die_draw( + DCtx *ctx, + const real32_t x, + const real32_t y, + const real32_t width, + const real32_t height, + const real32_t padding, + const real32_t corner, + const real32_t radius, + const uint32_t face); + +_casino_api extern const real32_t kDEF_PADDING; + +_casino_api extern const real32_t kDEF_CORNER; + +_casino_api extern const real32_t kDEF_RADIUS; diff --git a/src/demo/dice/CMakeLists.txt b/src/demo/dice/CMakeLists.txt index 7565984..3ba3f44 100644 --- a/src/demo/dice/CMakeLists.txt +++ b/src/demo/dice/CMakeLists.txt @@ -1 +1 @@ -processDesktopApp(Dice "demo/casino") \ No newline at end of file +processDesktopApp(Dice "osapp;casino" "") diff --git a/src/demo/dice/main.c b/src/demo/dice/main.c index 09d405c..3b1a0c9 100644 --- a/src/demo/dice/main.c +++ b/src/demo/dice/main.c @@ -8,7 +8,7 @@ * */ -/* NAppGUI Hello World */ +/* Dice application */ #include "nappgui.h" #include "ddraw.h" @@ -30,9 +30,9 @@ static void i_OnRedraw(App *app, Event *e) color_t green = color_rgb(102, 153, 26); real32_t w = params->width / 3; real32_t h = params->height / 2; - real32_t p = .15f; - real32_t c = .15f; - real32_t r = .35f; + real32_t p = kDEF_PADDING; + real32_t c = kDEF_CORNER; + real32_t r = kDEF_RADIUS; draw_clear(params->ctx, green); die_draw(params->ctx, 0.f, 0.f, w, h, p, c, r, app->face[0]); die_draw(params->ctx, w, 0.f, w, h, p, c, r, app->face[1]); @@ -95,8 +95,8 @@ static void i_OnClose(App *app, Event *e) static App *i_create(void) { App *app = heap_new0(App); - Panel *panel = i_panel(app); - app->window = window_create(ekWNSTD); + Panel *panel = i_panel(app); + app->window = window_create(ekWINDOW_STD); window_panel(app->window, panel); window_title(app->window, "Dice"); window_origin(app->window, v2df(500.f, 200.f)); diff --git a/src/demo/dice/res/banner.bmp b/src/demo/dice/res/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/src/demo/dice/res/banner.bmp and /dev/null differ diff --git a/src/demo/dice/res/license.txt b/src/demo/dice/res/license.txt deleted file mode 100644 index 0aba933..0000000 --- a/src/demo/dice/res/license.txt +++ /dev/null @@ -1,5 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode diff --git a/src/demo/dice/res/pack.txt b/src/demo/dice/res/pack.txt deleted file mode 100644 index ae4d04a..0000000 --- a/src/demo/dice/res/pack.txt +++ /dev/null @@ -1,3 +0,0 @@ -VENDOR=NAppGUI -VERSION=1.0 -DESC=Write here the application description diff --git a/src/demo/die/CMakeLists.txt b/src/demo/die/CMakeLists.txt index 7f051dc..b974be5 100644 --- a/src/demo/die/CMakeLists.txt +++ b/src/demo/die/CMakeLists.txt @@ -1 +1,2 @@ -processDesktopApp(Die "demo/casino") \ No newline at end of file +processDesktopApp(Die "osapp;casino" "") +processDesktopApp(Die2 "osapp;casino_d" "") diff --git a/src/demo/die/dgui.c b/src/demo/die/dgui.c index 9dca2ce..b6150bd 100644 --- a/src/demo/die/dgui.c +++ b/src/demo/die/dgui.c @@ -13,7 +13,7 @@ #include "dgui.h" #include "ddraw.h" #include "guiall.h" -#include "all.h" +#include "res_die.h" /*---------------------------------------------------------------------------*/ @@ -151,12 +151,12 @@ static void i_OnLang(App *app, Event *e) Window *dgui_window(App *app) { - gui_respack(all_respack); + gui_respack(res_die_respack); gui_language(""); { Panel *panel = i_panel(app); - Window *window = window_create(ekWNSRES); + Window *window = window_create(ekWINDOW_STDRES); window_panel(window, panel); window_title(window, TEXT_TITLE); return window; diff --git a/src/demo/die/res/banner.bmp b/src/demo/die/res/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/src/demo/die/res/banner.bmp and /dev/null differ diff --git a/src/demo/die/res/license.txt b/src/demo/die/res/license.txt deleted file mode 100644 index 0aba933..0000000 --- a/src/demo/die/res/license.txt +++ /dev/null @@ -1,5 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode diff --git a/src/demo/die/res/pack.txt b/src/demo/die/res/pack.txt deleted file mode 100644 index f536138..0000000 --- a/src/demo/die/res/pack.txt +++ /dev/null @@ -1,4 +0,0 @@ -VENDOR=NAppGUI -VERSION=1.0 -DESC=Die Face Drawing. - diff --git a/src/demo/die/res/all/cards.png b/src/demo/die/res/res_die/cards.png similarity index 100% rename from src/demo/die/res/all/cards.png rename to src/demo/die/res/res_die/cards.png diff --git a/src/demo/die/res/all/es_es/strings.msg b/src/demo/die/res/res_die/es_es/strings.msg similarity index 100% rename from src/demo/die/res/all/es_es/strings.msg rename to src/demo/die/res/res_die/es_es/strings.msg diff --git a/src/demo/die/res/all/spain.png b/src/demo/die/res/res_die/spain.png similarity index 100% rename from src/demo/die/res/all/spain.png rename to src/demo/die/res/res_die/spain.png diff --git a/src/demo/die/res/all/strings.msg b/src/demo/die/res/res_die/strings.msg similarity index 100% rename from src/demo/die/res/all/strings.msg rename to src/demo/die/res/res_die/strings.msg diff --git a/src/demo/die/res/all/usa.png b/src/demo/die/res/res_die/usa.png similarity index 100% rename from src/demo/die/res/all/usa.png rename to src/demo/die/res/res_die/usa.png diff --git a/src/demo/fractals/CMakeLists.txt b/src/demo/fractals/CMakeLists.txt index 9782f64..1312ed9 100644 --- a/src/demo/fractals/CMakeLists.txt +++ b/src/demo/fractals/CMakeLists.txt @@ -1 +1 @@ -processDesktopApp(Fractals "") \ No newline at end of file +processDesktopApp(Fractals "osapp" "") diff --git a/src/demo/fractals/fractals.c b/src/demo/fractals/fractals.c index 466858f..aeaaa17 100644 --- a/src/demo/fractals/fractals.c +++ b/src/demo/fractals/fractals.c @@ -48,7 +48,7 @@ static const uint32_t i_HEIGHT = 601; static uint32_t i_inset(real64_t zreal, real64_t zimag, real64_t creal, real64_t cimag) { uint32_t i; - for(i = 0; i < i_ITERATIONS; ++i) + for(i = 0; i < i_ITERATIONS; ++i) { real64_t ztmp, zdist; ztmp = zreal * zreal - zimag * zimag; @@ -57,7 +57,7 @@ static uint32_t i_inset(real64_t zreal, real64_t zimag, real64_t creal, real64_t zreal = zreal + creal; zimag = zimag + cimag; zdist = zimag * zimag + zreal * zreal; - if (zdist > 3) + if (zdist > 3) return i; } @@ -260,7 +260,7 @@ static Panel *i_panel(App *app) slider_OnMoved(slider, listener(app, i_OnSlider, App)); button_text(button1, "Vert"); button_text(button2, "Hotz"); - button_state(button1, ekON); + button_state(button1, ekGUI_ON); button_OnClick(button1, listener(app, i_OnVertical, App)); imageview_size(view, s2di(i_WIDTH, i_HEIGHT)); layout_slider(layout1, slider, 0, 0); @@ -303,7 +303,7 @@ static App *i_create(void) { App *app = heap_new0(App); Panel *panel = i_panel(app); - app->window = window_create(ekWNSTD); + app->window = window_create(ekWINDOW_STD); app->clock = clock_create(0); i_image(app); window_panel(app->window, panel); diff --git a/src/demo/fractals/res/banner.bmp b/src/demo/fractals/res/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/src/demo/fractals/res/banner.bmp and /dev/null differ diff --git a/src/demo/fractals/res/license.txt b/src/demo/fractals/res/license.txt deleted file mode 100644 index 0aba933..0000000 --- a/src/demo/fractals/res/license.txt +++ /dev/null @@ -1,5 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode diff --git a/src/demo/fractals/res/pack.txt b/src/demo/fractals/res/pack.txt deleted file mode 100644 index ae4d04a..0000000 --- a/src/demo/fractals/res/pack.txt +++ /dev/null @@ -1,3 +0,0 @@ -VENDOR=NAppGUI -VERSION=1.0 -DESC=Write here the application description diff --git a/src/demo/hello/CMakeLists.txt b/src/demo/hello/CMakeLists.txt index 2f68efc..05d0595 100644 --- a/src/demo/hello/CMakeLists.txt +++ b/src/demo/hello/CMakeLists.txt @@ -1 +1 @@ -processDesktopApp(HelloWorld "") \ No newline at end of file +processDesktopApp(HelloWorld "osapp" "") diff --git a/src/demo/hello/main.c b/src/demo/hello/main.c index a9fcc1e..b89b5f3 100644 --- a/src/demo/hello/main.c +++ b/src/demo/hello/main.c @@ -72,7 +72,7 @@ static App *i_create(void) { App *app = heap_new0(App); Panel *panel = i_panel(app); - app->window = window_create(ekWNSTD); + app->window = window_create(ekWINDOW_STD); window_panel(app->window, panel); window_title(app->window, "Hello, World!"); window_origin(app->window, v2df(500, 200)); diff --git a/src/demo/hello/res/banner.bmp b/src/demo/hello/res/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/src/demo/hello/res/banner.bmp and /dev/null differ diff --git a/src/demo/hello/res/license.txt b/src/demo/hello/res/license.txt deleted file mode 100644 index 0aba933..0000000 --- a/src/demo/hello/res/license.txt +++ /dev/null @@ -1,5 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode diff --git a/src/demo/hello/res/pack.txt b/src/demo/hello/res/pack.txt deleted file mode 100644 index 623f8bc..0000000 --- a/src/demo/hello/res/pack.txt +++ /dev/null @@ -1,4 +0,0 @@ -VENDOR=NAppGUI -VERSION=1.0 -DESC=HelloWorld program for NAppGUI SDK. - diff --git a/src/demo/hellocpp/CMakeLists.txt b/src/demo/hellocpp/CMakeLists.txt index 9b63839..fd4112a 100644 --- a/src/demo/hellocpp/CMakeLists.txt +++ b/src/demo/hellocpp/CMakeLists.txt @@ -1 +1 @@ -processDesktopApp(HelloCpp "") \ No newline at end of file +processDesktopApp(HelloCpp "osapp" "") diff --git a/src/demo/hellocpp/main.cpp b/src/demo/hellocpp/main.cpp index 0aefe55..242e151 100644 --- a/src/demo/hellocpp/main.cpp +++ b/src/demo/hellocpp/main.cpp @@ -9,7 +9,7 @@ */ /* NAppGUI C++ Hello World */ - + #include "nappgui.h" class App; @@ -96,7 +96,7 @@ void App::i_OnClose(Event *e) MainWindow::MainWindow(App *app) { Panel *panel = i_panel(); - this->window = window_create(ekWNSTD); + this->window = window_create(ekWINDOW_STD); this->clicks = 0; window_panel(this->window, panel); window_title(this->window, "Hello, C++!"); diff --git a/src/demo/hellocpp/res/banner.bmp b/src/demo/hellocpp/res/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/src/demo/hellocpp/res/banner.bmp and /dev/null differ diff --git a/src/demo/hellocpp/res/license.txt b/src/demo/hellocpp/res/license.txt deleted file mode 100644 index 0aba933..0000000 --- a/src/demo/hellocpp/res/license.txt +++ /dev/null @@ -1,5 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode diff --git a/src/demo/hellocpp/res/pack.txt b/src/demo/hellocpp/res/pack.txt deleted file mode 100644 index 623f8bc..0000000 --- a/src/demo/hellocpp/res/pack.txt +++ /dev/null @@ -1,4 +0,0 @@ -VENDOR=NAppGUI -VERSION=1.0 -DESC=HelloWorld program for NAppGUI SDK. - diff --git a/src/demo/products/CMakeLists.txt b/src/demo/products/CMakeLists.txt index 87399cf..b64447e 100644 --- a/src/demo/products/CMakeLists.txt +++ b/src/demo/products/CMakeLists.txt @@ -1 +1,2 @@ -processDesktopApp(Products "inet") \ No newline at end of file +processDesktopApp(Products "osapp;inet" "") +processDesktopApp(Products_d "osapp_d;inet_d" "") diff --git a/src/demo/products/prctrl.c b/src/demo/products/prctrl.c index 8a7fc2d..33d5011 100644 --- a/src/demo/products/prctrl.c +++ b/src/demo/products/prctrl.c @@ -15,7 +15,7 @@ #include "nappgui.h" #include "httpreq.h" #include "json.h" -#include "res_gui.h" +#include "res_products.h" typedef enum _status_t { @@ -61,10 +61,10 @@ struct _ctrl_t Cell *minus_cell; Cell *filter_cell; Cell *slider_cell; - Cell *counter_cell; + Cell *counter_cell; Cell *code_cell; Cell *desc_cell; - Cell *price_cell; + Cell *price_cell; Cell *lang_cell; Cell *setting_cell; Cell *user_cell; @@ -147,7 +147,7 @@ static void i_update_product(Ctrl *ctrl) product = model_product(ctrl->model, ctrl->selected); bstd_sprintf(msg, 64, "[%d/%d]", ctrl->selected + 1, total); label_text(counter, msg); - slider_value(slider, (real32_t)ctrl->selected / (real32_t)(total > 1 ? total - 1 : 1)); + slider_value(slider, (real32_t)ctrl->selected / (real32_t)(total > 1 ? total - 1 : 1)); enabled = TRUE; for (i = 0; i < n; ++i) ctrl->stats[i] = bmath_randf(2.f, i_MAX_STATS - 2.f); @@ -230,16 +230,16 @@ void ctrl_run(Ctrl *ctrl) ctrl->status = ekWAIT_LOGIN; setting_button = cell_button(ctrl->setting_cell); layout_show_col(ctrl->main_layout, 1, TRUE); - button_state(setting_button, ekON); - menuitem_state(ctrl->setting_item, ekON); + button_state(setting_button, ekGUI_ON); + menuitem_state(ctrl->setting_item, ekGUI_ON); lang_popup = cell_popup(ctrl->lang_cell); lang_index = popup_get_selected(lang_popup); lang_item = menu_get_item(ctrl->lang_menu, lang_index); - menuitem_state(lang_item, ekON); + menuitem_state(lang_item, ekGUI_ON); menuitem_enabled(ctrl->login_item, TRUE); menuitem_enabled(ctrl->logout_item, FALSE); menuitem_enabled(ctrl->import_item, FALSE); - menuitem_enabled(ctrl->export_item, FALSE); + menuitem_enabled(ctrl->export_item, FALSE); i_status(ctrl); cell_focus(ctrl->user_cell); i_update_product(ctrl); @@ -739,7 +739,7 @@ static void i_OnLogin(Ctrl *ctrl, Event *e) i_status(ctrl); osapp_task(ctrl, 0, i_login_begin, NULL, i_login_end, Ctrl); } - + unref(e); } @@ -804,8 +804,8 @@ void ctrl_logout_item(Ctrl *ctrl, MenuItem *item) static void i_OnSetting(Ctrl *ctrl, Event *e) { - state_t state = ekON; - if (event_type(e) == ekEVBUTTON) + gui_state_t state = ekGUI_ON; + if (event_type(e) == ekGUI_EVENT_BUTTON) { const EvButton *params = event_params(e, EvButton); state = params->state; @@ -813,14 +813,14 @@ static void i_OnSetting(Ctrl *ctrl, Event *e) else { Button *button = cell_button(ctrl->setting_cell); - cassert(event_type(e) == ekEVMENU); + cassert(event_type(e) == ekGUI_EVENT_MENU); state = button_get_state(button); - state = state == ekON ? ekOFF : ekON; + state = state == ekGUI_ON ? ekGUI_OFF : ekGUI_ON; button_state(button, state); } menuitem_state(ctrl->setting_item, state); - layout_show_col(ctrl->main_layout, 1, state == ekON ? TRUE : FALSE); + layout_show_col(ctrl->main_layout, 1, state == ekGUI_ON ? TRUE : FALSE); layout_update(ctrl->main_layout); } @@ -897,7 +897,7 @@ static void i_OnLang(Ctrl *ctrl, Event *e) MenuItem *item = NULL; uint32_t lang_id = 0; static const char_t *LANGS[] = { "en_US", "es_ES", "pt_PT", "it_IT", "vi_VN", "ru_RU", "ja_JP" }; - if (event_type(e) == ekEVPOPUP) + if (event_type(e) == ekGUI_EVENT_POPUP) { const EvButton *params = event_params(e, EvButton); item = menu_get_item(ctrl->lang_menu, params->index); @@ -907,14 +907,14 @@ static void i_OnLang(Ctrl *ctrl, Event *e) { const EvMenu *params = event_params(e, EvMenu); PopUp *popup = cell_popup(ctrl->lang_cell); - cassert(event_type(e) == ekEVMENU); + cassert(event_type(e) == ekGUI_EVENT_MENU); popup_selected(popup, params->index); item = event_sender(e, MenuItem); lang_id = params->index; } menu_off_items(ctrl->lang_menu); - menuitem_state(item, ekON); + menuitem_state(item, ekGUI_ON); gui_language(LANGS[lang_id]); } @@ -931,13 +931,13 @@ void ctrl_lang_cell(Ctrl *ctrl, Cell *cell) void ctrl_lang_menu(Ctrl *ctrl, Menu *menu) { - uint32_t i, n = menu_size(menu); + uint32_t i, n = menu_size(menu); for (i = 0; i < n; ++i) { MenuItem *item = menu_get_item(menu, i); menuitem_OnClick(item, listener(ctrl, i_OnLang, Ctrl)); } - ctrl->lang_menu = menu; + ctrl->lang_menu = menu; } /*---------------------------------------------------------------------------*/ diff --git a/src/demo/products/prmenu.c b/src/demo/products/prmenu.c index 2a3e5ed..e8021d0 100644 --- a/src/demo/products/prmenu.c +++ b/src/demo/products/prmenu.c @@ -13,7 +13,7 @@ #include "prmenu.h" #include "prctrl.h" #include "guiall.h" -#include "res_gui.h" +#include "res_products.h" /*---------------------------------------------------------------------------*/ diff --git a/src/demo/products/prmodel.c b/src/demo/products/prmodel.c index 4f75ff1..7c6012f 100644 --- a/src/demo/products/prmodel.c +++ b/src/demo/products/prmodel.c @@ -14,7 +14,7 @@ #include "guiall.h" #include "httpreq.h" #include "json.h" -#include "res_gui.h" +#include "res_products.h" typedef struct _pjson_t PJson; diff --git a/src/demo/products/products.c b/src/demo/products/products.c index e55b5ac..a706200 100644 --- a/src/demo/products/products.c +++ b/src/demo/products/products.c @@ -16,7 +16,7 @@ #include "prctrl.h" #include "prview.h" #include "inet.h" -#include "res_gui.h" +#include "res_products.h" typedef struct _app_t App; struct _app_t @@ -52,7 +52,7 @@ static App *i_create(void) kSTATSK = gui_alt_color(color_bgr(0xFF8034), color_bgr(0xFF8034)); kTXTRED = gui_alt_color(color_bgr(0xFF0000), color_bgr(0xEB665A)); inet_start(); - gui_respack(res_gui_respack); + gui_respack(res_products_respack); gui_language(""); gui_OnThemeChanged(listener(app, i_OnThemeChanged, App)); model_bind(); diff --git a/src/demo/products/prview.c b/src/demo/products/prview.c index 5d38812..2fd6d0b 100644 --- a/src/demo/products/prview.c +++ b/src/demo/products/prview.c @@ -13,7 +13,7 @@ #include "prview.h" #include "prctrl.h" #include "guiall.h" -#include "res_gui.h" +#include "res_products.h" /*---------------------------------------------------------------------------*/ @@ -198,7 +198,7 @@ static Layout *i_form(Ctrl *ctrl) layout_vexpand(layout, 2); cell = layout_cell(layout, 0, 1); cell_padding4(cell, 0, 10, 0, 10); - ctrl_slider_cell(ctrl, cell); + ctrl_slider_cell(ctrl, cell); return layout; } @@ -227,7 +227,7 @@ static Layout *i_login(Ctrl *ctrl) popup_add_elem(popup0, VIETNAMESE, (const Image*)VIETNAM_PNG); popup_add_elem(popup0, RUSSIAN, (const Image*)RUSSIA_PNG); popup_add_elem(popup0, JAPANESE, (const Image*)JAPAN_PNG); - popup_tooltip(popup0, TWIN_SETLANG); + popup_tooltip(popup0, TWIN_SETLANG); imageview_image(view0, (const Image*)USER_PNG); edit_passmode(edit1, TRUE); button_text(button, TWIN_LOGIN); @@ -346,7 +346,7 @@ Window *prview_create(Ctrl *ctrl) Window *window = NULL; ctrl_theme_images(ctrl); panel_layout(panel, layout); - window = window_create(ekWNSTD); + window = window_create(ekWINDOW_STD); window_panel(window, panel); window_title(window, TWIN_TITLE); ctrl_window(ctrl, window); diff --git a/src/demo/products/res/banner.bmp b/src/demo/products/res/banner.bmp deleted file mode 100644 index e4b602f..0000000 Binary files a/src/demo/products/res/banner.bmp and /dev/null differ diff --git a/src/demo/products/res/license.txt b/src/demo/products/res/license.txt deleted file mode 100644 index 0aba933..0000000 --- a/src/demo/products/res/license.txt +++ /dev/null @@ -1,5 +0,0 @@ -Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode diff --git a/src/demo/products/res/pack.txt b/src/demo/products/res/pack.txt deleted file mode 100644 index f85a344..0000000 --- a/src/demo/products/res/pack.txt +++ /dev/null @@ -1,4 +0,0 @@ -VENDOR=NAppGUI -VERSION=1.0 -DESC=JSON based client application. - diff --git a/src/demo/products/res/res_gui/about.png b/src/demo/products/res/res_products/about.png similarity index 100% rename from src/demo/products/res/res_gui/about.png rename to src/demo/products/res/res_products/about.png diff --git a/src/demo/products/res/res_gui/add.png b/src/demo/products/res/res_products/add.png similarity index 100% rename from src/demo/products/res/res_gui/add.png rename to src/demo/products/res/res_products/add.png diff --git a/src/demo/products/res/res_gui/back.png b/src/demo/products/res/res_products/back.png similarity index 100% rename from src/demo/products/res/res_gui/back.png rename to src/demo/products/res/res_products/back.png diff --git a/src/demo/products/res/res_gui/back16.png b/src/demo/products/res/res_products/back16.png similarity index 100% rename from src/demo/products/res/res_gui/back16.png rename to src/demo/products/res/res_products/back16.png diff --git a/src/demo/products/res/res_gui/back16d.png b/src/demo/products/res/res_products/back16d.png similarity index 100% rename from src/demo/products/res/res_gui/back16d.png rename to src/demo/products/res/res_products/back16d.png diff --git a/src/demo/products/res/res_gui/backd.png b/src/demo/products/res/res_products/backd.png similarity index 100% rename from src/demo/products/res/res_gui/backd.png rename to src/demo/products/res/res_products/backd.png diff --git a/src/demo/products/res/res_gui/edit.png b/src/demo/products/res/res_products/edit.png similarity index 100% rename from src/demo/products/res/res_gui/edit.png rename to src/demo/products/res/res_products/edit.png diff --git a/src/demo/products/res/res_gui/error.png b/src/demo/products/res/res_products/error.png similarity index 100% rename from src/demo/products/res/res_gui/error.png rename to src/demo/products/res/res_products/error.png diff --git a/src/demo/products/res/res_gui/es_ES/strings.msg b/src/demo/products/res/res_products/es_ES/strings.msg similarity index 100% rename from src/demo/products/res/res_gui/es_ES/strings.msg rename to src/demo/products/res/res_products/es_ES/strings.msg diff --git a/src/demo/products/res/res_gui/exit.png b/src/demo/products/res/res_products/exit.png similarity index 100% rename from src/demo/products/res/res_gui/exit.png rename to src/demo/products/res/res_products/exit.png diff --git a/src/demo/products/res/res_gui/first.png b/src/demo/products/res/res_products/first.png similarity index 100% rename from src/demo/products/res/res_gui/first.png rename to src/demo/products/res/res_products/first.png diff --git a/src/demo/products/res/res_gui/first16.png b/src/demo/products/res/res_products/first16.png similarity index 100% rename from src/demo/products/res/res_gui/first16.png rename to src/demo/products/res/res_products/first16.png diff --git a/src/demo/products/res/res_gui/first16d.png b/src/demo/products/res/res_products/first16d.png similarity index 100% rename from src/demo/products/res/res_gui/first16d.png rename to src/demo/products/res/res_products/first16d.png diff --git a/src/demo/products/res/res_gui/firstd.png b/src/demo/products/res/res_products/firstd.png similarity index 100% rename from src/demo/products/res/res_gui/firstd.png rename to src/demo/products/res/res_products/firstd.png diff --git a/src/demo/products/res/res_gui/it_IT/strings.msg b/src/demo/products/res/res_products/it_IT/strings.msg similarity index 100% rename from src/demo/products/res/res_gui/it_IT/strings.msg rename to src/demo/products/res/res_products/it_IT/strings.msg diff --git a/src/demo/products/res/res_gui/italy.png b/src/demo/products/res/res_products/italy.png similarity index 100% rename from src/demo/products/res/res_gui/italy.png rename to src/demo/products/res/res_products/italy.png diff --git a/src/demo/products/res/res_gui/ja_JP/strings.msg b/src/demo/products/res/res_products/ja_JP/strings.msg similarity index 100% rename from src/demo/products/res/res_gui/ja_JP/strings.msg rename to src/demo/products/res/res_products/ja_JP/strings.msg diff --git a/src/demo/products/res/res_gui/japan.png b/src/demo/products/res/res_products/japan.png similarity index 100% rename from src/demo/products/res/res_gui/japan.png rename to src/demo/products/res/res_products/japan.png diff --git a/src/demo/products/res/res_gui/last.png b/src/demo/products/res/res_products/last.png similarity index 100% rename from src/demo/products/res/res_gui/last.png rename to src/demo/products/res/res_products/last.png diff --git a/src/demo/products/res/res_gui/last16.png b/src/demo/products/res/res_products/last16.png similarity index 100% rename from src/demo/products/res/res_gui/last16.png rename to src/demo/products/res/res_products/last16.png diff --git a/src/demo/products/res/res_gui/last16d.png b/src/demo/products/res/res_products/last16d.png similarity index 100% rename from src/demo/products/res/res_gui/last16d.png rename to src/demo/products/res/res_products/last16d.png diff --git a/src/demo/products/res/res_gui/lastd.png b/src/demo/products/res/res_products/lastd.png similarity index 100% rename from src/demo/products/res/res_gui/lastd.png rename to src/demo/products/res/res_products/lastd.png diff --git a/src/demo/products/res/res_gui/login16.png b/src/demo/products/res/res_products/login16.png similarity index 100% rename from src/demo/products/res/res_gui/login16.png rename to src/demo/products/res/res_products/login16.png diff --git a/src/demo/products/res/res_gui/logout16.png b/src/demo/products/res/res_products/logout16.png similarity index 100% rename from src/demo/products/res/res_gui/logout16.png rename to src/demo/products/res/res_products/logout16.png diff --git a/src/demo/products/res/res_gui/logout16d.png b/src/demo/products/res/res_products/logout16d.png similarity index 100% rename from src/demo/products/res/res_gui/logout16d.png rename to src/demo/products/res/res_products/logout16d.png diff --git a/src/demo/products/res/res_gui/minus.png b/src/demo/products/res/res_products/minus.png similarity index 100% rename from src/demo/products/res/res_gui/minus.png rename to src/demo/products/res/res_products/minus.png diff --git a/src/demo/products/res/res_gui/next.png b/src/demo/products/res/res_products/next.png similarity index 100% rename from src/demo/products/res/res_gui/next.png rename to src/demo/products/res/res_products/next.png diff --git a/src/demo/products/res/res_gui/next16.png b/src/demo/products/res/res_products/next16.png similarity index 100% rename from src/demo/products/res/res_gui/next16.png rename to src/demo/products/res/res_products/next16.png diff --git a/src/demo/products/res/res_gui/next16d.png b/src/demo/products/res/res_products/next16d.png similarity index 100% rename from src/demo/products/res/res_gui/next16d.png rename to src/demo/products/res/res_products/next16d.png diff --git a/src/demo/products/res/res_gui/nextd.png b/src/demo/products/res/res_products/nextd.png similarity index 100% rename from src/demo/products/res/res_gui/nextd.png rename to src/demo/products/res/res_products/nextd.png diff --git a/src/demo/products/res/res_gui/noimage.png b/src/demo/products/res/res_products/noimage.png similarity index 100% rename from src/demo/products/res/res_gui/noimage.png rename to src/demo/products/res/res_products/noimage.png diff --git a/src/demo/products/res/res_gui/ok.png b/src/demo/products/res/res_products/ok.png similarity index 100% rename from src/demo/products/res/res_gui/ok.png rename to src/demo/products/res/res_products/ok.png diff --git a/src/demo/products/res/res_gui/open.png b/src/demo/products/res/res_products/open.png similarity index 100% rename from src/demo/products/res/res_gui/open.png rename to src/demo/products/res/res_products/open.png diff --git a/src/demo/products/res/res_gui/portugal.png b/src/demo/products/res/res_products/portugal.png similarity index 100% rename from src/demo/products/res/res_gui/portugal.png rename to src/demo/products/res/res_products/portugal.png diff --git a/src/demo/products/res/res_gui/pt_PT/strings.msg b/src/demo/products/res/res_products/pt_PT/strings.msg similarity index 100% rename from src/demo/products/res/res_gui/pt_PT/strings.msg rename to src/demo/products/res/res_products/pt_PT/strings.msg diff --git a/src/demo/products/res/res_gui/ru_RU/strings.msg b/src/demo/products/res/res_products/ru_RU/strings.msg similarity index 100% rename from src/demo/products/res/res_gui/ru_RU/strings.msg rename to src/demo/products/res/res_products/ru_RU/strings.msg diff --git a/src/demo/products/res/res_gui/russia.png b/src/demo/products/res/res_products/russia.png similarity index 100% rename from src/demo/products/res/res_gui/russia.png rename to src/demo/products/res/res_products/russia.png diff --git a/src/demo/products/res/res_gui/save.png b/src/demo/products/res/res_products/save.png similarity index 100% rename from src/demo/products/res/res_gui/save.png rename to src/demo/products/res/res_products/save.png diff --git a/src/demo/products/res/res_gui/saved.png b/src/demo/products/res/res_products/saved.png similarity index 100% rename from src/demo/products/res/res_gui/saved.png rename to src/demo/products/res/res_products/saved.png diff --git a/src/demo/products/res/res_gui/settings.png b/src/demo/products/res/res_products/settings.png similarity index 100% rename from src/demo/products/res/res_gui/settings.png rename to src/demo/products/res/res_products/settings.png diff --git a/src/demo/products/res/res_gui/settings16.png b/src/demo/products/res/res_products/settings16.png similarity index 100% rename from src/demo/products/res/res_gui/settings16.png rename to src/demo/products/res/res_products/settings16.png diff --git a/src/demo/products/res/res_gui/spain.png b/src/demo/products/res/res_products/spain.png similarity index 100% rename from src/demo/products/res/res_gui/spain.png rename to src/demo/products/res/res_products/spain.png diff --git a/src/demo/products/res/res_gui/spin.gif b/src/demo/products/res/res_products/spin.gif similarity index 100% rename from src/demo/products/res/res_gui/spin.gif rename to src/demo/products/res/res_products/spin.gif diff --git a/src/demo/products/res/res_gui/strings.msg b/src/demo/products/res/res_products/strings.msg similarity index 100% rename from src/demo/products/res/res_gui/strings.msg rename to src/demo/products/res/res_products/strings.msg diff --git a/src/demo/products/res/res_gui/usa.png b/src/demo/products/res/res_products/usa.png similarity index 100% rename from src/demo/products/res/res_gui/usa.png rename to src/demo/products/res/res_products/usa.png diff --git a/src/demo/products/res/res_gui/user.png b/src/demo/products/res/res_products/user.png similarity index 100% rename from src/demo/products/res/res_gui/user.png rename to src/demo/products/res/res_products/user.png diff --git a/src/demo/products/res/res_gui/vi_VN/strings.msg b/src/demo/products/res/res_products/vi_VN/strings.msg similarity index 100% rename from src/demo/products/res/res_gui/vi_VN/strings.msg rename to src/demo/products/res/res_products/vi_VN/strings.msg diff --git a/src/demo/products/res/res_gui/vietnam.png b/src/demo/products/res/res_products/vietnam.png similarity index 100% rename from src/demo/products/res/res_gui/vietnam.png rename to src/demo/products/res/res_products/vietnam.png diff --git a/src/draw2d/CMakeLists.txt b/src/draw2d/CMakeLists.txt index 6735243..03129cb 100644 --- a/src/draw2d/CMakeLists.txt +++ b/src/draw2d/CMakeLists.txt @@ -1 +1,2 @@ -processStaticLib(draw2d "geom2d") \ No newline at end of file +processStaticLib(draw2d "geom2d" "") +processDynamicLib(draw2d_d "geom2d_d" "") diff --git a/src/draw2d/btext.c b/src/draw2d/btext.c deleted file mode 100644 index 88bd110..0000000 --- a/src/draw2d/btext.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - * NAppGUI Cross-platform C SDK - * 2015-2022 Francisco Garcia Collado - * MIT Licence - * https://nappgui.com/en/legal/license.html - * - * File: btext.c - * - */ - -/* Text formatted blocks */ - -#include "btexth.inl" -#include "btext.inl" -#include "dctx.h" -#include "arrst.h" -#include "cassert.h" -#include "color.h" -#include "font.h" -#include "heap.h" -#include "strings.h" - -typedef struct _attr_t Attr; -typedef struct _text_t Text; -typedef struct _line_t Line; - -struct _attr_t -{ - String *font_family; - real32_t font_relsize; - real32_t font_size; - uint32_t font_style; - color_t line_color; - color_t fill_color; - align_t halign; - uint32_t track_id; - drawop_t op; -}; - -struct _text_t -{ - Attr attr; - String *text; -}; - -struct _line_t -{ - real32_t width; -}; - -struct _btext_t -{ - bool_t metrics; - Attr attr; - uint32_t track_id; - ArrSt(Attr) *stack; - ArrSt(Text) *texts; -}; - -DeclSt(Attr); -DeclSt(Text); - -/*---------------------------------------------------------------------------*/ - -BText *btext_create(void) -{ - BText *block = heap_new0(BText); - block->attr.halign = ekLEFT; - block->attr.op = ekFILL; - block->track_id = UINT32_MAX; - block->stack = arrst_create(Attr); - block->texts = arrst_create(Text); - return block; -} - -/*---------------------------------------------------------------------------*/ - -static void i_remove_attr(Attr *attr) -{ - str_destopt(&attr->font_family); -} - -/*---------------------------------------------------------------------------*/ - -static void i_remove_text(Text *text) -{ - i_remove_attr(&text->attr); - str_destroy(&text->text); -} - -/*---------------------------------------------------------------------------*/ - -void btext_destroy(BText **block) -{ - cassert_no_null(block); - cassert_no_null(*block); - arrst_destroy(&(*block)->stack, i_remove_attr, Attr); - arrst_destroy(&(*block)->texts, i_remove_text, Text); - heap_delete(block, BText); -} - -/*---------------------------------------------------------------------------*/ - -static __INLINE void i_push( - ArrSt(Attr) *stack, - const char_t *ffamily, - const real32_t frelsize, - const real32_t fsize, - const uint32_t fstyle, - const color_t line_color, - const color_t fill_color, - const align_t halign, - const drawop_t op, - const uint32_t track_id) -{ - Attr *attr = arrst_new(stack, Attr); - attr->font_family = ffamily ? str_c(ffamily) : NULL; - attr->font_relsize = frelsize; - attr->font_size = fsize; - attr->font_style = fstyle; - attr->line_color = line_color; - attr->fill_color = fill_color; - attr->halign = halign; - attr->op = op; - attr->track_id = track_id; -} - -/*---------------------------------------------------------------------------*/ - -void btext_push_font_family(BText *block, const char_t *family) -{ - cassert_no_null(block); - cassert_no_null(family); - i_push(block->stack, family, 0, 0, 0, 0, 0, ENUM_MAX(align_t), ENUM_MAX(drawop_t), UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -void btext_push_font_relsize(BText *block, const real32_t rsize) -{ - cassert_no_null(block); - i_push(block->stack, NULL, rsize, 0, 0, 0, 0, ENUM_MAX(align_t), ENUM_MAX(drawop_t), UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -void btext_push_font_size(BText *block, const real32_t size) -{ - cassert_no_null(block); - i_push(block->stack, NULL, 0, size, 0, 0, 0, ENUM_MAX(align_t), ENUM_MAX(drawop_t), UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -void btext_push_font_style(BText *block, const uint32_t style) -{ - cassert_no_null(block); - i_push(block->stack, NULL, 0, 0, style, 0, 0, ENUM_MAX(align_t), ENUM_MAX(drawop_t), UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -void btext_push_line_color(BText *block, const color_t color) -{ - cassert_no_null(block); - i_push(block->stack, NULL, 0, 0, 0, color, 0, ENUM_MAX(align_t), ENUM_MAX(drawop_t), UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -void btext_push_fill_color(BText *block, const color_t color) -{ - cassert_no_null(block); - i_push(block->stack, NULL, 0, 0, 0, 0, color, ENUM_MAX(align_t), ENUM_MAX(drawop_t), UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -void btext_push_halign(BText *block, const align_t align) -{ - cassert_no_null(block); - i_push(block->stack, NULL, 0, 0, 0, 0, 0, align, ENUM_MAX(drawop_t), UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -void btext_push_drawop(BText *block, const drawop_t op) -{ - cassert_no_null(block); - i_push(block->stack, NULL, 0, 0, 0, 0, 0, ENUM_MAX(align_t), op, UINT32_MAX); -} - -/*---------------------------------------------------------------------------*/ - -uint32_t btext_push_track(BText *block) -{ - cassert_no_null(block); - block->track_id += 1; - i_push(block->stack, NULL, 0, 0, 0, 0, 0, ENUM_MAX(align_t), ENUM_MAX(drawop_t), block->track_id); - return block->track_id; -} - -/*---------------------------------------------------------------------------*/ - -void btext_pop(BText *block) -{ - cassert_no_null(block); - arrst_pop(block->stack, i_remove_attr, Attr); -} - -/*---------------------------------------------------------------------------*/ - -static void i_copy_attr(Attr *dest, const Attr *src) -{ - cassert_no_null(dest); - cassert_no_null(src); - *dest = *src; - if (src->font_family != NULL) - dest->font_family = str_copy(src->font_family); -} - -/*---------------------------------------------------------------------------*/ - -void btext_text(BText *block, const char_t *text) -{ - Text *ttext; - cassert_no_null(block); - ttext = arrst_new(block->texts, Text); - i_copy_attr(&ttext->attr, &block->attr); - ttext->text = str_c(text); -} - -/*---------------------------------------------------------------------------*/ - -void btext_update(BText *block, const real32_t max_width, const real32_t max_height, const Font *font) -{ - unref(block); - unref(max_width); - unref(max_height); - unref(font); -} - -/*---------------------------------------------------------------------------*/ - -void btext_bounds(const BText *block, real32_t *width, real32_t *height) -{ - unref(block); - unref(width); - unref(height); -} - -/*---------------------------------------------------------------------------*/ - -void btext_draw(DCtx *ctx, const BText *block, const real32_t x, const real32_t y, const align_t halign, const align_t valign) -{ - unref(ctx); - unref(block); - unref(x); - unref(y); - unref(halign); - unref(valign); -} - -/*---------------------------------------------------------------------------*/ - -void btext_draw_raster(DCtx *ctx, const BText *block, const real32_t x, const real32_t y, const align_t halign, const align_t valign) -{ - unref(ctx); - unref(block); - unref(x); - unref(y); - unref(halign); - unref(valign); -} - -/*---------------------------------------------------------------------------*/ - -uint32_t btext_track(const BText *block, const real32_t x, const real32_t y) -{ - unref(block); - unref(x); - unref(y); - return UINT32_MAX; -} - -/*---------------------------------------------------------------------------*/ - -void btext_track_line_color(BText *block, const uint32_t track_id, const color_t color) -{ - unref(block); - unref(track_id); - unref(color); -} - -/*---------------------------------------------------------------------------*/ - -void btext_track_fill_color(BText *block, const uint32_t track_id, const color_t color) -{ - unref(block); - unref(track_id); - unref(color); -} - -/*---------------------------------------------------------------------------*/ - -void btext_track_underline(BText *block, const uint32_t track_id, bool_t underline) -{ - unref(block); - unref(track_id); - unref(underline); -} - diff --git a/src/draw2d/btext.inl b/src/draw2d/btext.inl deleted file mode 100644 index db37e6d..0000000 --- a/src/draw2d/btext.inl +++ /dev/null @@ -1,22 +0,0 @@ -/* - * NAppGUI Cross-platform C SDK - * 2015-2022 Francisco Garcia Collado - * MIT Licence - * https://nappgui.com/en/legal/license.html - * - * File: btext.inl - * - */ - -/* Attributed strings */ - -#include "draw2d.ixx" - -__EXTERN_C - -//void astr_slices_bounds(AString *astr, DCtx *ctx); -// -//void astr_bounds(const AString *astr, const real32_t refwidth, real32_t *width, real32_t *height); - -__END_C - diff --git a/src/draw2d/btexth.inl b/src/draw2d/btexth.inl deleted file mode 100644 index 875691b..0000000 --- a/src/draw2d/btexth.inl +++ /dev/null @@ -1,60 +0,0 @@ -/* - * NAppGUI Cross-platform C SDK - * 2015-2022 Francisco Garcia Collado - * MIT Licence - * https://nappgui.com/en/legal/license.html - * - * File: btexth.inl - * - */ - -/* Text formatted blocks */ - -#include "draw2d.ixx" - -__EXTERN_C - -BText *btext_create(void); - -void btext_destroy(BText **block); - -void btext_push_font_family(BText *block, const char_t *family); - -void btext_push_font_relsize(BText *block, const real32_t rsize); - -void btext_push_font_size(BText *block, const real32_t size); - -void btext_push_font_style(BText *block, const uint32_t style); - -void btext_push_line_color(BText *block, const color_t color); - -void btext_push_fill_color(BText *block, const color_t color); - -void btext_push_halign(BText *block, const align_t align); - -void btext_push_drawop(BText *block, const drawop_t op); - -uint32_t btext_push_track(BText *block); - -void btext_pop(BText *block); - -void btext_text(BText *block, const char_t *text); - -void btext_update(BText *block, const real32_t max_width, const real32_t max_height, const Font *font); - -void btext_bounds(const BText *block, real32_t *width, real32_t *height); - -void btext_draw(DCtx *ctx, const BText *block, const real32_t x, const real32_t y, const align_t halign, const align_t valign); - -void btext_draw_raster(DCtx *ctx, const BText *block, const real32_t x, const real32_t y, const align_t halign, const align_t valign); - -uint32_t btext_track(const BText *block, const real32_t x, const real32_t y); - -void btext_track_line_color(BText *block, const uint32_t track_id, const color_t color); - -void btext_track_fill_color(BText *block, const uint32_t track_id, const color_t color); - -void btext_track_underline(BText *block, const uint32_t track_id, bool_t underline); - -__END_C - diff --git a/src/draw2d/color.c b/src/draw2d/color.c index a8a50c6..6e06092 100644 --- a/src/draw2d/color.c +++ b/src/draw2d/color.c @@ -174,9 +174,14 @@ color_t color_html(const char_t *html) static __INLINE color_t i_effective(color_t c) { if (i_alpha(c) == 0) - return draw2d_get_named_color(c); + { + cassert(c <= 0xFFFF); + return draw2d_get_indexed_color((uint16_t)c); + } else + { return c; + } } /*---------------------------------------------------------------------------*/ @@ -194,7 +199,7 @@ void color_to_hsbf(const color_t color, real32_t *hue, real32_t *sat, real32_t * cassert_no_null(sat); cassert_no_null(bright); - // Very improbable + /* Very improbable */ if (i_alpha(color) == 0) { register color_t c = i_effective(color); @@ -223,7 +228,7 @@ void color_to_hsbf(const color_t color, real32_t *hue, real32_t *sat, real32_t * else { real32_t deltaR, deltaG, deltaB; - + cassert(max > 0); *sat = delta / max; @@ -235,10 +240,10 @@ void color_to_hsbf(const color_t color, real32_t *hue, real32_t *sat, real32_t * *hue = deltaB - deltaG; else if (bmath_absf(g - max) < i_TOL) *hue = 0.3333333f + deltaR - deltaB; - else if (bmath_absf(b - max) < i_TOL) + else if (bmath_absf(b - max) < i_TOL) *hue = 0.6666667f + deltaG - deltaR; - if (*hue < 0) + if (*hue < 0) *hue += 1.f; else if (*hue > 1.0f) *hue -= 1.f; diff --git a/src/draw2d/color.h b/src/draw2d/color.h index d83c175..525d10e 100644 --- a/src/draw2d/color.h +++ b/src/draw2d/color.h @@ -15,60 +15,62 @@ __EXTERN_C -color_t color_rgb(const uint8_t r, const uint8_t g, const uint8_t b); +_draw2d_api color_t color_rgb(const uint8_t r, const uint8_t g, const uint8_t b); -color_t color_rgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a); +_draw2d_api color_t color_rgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a); -color_t color_rgbaf(const real32_t r, const real32_t g, const real32_t b, const real32_t a); +_draw2d_api color_t color_rgbaf(const real32_t r, const real32_t g, const real32_t b, const real32_t a); -color_t color_hsbf(const real32_t hue, const real32_t sat, const real32_t bright); +_draw2d_api color_t color_hsbf(const real32_t hue, const real32_t sat, const real32_t bright); -color_t color_red(const uint8_t r); +_draw2d_api color_t color_red(const uint8_t r); -color_t color_green(const uint8_t g); +_draw2d_api color_t color_green(const uint8_t g); -color_t color_blue(const uint8_t b); +_draw2d_api color_t color_blue(const uint8_t b); -color_t color_gray(const uint8_t l); +_draw2d_api color_t color_gray(const uint8_t l); -color_t color_bgr(const uint32_t bgr); +_draw2d_api color_t color_bgr(const uint32_t bgr); -color_t color_html(const char_t *html); +_draw2d_api color_t color_html(const char_t *html); -void color_to_hsbf(const color_t color, real32_t *hue, real32_t *sat, real32_t *bright); +_draw2d_api color_t color_indexed(const uint16_t index, const color_t color); -void color_to_html(const color_t color, char_t *html, const uint32_t size); +_draw2d_api void color_to_hsbf(const color_t color, real32_t *hue, real32_t *sat, real32_t *bright); -void color_get_rgb(const color_t color, uint8_t *r, uint8_t *g, uint8_t *b); +_draw2d_api void color_to_html(const color_t color, char_t *html, const uint32_t size); -void color_get_rgbf(const color_t color, real32_t *r, real32_t *g, real32_t *b); +_draw2d_api void color_get_rgb(const color_t color, uint8_t *r, uint8_t *g, uint8_t *b); -void color_get_rgba(const color_t color, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a); +_draw2d_api void color_get_rgbf(const color_t color, real32_t *r, real32_t *g, real32_t *b); -void color_get_rgbaf(const color_t color, real32_t *r, real32_t *g, real32_t *b, real32_t *a); +_draw2d_api void color_get_rgba(const color_t color, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a); -uint8_t color_get_alpha(const color_t color); +_draw2d_api void color_get_rgbaf(const color_t color, real32_t *r, real32_t *g, real32_t *b, real32_t *a); -color_t color_set_alpha(const color_t color, const uint8_t alpha); +_draw2d_api uint8_t color_get_alpha(const color_t color); -extern const color_t kCOLOR_TRANSPARENT; +_draw2d_api color_t color_set_alpha(const color_t color, const uint8_t alpha); -extern const color_t kCOLOR_DEFAULT; +_draw2d_api extern const color_t kCOLOR_TRANSPARENT; -extern const color_t kCOLOR_BLACK; +_draw2d_api extern const color_t kCOLOR_DEFAULT; -extern const color_t kCOLOR_WHITE; +_draw2d_api extern const color_t kCOLOR_BLACK; -extern const color_t kCOLOR_RED; +_draw2d_api extern const color_t kCOLOR_WHITE; -extern const color_t kCOLOR_GREEN; +_draw2d_api extern const color_t kCOLOR_RED; -extern const color_t kCOLOR_BLUE; +_draw2d_api extern const color_t kCOLOR_GREEN; -extern const color_t kCOLOR_YELLOW; +_draw2d_api extern const color_t kCOLOR_BLUE; -extern const color_t kCOLOR_CYAN; +_draw2d_api extern const color_t kCOLOR_YELLOW; -extern const color_t kCOLOR_MAGENTA; +_draw2d_api extern const color_t kCOLOR_CYAN; + +_draw2d_api extern const color_t kCOLOR_MAGENTA; __END_C diff --git a/src/draw2d/dctx.c b/src/draw2d/dctx.c index 55ea096..b9075b0 100644 --- a/src/draw2d/dctx.c +++ b/src/draw2d/dctx.c @@ -11,8 +11,9 @@ /* Draw context */ #include "dctx.h" -#include "draw.h" +#include "dctxh.h" #include "dctx.inl" +#include "draw.h" #include "cassert.h" #include "color.h" #include "font.h" @@ -106,18 +107,4 @@ void draw_matrix_cartesiand(DCtx *ctx, const T2Dd *t2d) dctx_transform(ctx, &ct2d, TRUE); } - /*---------------------------------------------------------------------------*/ - -//void dctx_astr_bounds(DCtx *ctx, const AString *str, const real32_t refwidth, real32_t *width, real32_t *height); -//void dctx_astr_bounds(DCtx *ctx, const AString *str, const real32_t refwidth, real32_t *width, real32_t *height) -//{ -// cassert_no_null(ctx); -// cassert_no_null(str); -// unref(refwidth); -// cassert_no_null(width); -// cassert_no_null(height); -// //astr_slices_bounds((AString*)str, ctx); -// -// //fdfg -//} diff --git a/src/draw2d/dctx.h b/src/draw2d/dctx.h index f9dacc6..74f8bea 100644 --- a/src/draw2d/dctx.h +++ b/src/draw2d/dctx.h @@ -15,21 +15,21 @@ __EXTERN_C -DCtx *dctx_bitmap(const uint32_t width, const uint32_t height, const pixformat_t format); +_draw2d_api DCtx *dctx_bitmap(const uint32_t width, const uint32_t height, const pixformat_t format); -Image *dctx_image(DCtx **ctx); +_draw2d_api Image *dctx_image(DCtx **ctx); -void draw_clear(DCtx *ctx, const color_t color); +_draw2d_api void draw_clear(DCtx *ctx, const color_t color); -void draw_matrixf(DCtx *ctx, const T2Df *t2d); +_draw2d_api void draw_matrixf(DCtx *ctx, const T2Df *t2d); -void draw_matrixd(DCtx *ctx, const T2Dd *t2d); +_draw2d_api void draw_matrixd(DCtx *ctx, const T2Dd *t2d); -void draw_matrix_cartesianf(DCtx *ctx, const T2Df *t2d); +_draw2d_api void draw_matrix_cartesianf(DCtx *ctx, const T2Df *t2d); -void draw_matrix_cartesiand(DCtx *ctx, const T2Dd *t2d); +_draw2d_api void draw_matrix_cartesiand(DCtx *ctx, const T2Dd *t2d); -void draw_antialias(DCtx *ctx, const bool_t on); +_draw2d_api void draw_antialias(DCtx *ctx, const bool_t on); __END_C diff --git a/src/draw2d/dctx.inl b/src/draw2d/dctx.inl index dea84f6..9b5046f 100644 --- a/src/draw2d/dctx.inl +++ b/src/draw2d/dctx.inl @@ -14,22 +14,8 @@ __EXTERN_C -DCtx *dctx_create(void *custom_data); - -void dctx_destroy(DCtx **ctx); - void dctx_init(DCtx *ctx); -void dctx_set_gcontext(DCtx *ctx, void *gcontext, const uint32_t width, const uint32_t height, const real32_t offset_x, const real32_t offset_y, const uint32_t background, const bool_t reset); - -void dctx_unset_gcontext(DCtx *ctx); - -void dctx_size(const DCtx *ctx, uint32_t *width, uint32_t *height); - void dctx_transform(DCtx *ctx, const T2Df *t2d, const bool_t cartesian); __END_C - - - - diff --git a/src/draw2d/dctxh.h b/src/draw2d/dctxh.h new file mode 100644 index 0000000..66ba08c --- /dev/null +++ b/src/draw2d/dctxh.h @@ -0,0 +1,71 @@ +/* + * NAppGUI Cross-platform C SDK + * 2015-2022 Francisco Garcia Collado + * MIT Licence + * https://nappgui.com/en/legal/license.html + * + * File: dctxh.h + * + */ + +/* Undocumented (hidden) API about drawing context */ + +#include "draw2d.hxx" + +__EXTERN_C + +_draw2d_api DCtx *dctx_create(void); + +_draw2d_api void dctx_destroy(DCtx **ctx); + +_draw2d_api void dctx_set_gcontext(DCtx *ctx, void *gcontext, const uint32_t width, const uint32_t height, const real32_t offset_x, const real32_t offset_y, const uint32_t background, const bool_t reset); + +_draw2d_api void dctx_unset_gcontext(DCtx *ctx); + +_draw2d_api void dctx_update_view(DCtx *ctx, void *view); + +_draw2d_api void dctx_set_flipped(DCtx *ctx, const bool_t flipped); + +_draw2d_api void dctx_size(const DCtx *ctx, uint32_t *width, uint32_t *height); + +_draw2d_api void dctx_offset(const DCtx *ctx, real32_t *offset_x, real32_t *offset_y); + +_draw2d_api real32_t dctx_text_width(const DCtx *ctx); + +_draw2d_api align_t dctx_text_intalign(const DCtx *ctx); + +_draw2d_api color_t dctx_text_color(const DCtx *ctx); + +_draw2d_api color_t dctx_background_color(const DCtx *ctx); + +_draw2d_api ellipsis_t dctx_text_trim(const DCtx *ctx); + +_draw2d_api void dctx_set_raster_mode(DCtx *ctx); + +_draw2d_api void *dctx_native(DCtx *ctx); + +_draw2d_api void *dctx_internal_bitmap(DCtx *ctx); + +_draw2d_api void dctx_text_raster(DCtx *ctx, const char_t *text, const real32_t x, const real32_t y); + +_draw2d_api void dctx_image_raster(DCtx *ctx, const Image *image, const real32_t x, const real32_t y); + +_draw2d_api void dctx_set_default_osfont(DCtx *ctx, const void *font); + +_draw2d_api void dctx_data_imp(DCtx *ctx, void *data, FPtr_destroy func_destroy_data); + +_draw2d_api void *dctx_get_data_imp(const DCtx *ctx); + +_draw2d_api void draw_lineimp(DCtx *ctx, const real32_t x0, const real32_t y0, const real32_t x1, const real32_t y1, const bool_t raster); + +__END_C + +#define dctx_data(ctx, data, func_destroy_data, type)\ + (\ + (void)((type*)data == data),\ + FUNC_CHECK_DESTROY(func_destroy_data, type),\ + dctx_data_imp(ctx, (void*)data, (FPtr_destroy)func_destroy_data)\ + ) + +#define dctx_get_data(ctx, type)\ + (type*)dctx_get_data_imp(ctx) diff --git a/src/draw2d/draw.h b/src/draw2d/draw.h index 22f5ae0..43b1156 100644 --- a/src/draw2d/draw.h +++ b/src/draw2d/draw.h @@ -15,66 +15,66 @@ __EXTERN_C -void draw_line(DCtx *ctx, const real32_t x0, const real32_t y0, const real32_t x1, const real32_t y1); +_draw2d_api void draw_line(DCtx *ctx, const real32_t x0, const real32_t y0, const real32_t x1, const real32_t y1); -void draw_polyline(DCtx *ctx, const bool_t closed, const V2Df *points, const uint32_t n); +_draw2d_api void draw_polyline(DCtx *ctx, const bool_t closed, const V2Df *points, const uint32_t n); -void draw_arc(DCtx *ctx, const real32_t x, const real32_t y, const real32_t radius, const real32_t start, const real32_t sweep); +_draw2d_api void draw_arc(DCtx *ctx, const real32_t x, const real32_t y, const real32_t radius, const real32_t start, const real32_t sweep); -void draw_bezier(DCtx *ctx, const real32_t x0, const real32_t y0, const real32_t x1, const real32_t y1, const real32_t x2, const real32_t y2, const real32_t x3, const real32_t y3); +_draw2d_api void draw_bezier(DCtx *ctx, const real32_t x0, const real32_t y0, const real32_t x1, const real32_t y1, const real32_t x2, const real32_t y2, const real32_t x3, const real32_t y3); -void draw_line_color(DCtx *ctx, const color_t color); +_draw2d_api void draw_line_color(DCtx *ctx, const color_t color); -void draw_line_fill(DCtx *ctx); +_draw2d_api void draw_line_fill(DCtx *ctx); -void draw_line_width(DCtx *ctx, const real32_t width); +_draw2d_api void draw_line_width(DCtx *ctx, const real32_t width); -void draw_line_cap(DCtx *ctx, const linecap_t cap); +_draw2d_api void draw_line_cap(DCtx *ctx, const linecap_t cap); -void draw_line_join(DCtx *ctx, const linejoin_t join); +_draw2d_api void draw_line_join(DCtx *ctx, const linejoin_t join); -void draw_line_dash(DCtx *ctx, const real32_t *pattern, const uint32_t n); +_draw2d_api void draw_line_dash(DCtx *ctx, const real32_t *pattern, const uint32_t n); -void draw_rect(DCtx *ctx, const drawop_t op, const real32_t x, const real32_t y, const real32_t width, const real32_t height); +_draw2d_api void draw_rect(DCtx *ctx, const drawop_t op, const real32_t x, const real32_t y, const real32_t width, const real32_t height); -void draw_rndrect(DCtx *ctx, const drawop_t op, const real32_t x, const real32_t y, const real32_t width, const real32_t height, const real32_t radius); +_draw2d_api void draw_rndrect(DCtx *ctx, const drawop_t op, const real32_t x, const real32_t y, const real32_t width, const real32_t height, const real32_t radius); -void draw_circle(DCtx *ctx, const drawop_t op, const real32_t x, const real32_t y, const real32_t radius); +_draw2d_api void draw_circle(DCtx *ctx, const drawop_t op, const real32_t x, const real32_t y, const real32_t radius); -void draw_ellipse(DCtx *ctx, const drawop_t op, const real32_t x, const real32_t y, const real32_t radx, const real32_t rady); +_draw2d_api void draw_ellipse(DCtx *ctx, const drawop_t op, const real32_t x, const real32_t y, const real32_t radx, const real32_t rady); -void draw_polygon(DCtx *ctx, const drawop_t op, const V2Df *points, const uint32_t n); +_draw2d_api void draw_polygon(DCtx *ctx, const drawop_t op, const V2Df *points, const uint32_t n); -void draw_fill_color(DCtx *ctx, const color_t color); +_draw2d_api void draw_fill_color(DCtx *ctx, const color_t color); -void draw_fill_linear(DCtx *ctx, const color_t *color, const real32_t *stop, const uint32_t n, const real32_t x0, const real32_t y0, const real32_t x1, const real32_t y1); +_draw2d_api void draw_fill_linear(DCtx *ctx, const color_t *color, const real32_t *stop, const uint32_t n, const real32_t x0, const real32_t y0, const real32_t x1, const real32_t y1); -void draw_fill_matrix(DCtx *ctx, const T2Df *t2d); +_draw2d_api void draw_fill_matrix(DCtx *ctx, const T2Df *t2d); -void draw_fill_wrap(DCtx *ctx, const fillwrap_t wrap); +_draw2d_api void draw_fill_wrap(DCtx *ctx, const fillwrap_t wrap); -void draw_font(DCtx *ctx, const Font *font); +_draw2d_api void draw_font(DCtx *ctx, const Font *font); -void draw_text_color(DCtx *ctx, const color_t color); +_draw2d_api void draw_text_color(DCtx *ctx, const color_t color); -void draw_text(DCtx *ctx, const char_t *text, const real32_t x, const real32_t y); +_draw2d_api void draw_text(DCtx *ctx, const char_t *text, const real32_t x, const real32_t y); -void draw_text_path(DCtx *ctx, const drawop_t op, const char_t *text, const real32_t x, const real32_t y); +_draw2d_api void draw_text_path(DCtx *ctx, const drawop_t op, const char_t *text, const real32_t x, const real32_t y); -void draw_text_width(DCtx *ctx, const real32_t width); +_draw2d_api void draw_text_width(DCtx *ctx, const real32_t width); -void draw_text_trim(DCtx *ctx, const ellipsis_t ellipsis); +_draw2d_api void draw_text_trim(DCtx *ctx, const ellipsis_t ellipsis); -void draw_text_align(DCtx *ctx, const align_t halign, const align_t valign); +_draw2d_api void draw_text_align(DCtx *ctx, const align_t halign, const align_t valign); -void draw_text_halign(DCtx *ctx, const align_t halign); +_draw2d_api void draw_text_halign(DCtx *ctx, const align_t halign); -void draw_text_extents(DCtx *ctx, const char_t *text, const real32_t refwidth, real32_t *width, real32_t *height); +_draw2d_api void draw_text_extents(DCtx *ctx, const char_t *text, const real32_t refwidth, real32_t *width, real32_t *height); -void draw_image(DCtx *ctx, const Image *image, const real32_t x, const real32_t y); +_draw2d_api void draw_image(DCtx *ctx, const Image *image, const real32_t x, const real32_t y); -void draw_image_frame(DCtx *ctx, const Image *image, const uint32_t frame, const real32_t x, const real32_t y); +_draw2d_api void draw_image_frame(DCtx *ctx, const Image *image, const uint32_t frame, const real32_t x, const real32_t y); -void draw_image_align(DCtx *ctx, const align_t halign, const align_t valign); +_draw2d_api void draw_image_align(DCtx *ctx, const align_t halign, const align_t valign); __END_C diff --git a/src/draw2d/draw.inl b/src/draw2d/draw.inl index 264657f..3a236f7 100644 --- a/src/draw2d/draw.inl +++ b/src/draw2d/draw.inl @@ -14,9 +14,11 @@ __EXTERN_C -void drawimp_alloc_globals(void); +void draw_alloc_globals(void); -void drawimp_dealloc_globals(void); +void draw_dealloc_globals(void); + +void draw_word_extents(MeasureStr *data, const char_t *word, real32_t *width, real32_t *height); void draw_imgimp(DCtx *ctx, const OSImage *image, const uint32_t frame_index, const real32_t x, const real32_t y, const bool_t raster); diff --git a/src/draw2d/draw2d.cpp b/src/draw2d/draw2d.c similarity index 79% rename from src/draw2d/draw2d.cpp rename to src/draw2d/draw2d.c index 2cebf1d..d091415 100644 --- a/src/draw2d/draw2d.cpp +++ b/src/draw2d/draw2d.c @@ -4,7 +4,7 @@ * MIT Licence * https://nappgui.com/en/legal/license.html * - * File: draw2d.cpp + * File: draw2d.c * */ @@ -12,113 +12,116 @@ #include "draw2d.h" #include "draw2d.inl" -#include "dbind.inl" #include "draw.inl" #include "font.inl" #include "image.inl" -#include "respack.inl" #include "image.h" +#include "color.h" #include "arrpt.h" #include "arrst.h" +#include "blib.h" #include "bmem.h" #include "cassert.h" #include "core.h" +#include "dbindh.h" #include "font.h" #include "heap.h" #include "log.h" #include "strings.h" +typedef struct _icolor_t IColor; + +struct _icolor_t +{ + uint16_t index; + color_t color; +}; + +DeclSt(IColor); + #define i_WORD_TYPE_END 0 #define i_WORD_TYPE_NEW_LINE 1 #define i_WORD_TYPE_BLANCKS 2 #define i_WORD_TYPE_TEXT 3 +static uint32_t i_NUM_USERS = 0; +static ArrPt(String) *i_FONT_FAMILIES; +static ArrSt(IColor) *i_INDEXED_COLORS; + /*---------------------------------------------------------------------------*/ -class Draw2D +static void i_draw2d_atexit(void) { -public: - static uint32_t NUM_USERS; - ArrPt(String) *font_families; - ArrSt(color_t) *named_colors; - - ~Draw2D() - { - if (NUM_USERS != 0) - { - log_printf("Error! osdraw is not properly closed (%d)\n", NUM_USERS); - } - } -}; - -static Draw2D i_DRAW2D; -uint32_t Draw2D::NUM_USERS = 0; + if (i_NUM_USERS != 0) + log_printf("Error! draw2d is not properly closed (%d)\n", i_NUM_USERS); +} /*---------------------------------------------------------------------------*/ void draw2d_start(void) { - if (i_DRAW2D.NUM_USERS == 0) + if (i_NUM_USERS == 0) { core_start(); osimage_alloc_globals(); osfont_alloc_globals(); - drawimp_alloc_globals(); + draw_alloc_globals(); + blib_atexit(i_draw2d_atexit); + + i_FONT_FAMILIES = arrpt_create(String); - i_DRAW2D.font_families = arrpt_create(String); - { String *str = str_c("__SYSTEM__"); - arrpt_append(i_DRAW2D.font_families, str, String); + arrpt_append(i_FONT_FAMILIES, str, String); } { String *str = str_c("__MONOSPACE__"); - arrpt_append(i_DRAW2D.font_families, str, String); + arrpt_append(i_FONT_FAMILIES, str, String); } - i_DRAW2D.named_colors = arrst_create(color_t); + i_INDEXED_COLORS = arrst_create(IColor); dbind_opaque(Image, image_from_data, NULL, image_copy, NULL, image_write, image_destroy); } - i_DRAW2D.NUM_USERS += 1; + i_NUM_USERS += 1; } /*---------------------------------------------------------------------------*/ void draw2d_finish(void) { - cassert(i_DRAW2D.NUM_USERS > 0); - i_DRAW2D.NUM_USERS -= 1; - if (i_DRAW2D.NUM_USERS == 0) + cassert(i_NUM_USERS > 0); + if (i_NUM_USERS == 1) { - _dbind_finish(); // Destroy possible images - arrpt_destroy(&i_DRAW2D.font_families, str_destroy, String); - arrst_destroy(&i_DRAW2D.named_colors, NULL, color_t); + /* Destroy all image in dbind, before release OS image support */ + dbind_opaque_destroy("Image"); + arrpt_destroy(&i_FONT_FAMILIES, str_destroy, String); + arrst_destroy(&i_INDEXED_COLORS, NULL, IColor); osfont_dealloc_globals(); osimage_dealloc_globals(); - drawimp_dealloc_globals(); + draw_dealloc_globals(); core_finish(); } + + i_NUM_USERS -= 1; } /*---------------------------------------------------------------------------*/ uint32_t draw2d_register_font(const char_t *font_family) { - arrpt_foreach(family, i_DRAW2D.font_families, String) + arrpt_foreach(family, i_FONT_FAMILIES, String) if (str_cmp(family, font_family) == 0) return family_i; arrpt_end(); if (font_exists_family(font_family) == TRUE) { - uint32_t num_elems = 0; - String *family = NULL; - num_elems = arrpt_size(i_DRAW2D.font_families, String); - family = str_c(font_family); - arrpt_append(i_DRAW2D.font_families, family, String); + uint32_t num_elems = arrpt_size(i_FONT_FAMILIES, String); + String *family = str_c(font_family); + arrpt_append(i_FONT_FAMILIES, family, String); return num_elems; } else @@ -131,43 +134,57 @@ uint32_t draw2d_register_font(const char_t *font_family) const char_t *draw2d_font_family(const uint32_t family) { - const String *font_family = arrpt_get(i_DRAW2D.font_families, family, String); + const String *font_family = arrpt_get(i_FONT_FAMILIES, family, String); return osfont_family(tc(font_family)); } /*---------------------------------------------------------------------------*/ -void draw2d_set_named_color(const uint32_t index, const color_t color) +color_t color_indexed(const uint16_t index, const color_t color) { - uint32_t n = arrst_size(i_DRAW2D.named_colors, color_t); - color_t *col = NULL; - if (index >= n) + if (index == 0) + return kCOLOR_DEFAULT; + + cassert((uint8_t)(color >> 24) != 0); + + arrst_foreach(ic, i_INDEXED_COLORS, IColor) + if (index == ic->index) + { + ic->color = color; + return color; + } + arrst_end() + { - uint32_t i; - for (i = n; i <= index; ++i) - arrst_append(i_DRAW2D.named_colors, 0, color_t); + IColor *nc = arrst_new(i_INDEXED_COLORS, IColor); + nc->index = index; + nc->color = color; + return color; } - - col = arrst_get(i_DRAW2D.named_colors, index, color_t); - *col = color; } /*---------------------------------------------------------------------------*/ -color_t draw2d_get_named_color(const uint32_t index) +color_t draw2d_get_indexed_color(const uint16_t index) { - // Named color should be initialized - color_t *col = arrst_get(i_DRAW2D.named_colors, index, color_t); - cassert(index == 0 || *col != 0); - return *col; + if (index == 0) + return kCOLOR_DEFAULT; + + arrst_foreach(ic, i_INDEXED_COLORS, IColor) + if (ic->index == index) + return ic->color; + arrst_end() + + cassert(FALSE); + return kCOLOR_DEFAULT; } /*---------------------------------------------------------------------------*/ -static __INLINE real32_t i_ceil(const real32_t n) +static __INLINE real32_t i_ceil(const real32_t n) { int32_t in = (int32_t)n; - if (n == (real32_t)in) + if (n == (real32_t)in) { return (real32_t)in; } @@ -325,7 +342,7 @@ void draw2d_extents_imp(void *data, FPtr_word_extents func_word_extents, const b cassert(next_text > ctext); str_copy_cn(word, sizeof(word), ctext, size); word[size] = '\0'; - func_word_extents(data, word, &word_width, &word_height); + func_word_extents(data, word, &word_width, &word_height); if (current_width + word_width <= ref_width) { current_width += word_width; @@ -348,7 +365,7 @@ void draw2d_extents_imp(void *data, FPtr_word_extents func_word_extents, const b cassert(word_type == i_WORD_TYPE_TEXT); str_copy_cn(word, sizeof(word), ctext, size); word[size] = '\0'; - func_word_extents(data, word, &word_width, &word_height); + func_word_extents(data, word, &word_width, &word_height); if (current_width + word_width <= ref_width) { diff --git a/src/draw2d/draw2d.def b/src/draw2d/draw2d.def new file mode 100644 index 0000000..ec939eb --- /dev/null +++ b/src/draw2d/draw2d.def @@ -0,0 +1,21 @@ +/* Draw2d library import/export */ + +#if defined(DRAW2D_IMPORT) + #if defined(__GNUC__) + #define _draw2d_api + #elif defined(_MSC_VER) + #define _draw2d_api __declspec(dllimport) + #else + #error Unknown compiler + #endif +#elif defined(NAPPGUI_SHARED_LIB) + #if defined(__GNUC__) + #define _draw2d_api __attribute__((visibility("default"))) + #elif defined(_MSC_VER) + #define _draw2d_api __declspec(dllexport) + #else + #error Unknown compiler + #endif +#else + #define _draw2d_api +#endif diff --git a/src/draw2d/draw2d.h b/src/draw2d/draw2d.h index 494031f..8c6079a 100644 --- a/src/draw2d/draw2d.h +++ b/src/draw2d/draw2d.h @@ -15,10 +15,11 @@ __EXTERN_C -void draw2d_start(void); +_draw2d_api void draw2d_start(void); -void draw2d_finish(void); - -#define resid_image(resid) (const Image*)(resid) +_draw2d_api void draw2d_finish(void); __END_C + +#define resid_image(resid) \ + (const Image*)(resid) diff --git a/src/draw2d/draw2d.hxx b/src/draw2d/draw2d.hxx index 72ec60a..5e73d42 100644 --- a/src/draw2d/draw2d.hxx +++ b/src/draw2d/draw2d.hxx @@ -15,6 +15,7 @@ #define __DRAW2D_HXX__ #include "geom2d.hxx" +#include "draw2d.def" typedef enum _pixformat_t { @@ -99,6 +100,13 @@ typedef enum _ellipsis_t ekELLIPMLINE } ellipsis_t; +typedef enum _indicator_t +{ + ekINDNONE = 0, + ekINDUP_ARROW, + ekINDDOWN_ARROW +} indicator_t; + typedef uint32_t color_t; typedef struct _dctx_t DCtx; typedef struct _palette_t Palette; diff --git a/src/draw2d/draw2d.inl b/src/draw2d/draw2d.inl index 2bd6e63..9753dff 100644 --- a/src/draw2d/draw2d.inl +++ b/src/draw2d/draw2d.inl @@ -18,14 +18,10 @@ uint32_t draw2d_register_font(const char_t *font_family); const char_t *draw2d_font_family(const uint32_t family); -void draw2d_set_named_color(const uint32_t index, const color_t color); - -color_t draw2d_get_named_color(const uint32_t index); +color_t draw2d_get_indexed_color(const uint16_t index); void draw2d_extents_imp(void *data, FPtr_word_extents func_word_extents, const bool_t newlines, const char_t *str, const real32_t refwidth, real32_t *width, real32_t *height); -void draw2d_word_extents(MeasureStr *data, const char_t *word, real32_t *width, real32_t *height); - __END_C #define draw2d_extents(data, func_word_extents, newlines, str, refwidth, width, height, type)\ diff --git a/src/draw2d/draw2d.ixx b/src/draw2d/draw2d.ixx index 27db2da..d3b2a75 100644 --- a/src/draw2d/draw2d.ixx +++ b/src/draw2d/draw2d.ixx @@ -14,17 +14,8 @@ #define __OSDRAW_IXX__ #include "draw2d.hxx" -#include "draw2dh.ixx" typedef struct _measurestr_t MeasureStr; -typedef struct _ccursor_t Cursor; - -#define label_type(flags) ((flags) & ekLBTYPE) -#define button_type(flags) ((flags) & ekBTTYPE) -#define edit_type(flags) ((flags) & ekEDTYPE) -#define slider_type(flags) ((flags) & ekSLTYPE) -#define progress_type(flags) ((flags) & ekPGTYPE) -#define split_type(flags) ((flags) & ekSPTYPE) enum font_family_t { @@ -32,483 +23,11 @@ enum font_family_t ekFONT_FAMILY_MONOSPACE = 1 }; -typedef enum _guitype_t -{ - /* Basic controls */ - ekGUI_COMPONENT_LABEL = 0, - ekGUI_COMPONENT_BUTTON = 1, - ekGUI_COMPONENT_POPUP = 2, - ekGUI_COMPONENT_EDITBOX = 3, - ekGUI_COMPONENT_COMBOBOX = 4, - ekGUI_COMPONENT_SLIDER = 5, - ekGUI_COMPONENT_UPDOWN = 6, - ekGUI_COMPONENT_PROGRESS = 7, - - /* View Controls */ - ekGUI_COMPONENT_TEXTVIEW = 8, - ekGUI_COMPONENT_TABLEVIEW = 9, - ekGUI_COMPONENT_TREEVIEW = 10, - ekGUI_COMPONENT_BOXVIEW = 11, - ekGUI_COMPONENT_SPLITVIEW = 12, - ekGUI_COMPONENT_CUSTOMVIEW = 13, - - /* Others */ - ekGUI_COMPONENT_PANEL = 14, - ekGUI_COMPONENT_LINE = 15, - ekGUI_COMPONENT_HEADER = 16, - - /* Non-Components */ - ekGUI_COMPONENT_WINDOW = 17, - ekGUI_COMPONENT_TOOLBAR = 18 -} guitype_t; - -#define GUI_CONTEXT_NUM_COMPONENTS 17 - -typedef enum _gui_role_t -{ - ekGUI_ROLE_MAIN = 0, - ekGUI_ROLE_OVERLAY = 1, - ekGUI_ROLE_MODAL = 2, - ekGUI_ROLE_MANAGED = 3 -} gui_role_t; - -typedef enum _cstate_t -{ - ekCSTATE_NORMAL, - ekCSTATE_HOT, - ekCSTATE_PRESSED, - ekCSTATE_BKNORMAL, - ekCSTATE_BKHOT, - ekCSTATE_BKPRESSED, - ekCSTATE_DISABLED -} cstate_t; - -typedef enum _multisel_t -{ - ekMULTISEL_NO, - ekMULTISEL_SINGLE, - ekMULTISEL_BURST -} multisel_t; - typedef struct _osfont_t OSFont; typedef struct _osimage_t OSImage; -typedef struct _higram_t Higram; -typedef struct _btext_t BText; typedef void(*FPtr_word_extents)(void *data, const char_t *word, real32_t *width, real32_t *height); #define FUNC_CHECK_WORD_EXTENTS(func, type)\ (void)((void(*)(type*, const char_t*, real32_t*, real32_t*))func == func) -typedef void(*FPtr_call)(void *item); -#define FUNC_CHECK_CALL(func, type)\ - (void)((void(*)(type*))func == func) - -typedef void*(*FPtr_create)(const uint32_t flags); -#define FUNC_CHECK_CREATE(func, type)\ - (void)((type*(*)(const uint32_t))func == func) - -typedef void*(*FPtr_create_enum)(const enum_t value); -#define FUNC_CHECK_CREATE_ENUM(func, type, enum_type)\ - (void)((type*(*)(const enum_type))func == func) - -typedef void(*FPtr_set_bool)(void *item, const bool_t value); -#define FUNC_CHECK_SET_BOOL(func, type)\ - (void)((void(*)(type*, const bool_t))func == func) - -typedef void(*FPtr_set_uint32)(void *item, const uint32_t value); -#define FUNC_CHECK_SET_UINT32(func, type)\ - (void)((void(*)(type*, const uint32_t))func == func) - -typedef void(*FPtr_set4_uint32)(void *item, const uint32_t value1, const uint32_t value2, const uint32_t value3, const uint32_t value4); -#define FUNC_CHECK_SET4_UINT32(func, type)\ - (void)((void(*)(type*, const uint32_t, const uint32_t, const uint32_t, const uint32_t))func == func) - -typedef uint32_t(*FPtr_get_uint32)(const void *item); -#define FUNC_CHECK_GET_UINT32(func, type)\ - (void)((uint32_t(*)(const type*))func == func) - -typedef enum_t(*FPtr_get_enum)(const void *item); -#define FUNC_CHECK_GET_ENUM(func, type, type_enum)\ - (void)((type_enum(*)(const type*))func == func) - -typedef enum_t(*FPtr_get_enum2)(const void *item, const enum_t); -#define FUNC_CHECK_GET_ENUM2(func, type, type_enum, type_enum2)\ - (void)((type_enum(*)(const type*, const type_enum2))func == func) - -typedef void(*FPtr_set_enum)(void *item, const enum_t value); -#define FUNC_CHECK_SET_ENUM(func, type, type_enum)\ - (void)((void(*)(type*, const type_enum))func == func) - -typedef void(*FPtr_set_real32)(void *item, const real32_t value); -#define FUNC_CHECK_SET_REAL32(func, type)\ - (void)((void(*)(type*, const real32_t))func == func) - -typedef void(*FPtr_set2_real32)(void *item, const real32_t value1, const real32_t value2); -#define FUNC_CHECK_SET2_REAL32(func, type)\ - (void)((void(*)(type*, const real32_t, const real32_t))func == func) - -typedef void(*FPtr_set4_real32)(void *item, const real32_t value1, const real32_t value2, const real32_t value3, const real32_t value4); -#define FUNC_CHECK_SET4_REAL32(func, type)\ - (void)((void(*)(type*, const real32_t, const real32_t, const real32_t, const real32_t))func == func) - -typedef real32_t(*FPtr_get_real32)(const void *item); -#define FUNC_CHECK_GET_REAL32(func, type)\ - (void)((real32_t(*)(const type*))func == func) - -typedef void(*FPtr_get2_real32)(const void *item, real32_t *value1, real32_t *value2); -#define FUNC_CHECK_GET2_REAL32(func, type)\ - (void)((void(*)(const type*, real32_t*, real32_t*))func == func) - -typedef void(*FPtr_set_text)(void *item, const char_t *text); -#define FUNC_CHECK_SET_TEXT(func, type)\ - (void)((void(*)(type*, const char_t*))func == func) - -typedef const char_t*(*FPtr_get_text)(const void *item); -#define FUNC_CHECK_GET_TEXT(func, type)\ - (void)((const char_t*(*)(const type*))func == func) - -typedef const void*(*FPtr_get_const_ptr)(const void *item); -#define FUNC_CHECK_GET_CONST_PTR(func, type, ptr_type)\ - (void)((const ptr_type*(*)(const type*))func == func) - -typedef void*(*FPtr_get_ptr)(const void *item); -#define FUNC_CHECK_GET_PTR(func, type, ptr_type)\ - (void)((ptr_type*(*)(const type*))func == func) - -typedef void(*FPtr_set_ptr)(void *item, void *ptr); -#define FUNC_CHECK_SET_PTR(func, type, ptr_type)\ - (void)((void(*)(type*, ptr_type*))func == func) - -typedef void(*FPtr_set_const_ptr)(void *item, const void *ptr); -#define FUNC_CHECK_SET_CONST_PTR(func, type, ptr_type)\ - (void)((void(*)(type*, const ptr_type*))func == func) - -typedef void(*FPtr_set_listener)(void *item, Listener *listener); -#define FUNC_CHECK_SET_LISTENER(func, type)\ - (void)((void(*)(type*, Listener*))func == func) - -typedef void(*FPtr_set_elem)(void *item, const op_t op, const uint32_t index, const char_t *text, const Image *data); -#define FUNC_CHECK_SET_ELEM(func, type)\ - (void)((void(*)(type*, const op_t, const uint32_t, const char_t*, const Image*))func == func) - -typedef void(*FPtr_bounds1)(const void *item, const char_t *text, const real32_t refwidth, real32_t *width, real32_t *height); -#define FUNC_CHECK_BOUNDS1(func, type)\ - (void)((void(*)(const type*, const char_t*, const real32_t, real32_t*, real32_t*))func == func) - -typedef void(*FPtr_bounds2)(const void *item, const char_t *text, const real32_t refwidth, const real32_t refheight, real32_t *width, real32_t *height); -#define FUNC_CHECK_BOUNDS2(func, type)\ - (void)((void(*)(const type*, const char_t*, const real32_t, const real32_t, real32_t*, real32_t*))func == func) - -typedef void(*FPtr_bounds3)(const void *item, const char_t *text, real32_t *width, real32_t *height); -#define FUNC_CHECK_BOUNDS3(func, type)\ - (void)((void(*)(const type*, const char_t*, real32_t*, real32_t*))func == func) - -typedef void(*FPtr_bounds4)(const void *item, const real32_t refwidth, const uint32_t lines, real32_t *width, real32_t *height); -#define FUNC_CHECK_BOUNDS4(func, type)\ - (void)((void(*)(const type*, const real32_t, const uint32_t, real32_t*, real32_t*))func == func) - -typedef void(*FPtr_bounds5)(const void *item, const real32_t refwidth, real32_t *width, real32_t *height); -#define FUNC_CHECK_BOUNDS5(func, type)\ - (void)((void(*)(const type*, const real32_t, real32_t*, real32_t*))func == func) - -typedef void(*FPtr_bounds6)(const void *item, const real32_t length, const fsize_t size, real32_t *width, real32_t *height); -#define FUNC_CHECK_BOUNDS6(func, type)\ - (void)((void(*)(const type*, const real32_t, const fsize_t , real32_t*, real32_t*))func == func) - -typedef void(*FPtr_area)(void *item, void *obj, const color_t bgcolor, const color_t skcolor, const real32_t x, const real32_t y, const real32_t width, const real32_t height); -#define FUNC_CHECK_AREA(func, type)\ - (void)((void(*)(type*, void*, const color_t, const color_t, const real32_t, const real32_t, const real32_t, const real32_t))func == func) - -typedef void(*FPtr_bar_tickmarks)(void *item, const uint32_t num_tickmarks, const bool_t tickmarks_at_left_top); -#define FUNC_CHECK_BAR_TICKMARKS(func, type)\ - (void)((void(*)(type*, const uint32_t, const bool_t))func == func) - -typedef real32_t(*FPtr_get_real32_enum)(const void *item, const enum_t value); -#define FUNC_CHECK_GET_REAL32_ENUM(func, type, type_enum)\ - (void)((real32_t(*)(const type*, const type_enum))func == func) - -typedef void*(*FPtr_window_managed)(void*); -#define FUNC_CHECK_WINDOW_MANAGED(func, type)\ - (void)((type*(*)(void*))func == func) - -typedef void(*FPtr_window_z_order)(void*, void*); -#define FUNC_CHECK_WINDOW_Z_ORDER(func, type)\ - (void)((void(*)(type*, type*))func == func) - -typedef uint32_t(*FPtr_window_modal)(void*, void*); -#define FUNC_CHECK_WINDOW_MODAL(func, type)\ - (void)((uint32_t(*)(type*, type*))func == func) - -typedef void(*FPtr_set_property)(void *item, const guiprop_t property, const void *value); -#define FUNC_CHECK_SET_PROPERTY(func, type)\ - (void)((void(*)(type*, const guiprop_t, const void*))func == func) - -typedef void(*FPtr_menu_launch)(void *item, void *window, const real32_t x, const real32_t y); -#define FUNC_CHECK_MENU_LAUNCH(func, type, window_type)\ - (void)((void(*)(type*, window_type*, const real32_t, const real32_t))func == func) - -typedef void(*FPtr_set_key)(void *item, const uint32_t key, const uint32_t modifiers); -#define FUNC_CHECK_SET_KEY(func, type)\ - (void)((void(*)(type*, const uint32_t, const uint32_t))func == func) - -typedef const char_t*(*FPtr_comwin_file)(void *parent, const char_t **ftypes, const uint32_t size, const char_t *start_dir, const bool_t open); -#define FUNC_CHECK_COMWIN_FILE(func, type)\ - (void)((const char_t*(*)(type*, const char_t**, const uint32_t, const char_t*, const bool_t))func == func) - -typedef void(*FPtr_comwin_color)(void *parent, const char_t *title, const real32_t x, const real32_t y, const align_t halign, const align_t valign, color_t current, color_t *colors, const uint32_t n, Listener *OnChange); -#define FUNC_CHECK_COMWIN_COLOR(func, type)\ - (void)((void(*)(type*, const char_t*, const real32_t, const real32_t, const align_t, const align_t, const color_t, color_t*, const uint32_t, Listener*))func == func) - -typedef Cursor*(*FPtr_cursor)(const enum_t, const Image*, const real32_t, const real32_t); - -typedef void(*FPtr_rect)(void*, const uint32_t, const uint32_t, const uint32_t, const uint32_t, const enum_t); -#define FUNC_CHECK_RECT(func, type, enum_type)\ - (void)((void(*)(type*, const uint32_t, const uint32_t, const uint32_t, const uint32_t, const enum_type))func == func) - -typedef void(*FPtr_text)(void*, const char_t*, const uint32_t, const uint32_t, const enum_t); -#define FUNC_CHECK_TEXT(func, type, enum_type)\ - (void)((void(*)(type*, const char_t*, const uint32_t, const uint32_t, const enum_type))func == func) - -typedef void(*FPtr_image)(void*, const Image*, const uint32_t, const uint32_t, const enum_t); -#define FUNC_CHECK_IMAGE(func, type, enum_type)\ - (void)((void(*)(type*, const Image*, const uint32_t, const uint32_t, const enum_type))func == func) - -typedef void(*FPtr_indexed)(const uint32_t, void*); -#define FUNC_CHECK_INDEXED(func)\ - (void)((void(*)(const uint32_t, void*))func == func) - -struct _gui_context_t -{ - uint32_t retain_count; - - /*! */ - FPtr_set_text func_set_tooltip[GUI_CONTEXT_NUM_COMPONENTS]; - FPtr_destroy func_destroy[GUI_CONTEXT_NUM_COMPONENTS]; - FPtr_set_ptr func_attach_to_panel[GUI_CONTEXT_NUM_COMPONENTS]; - FPtr_set_ptr func_detach_from_panel[GUI_CONTEXT_NUM_COMPONENTS]; - FPtr_set_bool func_set_visible[GUI_CONTEXT_NUM_COMPONENTS]; - FPtr_set_bool func_set_enabled[GUI_CONTEXT_NUM_COMPONENTS]; - FPtr_get2_real32 func_get_size[GUI_CONTEXT_NUM_COMPONENTS]; - FPtr_get2_real32 func_get_origin[GUI_CONTEXT_NUM_COMPONENTS]; - FPtr_set4_real32 func_set_frame[GUI_CONTEXT_NUM_COMPONENTS]; - - /*!