diff options
-rw-r--r-- | chat.h | 2 | ||||
-rw-r--r-- | input.c | 11 | ||||
-rw-r--r-- | url.c | 13 |
3 files changed, 11 insertions, 15 deletions
diff --git a/chat.h b/chat.h index be1e05b..9961955 100644 --- a/chat.h +++ b/chat.h @@ -141,7 +141,7 @@ void tabReject(void); void urlScan(struct Tag tag, const char *str); void urlList(struct Tag tag); -void urlOpen(struct Tag tag, size_t fromEnd); +void urlOpen(struct Tag tag, size_t at, size_t to); void spawn(char *const argv[]); diff --git a/input.c b/input.c index cb7575f..c2599c1 100644 --- a/input.c +++ b/input.c @@ -90,14 +90,9 @@ static void inputUrl(struct Tag tag, char *params) { urlList(tag); } static void inputOpen(struct Tag tag, char *params) { - if (!params) { urlOpen(tag, 1); return; } - size_t from = strtoul(strsep(¶ms, "-,"), NULL, 0); - if (!params) { urlOpen(tag, from); return; } - size_t to = strtoul(strsep(¶ms, "-,"), NULL, 0); - if (to < from) to = from; - for (size_t i = from; i <= to; ++i) { - urlOpen(tag, i); - } + size_t at = (params ? strtoul(strsep(¶ms, "-,"), NULL, 0) : 1); + size_t to = (params ? strtoul(params, NULL, 0) : at); + urlOpen(tag, at - 1, to); } static void inputView(struct Tag tag, char *params) { diff --git a/url.c b/url.c index b7172ce..3a7628f 100644 --- a/url.c +++ b/url.c @@ -72,14 +72,15 @@ void urlList(struct Tag tag) { } } -void urlOpen(struct Tag tag, size_t fromEnd) { - size_t count = 0; +void urlOpen(struct Tag tag, size_t at, size_t to) { + size_t argc = 1; + char *argv[2 + RING_LEN] = { "open" }; + size_t tagIndex = 0; for (size_t i = 0; i < RING_LEN; ++i) { struct Entry entry = ring.buf[(ring.end - i) & (RING_LEN - 1)]; if (!entry.url || entry.tag != tag.id) continue; - if (++count != fromEnd) continue; - char *argv[] = { "open", entry.url, NULL }; - spawn(argv); - return; + if (tagIndex >= at && tagIndex < to) argv[argc++] = entry.url; + tagIndex++; } + if (argc > 1) spawn(argv); } |