Skip to content

Commit 529f181

Browse files
finduraffinduraf
authored andcommitted
Merge remote-tracking branch 'fejoa/libpcre2' into k8
2 parents 0ac2840 + 758113a commit 529f181

13 files changed

Lines changed: 110 additions & 93 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
3+
"features": {
4+
}
5+
}

.github/workflows/build-msys2-nonwizard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
msystem: MINGW32
1515
release: false
1616
update: false
17-
install: git mingw-w64-i686-gcc make mingw-w64-i686-cmake mingw-w64-i686-libpng mingw-w64-i686-SDL2 mingw-w64-i686-SDL2_mixer
17+
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
1818
- name: CI-Build
1919
run: |
2020
cd D:/a/ivan/ivan

.github/workflows/build-msys2-wizmode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
msystem: MINGW32
1515
release: false
1616
update: false
17-
install: git mingw-w64-i686-gcc make mingw-w64-i686-cmake mingw-w64-i686-libpng mingw-w64-i686-SDL2 mingw-w64-i686-SDL2_mixer
17+
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
1818
- name: Get tag name, print
1919
shell: bash
2020
run: |

.github/workflows/build-ubuntu-nonwizard.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
# well on Windows or Mac. You can convert this to a matrix build if you need
1313
# cross-platform coverage.
1414
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-22.04
1616

1717
steps:
1818
- uses: actions/checkout@v2
@@ -22,11 +22,11 @@ jobs:
2222
# We'll use this as our working directory for all subsequent commands
2323
run: cmake -E make_directory ${{runner.workspace}}/build
2424

25-
- name: Install SDL2
25+
- name: Install dependencies
2626
run: |
2727
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse"
2828
sudo apt-get update -y -qq
29-
sudo apt-get install libsdl2-dev libsdl2-mixer-dev
29+
sudo apt-get install libsdl2-dev libsdl2-mixer-dev libpcre2-dev libpng-dev
3030
3131
- name: Configure CMake
3232
# Use a bash shell so we can use the same syntax for environment variable

.github/workflows/build-ubuntu-wizmode.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
# well on Windows or Mac. You can convert this to a matrix build if you need
1313
# cross-platform coverage.
1414
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-22.04
1616

1717
steps:
1818
- uses: actions/checkout@v2
@@ -22,11 +22,11 @@ jobs:
2222
# We'll use this as our working directory for all subsequent commands
2323
run: cmake -E make_directory ${{runner.workspace}}/build
2424

25-
- name: Install SDL2
25+
- name: Install dependencies
2626
run: |
2727
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse"
2828
sudo apt-get update -y -qq
29-
sudo apt-get install libsdl2-dev libsdl2-mixer-dev
29+
sudo apt-get install libsdl2-dev libsdl2-mixer-dev libpcre2-dev libpng-dev
3030
3131
- name: Configure CMake
3232
# Use a bash shell so we can use the same syntax for environment variable

.github/workflows/codeql.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ env:
1515
jobs:
1616
analyze:
1717
name: Analyze
18-
runs-on: ubuntu-latest
18+
runs-on: ubuntu-22.04
1919
permissions:
2020
actions: read
2121
contents: read
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
language: [ 'cpp', 'ruby' ]
27+
language: [ 'cpp' ]
2828
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
2929
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
3030

@@ -35,15 +35,15 @@ jobs:
3535
- name: Create Build Environment
3636
run: cmake -E make_directory ${{runner.workspace}}/build
3737

38-
- name: Install SDL2
38+
- name: Install dependencies # SDL2, libpcre2
3939
run: |
4040
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse"
4141
sudo apt-get update -y -qq
42-
sudo apt-get install libsdl2-dev libsdl2-mixer-dev
42+
sudo apt-get install libsdl2-dev libsdl2-mixer-dev libpcre2-dev libpng-dev
4343
4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL
46-
uses: github/codeql-action/init@v2
46+
uses: github/codeql-action/init@v3
4747
with:
4848
languages: ${{ matrix.language }}
4949
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -71,6 +71,6 @@ jobs:
7171
run: cmake --build . --config $BUILD_TYPE -- -j 4
7272

