Skip to content

Commit

Permalink
Drop support for old PCRE
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Strickroth <[email protected]>
  • Loading branch information
csware authored and xuhdev committed Nov 9, 2018
1 parent ffb01f6 commit d0b1237
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 133 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ addons:

# Settings to try
env:
- OPTIONS="-DCMAKE_BUILD_TYPE=Release -DBUILD_STATICALLY_LINKED_EXE=ON -DPCRE=ON"
- OPTIONS="-DCMAKE_BUILD_TYPE=Release -DBUILD_STATICALLY_LINKED_EXE=OFF -DPCRE=ON"
- OPTIONS="-DCMAKE_BUILD_TYPE=Release -DBUILD_STATICALLY_LINKED_EXE=ON -DPCRE=OFF"
- OPTIONS="-DCMAKE_BUILD_TYPE=Release -DBUILD_STATICALLY_LINKED_EXE=OFF -DPCRE=OFF"
- OPTIONS="-DCMAKE_BUILD_TYPE=Release -DBUILD_STATICALLY_LINKED_EXE=ON"
- OPTIONS="-DCMAKE_BUILD_TYPE=Release -DBUILD_STATICALLY_LINKED_EXE=OFF"

# Run the Build script
script:
Expand Down
37 changes: 0 additions & 37 deletions CMake_Modules/FindPCRE.cmake

This file was deleted.

31 changes: 12 additions & 19 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,30 @@ environment:
CONFIG: Release
ARCH: x64
CMAKE_INSTALL_PREFIX: ..\build
PCRE2_DEST: C:\projects\bin\%ARCH%-static\pcre2
CORE_DEST: C:\projects\bin\%ARCH%-static\core
PCRE_DEST: C:\projects\bin\%ARCH%-static\pcre
matrix:
- USE_PCRE: 1
PCRE_FILENAME: pcre-8.41
- USE_PCRE2: 1
PCRE_FILENAME: pcre2-10.32

install:
- cmake --version
- git submodule init
- git submodule update
- cd C:\projects
# Prepare pcre
- curl -o pcre.zip https://ftp.pcre.org/pub/pcre/%PCRE_FILENAME%.zip
- 7z x -y pcre.zip > nul
- rename %PCRE_FILENAME% pcre
# Build and install PCRE
- mkdir %PCRE_DEST%
- cd %PCRE_DEST%
- if "%USE_PCRE%"=="1" cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" -DPCRE_STATIC_RUNTIME="ON" -DBUILD_SHARED_LIBS="OFF" -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_BUILD_TESTS=OFF C:\projects\pcre
- if "%USE_PCRE2%"=="1" cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" -DPCRE2_STATIC_RUNTIME="ON" -DBUILD_SHARED_LIBS="OFF" -DPCRE2_BUILD_PCRE2GREP="OFF" -DPCRE2_BUILD_TESTS="OFF" C:\projects\pcre
- cd %PCRE_DEST%
- cmake --build %PCRE_DEST% --target install -- /p:Configuration=%CONFIG%
# Download PCRE2 sources
- curl -o pcre2.zip https://ftp.pcre.org/pub/pcre/pcre2-10.32.zip
- 7z x -y pcre2.zip > nul
- rename pcre2-10.32 pcre2
# Build and install PCRE2
- mkdir %PCRE2_DEST%
- cd %PCRE2_DEST%
- cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" -DPCRE2_STATIC_RUNTIME="ON" -DBUILD_SHARED_LIBS="OFF" -DPCRE2_BUILD_PCRE2GREP="OFF" -DPCRE2_BUILD_TESTS="OFF" C:\projects\pcre2
- cd %PCRE2_DEST%
- cmake --build %PCRE2_DEST% --target install -- /p:Configuration=%CONFIG%

