[gnome-terminal] Revert "screen: Rewrite URL regexes"



commit 01722264d1a8bd96ab234ea2a316bbec8e9443d8
Author: Christian Persch <chpe gnome org>
Date:   Sun Feb 21 15:46:04 2016 +0100

    Revert "screen: Rewrite URL regexes"
    
    This reverts commit 0c9a82e762135437faf591d9c53d056133da4c03.

 src/Makefile.am       |   27 ---------------------------
 src/terminal-screen.c |   33 +++++++++++++++++++++++----------
 2 files changed, 23 insertions(+), 37 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 17f55e9..3e5315b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,8 +6,6 @@ bin_PROGRAMS = gnome-terminal
 libexec_PROGRAMS = gnome-terminal-server
 noinst_PROGRAMS =
 
-check_PROGRAMS = terminal-regex
-
 if WITH_NAUTILUS_EXTENSION
 nautilusextension_LTLIBRARIES = libterminal-nautilus.la
 endif # WITH_NAUTILUS_EXTENSION
@@ -63,7 +61,6 @@ gnome_terminal_server_SOURCES = \
        terminal-prefs.h \
        terminal-profiles-list.c \
        terminal-profiles-list.h \
-       terminal-regex.h \
        terminal-schemas.h \
        terminal-settings-list.c \
        terminal-settings-list.h \
@@ -153,30 +150,6 @@ terminal-gdbus-generated.c terminal-gdbus-generated.h: org.gnome.Terminal.xml Ma
 terminal-resources.h terminal-resources.c: terminal.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) 
--generate-dependencies --sourcedir $(srcdir) $(srcdir)/terminal.gresource.xml)
        $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate 
--c-name terminal $<
 
-# Checks
-
-TESTS = \
-       terminal-regex \
-       $(NULL)
-
-# Check programmes
-
-terminal_regex_CPPFLAGS = \
-       $(AM_CPPFLAGS)
-terminal_regex_SOURCES = \
-       terminal-regex.c \
-       terminal-regex.h \
-       $(NULL)
-terminal_regex_CFLAGS = \
-       -DTERMINAL_REGEX_MAIN \
-       $(TERM_CFLAGS) \
-       $(WARN_CFLAGS) \
-       $(AM_CFLAGS)
-terminal_regex_LDFLAGS = \
-       $(AM_LDFLAGS)
-terminal_regex_LDADD = \
-       $(TERM_LIBS)
-
 # Terminal client
 
 if ENABLE_GTERMINAL
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 33a34ab..97854ad 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -23,7 +23,6 @@
 #include "terminal-pcre2.h"
 #endif
 
-#include "terminal-regex.h"
 #include "terminal-screen.h"
 
 #include <errno.h>
@@ -166,22 +165,34 @@ static void terminal_screen_set_override_command (TerminalScreen  *screen,
 
 static guint signals[LAST_SIGNAL];
 
+#define USERCHARS "-[:alnum:]"
+#define USERCHARS_CLASS "[" USERCHARS "]"
+#define PASSCHARS_CLASS "[-[:alnum:]\\Q,?;.:/!%$^*&~\"#'\\E]"
+#define HOSTCHARS_CLASS "[-[:alnum:]]"
+#define HOST HOSTCHARS_CLASS "+(\\." HOSTCHARS_CLASS "+)*"
+#define PORT "(?:\\:[[:digit:]]{1,5})?"
+#define PATHCHARS_CLASS "[-[:alnum:]\\Q_$.+!*,:;@&=?/~#%\\E]"
+#define PATHTERM_CLASS "[^\\Q]'.:}>) \t\r\n,\"\\E]"
+#define SCHEME "(?:news:|telnet:|nntp:|file:\\/|https?:|ftps?:|sftp:|webcal:)"
+#define USERPASS USERCHARS_CLASS "+(?:" PASSCHARS_CLASS "+)?"
+#define URLPATH   
"(?:(/"PATHCHARS_CLASS"+(?:[(]"PATHCHARS_CLASS"*[)])*"PATHCHARS_CLASS"*)*"PATHTERM_CLASS")?"
+
 typedef struct {
   const char *pattern;
   TerminalURLFlavor flavor;
+  gboolean caseless;
 } TerminalRegexPattern;
 
 static const TerminalRegexPattern url_regex_patterns[] = {
-  { REGEX_URL_AS_IS, FLAVOR_AS_IS },
-  { REGEX_URL_HTTP,  FLAVOR_DEFAULT_TO_HTTP },
-  { REGEX_URL_FILE,  FLAVOR_AS_IS },
-  { REGEX_URL_VOIP,  FLAVOR_VOIP_CALL },
-  { REGEX_EMAIL,     FLAVOR_EMAIL },
-  { REGEX_NEWS_MAN,  FLAVOR_AS_IS },
+  { SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, FLAVOR_AS_IS, TRUE },
+  { "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH , FLAVOR_DEFAULT_TO_HTTP, TRUE  },
+  { "(?:callto:|h323:|sip:)" USERCHARS_CLASS "[" USERCHARS ".]*(?:" PORT "/[a-z0-9]+)?\\@" HOST, 
FLAVOR_VOIP_CALL, TRUE },
+  { "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, FLAVOR_EMAIL, TRUE },
+  { "(?:news:|man:|info:)[-[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", FLAVOR_AS_IS, TRUE },
 };
 
 static const TerminalRegexPattern extra_regex_patterns[] = {
-  { "(0[Xx][[:xdigit:]]+|[[:digit:]]+)", FLAVOR_NUMBER },
+  { "(0[Xx][[:xdigit:]]+|[[:digit:]]+)", FLAVOR_NUMBER, FALSE },
 };
 
 #ifdef WITH_PCRE2
@@ -245,7 +256,8 @@ precompile_regexes (const TerminalRegexPattern *regex_patterns,
 
 #ifdef WITH_PCRE2
       (*regexes)[i] = vte_regex_new (regex_patterns[i].pattern, -1,
-                                     PCRE2_UTF | PCRE2_NO_UTF_CHECK | PCRE2_MULTILINE,
+                                     PCRE2_UTF | PCRE2_NO_UTF_CHECK | PCRE2_MULTILINE |
+                                     (regex_patterns[i].caseless ? PCRE2_CASELESS : 0),
                                      &error);
       g_assert_no_error (error);
 
@@ -257,7 +269,8 @@ precompile_regexes (const TerminalRegexPattern *regex_patterns,
 #else
       (*regexes)[i] = g_regex_new (regex_patterns[i].pattern,
                                    G_REGEX_OPTIMIZE |
-                                   G_REGEX_MULTILINE,
+                                   G_REGEX_MULTILINE |
+                                   (regex_patterns[i].caseless ? G_REGEX_CASELESS : 0),
                                    0, &error);
       g_assert_no_error (error);
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]