aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorndren <andreien@ctemplar.com>2022-03-12 13:02:32 +0000
committerGitHub <noreply@github.com>2022-03-12 14:02:32 +0100
commitf614f35e7354980bf4f0a66ca99be9b5f3a7ac90 (patch)
treef21dade3cbddd36c01ccf17eb3ee2bea9a29e909
parent04676936e71f6fccccb098f3232d16572b140902 (diff)
Replace pcre with pcre2
Closes: https://github.com/swaywm/sway/issues/6838
-rw-r--r--.builds/alpine.yml1
-rw-r--r--.builds/archlinux.yml1
-rw-r--r--.builds/freebsd.yml1
-rw-r--r--README.de.md2
-rw-r--r--README.dk.md2
-rw-r--r--README.es.md2
-rw-r--r--README.fr.md2
-rw-r--r--README.gr.md2
-rw-r--r--README.hu.md2
-rw-r--r--README.ir.md2
-rw-r--r--README.ja.md2
-rw-r--r--README.ko.md2
-rw-r--r--README.md2
-rw-r--r--README.nl.md2
-rw-r--r--README.pl.md2
-rw-r--r--README.pt.md2
-rw-r--r--README.ro.md2
-rw-r--r--README.ru.md2
-rw-r--r--README.tr.md2
-rw-r--r--README.uk.md2
-rw-r--r--README.zh-CN.md2
-rw-r--r--README.zh-TW.md2
-rw-r--r--include/sway/criteria.h7
-rw-r--r--meson.build2
-rw-r--r--sway/criteria.c44
-rw-r--r--sway/meson.build2
26 files changed, 53 insertions, 43 deletions
diff --git a/.builds/alpine.yml b/.builds/alpine.yml
index abf636ab..324cf6ce 100644
--- a/.builds/alpine.yml
+++ b/.builds/alpine.yml
@@ -12,6 +12,7 @@ packages:
- mesa-dev
- meson
- pango-dev
+ - pcre2-dev
- pixman-dev
- scdoc
- wayland-dev
diff --git a/.builds/archlinux.yml b/.builds/archlinux.yml
index ac4cdb4d..ac5536e5 100644
--- a/.builds/archlinux.yml
+++ b/.builds/archlinux.yml
@@ -9,6 +9,7 @@ packages:
- libxkbcommon
- meson
- pango
+ - pcre2
- scdoc
- wayland
- wayland-protocols
diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml
index 97e7eccc..aa3007d8 100644
--- a/.builds/freebsd.yml
+++ b/.builds/freebsd.yml
@@ -4,6 +4,7 @@ packages:
- devel/json-c
- devel/libevdev
- devel/meson
+- devel/pcre2
- devel/pkgconf
- graphics/cairo
- graphics/gdk-pixbuf2
diff --git a/README.de.md b/README.de.md
index 01b5e9ad..059fda89 100644
--- a/README.de.md
+++ b/README.de.md
@@ -18,7 +18,7 @@ sway benötigt die folgenden Pakete:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols\*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.dk.md b/README.dk.md
index f712e96b..3a641295 100644
--- a/README.dk.md
+++ b/README.dk.md
@@ -29,7 +29,7 @@ Installationsafhængigheder:
* [wlroots]
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.es.md b/README.es.md
index 7af7d90b..5e598e1a 100644
--- a/README.es.md
+++ b/README.es.md
@@ -28,7 +28,7 @@ Instale las dependencias:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.fr.md b/README.fr.md
index 359a30f9..e99160e8 100644
--- a/README.fr.md
+++ b/README.fr.md
@@ -35,7 +35,7 @@ Installez les dépendances :
* [wlroots]
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.gr.md b/README.gr.md
index 4c30e29d..f325cb88 100644
--- a/README.gr.md
+++ b/README.gr.md
@@ -28,7 +28,7 @@ sway και wlroots γιά τεστάρισμα ή development.
* [wlroots]
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.hu.md b/README.hu.md
index 4e006f25..9e3bc9e1 100644
--- a/README.hu.md
+++ b/README.hu.md
@@ -28,7 +28,7 @@ Telepítsd a függőségeket:
* [wlroots]
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.ir.md b/README.ir.md
index 4542b93b..64956a9e 100644
--- a/README.ir.md
+++ b/README.ir.md
@@ -29,7 +29,7 @@ Patreon با نام کاربری SirCmpwn](https://patreon.com/sircmpwn) مرا
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.ja.md b/README.ja.md
index 786e169c..ece9ce48 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -30,7 +30,7 @@ Swayは沢山のディストリビューションで提供されています。"
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.ko.md b/README.ko.md
index 1086da0c..7a1f4ce1 100644
--- a/README.ko.md
+++ b/README.ko.md
@@ -27,7 +27,7 @@ IRC 채널을 방문하거나 sir@cmpwn.com으로 이메일을 보내 상담 받
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.md b/README.md
index 9c15b491..8e70aef5 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,7 @@ Install dependencies:
* [wlroots]
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.nl.md b/README.nl.md
index c0a93063..8a344f03 100644
--- a/README.nl.md
+++ b/README.nl.md
@@ -28,7 +28,7 @@ Afhankelijkheden installeren:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.pl.md b/README.pl.md
index 6d376b68..ab99abb1 100644
--- a/README.pl.md
+++ b/README.pl.md
@@ -28,7 +28,7 @@ Zainstaluj zależności:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.pt.md b/README.pt.md
index 92a4b54d..b22948aa 100644
--- a/README.pt.md
+++ b/README.pt.md
@@ -30,7 +30,7 @@ Instale as dependências:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.ro.md b/README.ro.md
index f7785b8f..4ce05093 100644
--- a/README.ro.md
+++ b/README.ro.md
@@ -25,7 +25,7 @@ Dependențe pentru instalare:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.ru.md b/README.ru.md
index d563859c..fb6f3344 100644
--- a/README.ru.md
+++ b/README.ru.md
@@ -29,7 +29,7 @@ sway и wlroots для тестирования или разработки.
* [wlroots]
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.tr.md b/README.tr.md
index 5c98a538..e09d2eaf 100644
--- a/README.tr.md
+++ b/README.tr.md
@@ -26,7 +26,7 @@ Aşağıdaki bağımlılıkları yükleyin:
* [wlroots]
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.uk.md b/README.uk.md
index ff9ebec3..d9adcd13 100644
--- a/README.uk.md
+++ b/README.uk.md
@@ -39,7 +39,7 @@ Sway доступний у багатьох дистрибутивах Linux (а
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 561d6c14..e3235f17 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -28,7 +28,7 @@ Sway 在很多发行版中可用. 尝试在你的发行版中安装 "sway" 包.
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/README.zh-TW.md b/README.zh-TW.md
index bc30b903..a7168244 100644
--- a/README.zh-TW.md
+++ b/README.zh-TW.md
@@ -28,7 +28,7 @@ Sway 在許多發行版都有提供。請自己嘗試於你的發行版安裝
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
-* pcre
+* pcre2
* json-c
* pango
* cairo
diff --git a/include/sway/criteria.h b/include/sway/criteria.h
index ad8610cd..59f57f94 100644
--- a/include/sway/criteria.h
+++ b/include/sway/criteria.h
@@ -1,7 +1,8 @@
#ifndef _SWAY_CRITERIA_H
#define _SWAY_CRITERIA_H
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
#include "config.h"
#include "list.h"
#include "tree/view.h"
@@ -15,13 +16,13 @@ enum criteria_type {
};
enum pattern_type {
- PATTERN_PCRE,
+ PATTERN_PCRE2,
PATTERN_FOCUSED,
};
struct pattern {
enum pattern_type match_type;
- pcre *regex;
+ pcre2_code *regex;
};
struct criteria {
diff --git a/meson.build b/meson.build
index 71183007..5bedeb2e 100644
--- a/meson.build
+++ b/meson.build
@@ -45,7 +45,7 @@ subproject(
)
jsonc = dependency('json-c', version: '>=0.13')
-pcre = dependency('libpcre')
+pcre2 = dependency('libpcre2-8')
wayland_server = dependency('wayland-server', version: '>=1.20.0')
wayland_client = dependency('wayland-client')
wayland_cursor = dependency('wayland-cursor')
diff --git a/sway/criteria.c b/sway/criteria.c
index d2a5566f..4711a165 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -3,7 +3,8 @@
#include <stdio.h>
#include <stdbool.h>
#include <strings.h>
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
#include "sway/criteria.h"
#include "sway/tree/container.h"
#include "sway/config.h"
@@ -40,17 +41,19 @@ bool criteria_is_empty(struct criteria *criteria) {
char *error = NULL;
// Returns error string on failure or NULL otherwise.
-static bool generate_regex(pcre **regex, char *value) {
- const char *reg_err;
- int offset;
-
- *regex = pcre_compile(value, PCRE_UTF8 | PCRE_UCP, &reg_err, &offset, NULL);
+static bool generate_regex(pcre2_code **regex, char *value) {
+ int errorcode;
+ PCRE2_SIZE offset;
+ *regex = pcre2_compile((PCRE2_SPTR)value, PCRE2_ZERO_TERMINATED, PCRE2_UTF | PCRE2_UCP, &errorcode, &offset, NULL);
if (!*regex) {
+ PCRE2_UCHAR buffer[256];
+ pcre2_get_error_message(errorcode, buffer, sizeof(buffer));
+
const char *fmt = "Regex compilation for '%s' failed: %s";
- int len = strlen(fmt) + strlen(value) + strlen(reg_err) - 3;
+ int len = strlen(fmt) + strlen(value) + strlen((char*) buffer) - 3;
error = malloc(len);
- snprintf(error, len, fmt, value, reg_err);
+ snprintf(error, len, fmt, value, buffer);
return false;
}
@@ -66,7 +69,7 @@ static bool pattern_create(struct pattern **pattern, char *value) {
if (strcmp(value, "__focused__") == 0) {
(*pattern)->match_type = PATTERN_FOCUSED;
} else {
- (*pattern)->match_type = PATTERN_PCRE;
+ (*pattern)->match_type = PATTERN_PCRE2;
if (!generate_regex(&(*pattern)->regex, value)) {
return false;
};
@@ -77,7 +80,7 @@ static bool pattern_create(struct pattern **pattern, char *value) {
static void pattern_destroy(struct pattern *pattern) {
if (pattern) {
if (pattern->regex) {
- pcre_free(pattern->regex);
+ pcre2_code_free(pattern->regex);
}
free(pattern);
}
@@ -99,8 +102,11 @@ void criteria_destroy(struct criteria *criteria) {
free(criteria);
}
-static int regex_cmp(const char *item, const pcre *regex) {
- return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0);
+static int regex_cmp(const char *item, const pcre2_code *regex) {
+ pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(regex, NULL);
+ int result = pcre2_match(regex, (PCRE2_SPTR)item, strlen(item), 0, 0, match_data, NULL);
+ pcre2_match_data_free(match_data);
+ return result;
}
#if HAVE_XWAYLAND
@@ -192,7 +198,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false;
}
break;
- case PATTERN_PCRE:
+ case PATTERN_PCRE2:
if (regex_cmp(title, criteria->title->regex) != 0) {
return false;
}
@@ -212,7 +218,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false;
}
break;
- case PATTERN_PCRE:
+ case PATTERN_PCRE2:
if (regex_cmp(shell, criteria->shell->regex) != 0) {
return false;
}
@@ -232,7 +238,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false;
}
break;
- case PATTERN_PCRE:
+ case PATTERN_PCRE2:
if (regex_cmp(app_id, criteria->app_id->regex) != 0) {
return false;
}
@@ -264,7 +270,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false;
}
break;
- case PATTERN_PCRE:
+ case PATTERN_PCRE2:
if (regex_cmp(class, criteria->class->regex) != 0) {
return false;
}
@@ -284,7 +290,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false;
}
break;
- case PATTERN_PCRE:
+ case PATTERN_PCRE2:
if (regex_cmp(instance, criteria->instance->regex) != 0) {
return false;
}
@@ -304,7 +310,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false;
}
break;
- case PATTERN_PCRE:
+ case PATTERN_PCRE2:
if (regex_cmp(window_role, criteria->window_role->regex) != 0) {
return false;
}
@@ -363,7 +369,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false;
}
break;
- case PATTERN_PCRE:
+ case PATTERN_PCRE2:
if (regex_cmp(ws->name, criteria->workspace->regex) != 0) {
return false;
}
diff --git a/sway/meson.build b/sway/meson.build
index 8eab31a2..5f34ce6b 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -213,7 +213,7 @@ sway_deps = [
libudev,
math,
pango,
- pcre,
+ pcre2,
glesv2,
pixman,
server_protos,