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

Replace pcre with pcre2 #6883

Merged
merged 2 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .builds/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ packages:
- mesa-dev
- meson
- pango-dev
- pcre2-dev
- pixman-dev
- scdoc
- wayland-dev
Expand Down
1 change: 1 addition & 0 deletions .builds/archlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages:
- libxkbcommon
- meson
- pango
- pcre2
- scdoc
- wayland
- wayland-protocols
Expand Down
1 change: 1 addition & 0 deletions .builds/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ packages:
- devel/json-c
- devel/libevdev
- devel/meson
- devel/pcre2
- devel/pkgconf
- graphics/cairo
- graphics/gdk-pixbuf2
Expand Down
2 changes: 1 addition & 1 deletion README.de.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.dk.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Installationsafhængigheder:
* [wlroots]
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Instale las dependencias:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Installez les dépendances :
* [wlroots]
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.gr.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sway και wlroots γιά τεστάρισμα ή development.
* [wlroots]
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.hu.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Telepítsd a függőségeket:
* [wlroots]
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.ir.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Swayは沢山のディストリビューションで提供されています。"
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ IRC 채널을 방문하거나 [email protected]으로 이메일을 보내 상담 받
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Install dependencies:
* [wlroots]
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Afhankelijkheden installeren:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Zainstaluj zależności:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Instale as dependências:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.ro.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Dependențe pentru instalare:
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sway и wlroots для тестирования или разработки.
* [wlroots]
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.tr.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Aşağıdaki bağımlılıkları yükleyin:
* [wlroots]
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.uk.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Sway доступний у багатьох дистрибутивах Linux (а
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Sway 在很多发行版中可用. 尝试在你的发行版中安装 "sway" 包.
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
2 changes: 1 addition & 1 deletion README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Sway 在許多發行版都有提供。請自己嘗試於你的發行版安裝
* [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots)
* wayland
* wayland-protocols \*
* pcre
* pcre2
* json-c
* pango
* cairo
Expand Down
7 changes: 4 additions & 3 deletions include/sway/criteria.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
44 changes: 25 additions & 19 deletions sway/criteria.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
};
Expand All @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion sway/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ sway_deps = [
libudev,
math,
pango,
pcre,
pcre2,
glesv2,
pixman,
server_protos,
Expand Down