Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update actions to use libpcre2 #661

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions .devcontainer/noble-testing/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
"features": {
}
}
2 changes: 1 addition & 1 deletion .github/workflows/build-msys2-nonwizard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-msys2-wizmode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-ubuntu-nonwizard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-ubuntu-wizmode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
permissions:
actions: read
contents: read
Expand All @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'cpp', 'ruby' ]
language: [ 'cpp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

Expand All @@ -35,15 +35,15 @@ 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
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand Down Expand Up @@ -71,6 +71,6 @@ jobs:
run: cmake --build . --config $BUILD_TYPE -- -j 4

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
22 changes: 11 additions & 11 deletions FeLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 $<TARGET_FILE:ivan>
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
Expand Down Expand Up @@ -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})
Expand Down
30 changes: 18 additions & 12 deletions FeLib/Source/sfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

#include <cstdarg>
#include <cctype>
#include <pcre.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>

#include <ctype.h>

Expand Down Expand Up @@ -58,16 +59,16 @@ struct SoundFile
struct SoundInfo
{
std::vector<int> sounds;
std::unique_ptr<pcre*> re = std::unique_ptr<pcre*>(new (pcre*)());
std::unique_ptr<pcre_extra*> extra = std::unique_ptr<pcre_extra*>(new (pcre_extra*)(NULL));

std::unique_ptr<pcre2_code*> re = std::unique_ptr<pcre2_code*>(new (pcre2_code*)(NULL));
std::unique_ptr<pcre2_match_data*> match_data = std::unique_ptr<pcre2_match_data*>(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);
}
};

Expand All @@ -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)
{
Expand Down Expand Up @@ -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<const unsigned char *>(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;
Expand Down Expand Up @@ -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<const unsigned char *>(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;
Expand Down
16 changes: 8 additions & 8 deletions Main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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.
Expand Down
27 changes: 17 additions & 10 deletions Main/Source/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include <vector>
#include <bitset>
#include <ctime>
#include <pcre.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>

#if defined(UNIX) || defined(__DJGPP__)
#include <sys/stat.h>
Expand Down Expand Up @@ -1325,7 +1326,8 @@ int game::RotateMapNotes()
}

std::vector<festring> afsAutoPickupMatch;
pcre *reAutoPickup=NULL;
pcre2_code *reAutoPickup=NULL;
pcre2_match_data *match_data = NULL;
void game::UpdateAutoPickUpMatching() //simple matching syntax
{
afsAutoPickupMatch.clear();
Expand All @@ -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<const unsigned char *>(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<festring> 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<const unsigned char *>(fsName.CStr()), fsName.GetSize(), 0, 0, match_data, 0) >= 0;
}
int game::CheckAutoPickup(square* sqr)
{
Expand Down
1 change: 0 additions & 1 deletion Main/Source/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <cstdarg>
#include <cctype>
#include <pcre.h>

#include "iconf.h"
#include "message.h"
Expand Down
37 changes: 0 additions & 37 deletions cmake/FindPCRE.cmake

This file was deleted.

Loading