7373
- name: Perform CodeQL Analysis
74-
uses: github/codeql-action/analyze@v2
74+
uses: github/codeql-action/analyze@v3
7575
with:
7676
category: "/language:${{matrix.language}}"

FeLib/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
include(FindPkgConfig)
22
if(PKG_CONFIG_FOUND)
3-
pkg_check_modules(PCRE libpcre)
4-
set(PCRE_LIBRARIES ${PCRE_LDFLAGS})
3+
pkg_check_modules(PCRE2 libpcre2-dev)
4+
set(PCRE2_LIBRARIES ${PCRE2_LDFLAGS})
55
endif()
6-
if(NOT PCRE_FOUND)
6+
if(NOT PCRE2_FOUND)
77
if(MSVC)
8-
find_path(PCRE_INCLUDE_DIR NAMES pcre.h)
9-
find_library(PCRE_LIBRARY pcre)
8+
find_path(PCRE2_INCLUDE_DIR NAMES pcre2.h)
9+
find_library(PCRE2_LIBRARY pcre2)
1010
endif()
11-
find_package(PCRE REQUIRED)
12-
add_definitions(${PCRE_DEFINITIONS})
11+
find_package(PCRE2 REQUIRED)
12+
add_definitions(${PCRE2_DEFINITIONS})
1313
endif()
1414

