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 f76a3af9c..4c0b4a9ae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +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 [submodule "storage"] path = storage url = https://github.com/ennorehling/storage.git @@ -14,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/.travis.yml b/.travis.yml index b702efaab..8d5e50027 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ sudo: false language: c +dist: focal compiler: - gcc - clang @@ -9,17 +10,15 @@ addons: packages: - libbsd-dev - libdb-dev - - liblua5.1-dev - - libtolua-dev + - liblua5.3-dev - libncurses5-dev - libsqlite3-dev - libexpat1-dev + - libiniparser-dev + - libcjson-dev - valgrind - cppcheck - shellcheck - luarocks os: - linux -notifications: - slack: - secure: F89aXLWaE125PaJIlETv12jT4EfH6wLXJmGCPZzrN3OcLn2ahDWqjwuzR7lOEDf2nAISmeMPyDZMhEHXLNHAE5qP6lg9yliYQw5hzGmDK9m1xUq/pPEne/b2Y7K3my1mkRZ6n3asbHgSmBWAfCIk1JN8R5Rv+rmbLuWLc+zofts= diff --git a/CMakeLists.txt b/CMakeLists.txt index 23796c6c0..6458e7b5a 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) @@ -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,49 +20,44 @@ 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) -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) -find_package (Readline) - -if (ERESSEA_DB STREQUAL "db") -find_package (BerkeleyDB REQUIRED QUIET) -else() -find_package (SQLite3 REQUIRED QUIET) -endif() +if (NOT CURSES_FOUND) +find_package (Curses) +endif (NOT CURSES_FOUND) -find_package(EXPAT REQUIRED) -find_package (ToLua REQUIRED) +find_package (SQLite3 REQUIRED) +find_package (IniParser REQUIRED) +find_package (CJSON REQUIRED) +find_package (EXPAT 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) enable_testing() -add_subdirectory (cJSON) +add_subdirectory (tolua) +add_subdirectory (tools) add_subdirectory (storage) -add_subdirectory (iniparser) add_subdirectory (clibs) add_subdirectory (process) add_subdirectory (src eressea) 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 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/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/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/cmake/Modules/FindIniParser.cmake b/cmake/Modules/FindIniParser.cmake new file mode 100644 index 000000000..7c390fbc8 --- /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 PATH_SUFFIXES iniparser) +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/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 index 910b05cea..58dfcef87 100644 --- a/cmake/Modules/FindSQLite3.cmake +++ b/cmake/Modules/FindSQLite3.cmake @@ -1,63 +1,69 @@ -# - 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) +# 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() -# 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) +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() -mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARIES SQLITE3_EXECUTABLE) 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/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 diff --git a/s/cmake-init b/s/cmake-init index c32a40540..b4c1c6078 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -77,21 +77,20 @@ 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.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 - 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 @@ -111,20 +110,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 ${TOLUA_VERSION} from github..." - git clone https://github.com/ennorehling/tolua-${TOLUA_VERSION}.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 < -#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 "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 /* libc includes */ +#include #include #include #include @@ -193,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/config.pkg.c b/src/config.pkg.c index cc4bb6965..585ec2a55 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 @@ -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 f134b2164..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? */ @@ -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 */ diff --git a/src/eressea.pkg.c b/src/eressea.pkg.c index 289fc323a..2a41eac38 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 @@ -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/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/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/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/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/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/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/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/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"); 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/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..24d742c9d 100644 --- a/src/tests.c +++ b/src/tests.c @@ -10,36 +10,37 @@ #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 +#include #include #include #include @@ -366,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; @@ -447,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/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/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 85f2cc80d..dd5c55c79 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 #include #define USE_STRTOL @@ -79,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/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) 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 47bf09320..e8cf0e2fe 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -1,12 +1,9 @@ -#include #include "log.h" #include "path.h" #include "strings.h" #include "unicode.h" -#include - #include #include #include @@ -181,6 +178,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 +206,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 +264,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 +302,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/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 new file mode 160000 index 000000000..a3dec42d3 --- /dev/null +++ b/tolua @@ -0,0 +1 @@ +Subproject commit a3dec42d329dabcfe0a19c9bba506f7074883dba diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..3f60ba3ee --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,14 @@ +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/tools/inifile.c b/tools/inifile.c new file mode 100644 index 000000000..357f1dc7f --- /dev/null +++ b/tools/inifile.c @@ -0,0 +1,82 @@ +#define _CRT_SECURE_NO_WARNINGS +#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; +} 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 diff --git a/vs2019-build.bat b/vs2019-build.bat index 299778303..82733c683 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" + 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