commit 1b06df55ce7be4e6995e57db829aee9dc437966e
parent 9ef656bdf236bf0813cf5178181a8c67065fcc43
Author: Jacob R. Edwards <n/a>
Date: Mon, 3 Oct 2022 14:21:00 -0700
Fix seeking behavior
If the first item found is the current one, use the next match
instead; This is the behavior one would expect when seeking.
Additionally:
- Remove unused parameter in aps_seek()
- Move tests better suited to com_seek() there instead of com_play()
Diffstat:
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/aps/aps.c b/aps/aps.c
@@ -271,11 +271,19 @@ aps_errordrop(struct aps *aps, int fd, char *why)
}
int
-aps_seek(struct aps *aps, struct item *(*incr)(struct item *), char *pattern)
+aps_seek(struct aps *aps, char *pattern)
{
struct item *item;
+ struct search search;
+
+ if (prepsearch(&search, aps->queue, pattern))
+ return 1;
+
+ item = findnext(&search);
+ if (item == aps->queue)
+ item = findnext(&search);
+ stopsearch(&search);
- item = find(pattern, aps->queue, NULL);
if (item == NULL)
return 1;
queue_set(aps, item);
diff --git a/aps/aps.h b/aps/aps.h
@@ -34,6 +34,6 @@ int aps_update(struct aps *);
char *aps_read(struct aps *, int);
int aps_command(struct aps *, int);
void aps_errordrop(struct aps *, int, char *);
-int aps_seek(struct aps *, struct item *(*)(struct item *), char *);
+int aps_seek(struct aps *, char *);
int aps_play(struct aps *, struct item *);
int aps_unname(struct aps *);
diff --git a/aps/command.c b/aps/command.c
@@ -104,9 +104,11 @@ com_list(struct aps *aps, int fd, int argc, char **argv)
char *
com_seek(struct aps *aps, int fd, int argc, char **argv)
{
+ if (!aps->queue)
+ return "Empty queue";
if (!argc)
return "No pattern";
- if (aps_seek(aps, nextitem, *argv))
+ if (aps_seek(aps, *argv))
return errstr;
return NULL;
}
@@ -116,12 +118,8 @@ com_play(struct aps *aps, int fd, int argc, char **argv)
{
char *err;
- if (!aps->queue)
- return "Empty queue";
-
if (argc && (err = com_seek(aps, fd, argc, argv)))
return err;
-
if (pplay(aps->player, aps->queue->path))
return errstr;
return NULL;