build_script:
# Build and install editorconfig-core-c
- mkdir %CORE_DEST%
- cd %CORE_DEST%
- if "%USE_PCRE%"=="1" cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" -DMSVC_MD="OFF" -DPCRE="ON" -DPCRE_STATIC="ON" C:\projects\editorconfig-core-c
- if "%USE_PCRE2%"=="1" cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" -DMSVC_MD="OFF" -DPCRE="OFF" -DPCRE2_STATIC="ON" C:\projects\editorconfig-core-c
- cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" -DMSVC_MD="OFF" -DPCRE2_STATIC="ON" C:\projects\editorconfig-core-c
- cmake --build %CORE_DEST% --target install -- /p:Configuration=%CONFIG%

test_script:
Expand Down
11 changes: 1 addition & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,11 @@
include(CheckFunctionExists)
include(CheckTypeSize)

option(PCRE "Use PCRE instead of PCRE2" ON)
if(NOT PCRE)
find_package(PCRE2 REQUIRED)
else()
find_package(PCRE REQUIRED)
endif()
find_package(PCRE2 REQUIRED)

if(PCRE2_FOUND)
include_directories(BEFORE ${PCRE2_INCLUDE_DIRS})
option(PCRE2_STATIC "Turn this option ON when linking to PCRE2 static library" OFF)
add_compile_definitions(HAVE_PCRE2)
elseif(PCRE_FOUND)
include_directories(BEFORE ${PCRE_INCLUDE_DIRS})
option(PCRE_STATIC "Turn this option ON when linking to PCRE static library" OFF)
endif()

# config.h will be generated in src/auto, we should include it.
Expand Down
6 changes: 0 additions & 6 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,8 @@
#cmakedefine CMAKE_COMPILER_IS_GNUCC
#cmakedefine MSVC

#cmakedefine HAVE_PCRE2

#ifdef HAVE_PCRE2
#cmakedefine PCRE2_STATIC
#define PCRE2_CODE_UNIT_WIDTH 8
#else
#cmakedefine PCRE_STATIC
#endif

