diff options
Diffstat (limited to 'sway/criteria.c')
-rw-r--r-- | sway/criteria.c | 44 |
1 files changed, 25 insertions, 19 deletions
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 @@ | |||
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include <strings.h> | 5 | #include <strings.h> |
6 | #include <pcre.h> | 6 | #define PCRE2_CODE_UNIT_WIDTH 8 |
7 | #include <pcre2.h> | ||
7 | #include "sway/criteria.h" | 8 | #include "sway/criteria.h" |
8 | #include "sway/tree/container.h" | 9 | #include "sway/tree/container.h" |
9 | #include "sway/config.h" | 10 | #include "sway/config.h" |
@@ -40,17 +41,19 @@ bool criteria_is_empty(struct criteria *criteria) { | |||
40 | char *error = NULL; | 41 | char *error = NULL; |
41 | 42 | ||
42 | // Returns error string on failure or NULL otherwise. | 43 | // Returns error string on failure or NULL otherwise. |
43 | static bool generate_regex(pcre **regex, char *value) { | 44 | static bool generate_regex(pcre2_code **regex, char *value) { |
44 | const char *reg_err; | 45 | int errorcode; |
45 | int offset; | 46 | PCRE2_SIZE offset; |
46 | |||
47 | *regex = pcre_compile(value, PCRE_UTF8 | PCRE_UCP, ®_err, &offset, NULL); | ||
48 | 47 | ||
48 | *regex = pcre2_compile((PCRE2_SPTR)value, PCRE2_ZERO_TERMINATED, PCRE2_UTF | PCRE2_UCP, &errorcode, &offset, NULL); | ||
49 | if (!*regex) { | 49 | if (!*regex) { |
50 | PCRE2_UCHAR buffer[256]; | ||
51 | pcre2_get_error_message(errorcode, buffer, sizeof(buffer)); | ||
52 | |||
50 | const char *fmt = "Regex compilation for '%s' failed: %s"; | 53 | const char *fmt = "Regex compilation for '%s' failed: %s"; |
51 | int len = strlen(fmt) + strlen(value) + strlen(reg_err) - 3; | 54 | int len = strlen(fmt) + strlen(value) + strlen((char*) buffer) - 3; |
52 | error = malloc(len); | 55 | error = malloc(len); |
53 | snprintf(error, len, fmt, value, reg_err); | 56 | snprintf(error, len, fmt, value, buffer); |
54 | return false; | 57 | return false; |
55 | } | 58 | } |
56 | 59 | ||
@@ -66,7 +69,7 @@ static bool pattern_create(struct pattern **pattern, char *value) { | |||
66 | if (strcmp(value, "__focused__") == 0) { | 69 | if (strcmp(value, "__focused__") == 0) { |
67 | (*pattern)->match_type = PATTERN_FOCUSED; | 70 | (*pattern)->match_type = PATTERN_FOCUSED; |
68 | } else { | 71 | } else { |
69 | (*pattern)->match_type = PATTERN_PCRE; | 72 | (*pattern)->match_type = PATTERN_PCRE2; |
70 | if (!generate_regex(&(*pattern)->regex, value)) { | 73 | if (!generate_regex(&(*pattern)->regex, value)) { |
71 | return false; | 74 | return false; |
72 | }; | 75 | }; |
@@ -77,7 +80,7 @@ static bool pattern_create(struct pattern **pattern, char *value) { | |||
77 | static void pattern_destroy(struct pattern *pattern) { | 80 | static void pattern_destroy(struct pattern *pattern) { |
78 | if (pattern) { | 81 | if (pattern) { |
79 | if (pattern->regex) { | 82 | if (pattern->regex) { |
80 | pcre_free(pattern->regex); | 83 | pcre2_code_free(pattern->regex); |
81 | } | 84 | } |
82 | free(pattern); | 85 | free(pattern); |
83 | } | 86 | } |
@@ -99,8 +102,11 @@ void criteria_destroy(struct criteria *criteria) { | |||
99 | free(criteria); | 102 | free(criteria); |
100 | } | 103 | } |
101 | 104 | ||
102 | static int regex_cmp(const char *item, const pcre *regex) { | 105 | static int regex_cmp(const char *item, const pcre2_code *regex) { |
103 | return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0); | 106 | pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(regex, NULL); |
107 | int result = pcre2_match(regex, (PCRE2_SPTR)item, strlen(item), 0, 0, match_data, NULL); | ||
108 | pcre2_match_data_free(match_data); | ||
109 | return result; | ||
104 | } | 110 | } |
105 | 111 | ||
106 | #if HAVE_XWAYLAND | 112 | #if HAVE_XWAYLAND |
@@ -192,7 +198,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
192 | return false; | 198 | return false; |
193 | } | 199 | } |
194 | break; | 200 | break; |
195 | case PATTERN_PCRE: | 201 | case PATTERN_PCRE2: |
196 | if (regex_cmp(title, criteria->title->regex) != 0) { | 202 | if (regex_cmp(title, criteria->title->regex) != 0) { |
197 | return false; | 203 | return false; |
198 | } | 204 | } |
@@ -212,7 +218,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
212 | return false; | 218 | return false; |
213 | } | 219 | } |
214 | break; | 220 | break; |
215 | case PATTERN_PCRE: | 221 | case PATTERN_PCRE2: |
216 | if (regex_cmp(shell, criteria->shell->regex) != 0) { | 222 | if (regex_cmp(shell, criteria->shell->regex) != 0) { |
217 | return false; | 223 | return false; |
218 | } | 224 | } |
@@ -232,7 +238,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
232 | return false; | 238 | return false; |
233 | } | 239 | } |
234 | break; | 240 | break; |
235 | case PATTERN_PCRE: | 241 | case PATTERN_PCRE2: |
236 | if (regex_cmp(app_id, criteria->app_id->regex) != 0) { | 242 | if (regex_cmp(app_id, criteria->app_id->regex) != 0) { |
237 | return false; | 243 | return false; |
238 | } | 244 | } |
@@ -264,7 +270,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
264 | return false; | 270 | return false; |
265 | } | 271 | } |
266 | break; | 272 | break; |
267 | case PATTERN_PCRE: | 273 | case PATTERN_PCRE2: |
268 | if (regex_cmp(class, criteria->class->regex) != 0) { | 274 | if (regex_cmp(class, criteria->class->regex) != 0) { |
269 | return false; | 275 | return false; |
270 | } | 276 | } |
@@ -284,7 +290,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
284 | return false; | 290 | return false; |
285 | } | 291 | } |
286 | break; | 292 | break; |
287 | case PATTERN_PCRE: | 293 | case PATTERN_PCRE2: |
288 | if (regex_cmp(instance, criteria->instance->regex) != 0) { | 294 | if (regex_cmp(instance, criteria->instance->regex) != 0) { |
289 | return false; | 295 | return false; |
290 | } | 296 | } |
@@ -304,7 +310,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
304 | return false; | 310 | return false; |
305 | } | 311 | } |
306 | break; | 312 | break; |
307 | case PATTERN_PCRE: | 313 | case PATTERN_PCRE2: |
308 | if (regex_cmp(window_role, criteria->window_role->regex) != 0) { | 314 | if (regex_cmp(window_role, criteria->window_role->regex) != 0) { |
309 | return false; | 315 | return false; |
310 | } | 316 | } |
@@ -363,7 +369,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
363 | return false; | 369 | return false; |
364 | } | 370 | } |
365 | break; | 371 | break; |
366 | case PATTERN_PCRE: | 372 | case PATTERN_PCRE2: |
367 | if (regex_cmp(ws->name, criteria->workspace->regex) != 0) { | 373 | if (regex_cmp(ws->name, criteria->workspace->regex) != 0) { |
368 | return false; | 374 | return false; |
369 | } | 375 | } |