1515
file(GLOB FELIB_SOURCES Include/*.h Source/*.cpp)
@@ -71,7 +71,7 @@ if(MINGW)
7171

7272
install(CODE [[
7373
file(GET_RUNTIME_DEPENDENCIES
74-
LIBRARIES ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${PCRE_LIBRARIES} ${SDL2_mixer_LIBRARY}
74+
LIBRARIES ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${PCRE2_LIBRARIES} ${SDL2_mixer_LIBRARY}
7575
EXECUTABLES $<TARGET_FILE:ivan>
7676
RESOLVED_DEPENDENCIES_VAR _r_deps
7777
UNRESOLVED_DEPENDENCIES_VAR _u_deps
@@ -105,13 +105,13 @@ if(MSVC AND _VCPKG_INSTALLED_DIR)
105105
endif()
106106

107107
target_include_directories(FeLib PUBLIC Include)
108-
target_include_directories(FeLib SYSTEM PUBLIC ${SDL2_INCLUDE_DIR} PRIVATE ${PNG_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIR})
108+
target_include_directories(FeLib SYSTEM PUBLIC ${SDL2_INCLUDE_DIR} PRIVATE ${PNG_INCLUDE_DIRS} ${PCRE2_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIR})
109109
target_include_directories(FeLib PUBLIC ../xbrzscale ../xbrzscale/xbrz)
110110

111111
if((NOT BUILD_SHARED_LIBS) AND BUILD_STATIC_LIBS)
112-
target_link_libraries(FeLib ${PNG_LIBRARIES} ${SDL2_LIBRARIES} ${PCRE_LIBRARIES} ${SDL2_mixer_LIBRARY} -static-libgcc -static-libstdc++)
112+
target_link_libraries(FeLib ${PNG_LIBRARIES} ${SDL2_LIBRARIES} ${PCRE2_LIBRARIES} ${SDL2_mixer_LIBRARY} -static-libgcc -static-libstdc++)
113113
else()
114-
target_link_libraries(FeLib ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${PCRE_LIBRARIES} ${SDL2_mixer_LIBRARY})
114+
target_link_libraries(FeLib ${PNG_LIBRARIES} ${SDL2_LIBRARY} ${PCRE2_LIBRARIES} ${SDL2_mixer_LIBRARY})
115115
endif()
116116

117117
target_compile_options(FeLib PUBLIC ${SDL2_CFLAGS} ${SDL2_CFLAGS_OTHER})

FeLib/Source/sfx.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
#include <cstdarg>
1818
#include <cctype>
19-
#include <pcre.h>
19+
#define PCRE2_CODE_UNIT_WIDTH 8
20+
#include <pcre2.h>
2021

2122
#include <ctype.h>
2223

@@ -58,16 +59,16 @@ struct SoundFile
5859
struct SoundInfo
5960
{
6061
std::vector<int> sounds;
61-
std::unique_ptr<pcre*> re = std::unique_ptr<pcre*>(new (pcre*)());
62-
std::unique_ptr<pcre_extra*> extra = std::unique_ptr<pcre_extra*>(new (pcre_extra*)(NULL));
62+
63+
std::unique_ptr<pcre2_code*> re = std::unique_ptr<pcre2_code*>(new (pcre2_code*)(NULL));
64+
std::unique_ptr<pcre2_match_data*> match_data = std::unique_ptr<pcre2_match_data*>(new pcre2_match_data*(NULL));
6365

6466
SoundInfo() = default;
6567
SoundInfo(SoundInfo&) = delete;
6668
SoundInfo(SoundInfo&&) = default;
6769
~SoundInfo()
6870
{
69-
if(re.get() && *re) free(*re);
70-
if(extra.get() && *extra) pcre_free_study(*extra);
71+
if(re.get() && *re) pcre2_code_free(*re);
7172
}
7273
};
7374

@@ -91,8 +92,8 @@ festring getstr(FILE *f, truth word)
9192
FILE *debf = NULL;
9293
void soundeffects::initSound()
9394
{
94-
const char *error;
95-
int erroffset;
95+
int errorCode;
96+
PCRE2_SIZE erroffset;
9697

9798
if(SoundState == 0)
9899
{
@@ -174,10 +175,15 @@ void soundeffects::initSound()
174175
}
175176

176177
// configure the regex
177-
*si.re = pcre_compile(Pattern.CStr(), 0, &error, &erroffset, NULL);
178-
if(debf && !*si.re) fprintf(debf, "PCRE compilation failed at expression offset %d: %s\n", erroffset, error);
179-
if(*si.re) *si.extra = pcre_study(*si.re, 0, &error);
180-
if(error) *si.extra = NULL;
178+
*si.re = pcre2_compile(reinterpret_cast<const unsigned char *>(Pattern.CStr()), Pattern.GetSize(), 0, &errorCode, &erroffset, NULL);
179+
if(debf && !*si.re) fprintf(debf, "PCRE compilation failed at expression offset %ld: %d\n", erroffset, errorCode);
180+
181+
if (*si.match_data.get() && *si.match_data)
182+
{
183+
pcre2_match_data_free(*si.match_data);
184+
}
185+
186+
*si.match_data = pcre2_match_data_create_from_pattern(*si.re, NULL);
181187

182188
// configure the assigned files, now they are separated with ',' and the filename now accepts spaces.
183189
festring FileName;
@@ -257,7 +263,7 @@ SoundFile* soundeffects::findMatchingSound(festring Buffer)
257263
DBG1(Buffer.CStr());
258264
for(int i = patterns.size() - 1; i >= 0; i--){
259265
if(*patterns[i].re)
260-
if(pcre_exec(*patterns[i].re, *patterns[i].extra, Buffer.CStr(), Buffer.GetSize(), 0, 0, NULL, 0) >= 0){
266+
if(pcre2_match(*patterns[i].re, reinterpret_cast<const unsigned char *>(Buffer.CStr()), Buffer.GetSize(), 0, 0, *patterns[i].match_data, 0) >= 0){
261267
SoundFile* p = &files[patterns[i].sounds[rand() % patterns[i].sounds.size()]];
262268
DBG1(p->filename.CStr());
263269
return p;

Main/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
include(FindPkgConfig)
22
if(PKG_CONFIG_FOUND)
3-
pkg_check_modules(PCRE libpcre)
4-
set(PCRE_LIBRARIES ${PCRE_LDFLAGS})
3+
pkg_check_modules(PCRE2 libpcre2)
4+
set(PCRE2_LIBRARIES ${PCRE2_LDFLAGS})
55
endif()
66
if(NOT PCRE_FOUND)
77
if(MSVC)
8-
find_path(PCRE_INCLUDE_DIR NAMES pcre.h)
9-
find_library(PCRE_LIBRARY pcre)
8+
find_path(PCRE2_INCLUDE_DIR NAMES pcre2.h)
9+
find_library(PCRE2_LIBRARY pcre2)
1010
endif()
11-
find_package(PCRE REQUIRED)
12-
add_definitions(${PCRE_DEFINITIONS})
11+
find_package(PCRE2 REQUIRED)
12+
add_definitions(${PCRE2_DEFINITIONS})
1313
endif()
1414

1515
find_package(SDL2 REQUIRED)
@@ -33,8 +33,8 @@ set_source_files_properties(
3333
PROPERTIES HEADER_FILE_ONLY TRUE)
3434

3535
add_executable(ivan ${IVAN_SOURCES} Resource/Ivan.rc)
36-
target_include_directories(ivan PUBLIC Include ../Felib/Include ../audio ../fantasyname ../FastNoise ${PCRE_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIR})
37-
target_link_libraries(ivan FeLib FeAudio xbrzscale fantasyname fastnoise ${PCRE_LIBRARIES} ${SDL2_mixer_LIBRARY})
36+
target_include_directories(ivan PUBLIC Include ../Felib/Include ../audio ../fantasyname ../FastNoise ${PCRE2_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIR})
37+
target_link_libraries(ivan FeLib FeAudio xbrzscale fantasyname fastnoise ${PCRE2_LIBRARIES} ${SDL2_mixer_LIBRARY})
3838

3939
if(MSVC AND _VCPKG_INSTALLED_DIR)
4040
# Gum solution. Manually copy pcre.dll to where ivan.exe will end up.

Main/Source/game.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#include <vector>
1919
#include <bitset>
2020
#include <ctime>
21-
#include <pcre.h>
21+
#define PCRE2_CODE_UNIT_WIDTH 8
22+
#include <pcre2.h>
2223

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

13271328
std::vector<festring> afsAutoPickupMatch;
1328-
pcre *reAutoPickup=NULL;
1329+
pcre2_code *reAutoPickup=NULL;
1330+
pcre2_match_data *match_data = NULL;
13291331
void game::UpdateAutoPickUpMatching() //simple matching syntax
13301332
{
13311333
afsAutoPickupMatch.clear();
@@ -1341,24 +1343,29 @@ void game::UpdateAutoPickUpMatching() //simple matching syntax
13411343
}else{
13421344
//TODO test regex about: ignoring broken lanterns and bottles, ignore sticks on fire but pickup scrolls on fire
13431345
// static bool bDummyInit = [](){reAutoPickup=NULL;return true;}();
1344-
const char *errMsg;
1345-
int iErrOffset;
1346-
if(reAutoPickup)pcre_free(reAutoPickup);
1347-
reAutoPickup = pcre_compile(
1348-
ivanconfig::GetAutoPickUpMatching().CStr(), //pattern
1346+
int errCode;
1347+
PCRE2_SIZE iErrOffset;
1348+
if(reAutoPickup)pcre2_code_free(reAutoPickup);
1349+
reAutoPickup = pcre2_compile(
1350+
reinterpret_cast<const unsigned char *>(ivanconfig::GetAutoPickUpMatching().CStr()), //pattern
1351+
ivanconfig::GetAutoPickUpMatching().GetSize(), // PCRE2_ZERO_TERMINATED, // indicates the pattern is zero-terminated
13491352
0, //no options
1350-
&errMsg, &iErrOffset,
1353+
&errCode, &iErrOffset,
13511354
0); // default char tables
13521355
if (!reAutoPickup){
13531356
std::vector<festring> afsFullProblems;
1354-
afsFullProblems.push_back(festring(errMsg));
1357+
afsFullProblems.push_back(festring()+"error code:"+errCode);
13551358
afsFullProblems.push_back(festring()+"offset:"+iErrOffset);
13561359
bool bDummy = iosystem::AlertConfirmMsg("regex validation failed, if ignored will just not work at all",afsFullProblems,false);
13571360
}
1361+
match_data = pcre2_match_data_create_from_pattern(reAutoPickup, NULL);
13581362
}
13591363
}
13601364
bool game::IsAutoPickupMatch(cfestring fsName) {
1361-
return pcre_exec(reAutoPickup, 0, fsName.CStr(), fsName.GetSize(), 0, 0, NULL, 0) >= 0;
1365+
if (reAutoPickup == NULL) {
1366+
return false; // pattern not compiled
1367+
}
1368+
return pcre2_match(reAutoPickup, reinterpret_cast<const unsigned char *>(fsName.CStr()), fsName.GetSize(), 0, 0, match_data, 0) >= 0;
13621369
}
13631370
int game::CheckAutoPickup(square* sqr)
13641371
{

0 commit comments

Comments
 (0)