diff --git a/.devcontainer/noble-testing/devcontainer.json b/.devcontainer/noble-testing/devcontainer.json new file mode 100644 index 000000000..f20c28a8d --- /dev/null +++ b/.devcontainer/noble-testing/devcontainer.json @@ -0,0 +1,5 @@ +{ + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", + "features": { + } +} diff --git a/.github/workflows/build-msys2-nonwizard.yml b/.github/workflows/build-msys2-nonwizard.yml index 2606c11f3..93c2fb733 100644 --- a/.github/workflows/build-msys2-nonwizard.yml +++ b/.github/workflows/build-msys2-nonwizard.yml @@ -14,7 +14,7 @@ jobs: msystem: MINGW32 release: false update: false - install: git mingw-w64-i686-gcc make mingw-w64-i686-cmake mingw-w64-i686-libpng mingw-w64-i686-SDL2 mingw-w64-i686-SDL2_mixer + install: git mingw-w64-i686-gcc make mingw-w64-i686-cmake mingw-w64-i686-libpng mingw-w64-i686-SDL2 mingw-w64-i686-SDL2_mixer mingw-w64-i686-pcre2 - name: CI-Build run: | cd D:/a/ivan/ivan diff --git a/.github/workflows/build-msys2-wizmode.yml b/.github/workflows/build-msys2-wizmode.yml index 8fb6aca47..2f2e775f8 100644 --- a/.github/workflows/build-msys2-wizmode.yml +++ b/.github/workflows/build-msys2-wizmode.yml @@ -14,7 +14,7 @@ jobs: msystem: MINGW32 release: false update: false - install: git mingw-w64-i686-gcc make mingw-w64-i686-cmake mingw-w64-i686-libpng mingw-w64-i686-SDL2 mingw-w64-i686-SDL2_mixer + install: git mingw-w64-i686-gcc make mingw-w64-i686-cmake mingw-w64-i686-libpng mingw-w64-i686-SDL2 mingw-w64-i686-SDL2_mixer mingw-w64-i686-pcre2 - name: Get tag name, print shell: bash run: | diff --git a/.github/workflows/build-ubuntu-nonwizard.yml b/.github/workflows/build-ubuntu-nonwizard.yml index dc1174917..ad7bacb4b 100644 --- a/.github/workflows/build-ubuntu-nonwizard.yml +++ b/.github/workflows/build-ubuntu-nonwizard.yml @@ -22,11 +22,11 @@ jobs: # We'll use this as our working directory for all subsequent commands run: cmake -E make_directory ${{runner.workspace}}/build - - name: Install SDL2 + - name: Install dependencies run: | sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse" sudo apt-get update -y -qq - sudo apt-get install libsdl2-dev libsdl2-mixer-dev + sudo apt-get install libsdl2-dev libsdl2-mixer-dev libpcre2-dev libpng-dev - name: Configure CMake # Use a bash shell so we can use the same syntax for environment variable diff --git a/.github/workflows/build-ubuntu-wizmode.yml b/.github/workflows/build-ubuntu-wizmode.yml index 9c2a34e27..6791c7e61 100644 --- a/.github/workflows/build-ubuntu-wizmode.yml +++ b/.github/workflows/build-ubuntu-wizmode.yml @@ -22,11 +22,11 @@ jobs: # We'll use this as our working directory for all subsequent commands run: cmake -E make_directory ${{runner.workspace}}/build - - name: Install SDL2 + - name: Install dependencies run: | sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse" sudo apt-get update -y -qq - sudo apt-get install libsdl2-dev libsdl2-mixer-dev + sudo apt-get install libsdl2-dev libsdl2-mixer-dev libpcre2-dev libpng-dev - name: Configure CMake # Use a bash shell so we can use the same syntax for environment variable diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 9210acf9d..548238cf1 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -35,11 +35,11 @@ jobs: - name: Create Build Environment run: cmake -E make_directory ${{runner.workspace}}/build - - name: Install SDL2 + - name: Install dependencies # SDL2, libpcre2 run: | sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse" sudo apt-get update -y -qq - sudo apt-get install libsdl2-dev libsdl2-mixer-dev + sudo apt-get install libsdl2-dev libsdl2-mixer-dev libpcre2-dev libpng-dev # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/FeLib/CMakeLists.txt b/FeLib/CMakeLists.txt index 26e35ae72..8454130a1 100644 --- a/FeLib/CMakeLists.txt +++ b/FeLib/CMakeLists.txt @@ -1,15 +1,15 @@ include(FindPkgConfig) if(PKG_CONFIG_FOUND) - pkg_check_modules(PCRE libpcre) - set(PCRE_LIBRARIES ${PCRE_LDFLAGS}) + pkg_check_modules(PCRE2 libpcre2-dev) + set(PCRE2_LIBRARIES ${PCRE2_LDFLAGS}) endif() -if(NOT PCRE_FOUND) +if(NOT PCRE2_FOUND) if(MSVC) - find_path(PCRE_INCLUDE_DIR NAMES pcre.h) - find_library(PCRE_LIBRARY pcre) + find_path(PCRE2_INCLUDE_DIR NAMES pcre2.h) + find_library(PCRE2_LIBRARY pcre2) endif() - find_package(PCRE REQUIRED) - add_definitions(${PCRE_DEFINITIONS}) + find_package(PCRE2 REQUIRED) + add_definitions(${PCRE2_DEFINITIONS}) endif() file(GLOB FELIB_SOURCES Include/*.h Source/*.cpp) @@ -71,7 +71,7 @@ if(MINGW) install(CODE [[ file(GET_RUNTIME_DEPENDENCIES - LIBRARIES ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${PCRE_LIBRARIES} ${SDL2_mixer_LIBRARY} + LIBRARIES ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${PCRE2_LIBRARIES} ${SDL2_mixer_LIBRARY} EXECUTABLES $ RESOLVED_DEPENDENCIES_VAR _r_deps UNRESOLVED_DEPENDENCIES_VAR _u_deps @@ -105,13 +105,13 @@ if(MSVC AND _VCPKG_INSTALLED_DIR) endif() target_include_directories(FeLib PUBLIC Include) -target_include_directories(FeLib SYSTEM PUBLIC ${SDL2_INCLUDE_DIR} PRIVATE ${PNG_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIR}) +target_include_directories(FeLib SYSTEM PUBLIC ${SDL2_INCLUDE_DIR} PRIVATE ${PNG_INCLUDE_DIRS} ${PCRE2_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIR}) target_include_directories(FeLib PUBLIC ../xbrzscale ../xbrzscale/xbrz) if((NOT BUILD_SHARED_LIBS) AND BUILD_STATIC_LIBS) - target_link_libraries(FeLib ${PNG_LIBRARIES} ${SDL2_LIBRARIES} ${PCRE_LIBRARIES} ${SDL2_mixer_LIBRARY} -static-libgcc -static-libstdc++) + target_link_libraries(FeLib ${PNG_LIBRARIES} ${SDL2_LIBRARIES} ${PCRE2_LIBRARIES} ${SDL2_mixer_LIBRARY} -static-libgcc -static-libstdc++) else() - target_link_libraries(FeLib ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${PCRE_LIBRARIES} ${SDL2_mixer_LIBRARY}) + target_link_libraries(FeLib ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${PCRE2_LIBRARIES} ${SDL2_mixer_LIBRARY}) endif() target_compile_options(FeLib PUBLIC ${SDL2_CFLAGS} ${SDL2_CFLAGS_OTHER}) diff --git a/FeLib/Source/sfx.cpp b/FeLib/Source/sfx.cpp index bd2a6063a..314784887 100644 --- a/FeLib/Source/sfx.cpp +++ b/FeLib/Source/sfx.cpp @@ -16,7 +16,8 @@ #include #include -#include +#define PCRE2_CODE_UNIT_WIDTH 8 +#include #include @@ -58,16 +59,16 @@ struct SoundFile struct SoundInfo { std::vector sounds; - std::unique_ptr re = std::unique_ptr(new (pcre*)()); - std::unique_ptr extra = std::unique_ptr(new (pcre_extra*)(NULL)); + + std::unique_ptr re = std::unique_ptr(new (pcre2_code*)(NULL)); + std::unique_ptr match_data = std::unique_ptr(new pcre2_match_data*(NULL)); SoundInfo() = default; SoundInfo(SoundInfo&) = delete; SoundInfo(SoundInfo&&) = default; ~SoundInfo() { - if(re.get() && *re) free(*re); - if(extra.get() && *extra) pcre_free_study(*extra); + if(re.get() && *re) pcre2_code_free(*re); } }; @@ -91,8 +92,8 @@ festring getstr(FILE *f, truth word) FILE *debf = NULL; void soundeffects::initSound() { - const char *error; - int erroffset; + int errorCode; + PCRE2_SIZE erroffset; if(SoundState == 0) { @@ -174,10 +175,15 @@ void soundeffects::initSound() } // configure the regex - *si.re = pcre_compile(Pattern.CStr(), 0, &error, &erroffset, NULL); - if(debf && !*si.re) fprintf(debf, "PCRE compilation failed at expression offset %d: %s\n", erroffset, error); - if(*si.re) *si.extra = pcre_study(*si.re, 0, &error); - if(error) *si.extra = NULL; + *si.re = pcre2_compile(reinterpret_cast(Pattern.CStr()), Pattern.GetSize(), 0, &errorCode, &erroffset, NULL); + if(debf && !*si.re) fprintf(debf, "PCRE compilation failed at expression offset %ld: %d\n", erroffset, errorCode); + + if (*si.match_data.get() && *si.match_data) + { + pcre2_match_data_free(*si.match_data); + } + + *si.match_data = pcre2_match_data_create_from_pattern(*si.re, NULL); // configure the assigned files, now they are separated with ',' and the filename now accepts spaces. festring FileName; @@ -257,7 +263,7 @@ SoundFile* soundeffects::findMatchingSound(festring Buffer) DBG1(Buffer.CStr()); for(int i = patterns.size() - 1; i >= 0; i--){ if(*patterns[i].re) - if(pcre_exec(*patterns[i].re, *patterns[i].extra, Buffer.CStr(), Buffer.GetSize(), 0, 0, NULL, 0) >= 0){ + if(pcre2_match(*patterns[i].re, reinterpret_cast(Buffer.CStr()), Buffer.GetSize(), 0, 0, *patterns[i].match_data, 0) >= 0){ SoundFile* p = &files[patterns[i].sounds[rand() % patterns[i].sounds.size()]]; DBG1(p->filename.CStr()); return p; diff --git a/Main/CMakeLists.txt b/Main/CMakeLists.txt index 193e505ee..2dfbb618f 100644 --- a/Main/CMakeLists.txt +++ b/Main/CMakeLists.txt @@ -1,15 +1,15 @@ include(FindPkgConfig) if(PKG_CONFIG_FOUND) - pkg_check_modules(PCRE libpcre) - set(PCRE_LIBRARIES ${PCRE_LDFLAGS}) + pkg_check_modules(PCRE2 libpcre2) + set(PCRE2_LIBRARIES ${PCRE2_LDFLAGS}) endif() if(NOT PCRE_FOUND) if(MSVC) - find_path(PCRE_INCLUDE_DIR NAMES pcre.h) - find_library(PCRE_LIBRARY pcre) + find_path(PCRE2_INCLUDE_DIR NAMES pcre2.h) + find_library(PCRE2_LIBRARY pcre2) endif() - find_package(PCRE REQUIRED) - add_definitions(${PCRE_DEFINITIONS}) + find_package(PCRE2 REQUIRED) + add_definitions(${PCRE2_DEFINITIONS}) endif() find_package(SDL2 REQUIRED) @@ -33,8 +33,8 @@ set_source_files_properties( PROPERTIES HEADER_FILE_ONLY TRUE) add_executable(ivan ${IVAN_SOURCES} Resource/Ivan.rc) -target_include_directories(ivan PUBLIC Include ../Felib/Include ../audio ../fantasyname ../FastNoise ${PCRE_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIR}) -target_link_libraries(ivan FeLib FeAudio xbrzscale fantasyname fastnoise ${PCRE_LIBRARIES} ${SDL2_mixer_LIBRARY}) +target_include_directories(ivan PUBLIC Include ../Felib/Include ../audio ../fantasyname ../FastNoise ${PCRE2_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIR}) +target_link_libraries(ivan FeLib FeAudio xbrzscale fantasyname fastnoise ${PCRE2_LIBRARIES} ${SDL2_mixer_LIBRARY}) if(MSVC AND _VCPKG_INSTALLED_DIR) # Gum solution. Manually copy pcre.dll to where ivan.exe will end up. diff --git a/Main/Source/game.cpp b/Main/Source/game.cpp index 321449fd4..9c27c44a8 100644 --- a/Main/Source/game.cpp +++ b/Main/Source/game.cpp @@ -18,7 +18,8 @@ #include #include #include -#include +#define PCRE2_CODE_UNIT_WIDTH 8 +#include #if defined(UNIX) || defined(__DJGPP__) #include @@ -1325,7 +1326,8 @@ int game::RotateMapNotes() } std::vector afsAutoPickupMatch; -pcre *reAutoPickup=NULL; +pcre2_code *reAutoPickup=NULL; +pcre2_match_data *match_data = NULL; void game::UpdateAutoPickUpMatching() //simple matching syntax { afsAutoPickupMatch.clear(); @@ -1341,24 +1343,29 @@ void game::UpdateAutoPickUpMatching() //simple matching syntax }else{ //TODO test regex about: ignoring broken lanterns and bottles, ignore sticks on fire but pickup scrolls on fire // static bool bDummyInit = [](){reAutoPickup=NULL;return true;}(); - const char *errMsg; - int iErrOffset; - if(reAutoPickup)pcre_free(reAutoPickup); - reAutoPickup = pcre_compile( - ivanconfig::GetAutoPickUpMatching().CStr(), //pattern + int errCode; + PCRE2_SIZE iErrOffset; + if(reAutoPickup)pcre2_code_free(reAutoPickup); + reAutoPickup = pcre2_compile( + reinterpret_cast(ivanconfig::GetAutoPickUpMatching().CStr()), //pattern + ivanconfig::GetAutoPickUpMatching().GetSize(), // PCRE2_ZERO_TERMINATED, // indicates the pattern is zero-terminated 0, //no options - &errMsg, &iErrOffset, + &errCode, &iErrOffset, 0); // default char tables if (!reAutoPickup){ std::vector afsFullProblems; - afsFullProblems.push_back(festring(errMsg)); + afsFullProblems.push_back(festring()+"error code:"+errCode); afsFullProblems.push_back(festring()+"offset:"+iErrOffset); bool bDummy = iosystem::AlertConfirmMsg("regex validation failed, if ignored will just not work at all",afsFullProblems,false); } + match_data = pcre2_match_data_create_from_pattern(reAutoPickup, NULL); } } bool game::IsAutoPickupMatch(cfestring fsName) { - return pcre_exec(reAutoPickup, 0, fsName.CStr(), fsName.GetSize(), 0, 0, NULL, 0) >= 0; + if (reAutoPickup == NULL) { + return false; // pattern not compiled + } + return pcre2_match(reAutoPickup, reinterpret_cast(fsName.CStr()), fsName.GetSize(), 0, 0, match_data, 0) >= 0; } int game::CheckAutoPickup(square* sqr) { diff --git a/Main/Source/message.cpp b/Main/Source/message.cpp index 4f587d242..b89b1a4e2 100644 --- a/Main/Source/message.cpp +++ b/Main/Source/message.cpp @@ -16,7 +16,6 @@ #include #include -#include #include "iconf.h" #include "message.h" diff --git a/cmake/FindPCRE.cmake b/cmake/FindPCRE.cmake deleted file mode 100644 index dbbd60ada..000000000 --- a/cmake/FindPCRE.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2007-2009 LuaDist. -# Created by Peter Kapec -# Redistribution and use of this file is allowed according to the terms of the MIT license. -# For details see the COPYRIGHT file distributed with LuaDist. -# Note: -# Searching headers and libraries is very simple and is NOT as powerful as scripts -# distributed with CMake, because LuaDist defines directories to search for. -# Everyone is encouraged to contact the author with improvements. Maybe this file -# becomes part of CMake distribution sometimes. - -# - Find pcre -# Find the native PCRE headers and libraries. -# -# PCRE_INCLUDE_DIRS - where to find pcre.h, etc. -# PCRE_LIBRARIES - List of libraries when using pcre. -# PCRE_FOUND - True if pcre found. - -# Look for the header file. -FIND_PATH(PCRE_INCLUDE_DIR NAMES pcre.h) - -# Look for the library. -FIND_LIBRARY(PCRE_LIBRARY NAMES pcre) - -# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE. -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR) - -# Copy the results to the output variables. -IF(PCRE_FOUND) - SET(PCRE_LIBRARIES ${PCRE_LIBRARY}) - SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR}) -ELSE(PCRE_FOUND) - SET(PCRE_LIBRARIES) - SET(PCRE_INCLUDE_DIRS) -ENDIF(PCRE_FOUND) - -MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES) diff --git a/cmake/FindPCRE2.cmake b/cmake/FindPCRE2.cmake new file mode 100644 index 000000000..d834f2b7a --- /dev/null +++ b/cmake/FindPCRE2.cmake @@ -0,0 +1,37 @@ +# Copyright (C) 2007-2009 LuaDist. +# Created by Peter Kapec +# Redistribution and use of this file is allowed according to the terms of the MIT license. +# For details see the COPYRIGHT file distributed with LuaDist. +# Note: +# Searching headers and libraries is very simple and is NOT as powerful as scripts +# distributed with CMake, because LuaDist defines directories to search for. +# Everyone is encouraged to contact the author with improvements. Maybe this file +# becomes part of CMake distribution sometimes. + +# - Find pcre2 +# Find the native PCRE2 headers and libraries. +# +# PCRE2_INCLUDE_DIRS - where to find pcre2.h, etc. +# PCRE2_LIBRARIES - List of libraries when using pcre2. +# PCRE2_FOUND - True if pcre2 found. + +# Look for the header file. +FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2.h) + +# Look for the library. +FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8) + +# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE. +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR) + +# Copy the results to the output variables. +IF(PCRE2_FOUND) + SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) + SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) +ELSE(PCRE2_FOUND) + SET(PCRE2_LIBRARIES) + SET(PCRE2_INCLUDE_DIRS) +ENDIF(PCRE2_FOUND) + +MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)