commit da761e393375233683d206a7d2f4ad8d67167998
parent 7d5052fe69b9d5d25fe810cee4938bf8ceafeac3
Author: Jacob R. Edwards <n/a>
Date: Sat, 8 Oct 2022 19:35:02 -0700
Return seek errors
Diffstat:
3 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/aps/aps.c b/aps/aps.c
@@ -295,14 +295,18 @@ aps_errordrop(struct aps *aps, int fd, char *why)
aps_drop(aps, fd);
}
-int
+char *
aps_seek(struct aps *aps, char *pattern)
{
+ char *err;
struct item *item;
struct search search;
- if (prepsearch(&search, aps->queue, pattern))
- return 1;
+ if (!aps->queue)
+ return "Empty queue";
+
+ if ((err = prepsearch(&search, aps->queue, pattern)))
+ return err;
item = findnext(&search);
if (item == aps->queue)
@@ -310,9 +314,9 @@ aps_seek(struct aps *aps, char *pattern)
stopsearch(&search);
if (item == NULL)
- return 1;
+ return "No match";
queue_set(aps, item);
- return 0;
+ return NULL;
}
int
diff --git a/aps/aps.h b/aps/aps.h
@@ -33,6 +33,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 *, char *);
+char *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
@@ -105,13 +105,13 @@ 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, *argv))
- return errstr;
- return NULL;
+ char *err;
+
+ if (argc)
+ err = aps_seek(aps, *argv);
+ else
+ err = "No pattern";
+ return err;
}
char *