/* For gcc, we define _GNU_SOURCE to use gcc extensions */
#ifdef CMAKE_COMPILER_IS_GNUCC
Expand Down
4 changes: 2 additions & 2 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set_target_properties(editorconfig_shared PROPERTIES
if(WIN32)
target_link_libraries(editorconfig_shared Shlwapi)
endif()
target_link_libraries(editorconfig_shared ${PCRE_LIBRARIES} ${PCRE2_LIBRARIES})
target_link_libraries(editorconfig_shared ${PCRE2_LIBRARIES})

add_library(editorconfig_static STATIC ${editorconfig_LIBSRCS})
set_target_properties(editorconfig_static PROPERTIES
Expand All @@ -53,7 +53,7 @@ set_target_properties(editorconfig_static PROPERTIES
if(WIN32)
target_link_libraries(editorconfig_static Shlwapi)
endif()
target_link_libraries(editorconfig_static ${PCRE_LIBRARIES} ${PCRE2_LIBRARIES})
target_link_libraries(editorconfig_static ${PCRE2_LIBRARIES})

# EditorConfig package name for find_package() and the CMake package registry.
# On UNIX the system registry is usually just "lib/cmake/<package>".
Expand Down
55 changes: 0 additions & 55 deletions src/lib/ec_glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@

#include <ctype.h>
#include <string.h>
#ifdef HAVE_PCRE2
#include <pcre2.h>
#else
#include <pcre.h>
#endif

#define oom() { return -1; }
#include "utarray.h"
Expand Down Expand Up @@ -75,21 +71,12 @@ int ec_glob(const char *pattern, const char *string)
char * pcre_str_end;
int brace_level = 0;
_Bool is_in_bracket = 0;
#ifdef HAVE_PCRE2
int error_code;
size_t erroffset;
pcre2_code * re;
int rc;
size_t * pcre_result;
pcre2_match_data * pcre_match_data;
#else
const char * error_msg;
int erroffset;
pcre * re;
int rc;
int * pcre_result;
size_t pcre_result_len;
#endif
char l_pattern[2 * PATTERN_MAX];
_Bool are_brace_paired;
UT_array * nums; /* number ranges */
Expand Down Expand Up @@ -120,13 +107,8 @@ int ec_glob(const char *pattern, const char *string)
}

/* used to search for {num1..num2} case */
#ifdef HAVE_PCRE2
re = pcre2_compile("^\\{[\\+\\-]?\\d+\\.\\.[\\+\\-]?\\d+\\}$", PCRE2_ZERO_TERMINATED, 0,
&error_code, &erroffset, NULL);
#else
re = pcre_compile("^\\{[\\+\\-]?\\d+\\.\\.[\\+\\-]?\\d+\\}$", 0,
&error_msg, &erroffset, NULL);
#endif
if (!re) /* failed to compile */
return -1;

Expand Down Expand Up @@ -267,20 +249,12 @@ int ec_glob(const char *pattern, const char *string)
const char * double_dots;
int_pair pair;

#ifdef HAVE_PCRE2
pcre2_match_data * match_data = pcre2_match_data_create_from_pattern(re, NULL);

/* Check the case of {num1..num2} */
rc = pcre2_match(re, c, cc - c + 1, 0, 0, match_data, NULL);

pcre2_match_data_free(match_data);
#else
int pcre_res[3];

/* Check the case of {num1..num2} */
rc = pcre_exec(re, NULL, c, (int) (cc - c + 1), 0, 0,
pcre_res, 3);
#endif

if (rc < 0) /* not {num1..num2} case */
{
Expand Down Expand Up @@ -350,59 +324,35 @@ int ec_glob(const char *pattern, const char *string)

*(p_pcre ++) = '$';

#ifdef HAVE_PCRE2
pcre2_code_free(re); /* ^\\d+\\.\\.\\d+$ */

re = pcre2_compile(pcre_str, PCRE2_ZERO_TERMINATED, 0, &error_code, &erroffset, NULL);
#else
pcre_free(re); /* ^\\d+\\.\\.\\d+$ */

re = pcre_compile(pcre_str, 0, &error_msg, &erroffset, NULL);
#endif

if (!re) /* failed to compile */
{
utarray_free(nums);
return -1;
}

#ifdef HAVE_PCRE2
pcre_match_data = pcre2_match_data_create_from_pattern(re, NULL);
rc = pcre2_match(re, string, strlen(string), 0, 0, pcre_match_data, NULL);
#else
pcre_result_len = 3 * (utarray_len(nums) + 1);
pcre_result = (int *) calloc(pcre_result_len, sizeof(int_pair));
rc = pcre_exec(re, NULL, string, (int) strlen(string), 0, 0,
pcre_result, pcre_result_len);
#endif

if (rc < 0) /* failed to match */
{
#ifdef HAVE_PCRE2
if (rc == PCRE2_ERROR_NOMATCH)
#else
if (rc == PCRE_ERROR_NOMATCH)
#endif
ret = EC_GLOB_NOMATCH;
else
ret = rc;

#ifdef HAVE_PCRE2
pcre2_code_free(re);
pcre2_match_data_free(pcre_match_data);
#else
pcre_free(re);
free(pcre_result);
#endif
utarray_free(nums);

return ret;
}

/* Whether the numbers are in the desired range? */
#ifdef HAVE_PCRE2
pcre_result = pcre2_get_ovector_pointer(pcre_match_data);
#endif
for(p = (int_pair *) utarray_front(nums), i = 1; p;
++ i, p = (int_pair *) utarray_next(nums, p))
{
Expand All @@ -426,13 +376,8 @@ int ec_glob(const char *pattern, const char *string)
if (p != NULL) /* numbers not matched */
ret = EC_GLOB_NOMATCH;

#ifdef HAVE_PCRE2
pcre2_code_free(re);
pcre2_match_data_free(pcre_match_data);
#else
pcre_free(re);
free(pcre_result);
#endif
utarray_free(nums);

return ret;
Expand Down

0 comments on commit d0b1237

Please sign in to comment.