ap

An audio player suited to my tastes
Log | Files | Refs | README | LICENSE

commit 5e0d92c864eb7cd549c78a4f25e38988c6c719b9
parent abd858071695c0c0ba89c078bd7b83ea9d98a1cb
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Mon, 31 May 2021 02:56:40 -0700

Fix and improve seeking

- Use the item incrementing function instead of always going to the
  next item in nextmatch.  Also Don't assume a prefix of plus or
  minus is numerical in find.  This fixes reverse pattern seeking.

- Add the carot prefix for patterns to search from the beginning
  of the queue.

- In findnum use absolute number fixes reverse seeking.

Diffstat:
Mcommand.c | 32+++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/command.c b/command.c @@ -89,7 +89,7 @@ nextmatch(struct item *(*incr)(struct item *), struct item *item, if (len == 0 || !item) return (noneall ? item : NULL); - for (; item; item = item->next) { + for (; item; item = incr(item)) { for (i = 0; i < len; ++i) { if (match(patterns[i], item)) return item; @@ -150,49 +150,55 @@ findnum(struct aps *aps, char *num, char **err) { int n; struct item *(*incr)(struct item *); - struct item *start; + struct item *item; n = strtonum(num, INT_MIN, INT_MAX, err); if (*err) return NULL; incr = item_next; - if (strchr("+-", *num)) { - start = aps->queue.pos; + if (strchr("+-", *num) == NULL) { + item = aps->queue.head; } else { - if (*num == '-') + if (*num == '-') { incr = item_prev; - start = aps->queue.head; + n = -n; + } + item = aps->queue.pos; } *err = enotfound; - return item_seek(incr, start, n); + return item_seek(incr, item, n); } struct item * findpat(struct aps *aps, char *pat, char **err) { struct item *(*incr)(struct item *); + struct item *item; incr = item_next; - if (strchr("+-", *pat)) { + item = aps->queue.pos; + if (strchr("+-^", *pat)) { if (*pat == '-') incr = item_prev; + if (*pat == '^') + item = aps->queue.head; + else if (item) + item = incr(item); ++pat; } *err = enotfound; - return nextmatch(incr, aps->queue.pos, &pat, 1, 0); + return nextmatch(incr, item, &pat, 1, 0); } struct item * find(struct aps *aps, char *exp, char **err) { - struct item *(*incr)(struct item *); - - if (strchr("+-0123456789", *exp)) + if (isdigit(exp[0]) || (strchr("+-", exp[0]) && isdigit(exp[1]))) return findnum(aps, exp, err); - else + else return findpat(aps, exp, err); }