diff --git a/.travis.yml b/.travis.yml index f1e4283..317b952 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/CMake_Modules/FindPCRE.cmake b/CMake_Modules/FindPCRE.cmake deleted file mode 100644 index dbbd60a..0000000 --- a/CMake_Modules/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/appveyor.yml b/appveyor.yml index 4f77997..86fafb8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc98327..8efccfb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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. diff --git a/src/config.h.in b/src/config.h.in index a50a547..fa31591 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -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 diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 559b73f..353ab1c 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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 @@ -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/". diff --git a/src/lib/ec_glob.c b/src/lib/ec_glob.c index a9c655e..3225e56 100644 --- a/src/lib/ec_glob.c +++ b/src/lib/ec_glob.c @@ -29,11 +29,7 @@ #include #include -#ifdef HAVE_PCRE2 #include -#else -#include -#endif #define oom() { return -1; } #include "utarray.h" @@ -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 */ @@ -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; @@ -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 */ { @@ -350,15 +324,9 @@ 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 */ { @@ -366,43 +334,25 @@ int ec_glob(const char *pattern, const char *string) 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)) { @@ -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;