From 7ca68048c4f59019469777a5800e58d040f84a01 Mon Sep 17 00:00:00 2001
From: yuanxing <yuanxing@kylinsec.com.cn>
Date: Tue, 14 Jun 2022 11:18:05 +0800
Subject: [PATCH 1/2] fix url highlighting due to deprecation of
 vte_terminal_match_add_gregex
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 解决由于vte_terminal_match_add_gregex函数废弃的url高亮问题
---
 src/terminal-screen.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 438ecbd..6b946b3 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -45,6 +45,9 @@
 
 #include "eggshell.h"
 
+#define PCRE2_CODE_UNIT_WIDTH 0
+#include <pcre2.h>
+
 #define URL_MATCH_CURSOR  (GDK_HAND2)
 #define SKEY_MATCH_CURSOR (GDK_HAND2)
 
@@ -158,30 +161,30 @@ typedef struct
 {
 	const char *pattern;
 	TerminalURLFlavour flavor;
-	GRegexCompileFlags flags;
+	guint32 flags;
 } TerminalRegexPattern;
 
 static const TerminalRegexPattern url_regex_patterns[] =
 {
-	{ SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, FLAVOR_AS_IS, G_REGEX_CASELESS },
-	{ "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH , FLAVOR_DEFAULT_TO_HTTP, G_REGEX_CASELESS  },
-	{ "(?:callto:|h323:|sip:)" USERCHARS_CLASS "[" USERCHARS ".]*(?:" PORT "/[a-z0-9]+)?\\@" HOST, FLAVOR_VOIP_CALL, G_REGEX_CASELESS  },
-	{ "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, FLAVOR_EMAIL, G_REGEX_CASELESS  },
-	{ "news:[[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", FLAVOR_AS_IS, G_REGEX_CASELESS  },
+	{ SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, FLAVOR_AS_IS, PCRE2_CASELESS },
+	{ "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH , FLAVOR_DEFAULT_TO_HTTP, PCRE2_CASELESS  },
+	{ "(?:callto:|h323:|sip:)" USERCHARS_CLASS "[" USERCHARS ".]*(?:" PORT "/[a-z0-9]+)?\\@" HOST, FLAVOR_VOIP_CALL, PCRE2_CASELESS  },
+	{ "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, FLAVOR_EMAIL, PCRE2_CASELESS  },
+	{ "news:[[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", FLAVOR_AS_IS, PCRE2_CASELESS  },
 };
 
-static GRegex **url_regexes;
+static VteRegex **url_regexes;
 static TerminalURLFlavour *url_regex_flavors;
 static guint n_url_regexes;
 
 #ifdef ENABLE_SKEY
 static const TerminalRegexPattern skey_regex_patterns[] =
 {
-	{ "s/key [[:digit:]]* [-[:alnum:]]*",         FLAVOR_AS_IS },
-	{ "otp-[a-z0-9]* [[:digit:]]* [-[:alnum:]]*", FLAVOR_AS_IS },
+	{ "s/key [[:digit:]]* [-[:alnum:]]*",         FLAVOR_AS_IS, 0 },
+	{ "otp-[a-z0-9]* [[:digit:]]* [-[:alnum:]]*", FLAVOR_AS_IS, 0 },
 };
 
-static GRegex **skey_regexes;
+static VteRegex **skey_regexes;
 static guint n_skey_regexes;
 
 static void  terminal_screen_skey_match_remove (TerminalScreen            *screen);
@@ -357,7 +360,7 @@ terminal_screen_init (TerminalScreen *screen)
 
 		tag_data = g_slice_new (TagData);
 		tag_data->flavor = url_regex_flavors[i];
-		tag_data->tag = vte_terminal_match_add_gregex (terminal, url_regexes[i], 0);
+		tag_data->tag = vte_terminal_match_add_regex (terminal, url_regexes[i], 0);
 		vte_terminal_match_set_cursor_type (terminal, tag_data->tag, URL_MATCH_CURSOR);
 
 		priv->match_tags = g_slist_prepend (priv->match_tags, tag_data);
@@ -583,16 +586,15 @@ terminal_screen_class_init (TerminalScreenClass *klass)
 
 	/* Precompile the regexes */
 	n_url_regexes = G_N_ELEMENTS (url_regex_patterns);
-	url_regexes = g_new0 (GRegex*, n_url_regexes);
+	url_regexes = g_new0 (VteRegex*, n_url_regexes);
 	url_regex_flavors = g_new0 (TerminalURLFlavour, n_url_regexes);
 
 	for (i = 0; i < n_url_regexes; ++i)
 	{
 		GError *error = NULL;
 
-		url_regexes[i] = g_regex_new (url_regex_patterns[i].pattern,
-		                              url_regex_patterns[i].flags | G_REGEX_OPTIMIZE | G_REGEX_MULTILINE,
-		                              0, &error);
+		url_regexes[i] = vte_regex_new_for_match(url_regex_patterns[i].pattern, -1,
+				                         url_regex_patterns[i].flags | PCRE2_MULTILINE, &error);
 		if (error)
 		{
 			g_message ("%s", error->message);
@@ -604,15 +606,14 @@ terminal_screen_class_init (TerminalScreenClass *klass)
 
 #ifdef ENABLE_SKEY
 	n_skey_regexes = G_N_ELEMENTS (skey_regex_patterns);
-	skey_regexes = g_new0 (GRegex*, n_skey_regexes);
+	skey_regexes = g_new0 (VteRegex*, n_skey_regexes);
 
 	for (i = 0; i < n_skey_regexes; ++i)
 	{
 		GError *error = NULL;
 
-		skey_regexes[i] = g_regex_new (skey_regex_patterns[i].pattern,
-		                               G_REGEX_OPTIMIZE | G_REGEX_MULTILINE,
-		                               0, &error);
+		skey_regexes[i] = vte_regex_new_for_match(skey_regex_patterns[i].pattern, -1,
+							  PCRE2_MULTILINE, &error);
 		if (error)
 		{
 			g_message ("%s", error->message);
@@ -1027,7 +1028,7 @@ terminal_screen_profile_notify_cb (TerminalProfile *profile,
 
 				tag_data = g_slice_new (TagData);
 				tag_data->flavor = FLAVOR_SKEY;
-				tag_data->tag = vte_terminal_match_add_gregex (vte_terminal, skey_regexes[i], 0);
+				tag_data->tag = vte_terminal_match_add_regex (vte_terminal, skey_regexes[i], 0);
 				vte_terminal_match_set_cursor_type (vte_terminal, tag_data->tag, SKEY_MATCH_CURSOR);
 
 				priv->match_tags = g_slist_prepend (priv->match_tags, tag_data);
-- 
2.33.0

