commit 1b07b251bbdfcf532e78ee27e6fb46460e408b75
parent 7b1b114209843fc07097a4c144cef5c633cec070
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Fri, 16 Jul 2021 17:12:19 -0700
Fix next, prev, and name commands
Add find flag which, when given a string matching expression, skips
the initial item.
Diffstat:
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/aps/command.c b/aps/command.c
@@ -148,7 +148,7 @@ aps_name(struct aps *aps, int s, int argc, char **argv)
{
struct item *item;
- item = find(aps->queue, aps->queue, argv, argc, 0);
+ item = find(aps->queue, aps->queue, argv, argc, FIND_NEXT);
if (item == NULL)
return enotfound;
@@ -165,7 +165,7 @@ aps_next(struct aps *aps, int s, int argc, char **argv)
if (argc && argsub(&aps->next, argv, argc) == NULL)
return strerror(errno);
- n = find(aps->queue, aps->queue, aps->next, arglen(aps->next), 0);
+ n = find(aps->queue, aps->queue, aps->next, arglen(aps->next), FIND_NEXT);
if (n == NULL || queue_set(aps, n))
return strerror(errno);
return NULL;
@@ -176,7 +176,8 @@ aps_previous(struct aps *aps, int s, int argc, char **argv)
{
struct item *n;
- n = find(aps->queue, aps->queue, aps->next, arglen(aps->next), FIND_REVERSE);
+ n = find(aps->queue, aps->queue, aps->next, arglen(aps->next),
+ FIND_REVERSE | FIND_NEXT);
if (n == NULL || queue_set(aps, n))
return strerror(errno);
return NULL;
diff --git a/aps/find.c b/aps/find.c
@@ -78,6 +78,9 @@ finddir(struct item *(*incr)(struct item *), struct item *item, struct item *end
}
}
+ if (flags & FIND_NEXT)
+ item = incr(item);
+
while (item && !multimatch(item->path, patterns, len)) {
if ((item = incr(item)) == end) {
errno = ENOENT;
diff --git a/aps/find.h b/aps/find.h
@@ -1,5 +1,6 @@
enum findflag {
- FIND_REVERSE = 1
+ FIND_REVERSE = 1,
+ FIND_NEXT = 2
};
struct item *findnext(struct item *);