config: add url.protocols

This makes the protocols recognized by auto-detected URLs
configurable.

Closes #531
This commit is contained in:
Daniel Eklöf 2021-05-20 17:58:06 +02:00
parent 0f483d65ce
commit 53516aceec
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
6 changed files with 85 additions and 19 deletions

View file

@ -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];