From 01b319f349d630cc868743de091a9f09a0962765 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 11:23:36 +0100 Subject: [PATCH 01/24] use vcpkg packages on windows make cmake files smarter --- CMakeLists.txt | 16 ++------ cmake/Modules/FindBerkeleyDB.cmake | 50 ------------------------ cmake/Modules/FindReadline.cmake | 47 ---------------------- cmake/Modules/FindSQLite3.cmake | 63 ------------------------------ src/CMakeLists.txt | 18 ++++----- src/config.pkg.c | 2 +- src/eressea.pkg.c | 2 +- vs2019-build.bat | 4 +- 8 files changed, 17 insertions(+), 185 deletions(-) delete mode 100644 cmake/Modules/FindBerkeleyDB.cmake delete mode 100644 cmake/Modules/FindReadline.cmake delete mode 100644 cmake/Modules/FindSQLite3.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 23796c6c0..19aa5ab52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,24 +36,14 @@ CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT) endif (HAVE_LIBBSD) endif (MSVC) -find_package (Readline) - -if (ERESSEA_DB STREQUAL "db") -find_package (BerkeleyDB REQUIRED QUIET) -else() -find_package (SQLite3 REQUIRED QUIET) -endif() +find_package (SQLite3 REQUIRED) find_package(EXPAT REQUIRED) find_package (ToLua REQUIRED) if (TOLUA_FOUND) -if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3") -find_package (Lua 5.3 REQUIRED) -elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") +if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") find_package (Lua 5.2 REQUIRED) -elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3") -find_package ( Lua 5.3 REQUIRED) -else () +else() find_package (Lua51 REQUIRED) endif() endif(TOLUA_FOUND) diff --git a/cmake/Modules/FindBerkeleyDB.cmake b/cmake/Modules/FindBerkeleyDB.cmake deleted file mode 100644 index 88b0621fe..000000000 --- a/cmake/Modules/FindBerkeleyDB.cmake +++ /dev/null @@ -1,50 +0,0 @@ -# -*- cmake -*- - -# - Find BerkeleyDB -# Find the BerkeleyDB includes and library -# This module defines -# DB_INCLUDE_DIR, where to find db.h, etc. -# DB_LIBRARIES, the libraries needed to use BerkeleyDB. -# DB_FOUND, If false, do not try to use BerkeleyDB. -# also defined, but not for general use are -# DB_LIBRARY, where to find the BerkeleyDB library. - -FIND_PATH(DB_INCLUDE_DIR db.h - /usr/local/include/db4 - /usr/local/include - /usr/include/db4 - /usr/include - ) - -SET(DB_NAMES ${DB_NAMES} db) -FIND_LIBRARY(DB_LIBRARY - NAMES ${DB_NAMES} - PATHS /usr/lib /usr/local/lib - ) - -IF (DB_LIBRARY AND DB_INCLUDE_DIR) - SET(DB_LIBRARIES ${DB_LIBRARY}) - SET(DB_FOUND "YES") -ELSE (DB_LIBRARY AND DB_INCLUDE_DIR) - SET(DB_FOUND "NO") -ENDIF (DB_LIBRARY AND DB_INCLUDE_DIR) - - -IF (DB_FOUND) - IF (NOT DB_FIND_QUIETLY) - MESSAGE(STATUS "Found BerkeleyDB: ${DB_LIBRARIES}") - ENDIF (NOT DB_FIND_QUIETLY) -ELSE (DB_FOUND) - IF (DB_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find BerkeleyDB library") - ENDIF (DB_FIND_REQUIRED) -ENDIF (DB_FOUND) - -# Deprecated declarations. -SET (NATIVE_DB_INCLUDE_PATH ${DB_INCLUDE_DIR} ) -GET_FILENAME_COMPONENT (NATIVE_DB_LIB_PATH ${DB_LIBRARY} PATH) - -MARK_AS_ADVANCED( - DB_LIBRARY - DB_INCLUDE_DIR - ) diff --git a/cmake/Modules/FindReadline.cmake b/cmake/Modules/FindReadline.cmake deleted file mode 100644 index bb73fee7f..000000000 --- a/cmake/Modules/FindReadline.cmake +++ /dev/null @@ -1,47 +0,0 @@ -# - Try to find readline include dirs and libraries -# -# Usage of this module as follows: -# -# find_package(Readline) -# -# Variables used by this module, they can change the default behaviour and need -# to be set before calling find_package: -# -# READLINE_ROOT_DIR Set this variable to the root installation of -# readline if the module has problems finding the -# proper installation path. -# -# Variables defined by this module: -# -# READLINE_FOUND System has readline, include and lib dirs found -# READLINE_INCLUDE_DIR The readline include directories. -# READLINE_LIBRARY The readline library. - -find_path(READLINE_ROOT_DIR - NAMES include/readline/readline.h -) - -find_path(READLINE_INCLUDE_DIR - NAMES readline/readline.h - HINTS ${READLINE_ROOT_DIR}/include -) - -find_library(READLINE_LIBRARY - NAMES readline - HINTS ${READLINE_ROOT_DIR}/lib -) - -if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY) - set(READLINE_FOUND TRUE) -else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY) - FIND_LIBRARY(READLINE_LIBRARY NAMES readline) - include(FindPackageHandleStandardArgs) - FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY ) - MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY) -endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY) - -mark_as_advanced( - READLINE_ROOT_DIR - READLINE_INCLUDE_DIR - READLINE_LIBRARY -) diff --git a/cmake/Modules/FindSQLite3.cmake b/cmake/Modules/FindSQLite3.cmake deleted file mode 100644 index 910b05cea..000000000 --- a/cmake/Modules/FindSQLite3.cmake +++ /dev/null @@ -1,63 +0,0 @@ -# - Try to find the SQLite3 library -# Once done this will define -# -# SQLITE3_FOUND - System has SQLite3 -# SQLITE3_INCLUDE_DIR - The SQLite3 include directory -# SQLITE3_LIBRARIES - The libraries needed to use SQLite3 -# SQLITE3_DEFINITIONS - Compiler switches required for using SQLite3 -# SQLITE3_EXECUTABLE - The SQLite3 command line shell -# SQLITE3_VERSION_STRING - the version of SQLite3 found (since CMake 2.8.8) - -#============================================================================= -# Copyright 2006-2009 Kitware, Inc. -# Copyright 2006 Alexander Neundorf -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -# use pkg-config to get the directories and then use these values -# in the find_path() and find_library() calls -find_package(PkgConfig QUIET) -PKG_CHECK_MODULES(PC_SQLITE QUIET sqlite3) -set(SQLITE3_DEFINITIONS ${PC_SQLITE_CFLAGS_OTHER}) - -find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h - HINTS - ${PC_SQLITE_INCLUDEDIR} - ${PC_SQLITE_INCLUDE_DIRS} - ) - -find_library(SQLITE3_LIBRARIES NAMES sqlite3 - HINTS - ${PC_SQLITE_LIBDIR} - ${PC_SQLITE_LIBRARY_DIRS} - ) - -find_program(SQLITE3_EXECUTABLE sqlite3) - -if(PC_SQLITE_VERSION) - set(SQLITE3_VERSION_STRING ${PC_SQLITE_VERSION}) -elseif(SQLITE3_INCLUDE_DIR AND EXISTS "${SQLITE3_INCLUDE_DIR}/sqlite3.h") - file(STRINGS "${SQLITE3_INCLUDE_DIR}/sqlite3.h" sqlite3_version_str - REGEX "^#define[\t ]+SQLITE_VERSION[\t ]+\".*\"") - - string(REGEX REPLACE "^#define[\t ]+SQLITE_VERSION[\t ]+\"([^\"]*)\".*" "\\1" - SQLITE3_VERSION_STRING "${sqlite3_version_str}") - unset(sqlite3_version_str) -endif() - -# handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLite3 - REQUIRED_VARS SQLITE3_LIBRARIES SQLITE3_INCLUDE_DIR - VERSION_VAR SQLITE3_VERSION_STRING) - -mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARIES SQLITE3_EXECUTABLE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 48e665529..6744847e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -301,32 +301,32 @@ if (HAVE_LIBBSD) target_link_libraries(parser bsd) endif (HAVE_LIBBSD) -if (SQLITE3_FOUND) -include_directories (${SQLITE3_INCLUDE_DIR}) -target_link_libraries(eressea ${SQLITE3_LIBRARIES}) -target_link_libraries(test_eressea ${SQLITE3_LIBRARIES}) +if (SQLite3_FOUND) +target_include_directories (game PRIVATE ${SQLite3_INCLUDE_DIRS}) +target_link_libraries(eressea ${SQLite3_LIBRARIES}) +target_link_libraries(test_eressea ${SQLite3_LIBRARIES}) add_definitions(-DUSE_SQLITE) elseif (DB_FOUND) -include_directories (${DB_INCLUDE_DIR}) +#include_directories (${DB_INCLUDE_DIR}) target_link_libraries(eressea ${DB_LIBRARIES}) target_link_libraries(test_eressea ${DB_LIBRARIES}) add_definitions(-DUSE_DB) -endif(SQLITE3_FOUND) +endif(SQLite3_FOUND) if (READLINE_FOUND) -include_directories (${READLINE_INCLUDE_DIR}) +#include_directories (${READLINE_INCLUDE_DIR}) target_link_libraries(eressea ${READLINE_LIBRARY}) add_definitions(-DUSE_READLINE) endif (READLINE_FOUND) if (CURSES_FOUND) -include_directories (${CURSES_INCLUDE_DIR}) +target_include_directories (eressea ${CURSES_INCLUDE_DIRS}) target_link_libraries(eressea ${CURSES_LIBRARIES}) add_definitions(-DUSE_CURSES) endif(CURSES_FOUND) if (EXPAT_FOUND) -include_directories (${EXPAT_INCLUDE_DIRS}) +target_include_directories (game PRIVATE ${EXPAT_INCLUDE_DIRS}) target_link_libraries(eressea ${EXPAT_LIBRARIES}) target_link_libraries(test_eressea ${EXPAT_LIBRARIES}) endif (EXPAT_FOUND) diff --git a/src/config.pkg.c b/src/config.pkg.c index cc4bb6965..38e1f8785 100644 --- a/src/config.pkg.c +++ b/src/config.pkg.c @@ -2,7 +2,7 @@ ** Lua binding: config */ -#include "tolua.h" +#include #ifndef __cplusplus #include diff --git a/src/eressea.pkg.c b/src/eressea.pkg.c index 289fc323a..9318d975d 100644 --- a/src/eressea.pkg.c +++ b/src/eressea.pkg.c @@ -2,7 +2,7 @@ ** Lua binding: eressea */ -#include "tolua.h" +#include #ifndef __cplusplus #include diff --git a/vs2019-build.bat b/vs2019-build.bat index 299778303..107e6634c 100644 --- a/vs2019-build.bat +++ b/vs2019-build.bat @@ -8,6 +8,8 @@ REM CD .. REM SET ERESSEA=%CD% REM CD %SRCDIR% +SET CMAKE_MODULES="%CMAKE_ROOT%\share\cmake-3.19\Modules;%SRCDIR%\cmake\Modules" + IF exist build-vs%VSVERSION% goto HAVEDIR mkdir build-vs%VSVERSION% :HAVEDIR @@ -15,5 +17,5 @@ cd build-vs%VSVERSION% IF NOT EXIST CMakeCache.txt GOTO NOCACHE DEL CMakeCache.txt :NOCACHE -"%CMAKE_ROOT%\bin\cmake.exe" -A Win32 -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%LUA_DEV%;%WIN32_DEV%" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. +"%CMAKE_ROOT%\bin\cmake.exe" -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -A Win32 -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%LUA_DEV%;%WIN32_DEV%" -DCMAKE_MODULE_PATH="%CMAKE_MODULES%" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. PAUSE From 7faf64a2fe1187ccd1d597a3b5e13ace6e86f51d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 11:48:11 +0100 Subject: [PATCH 02/24] add FindSQLite3 for older cmake versions --- cmake/Modules/FindSQLite3.cmake | 69 +++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 cmake/Modules/FindSQLite3.cmake diff --git a/cmake/Modules/FindSQLite3.cmake b/cmake/Modules/FindSQLite3.cmake new file mode 100644 index 000000000..58dfcef87 --- /dev/null +++ b/cmake/Modules/FindSQLite3.cmake @@ -0,0 +1,69 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindSQLite3 +----------- + +.. versionadded:: 3.14 + +Find the SQLite libraries, v3 + +IMPORTED targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target: + +``SQLite::SQLite3`` + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables if found: + +``SQLite3_INCLUDE_DIRS`` + where to find sqlite3.h, etc. +``SQLite3_LIBRARIES`` + the libraries to link against to use SQLite3. +``SQLite3_VERSION`` + version of the SQLite3 library found +``SQLite3_FOUND`` + TRUE if found + +#]=======================================================================] + +# Look for the necessary header +find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h) +mark_as_advanced(SQLite3_INCLUDE_DIR) + +# Look for the necessary library +find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite) +mark_as_advanced(SQLite3_LIBRARY) + +# Extract version information from the header file +if(SQLite3_INCLUDE_DIR) + file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _ver_line + REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\"" + LIMIT_COUNT 1) + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" + SQLite3_VERSION "${_ver_line}") + unset(_ver_line) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SQLite3 + REQUIRED_VARS SQLite3_INCLUDE_DIR SQLite3_LIBRARY + VERSION_VAR SQLite3_VERSION) + +# Create the imported target +if(SQLite3_FOUND) + set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR}) + set(SQLite3_LIBRARIES ${SQLite3_LIBRARY}) + if(NOT TARGET SQLite::SQLite3) + add_library(SQLite::SQLite3 UNKNOWN IMPORTED) + set_target_properties(SQLite::SQLite3 PROPERTIES + IMPORTED_LOCATION "${SQLite3_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}") + endif() +endif() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6744847e0..b9273c11f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -320,7 +320,7 @@ add_definitions(-DUSE_READLINE) endif (READLINE_FOUND) if (CURSES_FOUND) -target_include_directories (eressea ${CURSES_INCLUDE_DIRS}) +target_include_directories (eressea PRIVATE ${CURSES_INCLUDE_DIRS}) target_link_libraries(eressea ${CURSES_LIBRARIES}) add_definitions(-DUSE_CURSES) endif(CURSES_FOUND) From 0a80e29c8579a3e896c3a481dfefd6dd2d45f48d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 12:10:47 +0100 Subject: [PATCH 03/24] use pdcurses from vcpkg if available --- CMakeLists.txt | 7 +++++-- vs2019-build.bat | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19aa5ab52..c1100e551 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ if (MSVC) find_package (PDCurses) set (CURSES_FOUND ${PDCURSES_FOUND}) set (CURSES_LIBRARIES ${PDCURSES_LIBRARY}) -set (CURSES_INCLUDE_DIR ${PDCURSES_INCLUDE_DIR}) +set (CURSES_INCLUDE_DIRS ${PDCURSES_INCLUDE_DIR}) set (HAVE_STRDUP 0) set (HAVE_STRLCAT 0) set (HAVE_LIBBSD 0) @@ -20,7 +20,6 @@ set (HAVE_EXECINFO_H 0) include (MSVC) else (MSVC) -find_package (Curses) include (CheckIncludeFile) CHECK_INCLUDE_FILE(signal.h HAVE_SIGNAL_H) CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H) @@ -36,6 +35,10 @@ CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT) endif (HAVE_LIBBSD) endif (MSVC) +if (NOT CURSES_FOUND) +find_package (Curses) +endif (NOT CURSES_FOUND) + find_package (SQLite3 REQUIRED) find_package(EXPAT REQUIRED) diff --git a/vs2019-build.bat b/vs2019-build.bat index 107e6634c..82733c683 100644 --- a/vs2019-build.bat +++ b/vs2019-build.bat @@ -8,7 +8,7 @@ REM CD .. REM SET ERESSEA=%CD% REM CD %SRCDIR% -SET CMAKE_MODULES="%CMAKE_ROOT%\share\cmake-3.19\Modules;%SRCDIR%\cmake\Modules" +SET CMAKE_MODULES="%CMAKE_ROOT%\share\cmake-3.19\Modules" IF exist build-vs%VSVERSION% goto HAVEDIR mkdir build-vs%VSVERSION% From 2e3ec23bd3a3cd8c36ce4073a65a5bc2daeff45f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 12:15:00 +0100 Subject: [PATCH 04/24] run tests where we can clean up after them --- s/runtests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/runtests b/s/runtests index 2c8049098..5fd1a9b02 100755 --- a/s/runtests +++ b/s/runtests @@ -21,8 +21,8 @@ if [ ! -e $ROOT/$BUILD ]; then exit fi -$UNIT_TESTS cd $ROOT/tests +$UNIT_TESTS $RUN_TESTS -v1 ../scripts/run-tests.lua $RUN_TESTS -v1 ../scripts/run-tests-e2.lua $RUN_TESTS -v1 ../scripts/run-tests-e3.lua From 2c4082941b6fde9c104dd486be4b609bcc1666f0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 13:32:24 +0100 Subject: [PATCH 05/24] fix compilation with Lua 5.4 (LUA_QL no longer exists) --- src/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/console.c b/src/console.c index f134b2164..11e0e1f81 100644 --- a/src/console.c +++ b/src/console.c @@ -227,7 +227,7 @@ static void dotty(lua_State * L) lua_insert(L, 1); if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) l_message(progname, lua_pushfstring(L, - "error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1))); + "error calling 'print' (%s)", lua_tostring(L, -1))); } } lua_settop(L, 0); /* clear stack */ From 683db969157bbafddc72fbfc9794e322dc1430c1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 13:55:36 +0100 Subject: [PATCH 06/24] we do not use dlmalloc --- .gitmodules | 6 ------ dlmalloc | 1 - iniparser | 1 - 3 files changed, 8 deletions(-) delete mode 160000 dlmalloc delete mode 160000 iniparser diff --git a/.gitmodules b/.gitmodules index f76a3af9c..7a89a17be 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ -[submodule "dlmalloc"] - path = dlmalloc - url = https://github.com/ennorehling/dlmalloc.git -[submodule "iniparser"] - path = iniparser - url = https://github.com/ennorehling/iniparser.git [submodule "cJSON"] path = cJSON url = https://github.com/ennorehling/cJSON.git diff --git a/dlmalloc b/dlmalloc deleted file mode 160000 index f1446c47c..000000000 --- a/dlmalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f1446c47ca1774ae84bf86a28502e91daf6b421a diff --git a/iniparser b/iniparser deleted file mode 160000 index 31d42782e..000000000 --- a/iniparser +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 31d42782e2713591da4c1a7db1aca4937137e352 From a80e60365ffa400a6e3abe527c49369c755fa075 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 14:36:45 +0100 Subject: [PATCH 07/24] add cmake support for iniparser package --- CMakeLists.txt | 5 ++- cmake/Modules/FindIniParser.cmake | 59 +++++++++++++++++++++++++++++++ src/CMakeLists.txt | 6 ++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 cmake/Modules/FindIniParser.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c1100e551..b9c5c7818 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,8 @@ find_package (Curses) endif (NOT CURSES_FOUND) find_package (SQLite3 REQUIRED) - -find_package(EXPAT REQUIRED) +find_package (IniParser REQUIRED) +find_package (EXPAT REQUIRED) find_package (ToLua REQUIRED) if (TOLUA_FOUND) if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") @@ -55,7 +55,6 @@ enable_testing() add_subdirectory (cJSON) add_subdirectory (storage) -add_subdirectory (iniparser) add_subdirectory (clibs) add_subdirectory (process) add_subdirectory (src eressea) diff --git a/cmake/Modules/FindIniParser.cmake b/cmake/Modules/FindIniParser.cmake new file mode 100644 index 000000000..0f976429d --- /dev/null +++ b/cmake/Modules/FindIniParser.cmake @@ -0,0 +1,59 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindIniParser +----------- + +.. versionadded:: 3.20 + +Find the IniParser libraries, v3 + +IMPORTED targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target: + +``Devillard::IniParser`` + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables if found: + +``IniParser_INCLUDE_DIRS`` + where to find sqlite3.h, etc. +``IniParser_LIBRARIES`` + the libraries to link against to use IniParser. +``IniParser_VERSION`` + version of the IniParser library found +``IniParser_FOUND`` + TRUE if found + +#]=======================================================================] + +# Look for the necessary header +find_path(IniParser_INCLUDE_DIR iniparser.h) +mark_as_advanced(IniParser_INCLUDE_DIR) + +# Look for the necessary library +find_library(IniParser_LIBRARY iniparser) +mark_as_advanced(IniParser_LIBRARY) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(IniParser + REQUIRED_VARS IniParser_INCLUDE_DIR IniParser_LIBRARY + VERSION_VAR IniParser_VERSION) + +# Create the imported target +if(IniParser_FOUND) + set(IniParser_INCLUDE_DIRS ${IniParser_INCLUDE_DIR}) + set(IniParser_LIBRARIES ${IniParser_LIBRARY}) + if(NOT TARGET Devillard::IniParser) + add_library(Devillard::IniParser UNKNOWN IMPORTED) + set_target_properties(Devillard::IniParser PROPERTIES + IMPORTED_LOCATION "${IniParser_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${IniParser_INCLUDE_DIR}") + endif() +endif() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9273c11f..3ec49bf09 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -301,6 +301,12 @@ if (HAVE_LIBBSD) target_link_libraries(parser bsd) endif (HAVE_LIBBSD) +if (IniParser_FOUND) +target_include_directories(game PUBLIC ${IniParser_INCLUDE_DIRS}) +target_link_libraries(eressea ${IniParser_LIBRARIES}) +target_link_libraries(test_eressea ${IniParser_LIBRARIES}) +endif (IniParser_FOUND) + if (SQLite3_FOUND) target_include_directories (game PRIVATE ${SQLite3_INCLUDE_DIRS}) target_link_libraries(eressea ${SQLite3_LIBRARIES}) From 4aedbd88cdc0adcb137490f4279d6c37774e865f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 14:46:10 +0100 Subject: [PATCH 08/24] find iniparser.h when installed in subdirectory --- cmake/Modules/FindIniParser.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindIniParser.cmake b/cmake/Modules/FindIniParser.cmake index 0f976429d..7c390fbc8 100644 --- a/cmake/Modules/FindIniParser.cmake +++ b/cmake/Modules/FindIniParser.cmake @@ -33,7 +33,7 @@ This module will set the following variables if found: #]=======================================================================] # Look for the necessary header -find_path(IniParser_INCLUDE_DIR iniparser.h) +find_path(IniParser_INCLUDE_DIR iniparser.h PATH_SUFFIXES iniparser) mark_as_advanced(IniParser_INCLUDE_DIR) # Look for the necessary library From 1f6d7e6c929c78092f0aa2ba9b52ae9f9abb2f33 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 15:10:48 +0100 Subject: [PATCH 09/24] eliminate cJSON submodule --- .gitmodules | 3 -- CMakeLists.txt | 2 +- cJSON | 1 - cmake/Modules/FindCJSON.cmake | 59 ++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 12 +++---- src/json.c | 3 +- src/util/crypto/CMakeLists.txt | 2 +- 7 files changed, 67 insertions(+), 15 deletions(-) delete mode 160000 cJSON create mode 100644 cmake/Modules/FindCJSON.cmake diff --git a/.gitmodules b/.gitmodules index 7a89a17be..306652a59 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "cJSON"] - path = cJSON - url = https://github.com/ennorehling/cJSON.git [submodule "storage"] path = storage url = https://github.com/ennorehling/storage.git diff --git a/CMakeLists.txt b/CMakeLists.txt index b9c5c7818..4447944f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ endif (NOT CURSES_FOUND) find_package (SQLite3 REQUIRED) find_package (IniParser REQUIRED) +find_package (CJSON REQUIRED) find_package (EXPAT REQUIRED) find_package (ToLua REQUIRED) if (TOLUA_FOUND) @@ -53,7 +54,6 @@ endif(TOLUA_FOUND) enable_testing() -add_subdirectory (cJSON) add_subdirectory (storage) add_subdirectory (clibs) add_subdirectory (process) diff --git a/cJSON b/cJSON deleted file mode 160000 index 460207f9c..000000000 --- a/cJSON +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 460207f9c09d501a2e302e5313b2f67dca0d6d63 diff --git a/cmake/Modules/FindCJSON.cmake b/cmake/Modules/FindCJSON.cmake new file mode 100644 index 000000000..83b924930 --- /dev/null +++ b/cmake/Modules/FindCJSON.cmake @@ -0,0 +1,59 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindCJSON +----------- + +.. versionadded:: 3.20 + +Find the cJSON libraries, v3 + +IMPORTED targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target: + +``DaveGamble::CJSON`` + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables if found: + +``CJSON_INCLUDE_DIRS`` + where to find sqlite3.h, etc. +``CJSON_LIBRARIES`` + the libraries to link against to use CJSON. +``CJSON_VERSION`` + version of the CJSON library found +``CJSON_FOUND`` + TRUE if found + +#]=======================================================================] + +# Look for the necessary header +find_path(CJSON_INCLUDE_DIR cJSON.h PATH_SUFFIXES cjson) +mark_as_advanced(CJSON_INCLUDE_DIR) + +# Look for the necessary library +find_library(CJSON_LIBRARY cjson) +mark_as_advanced(CJSON_LIBRARY) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CJSON + REQUIRED_VARS CJSON_INCLUDE_DIR CJSON_LIBRARY + VERSION_VAR CJSON_VERSION) + +# Create the imported target +if(CJSON_FOUND) + set(CJSON_INCLUDE_DIRS ${CJSON_INCLUDE_DIR}) + set(CJSON_LIBRARIES ${CJSON_LIBRARY}) + if(NOT TARGET DaveGamble::CJSON) + add_library(DaveGamble::CJSON UNKNOWN IMPORTED) + set_target_properties(DaveGamble::CJSON PROPERTIES + IMPORTED_LOCATION "${CJSON_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${CJSON_INCLUDE_DIR}") + endif() +endif() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3ec49bf09..afb619f8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ project (server C) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) -include_directories (${CJSON_INCLUDE_DIR}) include_directories (${CRYPTO_INCLUDE_DIR}) include_directories (${CLIBS_INCLUDE_DIR}) include_directories (${STORAGE_INCLUDE_DIR}) @@ -209,7 +208,7 @@ target_link_libraries(eressea ${LUA_LIBRARIES} ${STORAGE_LIBRARIES} ${CJSON_LIBRARIES} - ${INIPARSER_LIBRARIES} + ${IniParser_LIBRARIES} ) set(TESTS_SRC @@ -268,7 +267,7 @@ target_link_libraries(test_eressea ${CLIBS_LIBRARIES} ${STORAGE_LIBRARIES} ${CJSON_LIBRARIES} - ${INIPARSER_LIBRARIES} + ${IniParser_LIBRARIES} ) add_test(server test_eressea) @@ -301,11 +300,8 @@ if (HAVE_LIBBSD) target_link_libraries(parser bsd) endif (HAVE_LIBBSD) -if (IniParser_FOUND) -target_include_directories(game PUBLIC ${IniParser_INCLUDE_DIRS}) -target_link_libraries(eressea ${IniParser_LIBRARIES}) -target_link_libraries(test_eressea ${IniParser_LIBRARIES}) -endif (IniParser_FOUND) +target_include_directories (game PUBLIC ${CJSON_INCLUDE_DIRS}) +target_include_directories (game PUBLIC ${IniParser_INCLUDE_DIRS}) if (SQLite3_FOUND) target_include_directories (game PRIVATE ${SQLite3_INCLUDE_DIRS}) diff --git a/src/json.c b/src/json.c index 127d74f70..f25970af0 100644 --- a/src/json.c +++ b/src/json.c @@ -9,7 +9,8 @@ #include #include #include -#include "cJSON.h" + +#include #include #include diff --git a/src/util/crypto/CMakeLists.txt b/src/util/crypto/CMakeLists.txt index 9a82ff926..735dabc0a 100644 --- a/src/util/crypto/CMakeLists.txt +++ b/src/util/crypto/CMakeLists.txt @@ -13,7 +13,7 @@ SET (LIB_SRC ) ADD_LIBRARY (crypto ${LIB_SRC}) -set (CRYPTO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "cJSON headers") +set (CRYPTO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "crypto headers") set (CRYPTO_LIBRARIES crypto CACHE INTERNAL "crypto libraries") IF(WIN32) From 41bc2dcbe367b43236904d0314f797f0e6ace483 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 15:12:13 +0100 Subject: [PATCH 10/24] update package list --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4be1c324e..aba766a60 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ Debian-based Linux system, this is the apt-get command to install all of them: sudo apt-get install git cmake gcc make luarocks libxml2-dev \ - liblua5.2-dev libtolua-dev libncurses5-dev libsqlite3-dev + liblua5.2-dev libtolua-dev libncurses5-dev libsqlite3-dev \ + libcjson-dev libiniparser-dev # How to check out and build the Eressea server From ee8be2e96aa511c1c1000b9cb1dfbb6e024bbac8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 15:15:32 +0100 Subject: [PATCH 11/24] fix travis build --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index b702efaab..d6bf54606 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,8 @@ addons: - libncurses5-dev - libsqlite3-dev - libexpat1-dev + - libiniparser-dev + - libcjson-dev - valgrind - cppcheck - shellcheck From 7a5834cf82e761fc149b400b87f21ec24cb507d9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 20:48:19 +0100 Subject: [PATCH 12/24] tolua creates sources that abuse the LUALIB_API defines. Manually fixing the generated files so they don't try to declare dllimports. --- src/CMakeLists.txt | 8 ++++---- src/config.pkg.c | 8 ++++---- src/console.c | 2 +- src/eressea.pkg.c | 8 ++++---- src/game.pkg.c | 8 ++++---- src/locale.pkg.c | 8 ++++---- src/log.pkg.c | 8 ++++---- src/process.pkg.c | 13 ++++--------- src/settings.pkg.c | 8 ++++---- 9 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index afb619f8c..6307fde41 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -307,24 +307,24 @@ if (SQLite3_FOUND) target_include_directories (game PRIVATE ${SQLite3_INCLUDE_DIRS}) target_link_libraries(eressea ${SQLite3_LIBRARIES}) target_link_libraries(test_eressea ${SQLite3_LIBRARIES}) -add_definitions(-DUSE_SQLITE) +add_compile_definitions(game PRIVATE USE_SQLITE) elseif (DB_FOUND) #include_directories (${DB_INCLUDE_DIR}) target_link_libraries(eressea ${DB_LIBRARIES}) target_link_libraries(test_eressea ${DB_LIBRARIES}) -add_definitions(-DUSE_DB) +add_compile_definitions(game PRIVATE USE_DB) endif(SQLite3_FOUND) if (READLINE_FOUND) #include_directories (${READLINE_INCLUDE_DIR}) target_link_libraries(eressea ${READLINE_LIBRARY}) -add_definitions(-DUSE_READLINE) +add_compile_definitions(eressea PRIVATE DUSE_READLINE) endif (READLINE_FOUND) if (CURSES_FOUND) target_include_directories (eressea PRIVATE ${CURSES_INCLUDE_DIRS}) target_link_libraries(eressea ${CURSES_LIBRARIES}) -add_definitions(-DUSE_CURSES) +add_compile_definitions(eressea PRIVATE USE_CURSES) endif(CURSES_FOUND) if (EXPAT_FOUND) diff --git a/src/config.pkg.c b/src/config.pkg.c index 38e1f8785..585ec2a55 100644 --- a/src/config.pkg.c +++ b/src/config.pkg.c @@ -15,8 +15,8 @@ #include /* Exported function */ -TOLUA_API int tolua_config_open (lua_State* tolua_S); -LUALIB_API int luaopen_config (lua_State* tolua_S); +int tolua_config_open (lua_State* tolua_S); +int luaopen_config (lua_State* tolua_S); #undef tolua_reg_types #define tolua_reg_types tolua_reg_types_config @@ -108,7 +108,7 @@ static int tolua_config_eressea_config_parse00(lua_State* tolua_S) } /* Open lib function */ -LUALIB_API int luaopen_config (lua_State* tolua_S) +int luaopen_config (lua_State* tolua_S) { tolua_open(tolua_S); tolua_reg_types(tolua_S); @@ -127,7 +127,7 @@ LUALIB_API int luaopen_config (lua_State* tolua_S) return 1; } /* Open tolua function */ -TOLUA_API int tolua_config_open (lua_State* tolua_S) +int tolua_config_open (lua_State* tolua_S) { lua_pushcfunction(tolua_S, luaopen_config); lua_pushstring(tolua_S, "config"); diff --git a/src/console.c b/src/console.c index 11e0e1f81..a13dc3982 100644 --- a/src/console.c +++ b/src/console.c @@ -199,7 +199,7 @@ static int loadline(lua_State * L) if (!pushline(L, 1)) return -1; /* no input */ for (;;) { /* repeat until gets a complete line */ - status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + status = luaL_loadbuffer(L, lua_tostring(L, 1), (size_t)lua_strlen(L, 1), "=stdin"); if (!incomplete(L, status)) break; /* cannot try to add lines? */ if (!pushline(L, 0)) /* no more input? */ diff --git a/src/eressea.pkg.c b/src/eressea.pkg.c index 9318d975d..2a41eac38 100644 --- a/src/eressea.pkg.c +++ b/src/eressea.pkg.c @@ -15,8 +15,8 @@ #include /* Exported function */ -TOLUA_API int tolua_eressea_open (lua_State* tolua_S); -LUALIB_API int luaopen_eressea (lua_State* tolua_S); +int tolua_eressea_open (lua_State* tolua_S); +int luaopen_eressea (lua_State* tolua_S); #undef tolua_reg_types #define tolua_reg_types tolua_reg_types_eressea @@ -190,7 +190,7 @@ static int tolua_eressea_eressea_import00(lua_State* tolua_S) } /* Open lib function */ -LUALIB_API int luaopen_eressea (lua_State* tolua_S) +int luaopen_eressea (lua_State* tolua_S) { tolua_open(tolua_S); tolua_reg_types(tolua_S); @@ -209,7 +209,7 @@ LUALIB_API int luaopen_eressea (lua_State* tolua_S) return 1; } /* Open tolua function */ -TOLUA_API int tolua_eressea_open (lua_State* tolua_S) +int tolua_eressea_open (lua_State* tolua_S) { lua_pushcfunction(tolua_S, luaopen_eressea); lua_pushstring(tolua_S, "eressea"); diff --git a/src/game.pkg.c b/src/game.pkg.c index 30671021d..7fc23b0b0 100644 --- a/src/game.pkg.c +++ b/src/game.pkg.c @@ -15,8 +15,8 @@ #include /* Exported function */ -TOLUA_API int tolua_game_open (lua_State* tolua_S); -LUALIB_API int luaopen_game (lua_State* tolua_S); +int tolua_game_open (lua_State* tolua_S); +int luaopen_game (lua_State* tolua_S); #undef tolua_reg_types #define tolua_reg_types tolua_reg_types_game @@ -162,7 +162,7 @@ static int tolua_game_eressea_game_import00(lua_State* tolua_S) } /* Open lib function */ -LUALIB_API int luaopen_game (lua_State* tolua_S) +int luaopen_game (lua_State* tolua_S) { tolua_open(tolua_S); tolua_reg_types(tolua_S); @@ -183,7 +183,7 @@ LUALIB_API int luaopen_game (lua_State* tolua_S) return 1; } /* Open tolua function */ -TOLUA_API int tolua_game_open (lua_State* tolua_S) +int tolua_game_open (lua_State* tolua_S) { lua_pushcfunction(tolua_S, luaopen_game); lua_pushstring(tolua_S, "game"); diff --git a/src/locale.pkg.c b/src/locale.pkg.c index 1792b742e..01d83c681 100644 --- a/src/locale.pkg.c +++ b/src/locale.pkg.c @@ -15,8 +15,8 @@ #include /* Exported function */ -TOLUA_API int tolua_locale_open (lua_State* tolua_S); -LUALIB_API int luaopen_locale (lua_State* tolua_S); +int tolua_locale_open (lua_State* tolua_S); +int luaopen_locale (lua_State* tolua_S); #undef tolua_reg_types #define tolua_reg_types tolua_reg_types_locale @@ -142,7 +142,7 @@ static int tolua_locale_eressea_locale_direction00(lua_State* tolua_S) } /* Open lib function */ -LUALIB_API int luaopen_locale (lua_State* tolua_S) +int luaopen_locale (lua_State* tolua_S) { tolua_open(tolua_S); tolua_reg_types(tolua_S); @@ -162,7 +162,7 @@ LUALIB_API int luaopen_locale (lua_State* tolua_S) return 1; } /* Open tolua function */ -TOLUA_API int tolua_locale_open (lua_State* tolua_S) +int tolua_locale_open (lua_State* tolua_S) { lua_pushcfunction(tolua_S, luaopen_locale); lua_pushstring(tolua_S, "locale"); diff --git a/src/log.pkg.c b/src/log.pkg.c index 4303a5c2d..92e405751 100644 --- a/src/log.pkg.c +++ b/src/log.pkg.c @@ -15,8 +15,8 @@ #include /* Exported function */ -TOLUA_API int tolua_log_open (lua_State* tolua_S); -LUALIB_API int luaopen_log (lua_State* tolua_S); +int tolua_log_open (lua_State* tolua_S); +int luaopen_log (lua_State* tolua_S); #undef tolua_reg_types #define tolua_reg_types tolua_reg_types_log @@ -132,7 +132,7 @@ static int tolua_log_eressea_log_info00(lua_State* tolua_S) } /* Open lib function */ -LUALIB_API int luaopen_log (lua_State* tolua_S) +int luaopen_log (lua_State* tolua_S) { tolua_open(tolua_S); tolua_reg_types(tolua_S); @@ -152,7 +152,7 @@ LUALIB_API int luaopen_log (lua_State* tolua_S) return 1; } /* Open tolua function */ -TOLUA_API int tolua_log_open (lua_State* tolua_S) +int tolua_log_open (lua_State* tolua_S) { lua_pushcfunction(tolua_S, luaopen_log); lua_pushstring(tolua_S, "log"); diff --git a/src/process.pkg.c b/src/process.pkg.c index 3e818f7ce..f739528b7 100644 --- a/src/process.pkg.c +++ b/src/process.pkg.c @@ -7,16 +7,11 @@ #ifndef __cplusplus #include #endif -#ifdef __cplusplus - extern "C" int tolua_bnd_takeownership (lua_State* L); // from tolua_map.c -#else - int tolua_bnd_takeownership (lua_State* L); /* from tolua_map.c */ -#endif #include /* Exported function */ -TOLUA_API int tolua_process_open (lua_State* tolua_S); -LUALIB_API int luaopen_process (lua_State* tolua_S); +int tolua_process_open (lua_State* tolua_S); +int luaopen_process (lua_State* tolua_S); #undef tolua_reg_types #define tolua_reg_types tolua_reg_types_process @@ -942,7 +937,7 @@ static int tolua_process_eressea_process_set_default00(lua_State* tolua_S) } /* Open lib function */ -LUALIB_API int luaopen_process (lua_State* tolua_S) +int luaopen_process (lua_State* tolua_S) { tolua_open(tolua_S); tolua_reg_types(tolua_S); @@ -996,7 +991,7 @@ LUALIB_API int luaopen_process (lua_State* tolua_S) return 1; } /* Open tolua function */ -TOLUA_API int tolua_process_open (lua_State* tolua_S) +int tolua_process_open (lua_State* tolua_S) { lua_pushcfunction(tolua_S, luaopen_process); lua_pushstring(tolua_S, "process"); diff --git a/src/settings.pkg.c b/src/settings.pkg.c index 79ea280cb..fbb3d242d 100644 --- a/src/settings.pkg.c +++ b/src/settings.pkg.c @@ -15,8 +15,8 @@ #include /* Exported function */ -TOLUA_API int tolua_settings_open (lua_State* tolua_S); -LUALIB_API int luaopen_settings (lua_State* tolua_S); +int tolua_settings_open (lua_State* tolua_S); +int luaopen_settings (lua_State* tolua_S); #undef tolua_reg_types #define tolua_reg_types tolua_reg_types_settings @@ -83,7 +83,7 @@ static int tolua_settings_eressea_settings_get00(lua_State* tolua_S) } /* Open lib function */ -LUALIB_API int luaopen_settings (lua_State* tolua_S) +int luaopen_settings (lua_State* tolua_S) { tolua_open(tolua_S); tolua_reg_types(tolua_S); @@ -101,7 +101,7 @@ LUALIB_API int luaopen_settings (lua_State* tolua_S) return 1; } /* Open tolua function */ -TOLUA_API int tolua_settings_open (lua_State* tolua_S) +int tolua_settings_open (lua_State* tolua_S) { lua_pushcfunction(tolua_S, luaopen_settings); lua_pushstring(tolua_S, "settings"); From 35169a3573861c29fc454bf65687ada13624291e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 18:43:20 +0100 Subject: [PATCH 13/24] there is only one repository for tolua now --- s/cmake-init | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/s/cmake-init b/s/cmake-init index c32a40540..8164f866f 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -77,21 +77,16 @@ fi DEST=$(dirname $ROOT)/server -TOLUA_VERSION="5.2" LUA_INCLUDE=/usr/include LUA_DIR=/usr if [ -d /usr/local/include/lua ]; then - TOLUA_VERSION="5.2" LUA_INCLUDE=/usr/local/include/lua elif [ -d /usr/include/lua5.2 ]; then - TOLUA_VERSION="5.2" LUA_INCLUDE=/usr/include/lua5.2 elif [ -d /usr/include/lua5.1 ]; then - TOLUA_VERSION="5.1" LUA_INCLUDE=/usr/include/lua5.1 elif [ -d /usr/local/include/lua5.1 ]; then LUA_DIR=/usr/local - TOLUA_VERSION="5.1" LUA_INCLUDE=/usr/local/include/lua5.1 fi @@ -114,8 +109,8 @@ if [ "$HAVE_TOLUA" = "0" ] || [ -z $path ] ; then echo "tolua is not installed, building from source" cd $ROOT if [ ! -d tolua/include ]; then - echo "fetching tolua ${TOLUA_VERSION} from github..." - git clone https://github.com/ennorehling/tolua-${TOLUA_VERSION}.git tolua + echo "fetching tolua from github..." + git clone https://github.com/ennorehling/tolua.git tolua fi echo "building tolua..." cd tolua From 4cc411d94ca22e375f2714c824cdd9a10af51096 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 09:09:09 +0100 Subject: [PATCH 14/24] update tolua repo if needed --- s/cmake-init | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/s/cmake-init b/s/cmake-init index 8164f866f..884631add 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -106,20 +106,22 @@ HEREDOC path="$(which tolua)" if [ "$HAVE_TOLUA" = "0" ] || [ -z $path ] ; then - echo "tolua is not installed, building from source" - cd $ROOT - if [ ! -d tolua/include ]; then - echo "fetching tolua from github..." - git clone https://github.com/ennorehling/tolua.git tolua - fi - echo "building tolua..." +echo "tolua is not installed, building from source" +cd $ROOT +if [ ! -d tolua/include ]; then + echo "fetching tolua from github..." + git clone https://github.com/ennorehling/tolua.git tolua cd tolua - make - cd - +else + cd tolua + git pull --rebase +fi +echo "building tolua..." +make +cd - cat >> $BUILD/config.cmake < Date: Sun, 14 Feb 2021 11:05:28 +0100 Subject: [PATCH 15/24] include custom version of tolua as a submodule. change how libm and libbsd are detected. --- .gitignore | 1 - .gitmodules | 3 ++ CMakeLists.txt | 24 ++++++------ cmake/Modules/FindToLua.cmake | 73 ----------------------------------- src/CMakeLists.txt | 10 ++++- tolua | 1 + 6 files changed, 25 insertions(+), 87 deletions(-) delete mode 100644 cmake/Modules/FindToLua.cmake create mode 160000 tolua diff --git a/.gitignore b/.gitignore index 1edc125c6..5b1e405be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -tolua/ .vscode/ *.orig eressea.ini diff --git a/.gitmodules b/.gitmodules index 306652a59..4c0b4a9ae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,6 @@ [submodule "clibs"] path = clibs url = https://github.com/ennorehling/clibs +[submodule "tolua"] + path = tolua + url = https://github.com/ennorehling/tolua.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 4447944f6..eae4f2a88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.9) if (WIN32) -FILE(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH ) -FILE(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH ) +file(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH ) +file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH ) endif(WIN32) project (eressea-server C) @@ -21,17 +21,19 @@ include (MSVC) else (MSVC) include (CheckIncludeFile) -CHECK_INCLUDE_FILE(signal.h HAVE_SIGNAL_H) -CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H) -CHECK_INCLUDE_FILE(bsd/string.h HAVE_LIBBSD) +check_include_file(signal.h HAVE_SIGNAL_H) +check_include_file(execinfo.h HAVE_EXECINFO_H) + +include (CheckLibraryExists) +check_library_exists(m sin "" HAVE_LIBM) +check_library_exists(bsd strlcat "" HAVE_LIBBSD) include (CheckFunctionExists) -CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP) +check_function_exists(strdup HAVE_STRDUP) +check_function_exists(strlcat HAVE_STRLCAT) + if (HAVE_LIBBSD) -include (CheckLibraryExists) -CHECK_LIBRARY_EXISTS(bsd strlcat "bsd/string.h" HAVE_STRLCAT) -else (HAVE_LIBBSD) -CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT) + set (HAVE_STRLCAT 1) endif (HAVE_LIBBSD) endif (MSVC) @@ -43,7 +45,6 @@ find_package (SQLite3 REQUIRED) find_package (IniParser REQUIRED) find_package (CJSON REQUIRED) find_package (EXPAT REQUIRED) -find_package (ToLua REQUIRED) if (TOLUA_FOUND) if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") find_package (Lua 5.2 REQUIRED) @@ -54,6 +55,7 @@ endif(TOLUA_FOUND) enable_testing() +add_subdirectory (tolua) add_subdirectory (storage) add_subdirectory (clibs) add_subdirectory (process) diff --git a/cmake/Modules/FindToLua.cmake b/cmake/Modules/FindToLua.cmake deleted file mode 100644 index 92732981b..000000000 --- a/cmake/Modules/FindToLua.cmake +++ /dev/null @@ -1,73 +0,0 @@ -# - Try to find the ToLua library -# Once done this will define -# -# TOLUA_FOUND - System has ToLua -# TOLUA_INCLUDE_DIR - The ToLua include directory -# TOLUA_LIBRARIES - The libraries needed to use ToLua -# TOLUA_DEFINITIONS - Compiler switches required for using ToLua -# TOLUA_EXECUTABLE - The ToLua command line shell -# TOLUA_VERSION_STRING - the version of ToLua found (since CMake 2.8.8) - -#============================================================================= -# Copyright 2006-2009 Kitware, Inc. -# Copyright 2006 Alexander Neundorf -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -# use pkg-config to get the directories and then use these values -# in the find_path() and find_library() calls -find_package(PkgConfig QUIET) -PKG_CHECK_MODULES(PC_TOLUA QUIET ToLua) -set(TOLUA_DEFINITIONS ${PC_TOLUA_CFLAGS_OTHER}) - -find_path(TOLUA_INCLUDE_DIR NAMES tolua.h - HINTS - ${PC_TOLUA_DIR}/include - ${PC_TOLUA_INCLUDEDIR} - ${PC_TOLUA_INCLUDE_DIRS} - ) -find_library(TOLUA_LIBRARY NAMES tolua - HINTS - ${PC_TOLUA_DIR}/lib - ${PC_TOLUA_LIBDIR} - ${PC_TOLUA_LIBRARY_DIRS} - ) -find_program(TOLUA_EXECUTABLE tolua - HINTS - ${PC_TOLUA_DIR}/bin - ${PC_TOLUA_LIBDIR} - ${PC_TOLUA_LIBRARY_DIRS} -) - -SET( TOLUA_LIBRARIES "${TOLUA_LIBRARY}" CACHE STRING "ToLua Libraries") - -if(PC_TOLUA_VERSION) - set(TOLUA_VERSION_STRING ${PC_TOLUA_VERSION}) -elseif(TOLUA_INCLUDE_DIR AND EXISTS "${TOLUA_INCLUDE_DIR}/tolua.h") - file(STRINGS "${TOLUA_INCLUDE_DIR}/tolua.h" tolua_version_str - REGEX "^#define[\t ]+TOLUA_VERSION[\t ]+\".*\"") - - string(REGEX REPLACE "^#define[\t ]+TOLUA_VERSION[\t ]+\"tolua ([^\"]*)\".*" "\\1" - TOLUA_VERSION_STRING "${tolua_version_str}") - unset(tolua_version_str) -else(PC_TOLUA_VERSION) -message(ERROR "TOLUA_VERSION_STRING cannot be determined") -endif(PC_TOLUA_VERSION) - -# handle the QUIETLY and REQUIRED arguments and set TOLUA_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(ToLua - REQUIRED_VARS TOLUA_LIBRARY TOLUA_INCLUDE_DIR TOLUA_EXECUTABLE - VERSION_VAR TOLUA_VERSION_STRING) - -mark_as_advanced(TOLUA_INCLUDE_DIR TOLUA_LIBRARIES TOLUA_EXECUTABLE) - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6307fde41..398452769 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -191,12 +191,18 @@ target_link_libraries(parser ${CRYPTO_LIBRARIES} ) - add_executable(checker ${CHECK_SRC}) target_link_libraries(checker parser) +if (HAVE_LIBBSD) + set (EXTRA_LIBS ${EXTRA_LIBS} bsd) +endif (HAVE_LIBBSD) +if (HAVE_LIBM) + set (EXTRA_LIBS ${EXTRA_LIBS} m) +endif (HAVE_LIBM) + add_library(game ${ERESSEA_SRC}) -target_link_libraries(game parser version) +target_link_libraries(game ${EXTRA_LIBS} parser version) add_executable(eressea ${SERVER_SRC}) if (IWYU_PATH) diff --git a/tolua b/tolua new file mode 160000 index 000000000..e7e8a7c1a --- /dev/null +++ b/tolua @@ -0,0 +1 @@ +Subproject commit e7e8a7c1aa70de807cce14d0e126b4ecad9d3b9a From d119f668168be201609f421a592bef6a94a18b3e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 11:09:28 +0100 Subject: [PATCH 16/24] build with lua 5.3 no need to depend on the old tolua package in apt --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6bf54606..8737c3e58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,7 @@ addons: packages: - libbsd-dev - libdb-dev - - liblua5.1-dev - - libtolua-dev + - liblua5.3-dev - libncurses5-dev - libsqlite3-dev - libexpat1-dev From 0876d19037785419da1d3862faf66eef014d153b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 11:58:19 +0100 Subject: [PATCH 17/24] fix tolua include --- tolua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tolua b/tolua index e7e8a7c1a..e054dd7b9 160000 --- a/tolua +++ b/tolua @@ -1 +1 @@ -Subproject commit e7e8a7c1aa70de807cce14d0e126b4ecad9d3b9a +Subproject commit e054dd7b9280300828343e7007d083ab30b6531e From f18e9d0760e302788542e499551e771f7c1ec040 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 15:07:46 +0100 Subject: [PATCH 18/24] consider newer lua versions --- .travis.yml | 1 + s/cmake-init | 4 ++++ tolua | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8737c3e58..8d8ac72db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ sudo: false language: c +dist: bionic compiler: - gcc - clang diff --git a/s/cmake-init b/s/cmake-init index 884631add..b4c1c6078 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -81,6 +81,10 @@ LUA_INCLUDE=/usr/include LUA_DIR=/usr if [ -d /usr/local/include/lua ]; then LUA_INCLUDE=/usr/local/include/lua +elif [ -d /usr/include/lua5.4 ]; then + LUA_INCLUDE=/usr/include/lua5.4 +elif [ -d /usr/include/lua5.3 ]; then + LUA_INCLUDE=/usr/include/lua5.3 elif [ -d /usr/include/lua5.2 ]; then LUA_INCLUDE=/usr/include/lua5.2 elif [ -d /usr/include/lua5.1 ]; then diff --git a/tolua b/tolua index e054dd7b9..8a658c005 160000 --- a/tolua +++ b/tolua @@ -1 +1 @@ -Subproject commit e054dd7b9280300828343e7007d083ab30b6531e +Subproject commit 8a658c00574f2e4889f2631be167b597b6f087e7 From 1b143d9bbc0869d1d4a7bf6dbfcad89ab9ec27ef Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 16:57:35 +0100 Subject: [PATCH 19/24] try building on ubuntu focal image --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d8ac72db..8d5e50027 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ sudo: false language: c -dist: bionic +dist: focal compiler: - gcc - clang @@ -22,6 +22,3 @@ addons: - luarocks os: - linux -notifications: - slack: - secure: F89aXLWaE125PaJIlETv12jT4EfH6wLXJmGCPZzrN3OcLn2ahDWqjwuzR7lOEDf2nAISmeMPyDZMhEHXLNHAE5qP6lg9yliYQw5hzGmDK9m1xUq/pPEne/b2Y7K3my1mkRZ6n3asbHgSmBWAfCIk1JN8R5Rv+rmbLuWLc+zofts= From bcbef9b039babdf6716f148212cbfdbaa802d257 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 17:07:26 +0100 Subject: [PATCH 20/24] import the inifile builder from iniparser repo --- src/tools/inifile.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/tools/inifile.c diff --git a/src/tools/inifile.c b/src/tools/inifile.c new file mode 100644 index 000000000..e8db63740 --- /dev/null +++ b/src/tools/inifile.c @@ -0,0 +1,81 @@ +#include +#include +#include + +#include + +const char *progname = "inifile"; + +void usage(void) { + fprintf(stdout, "Usage: %s file.ini [add|del] \n", progname); +} + +int main(int argc, char ** argv) { + const char *inifile; + const char *command; + dictionary *ini; + FILE *F; + + inifile = (argc<2) ? 0 : argv[1]; + command = (argc<3) ? 0 : argv[2]; + + if (!inifile) { + fputs("Missing filename.\n", stderr); + usage(); + return 1; + } + if (!command) { + fputs("Missing command.\n", stderr); + usage(); + return 1; + } + ini = iniparser_load(inifile); + if (!ini) { + fprintf(stderr, "could not open %s.\n", inifile); + return 1; + } + if (strcmp(command, "add")==0) { + if (argc==4) { + iniparser_set(ini, argv[3], ""); + } + else if (argc==5) { + iniparser_set(ini, argv[3], argv[4]); + } + else { + fputs("set needs one or two arguments.\n", stderr); + return 1; + } + } + else if (strcmp(command, "get")==0) { + const char * str; + if (argc==4) { + str = iniparser_getstring(ini, argv[3], ""); + } + else if (argc==5) { + str = iniparser_getstring(ini, argv[3], argv[4]); + } + else { + fputs("set needs one or two arguments.\n", stderr); + return 1; + } + fprintf(stdout, "%s\n", str); + } + else if (strcmp(command, "del")==0) { + if (argc<4) { + fputs("del needs one argument.\n", stderr); + return 1; + } + iniparser_unset(ini, argv[3]); + } else { + fprintf(stderr, "unknown command %s.\n", command); + usage(); + return 1; + } + + if ((F=fopen(inifile, "wt"))!=0) { + iniparser_dump_ini(ini, F); + fclose(F); + } + iniparser_freedict(ini); + return 0; +} From 840c0161fb126d669bfe75622d28a4b0f8033597 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 18:27:24 +0100 Subject: [PATCH 21/24] separate stats and log --- src/automate.c | 1 + src/battle.c | 77 ++++++++++++++++++------------------ src/main.c | 17 ++++---- src/monsters.c | 25 ++++++------ src/randenc.c | 6 +-- src/teleport.c | 22 +++++------ src/test_eressea.c | 15 +++---- src/tests.c | 55 +++++++++++++------------- src/util/CMakeLists.txt | 2 + src/util/log.c | 87 ++--------------------------------------- src/util/log.h | 32 ++++++--------- src/util/log.test.c | 1 + src/util/stats.c | 70 +++++++++++++++++++++++++++++++++ src/util/stats.h | 15 +++++++ tolua | 2 +- 15 files changed, 210 insertions(+), 217 deletions(-) create mode 100644 src/util/stats.c create mode 100644 src/util/stats.h diff --git a/src/automate.c b/src/automate.c index e3f5b656a..53ac074a7 100644 --- a/src/automate.c +++ b/src/automate.c @@ -11,6 +11,7 @@ #include "util/keyword.h" #include "util/log.h" +#include "util/stats.h" #include "automate.h" #include "laws.h" diff --git a/src/battle.c b/src/battle.c index 2d45c6df8..ff0544442 100644 --- a/src/battle.c +++ b/src/battle.c @@ -13,48 +13,49 @@ #include "study.h" #include "spy.h" -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include +#include "spells/buildingcurse.h" +#include "spells/regioncurse.h" +#include "spells/unitcurse.h" + +#include "kernel/ally.h" +#include "kernel/alliance.h" +#include "kernel/build.h" +#include "kernel/building.h" +#include "kernel/curse.h" +#include "kernel/equipment.h" +#include "kernel/faction.h" +#include "kernel/group.h" +#include "kernel/item.h" +#include "kernel/messages.h" +#include "kernel/order.h" +#include "kernel/plane.h" +#include "kernel/race.h" +#include "kernel/region.h" +#include "kernel/ship.h" +#include "kernel/terrain.h" +#include "kernel/unit.h" +#include "kernel/spell.h" + +#include "reports.h" /* attributes includes */ -#include -#include -#include +#include "attributes/key.h" +#include "attributes/racename.h" +#include "attributes/otherfaction.h" /* util includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "util/assert.h" +#include "kernel/attrib.h" +#include "util/base36.h" +#include "util/language.h" +#include "util/lists.h" +#include "util/log.h" +#include "util/macros.h" +#include "util/parser.h" +#include "util/strings.h" +#include "util/stats.h" +#include "util/rand.h" +#include "util/rng.h" #include diff --git a/src/main.c b/src/main.c index b937c80fa..aa908b8ea 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,3 @@ -#ifdef _MSC_VER -#include -#endif - #include #include #include @@ -10,6 +6,7 @@ #include #include +#include #include #include @@ -142,9 +139,9 @@ static int get_arg(int argc, char **argv, size_t len, int index, const char **re return index; } -static int verbosity_to_flags(int verbosity) { +static int verbosity_to_flags(int value) { int flags = 0; - switch (verbosity) { + switch (value) { case 0: flags = 0; break; @@ -167,7 +164,7 @@ static int verbosity_to_flags(int verbosity) { static int parse_args(int argc, char **argv) { int i; - int log_stderr, log_flags = 3; + int log_flags = 3; for (i = 1; i != argc; ++i) { char *argi = argv[i]; @@ -245,9 +242,9 @@ static int parse_args(int argc, char **argv) log_open(logfile, log_flags); /* also log to stderr: */ - log_stderr = verbosity_to_flags(verbosity); - if (log_stderr) { - log_to_file(log_stderr | LOG_FLUSH | LOG_BRIEF, stderr); + log_flags = verbosity_to_flags(verbosity); + if (log_flags) { + log_to_file(log_flags | LOG_FLUSH | LOG_BRIEF, stderr); } return 0; } diff --git a/src/monsters.c b/src/monsters.c index 148e6f46d..058d98b9f 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -1,7 +1,3 @@ -#ifdef _MSC_VER -#include -#endif - #include "monsters.h" #include "economy.h" @@ -34,21 +30,22 @@ #include "kernel/unit.h" /* util includes */ -#include +#include "util/base36.h" #include "util/keyword.h" #include "util/language.h" -#include -#include -#include -#include +#include "util/log.h" +#include "util/stats.h" +#include "util/rand.h" +#include "util/rng.h" +#include "util/strings.h" /* attributes includes */ -#include -#include -#include -#include +#include "attributes/hate.h" +#include "attributes/otherfaction.h" +#include "attributes/stealth.h" +#include "attributes/targetregion.h" -#include +#include "spells/regioncurse.h" #include diff --git a/src/randenc.c b/src/randenc.c index 5464f0063..56e53832e 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -1,7 +1,3 @@ -#ifdef _MSC_VER -#include -#endif - #include "randenc.h" #include "chaos.h" @@ -41,7 +37,7 @@ #include "kernel/attrib.h" #include "util/language.h" #include "util/lists.h" -#include "util/log.h" +#include "util/stats.h" #include "util/rand.h" #include "util/message.h" #include "util/rng.h" diff --git a/src/teleport.c b/src/teleport.c index 067764946..486b7bd34 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -1,19 +1,19 @@ -#include -#include #include "teleport.h" /* kernel includes */ -#include -#include -#include -#include -#include -#include -#include +#include "kernel/config.h" +#include "kernel/equipment.h" +#include "kernel/unit.h" +#include "kernel/region.h" +#include "kernel/race.h" +#include "kernel/terrain.h" +#include "kernel/faction.h" +#include "kernel/plane.h" /* util includes */ -#include -#include +#include "util/log.h" +#include "util/stats.h" +#include "util/rng.h" #include "skill.h" #include "monsters.h" diff --git a/src/test_eressea.c b/src/test_eressea.c index 452b847c5..b644bc771 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -1,14 +1,15 @@ -#include -#include -#include +#include "eressea.h" +#include "kernel/config.h" +#include "util/log.h" +#include "util/stats.h" +#include "util/password.h" +#include "util/strings.h" +#include "util/variant.h" + #include #include #include #include -#include -#include -#include -#include #pragma warning(disable: 4210) diff --git a/src/tests.c b/src/tests.c index 9739591c8..7972b3adb 100644 --- a/src/tests.c +++ b/src/tests.c @@ -10,33 +10,34 @@ #include "kernel/callbacks.h" #include "kernel/config.h" #include "kernel/alliance.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "kernel/equipment.h" +#include "kernel/messages.h" +#include "kernel/plane.h" +#include "kernel/region.h" +#include "kernel/terrain.h" +#include "kernel/terrainid.h" +#include "kernel/item.h" +#include "kernel/unit.h" +#include "kernel/order.h" +#include "kernel/race.h" +#include "kernel/faction.h" +#include "kernel/building.h" +#include "kernel/ship.h" +#include "kernel/spell.h" +#include "kernel/spellbook.h" +#include "kernel/terrain.h" + +#include "util/aliases.h" +#include "util/functions.h" +#include "util/keyword.h" +#include "util/language.h" +#include "util/lists.h" +#include "util/message.h" +#include "util/log.h" +#include "util/stats.h" +#include "util/param.h" +#include "util/rand.h" +#include "util/assert.h" #include diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 5a0b57e6b..261086307 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -13,6 +13,7 @@ keyword.test.c language.test.c # lists.test.c # log.test.c +# stats.test.c message.test.c # nrmessage.test.c order_parser.test.c @@ -42,6 +43,7 @@ keyword.c language.c lists.c log.c +stats.c message.c mt19937ar.c nrmessage.c diff --git a/src/util/log.c b/src/util/log.c index 47bf09320..2d91240bb 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -1,4 +1,3 @@ -#include #include "log.h" #include "path.h" @@ -181,6 +180,7 @@ static void log_stdio(void *data, int level, const char *module, const char *for const char *prefix = log_prefix(level); size_t len = strlen(format); + (void)module; fprintf(out, "%s: ", prefix); _log_write(out, codepage, format, args); @@ -208,6 +208,9 @@ static void vlog(log_t *lg, int level, const char *format, va_list args) { static void log_write(int flags, const char *module, const char *format, va_list args) { log_t *lg; + + (void)module; + for (lg = loggers; lg; lg = lg->next) { int level = flags & LOG_LEVELS; if (lg->flags & level) { @@ -263,14 +266,6 @@ void log_info(const char *format, ...) va_end(args); } -void log_printf(FILE * io, const char *format, ...) -{ - va_list args; - va_start(args, format); - log_write(LOG_CPINFO, NULL, format, args); - va_end(args); -} - static FILE *logfile; void log_close(void) @@ -309,77 +304,3 @@ int log_level(log_t * log, int flags) log->flags = flags; return old; } - -static critbit_tree stats = CRITBIT_TREE(); - -int stats_count(const char *stat, int delta) { - void * match; - if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) { - size_t len; - char data[128]; - len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data); - cb_insert(&stats, data, len); - return delta; - } - else { - int *num; - cb_get_kv_ex(match, (void **)&num); - return *num += delta; - } -} - -#if 0 -#define STATS_BATCH 8 -void stats_walk(const char *prefix, void(*callback)(const char *, int, void *), void *udata) { - void *match[STATS_BATCH]; - int n, off = 0; - do { - int i; - n = cb_find_prefix_str(&stats, prefix, match, STATS_BATCH, off); - if (n == 0) { - break; - } - off += n; - for (i = 0; i != n; ++i) { - const void *kv = match[i]; - int *num; - cb_get_kv_ex(kv, &(void *)num); - callback(kv, *num, udata); - } - } while (n == STATS_BATCH); -} -#else - -struct walk_data { - int (*callback)(const char *, int, void *); - void *udata; -}; - -static int walk_cb(void * match, const void * key, size_t keylen, void *udata) { - struct walk_data *data = (struct walk_data *)udata; - int *num; - cb_get_kv_ex(match, (void **)&num); - return data->callback((const char*)match, *num, data->udata); -} - -int stats_walk(const char *prefix, int (*callback)(const char *, int, void *), void *udata) { - struct walk_data data; - data.callback = callback; - data.udata = udata; - return cb_foreach(&stats, prefix, strlen(prefix), walk_cb, &data); -} -#endif - -static int write_cb(const char *key, int val, void *udata) { - FILE * F = (FILE *)udata; - fprintf(F, "%s: %d\n", (const char *)key, val); - return 0; -} - -void stats_write(FILE *F, const char *prefix) { - stats_walk(prefix, write_cb, F); -} - -void stats_close(void) { - cb_clear(&stats); -} diff --git a/src/util/log.h b/src/util/log.h index ce254c406..7d8b2634b 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -1,11 +1,20 @@ -#ifndef H_UTIL_LOG -#define H_UTIL_LOG +#pragma once #ifdef __cplusplus extern "C" { #endif #include #include +#define LOG_CPERROR 0x01 +#define LOG_CPWARNING 0x02 +#define LOG_CPINFO 0x04 +#define LOG_CPDEBUG 0x08 +#define LOG_LEVELS 0x0F +#define LOG_FLUSH 0x10 +#define LOG_BRIEF 0x20 + +#define ERRNO_CHECK() errno_check(__FILE__, __LINE__) + struct log_t; typedef void(*log_fun)(void *data, int level, const char *module, const char *format, va_list args); @@ -22,29 +31,10 @@ extern "C" { void log_warning(const char *format, ...); void log_debug(const char *format, ...); void log_info(const char *format, ...); - void log_printf(FILE * ios, const char *format, ...); void errno_check(const char *file, int line); - int stats_count(const char *stat, int delta); - void stats_write(FILE *F, const char *prefix); - int stats_walk(const char *prefix, int (*callback)(const char *key, int val, void * udata), void *udata); - void stats_close(void); - -#define ERRNO_CHECK() errno_check(__FILE__, __LINE__) - - -#define LOG_CPERROR 0x01 -#define LOG_CPWARNING 0x02 -#define LOG_CPINFO 0x04 -#define LOG_CPDEBUG 0x08 -#define LOG_LEVELS 0x0F -#define LOG_FLUSH 0x10 -#define LOG_BRIEF 0x20 - - extern int log_stderr; #ifdef __cplusplus } #endif -#endif diff --git a/src/util/log.test.c b/src/util/log.test.c index 928ba5660..527776d4b 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -3,6 +3,7 @@ #endif #include "log.h" +#include "stats.h" #include "macros.h" #include diff --git a/src/util/stats.c b/src/util/stats.c new file mode 100644 index 000000000..c203907ec --- /dev/null +++ b/src/util/stats.c @@ -0,0 +1,70 @@ +#include "log.h" + +#include "path.h" +#include "strings.h" +#include "unicode.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static critbit_tree stats = CRITBIT_TREE(); + +int stats_count(const char* stat, int delta) { + void* match; + if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) { + size_t len; + char data[128]; + len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data); + cb_insert(&stats, data, len); + return delta; + } + else { + int* num; + cb_get_kv_ex(match, (void**)&num); + return *num += delta; + } +} + +struct walk_data { + int (*callback)(const char*, int, void*); + void* udata; +}; + +static int walk_cb(void* match, const void* key, size_t keylen, void* udata) { + struct walk_data* data = (struct walk_data*)udata; + int* num; + + (void)key; + (void)keylen; + cb_get_kv_ex(match, (void**)&num); + return data->callback((const char*)match, *num, data->udata); +} + +int stats_walk(const char* prefix, int (*callback)(const char*, int, void*), void* udata) { + struct walk_data data; + data.callback = callback; + data.udata = udata; + return cb_foreach(&stats, prefix, strlen(prefix), walk_cb, &data); +} + +static int write_cb(const char* key, int val, void* udata) { + FILE* F = (FILE*)udata; + fprintf(F, "%s: %d\n", (const char*)key, val); + return 0; +} + +void stats_write(FILE* F, const char* prefix) { + stats_walk(prefix, write_cb, F); +} + +void stats_close(void) { + cb_clear(&stats); +} diff --git a/src/util/stats.h b/src/util/stats.h new file mode 100644 index 000000000..d1a574d00 --- /dev/null +++ b/src/util/stats.h @@ -0,0 +1,15 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif +#include + + int stats_count(const char *stat, int delta); + void stats_write(FILE *F, const char *prefix); + int stats_walk(const char *prefix, int (*callback)(const char *key, int val, void * udata), void *udata); + void stats_close(void); + +#ifdef __cplusplus +} +#endif diff --git a/tolua b/tolua index 8a658c005..c36200dae 160000 --- a/tolua +++ b/tolua @@ -1 +1 @@ -Subproject commit 8a658c00574f2e4889f2631be167b597b6f087e7 +Subproject commit c36200dae924ffb6eab89b802801d807ff96bfd0 From 232c00ae97297b06965edb9628278cb10ea5dccd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 18:51:57 +0100 Subject: [PATCH 22/24] fix the inifile cli editor --- CMakeLists.txt | 1 + s/travis-build | 2 +- src/util/base36.c | 3 +-- tools/CMakeLists.txt | 11 +++++++++++ {src/tools => tools}/atoi36.c | 0 {src/tools => tools}/gethash.c | 0 {src/tools => tools}/inifile.c | 0 {src/tools => tools}/namegen.c | 0 8 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tools/CMakeLists.txt rename {src/tools => tools}/atoi36.c (100%) rename {src/tools => tools}/gethash.c (100%) rename {src/tools => tools}/inifile.c (100%) rename {src/tools => tools}/namegen.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index eae4f2a88..6458e7b5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ endif(TOLUA_FOUND) enable_testing() add_subdirectory (tolua) +add_subdirectory (tools) add_subdirectory (storage) add_subdirectory (clibs) add_subdirectory (process) diff --git a/s/travis-build b/s/travis-build index 7bbfbe85a..e326d7b10 100755 --- a/s/travis-build +++ b/s/travis-build @@ -6,7 +6,7 @@ inifile() { cd $ROOT if [ ! -e eressea.ini ]; then cp conf/eressea.ini . -$BUILD/iniparser/inifile eressea.ini add lua:paths lunit:scripts +$BUILD/tools/inifile eressea.ini add lua:paths lunit:scripts fi } diff --git a/src/util/base36.c b/src/util/base36.c index 85f2cc80d..edec82f62 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -1,10 +1,9 @@ -#include #include "base36.h" #include "log.h" +#include #include #include -#include #include #define USE_STRTOL diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..75746be2c --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.9) +project (tools C) + +add_executable(inifile inifile.c) +target_link_libraries(inifile ${IniParser_LIBRARIES}) +target_include_directories (inifile PRIVATE ${IniParser_INCLUDE_DIRS}) + +add_executable(gethash gethash.c) + +add_executable(atoi36 atoi36.c ${CMAKE_SOURCE_DIR}/src/util/base36.c) +target_include_directories(atoi36 PRIVATE ${CMAKE_SOURCE_DIR}/src/util) diff --git a/src/tools/atoi36.c b/tools/atoi36.c similarity index 100% rename from src/tools/atoi36.c rename to tools/atoi36.c diff --git a/src/tools/gethash.c b/tools/gethash.c similarity index 100% rename from src/tools/gethash.c rename to tools/gethash.c diff --git a/src/tools/inifile.c b/tools/inifile.c similarity index 100% rename from src/tools/inifile.c rename to tools/inifile.c diff --git a/src/tools/namegen.c b/tools/namegen.c similarity index 100% rename from src/tools/namegen.c rename to tools/namegen.c From e96cfcfbfca4e6d995a9d3a5668a644209b9b86c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 20:47:12 +0100 Subject: [PATCH 23/24] fix inifile and tolua builds remove our custom assert header --- src/battle.c | 4 ++-- src/kernel/region.c | 5 ++--- src/kernel/save.c | 1 - src/move.c | 6 +++--- src/spells.c | 4 ++-- src/tests.c | 6 +++--- src/util/assert.h | 7 ------- src/util/base36.c | 4 ++-- src/util/language.c | 2 +- src/util/log.c | 2 -- src/util/translation.c | 4 ++-- src/util/umlaut.c | 2 +- tolua | 2 +- tools/CMakeLists.txt | 5 ++++- 14 files changed, 23 insertions(+), 31 deletions(-) delete mode 100644 src/util/assert.h diff --git a/src/battle.c b/src/battle.c index ff0544442..0d153e525 100644 --- a/src/battle.c +++ b/src/battle.c @@ -44,7 +44,6 @@ #include "attributes/otherfaction.h" /* util includes */ -#include "util/assert.h" #include "kernel/attrib.h" #include "util/base36.h" #include "util/language.h" @@ -60,6 +59,7 @@ #include /* libc includes */ +#include #include #include #include @@ -194,7 +194,7 @@ void battle_message_faction(battle * b, faction * f, struct message *m) assert(f); if (f->battles == NULL || f->battles->r != r) { struct bmsg *bm = (struct bmsg *)calloc(1, sizeof(struct bmsg)); - assert_alloc(bm); + assert(bm); bm->next = f->battles; f->battles = bm; bm->r = r; diff --git a/src/kernel/region.c b/src/kernel/region.c index a3681158e..6fade14fc 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -26,7 +26,6 @@ #include /* util includes */ -#include #include #include #include @@ -698,7 +697,7 @@ void r_setdemand(region * r, const luxury_type * ltype, int value) d = *dp; if (!d) { d = *dp = malloc(sizeof(struct demand)); - assert_alloc(d); + assert(d); d->next = NULL; d->type = ltype; } @@ -763,7 +762,7 @@ int rsettrees(const region * r, int ageclass, int value) region *region_create(int uid) { region *r = (region *)calloc(1, sizeof(region)); - assert_alloc(r); + assert(r); r->uid = uid; rhash_uid(r); return r; diff --git a/src/kernel/save.c b/src/kernel/save.c index 6a55aeb36..f83a87ef8 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -40,7 +40,6 @@ #include /* util includes */ -#include #include #include #include diff --git a/src/move.c b/src/move.c index 0da6e17e0..68b5a4118 100644 --- a/src/move.c +++ b/src/move.c @@ -55,7 +55,6 @@ #include "skill.h" /* util includes */ -#include #include #include #include @@ -70,6 +69,7 @@ #include /* libc includes */ +#include #include #include #include @@ -112,7 +112,7 @@ get_followers(unit * u, region * r, const region_list * route_end, while (a) { if (a->data.v == u) { follower *fnew = (follower *)malloc(sizeof(follower)); - assert_alloc(fnew); + assert(fnew); fnew->uf = uf; fnew->ut = u; fnew->route_end = route_end; @@ -1483,7 +1483,7 @@ static void var_create_regions(arg_regions *dst, const region_list * begin, int assert(size > 0); dst->nregions = size; dst->regions = (region **) malloc(sizeof(region *) * (size_t)size); - assert_alloc(dst->regions); + assert(dst->regions); for (i = 0, rsrc = begin; i != size; rsrc = rsrc->next, ++i) { dst->regions[i] = rsrc->data; } diff --git a/src/spells.c b/src/spells.c index 0433eefa2..e5f1a3b53 100644 --- a/src/spells.c +++ b/src/spells.c @@ -57,7 +57,6 @@ #include /* util includes */ -#include #include #include #include @@ -81,6 +80,7 @@ #include /* libc includes */ +#include #include #include #include @@ -1269,7 +1269,7 @@ add_ironweapon(const struct item_type *type, const struct item_type *rusty, float chance) { iron_weapon *iweapon = malloc(sizeof(iron_weapon)); - assert_alloc(iweapon); + assert(iweapon); iweapon->type = type; iweapon->rusty = rusty; iweapon->chance = chance; diff --git a/src/tests.c b/src/tests.c index 7972b3adb..24d742c9d 100644 --- a/src/tests.c +++ b/src/tests.c @@ -37,10 +37,10 @@ #include "util/stats.h" #include "util/param.h" #include "util/rand.h" -#include "util/assert.h" #include +#include #include #include #include @@ -367,7 +367,7 @@ ship_type * test_create_shiptype(const char * name) stype->damage = 1; if (!stype->construction) { stype->construction = calloc(1, sizeof(construction)); - assert_alloc(stype->construction); + assert(stype->construction); stype->construction->maxsize = 5; stype->construction->minskill = 1; stype->construction->reqsize = 1; @@ -448,7 +448,7 @@ spell * test_create_spell(void) sp = create_spell("testspell"); sp->components = (spell_component *)calloc(4, sizeof(spell_component)); - assert_alloc(sp->components); + assert(sp->components); sp->components[0].amount = 1; sp->components[0].type = get_resourcetype(R_SILVER); sp->components[0].cost = SPC_FIX; diff --git a/src/util/assert.h b/src/util/assert.h deleted file mode 100644 index 79abce73e..000000000 --- a/src/util/assert.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef UTIL_ASSERT_H -#define UTIL_ASSERT_H - -#include - -#define assert_alloc(expr) assert((expr) || !"out of memory") -#endif diff --git a/src/util/base36.c b/src/util/base36.c index edec82f62..dd5c55c79 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -1,7 +1,7 @@ #include "base36.h" -#include "log.h" #include +#include #include #include #include @@ -78,7 +78,7 @@ const char *itoab_r(int i, int base, char *s, size_t len) } } else { - log_error("static buffer exhausted, itoab(%d, %d)", i, base); + fprintf(stderr, "static buffer exhausted, itoab(%d, %d)", i, base); assert(i == 0 || !"itoab: static buffer exhausted"); } } diff --git a/src/util/language.c b/src/util/language.c index 72e7f84f3..131b7078e 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -66,7 +66,7 @@ locale *get_or_create_locale(const char *name) } } *lp = l = (locale *)calloc(1, sizeof(locale)); - assert_alloc(l); + assert(l); l->hashkey = hkey; l->name = str_strdup(name); l->index = nextlocaleindex++; diff --git a/src/util/log.c b/src/util/log.c index 2d91240bb..e8cf0e2fe 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -4,8 +4,6 @@ #include "strings.h" #include "unicode.h" -#include - #include #include #include diff --git a/src/util/translation.c b/src/util/translation.c index 3d794d920..89d83cd24 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -41,7 +41,7 @@ void opstack_push(opstack ** stackp, variant data) opstack *stack = *stackp; if (stack == NULL) { stack = (opstack *)malloc(sizeof(opstack)); - assert_alloc(stack); + assert(stack); stack->size = 2; stack->begin = malloc(sizeof(variant) * stack->size); stack->top = stack->begin; @@ -52,7 +52,7 @@ void opstack_push(opstack ** stackp, variant data) void *tmp; stack->size += stack->size; tmp = realloc(stack->begin, sizeof(variant) * stack->size); - assert_alloc(tmp); + assert(tmp); stack->begin = (variant *)tmp; stack->top = stack->begin + pos; } diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 46e901994..0943e0485 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -176,7 +176,7 @@ void addtoken(tnode ** root, const char *str, variant id) index = lcs % NODEHASHSIZE; #endif ref = (tref *)malloc(sizeof(tref)); - assert_alloc(ref); + assert(ref); ref->wc = lcs; ref->node = node; ++node->refcount; diff --git a/tolua b/tolua index c36200dae..99ac2e060 160000 --- a/tolua +++ b/tolua @@ -1 +1 @@ -Subproject commit c36200dae924ffb6eab89b802801d807ff96bfd0 +Subproject commit 99ac2e060f32e92f378652a2a249f7e535232671 diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 75746be2c..3f60ba3ee 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -7,5 +7,8 @@ target_include_directories (inifile PRIVATE ${IniParser_INCLUDE_DIRS}) add_executable(gethash gethash.c) -add_executable(atoi36 atoi36.c ${CMAKE_SOURCE_DIR}/src/util/base36.c) +add_executable(atoi36 + atoi36.c + ${CMAKE_SOURCE_DIR}/src/util/base36.c + ) target_include_directories(atoi36 PRIVATE ${CMAKE_SOURCE_DIR}/src/util) From 729b31641a5145592903025a9cdf002fad8c803a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Feb 2021 20:56:27 +0100 Subject: [PATCH 24/24] tolua update again --- src/CMakeLists.txt | 2 -- tolua | 2 +- tools/inifile.c | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 398452769..fe90f7822 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,7 +73,6 @@ MACRO(TOLUA_BINDING PKGFILE FILES) ) ENDMACRO(TOLUA_BINDING) -IF(NOT MSVC) TOLUA_BINDING(log.pkg util/log.h) TOLUA_BINDING(locale.pkg bind_locale.h) TOLUA_BINDING(config.pkg bind_config.h) @@ -81,7 +80,6 @@ TOLUA_BINDING(process.pkg bind_process.h) TOLUA_BINDING(game.pkg bind_eressea.h config.h) TOLUA_BINDING(eressea.pkg bind_eressea.h) TOLUA_BINDING(settings.pkg kenel/config.h) -ENDIF() set (PARSER_SRC ${DB_SRC} diff --git a/tolua b/tolua index 99ac2e060..a3dec42d3 160000 --- a/tolua +++ b/tolua @@ -1 +1 @@ -Subproject commit 99ac2e060f32e92f378652a2a249f7e535232671 +Subproject commit a3dec42d329dabcfe0a19c9bba506f7074883dba diff --git a/tools/inifile.c b/tools/inifile.c index e8db63740..357f1dc7f 100644 --- a/tools/inifile.c +++ b/tools/inifile.c @@ -1,3 +1,4 @@ +#define _CRT_SECURE_NO_WARNINGS #include #include #include