diff --git a/putty.h b/putty.h index 13ec4f8f6..82b317b36 100644 --- a/putty.h +++ b/putty.h @@ -145,6 +145,12 @@ enum { URLHACK_UNDERLINE_NEVER }; +enum { + URLHACK_REGEX_CUSTOM = 0, + URLHACK_REGEX_CLASSIC = 1, + URLHACK_REGEX_LIBERAL, +}; + /* * HACK: PuttyTray * Tray options diff --git a/settings.c b/settings.c index e1b075187..6ba84176e 100644 --- a/settings.c +++ b/settings.c @@ -71,6 +71,13 @@ const char* urlhack_default_regex = "|(spotify:[^ ]+:[^ ]+)" ; +const char* urlhack_liberal_regex = + "(" + "([a-zA-Z]+://|[wW][wW][wW]\\.|spotify:|telnet:)" + "[^ '\")>]+" + ")" + ; + /* * Convenience functions to access the backends[] array * (which is only present in tools that manage settings). diff --git a/urlhack.c b/urlhack.c index 4b1f456a7..1a9bab1aa 100644 --- a/urlhack.c +++ b/urlhack.c @@ -1,4 +1,7 @@ #include +#include + +#include "putty.h" #include "urlhack.h" #include "misc.h" #include "puttymem.h" @@ -156,13 +159,28 @@ void urlhack_reset() window_text_current_pos = 0; } -void urlhack_set_regular_expression(const char* expression) +void urlhack_set_regular_expression(int mode, const char* expression) { + const char *to_use; + switch (mode) { + case URLHACK_REGEX_CUSTOM: + to_use = expression; + break; + case URLHACK_REGEX_CLASSIC: + to_use = urlhack_default_regex; + break; + case URLHACK_REGEX_LIBERAL: + to_use = urlhack_liberal_regex; + break; + default: + assert(!"illegal default regex setting"); + } + is_regexp_compiled = 0; urlhack_disabled = 0; set_regerror_func(rtfm); - urlhack_rx = regcomp((char*)(expression)); + urlhack_rx = regcomp((char*)(to_use)); if (urlhack_rx == 0) { urlhack_disabled = 1; @@ -178,7 +196,7 @@ void urlhack_go_find_me_some_hyperlinks(int screen_width) if (urlhack_disabled != 0) return; if (is_regexp_compiled == 0) { - urlhack_set_regular_expression(urlhack_default_regex); + urlhack_set_regular_expression(URLHACK_REGEX_CLASSIC, urlhack_default_regex); } urlhack_link_regions_clear(); diff --git a/windows/urlhack.h b/windows/urlhack.h index 458e51130..ff50ad6ee 100644 --- a/windows/urlhack.h +++ b/windows/urlhack.h @@ -8,6 +8,7 @@ typedef struct { int x0, y0, x1, y1; } text_region; extern const char* urlhack_default_regex; +extern const char* urlhack_liberal_regex; extern int urlhack_mouse_old_x, urlhack_mouse_old_y, urlhack_current_region; void urlhack_reset(); @@ -21,7 +22,7 @@ text_region urlhack_get_link_bounds(int x, int y); void urlhack_add_link_region(int x0, int y0, int x1, int y1); void urlhack_launch_url(const char* app, const wchar_t *url); int urlhack_is_ctrl_pressed(); -void urlhack_set_regular_expression(const char* expression); +void urlhack_set_regular_expression(int mode, const char* expression); void rtfm(const char *error); void urlhack_init(); diff --git a/windows/wincfg.c b/windows/wincfg.c index 3b2b6e783..56319364f 100644 --- a/windows/wincfg.c +++ b/windows/wincfg.c @@ -9,6 +9,7 @@ #include "putty.h" #include "dialog.h" #include "storage.h" +#include "urlhack.h" static void about_handler(union control *ctrl, void *dlg, void *data, int event) @@ -447,18 +448,20 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help, s = ctrl_getset(b, "Window/Hyperlinks", "regexp", "Regular expression"); - ctrl_checkbox(s, "Use the default regular expression", 'r', - HELPCTX(no_help), - conf_checkbox_handler, I(CONF_url_defregex)); + ctrl_radiobuttons(s, "URL selection:", NO_SHORTCUT, 1, + HELPCTX(no_help), + conf_radiobutton_handler, + I(CONF_url_defregex), + "Select sensible URLs", NO_SHORTCUT, I(URLHACK_REGEX_CLASSIC), + "Select nearly any URL", NO_SHORTCUT, I(URLHACK_REGEX_LIBERAL), + "Custom", NO_SHORTCUT, I(URLHACK_REGEX_CUSTOM), + NULL); - ctrl_editbox(s, "or specify your own:", NO_SHORTCUT, 100, + ctrl_editbox(s, "Customise regex:", NO_SHORTCUT, 100, HELPCTX(no_help), conf_editbox_handler, I(CONF_url_regex), I(1)); - ctrl_text(s, "The single white space will be cropped in front of the link, if exists.", - HELPCTX(no_help)); - /* * Windows supports a local-command proxy. This also means we * must adjust the text on the `Telnet command' control. diff --git a/windows/window.c b/windows/window.c index 312b4912a..8de7f6571 100644 --- a/windows/window.c +++ b/windows/window.c @@ -968,9 +968,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) SetMenuInfo(popup_menus[CTXMENU].menu, &mi); } - if (conf_get_int(term->conf, CONF_url_defregex) == 0) { - urlhack_set_regular_expression(conf_get_str(term->conf, CONF_url_regex)); - } + urlhack_set_regular_expression(conf_get_int(term->conf, CONF_url_defregex), + conf_get_str(term->conf, CONF_url_regex)); /* * Set up the initial input locale. @@ -2463,9 +2462,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, MakeWindowTransparent(hwnd, 255); } - if (conf_get_int(conf, CONF_url_defregex) == 0) { - urlhack_set_regular_expression(conf_get_str(conf, CONF_url_regex)); - } + urlhack_set_regular_expression(conf_get_int(term->conf, CONF_url_defregex), + conf_get_str(term->conf, CONF_url_regex)); + term->url_update = TRUE; term_update(term);