From 53516aceec01779cc62af134f11bd7d9be71fcba Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 20 May 2021 17:58:06 +0200 Subject: config: add url.protocols This makes the protocols recognized by auto-detected URLs configurable. Closes #531 --- url-mode.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index fc1812ae..dc63ebbe 100644 --- a/url-mode.c +++ b/url-mode.c @@ -212,23 +212,9 @@ static void auto_detected(const struct terminal *term, enum url_action action, url_list_t *urls) { - static const wchar_t *const prots[] = { - L"http://", - L"https://", - L"ftp://", - L"ftps://", - L"file://", - L"gemini://", - L"gopher://", - }; - - size_t max_prot_len = 0; - for (size_t i = 0; i < ALEN(prots); i++) { - size_t len = wcslen(prots[i]); - if (len > max_prot_len) - max_prot_len = len; - } + const struct config *conf = term->conf; + size_t max_prot_len = conf->url.max_prot_len; wchar_t proto_chars[max_prot_len]; struct coord proto_start[max_prot_len]; size_t proto_char_count = 0; @@ -266,15 +252,15 @@ auto_detected(const struct terminal *term, enum url_action action, proto_start[max_prot_len - 1] = (struct coord){c, r}; proto_char_count++; - for (size_t i = 0; i < ALEN(prots); i++) { - size_t prot_len = wcslen(prots[i]); + for (size_t i = 0; i < conf->url.prot_count; i++) { + size_t prot_len = wcslen(conf->url.protocols[i]); if (proto_char_count < prot_len) continue; const wchar_t *proto = &proto_chars[max_prot_len - prot_len]; - if (wcsncasecmp(prots[i], proto, prot_len) == 0) { + if (wcsncasecmp(conf->url.protocols[i], proto, prot_len) == 0) { state = STATE_URL; start = proto_start[max_prot_len - prot_len]; -- cgit v1.3