mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-24 09:05:48 -04:00
url-mode: use the same key combo for all occurrences of an URL
This commit is contained in:
parent
21a355f38a
commit
11464a65de
1 changed files with 25 additions and 5 deletions
30
url-mode.c
30
url-mode.c
|
|
@ -519,10 +519,13 @@ urls_assign_key_combos(const struct config *conf, url_list_t *urls)
|
||||||
wchar_t *combos[count];
|
wchar_t *combos[count];
|
||||||
generate_key_combos(conf, count, combos);
|
generate_key_combos(conf, count, combos);
|
||||||
|
|
||||||
size_t idx = 0;
|
size_t combo_idx = 0;
|
||||||
|
size_t id_idx = 0;
|
||||||
|
|
||||||
tll_foreach(*urls, it) {
|
tll_foreach(*urls, it) {
|
||||||
bool id_already_seen = false;
|
bool id_already_seen = false;
|
||||||
for (size_t i = 0; i < idx; i++) {
|
|
||||||
|
for (size_t i = 0; i < id_idx; i++) {
|
||||||
if (it->item.id == seen_ids[i]) {
|
if (it->item.id == seen_ids[i]) {
|
||||||
id_already_seen = true;
|
id_already_seen = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -531,13 +534,30 @@ urls_assign_key_combos(const struct config *conf, url_list_t *urls)
|
||||||
|
|
||||||
if (id_already_seen)
|
if (id_already_seen)
|
||||||
continue;
|
continue;
|
||||||
|
seen_ids[id_idx++] = it->item.id;
|
||||||
|
|
||||||
seen_ids[idx] = it->item.id;
|
/*
|
||||||
it->item.key = combos[idx++];
|
* Scan previous URLs, and check if *this* URL matches any of
|
||||||
|
* them; if so, re-use the *same* key combo.
|
||||||
|
*/
|
||||||
|
bool url_already_seen = false;
|
||||||
|
tll_foreach(*urls, it2) {
|
||||||
|
if (&it->item == &it2->item)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (strcmp(it->item.url, it2->item.url) == 0) {
|
||||||
|
it->item.key = xwcsdup(it2->item.key);
|
||||||
|
url_already_seen = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!url_already_seen)
|
||||||
|
it->item.key = combos[combo_idx++];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free combos we didn’t use up */
|
/* Free combos we didn’t use up */
|
||||||
for (size_t i = idx; i < count; i++)
|
for (size_t i = combo_idx; i < count; i++)
|
||||||
free(combos[i]);
|
free(combos[i]);
|
||||||
|
|
||||||
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue