commit efd09b125415e888997d6c5b6250500d6276b40b
parent a37d16d5a621ce092f2d815bb813898559b0297b
Author: sin <sin@2f30.org>
Date: Thu, 25 Dec 2014 17:11:45 +0000
Implement clearplaylist()
Diffstat:
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/cmd.c b/cmd.c
@@ -154,6 +154,20 @@ cmdadd(int fd, int argc, char **argv)
void
cmdclear(int fd, int argc, char **argv)
{
+ Song *s;
+
+ if (argc != 1) {
+ dprintf(fd, "ERR \"usage: clear\"\n");
+ return;
+ }
+
+ s = getcursong();
+ if (s) {
+ decoder->close();
+ s->state = NONE;
+ }
+ clearplaylist();
+ dprintf(fd, "OK\n");
}
void
@@ -169,7 +183,7 @@ cmdplaylist(int fd, int argc, char **argv)
return;
}
- playlistdump(fd);
+ dumpplaylist(fd);
dprintf(fd, "OK\n");
}
@@ -231,9 +245,9 @@ docmd(int clifd)
}
/* If no place left in the buffer reallocate twice as large. */
if (!resid) {
- new_buf = reallocarray(buf, sz, 2);
+ new_buf = realloc(buf, sz * 2);
if (!new_buf)
- err(1, "reallocarray");
+ err(1, "realloc");
buf = new_buf;
p = buf + sz;
resid = sz;
diff --git a/playlist.c b/playlist.c
@@ -7,6 +7,7 @@
#include "sad.h"
static Playlist playlist;
+static int rollingid;
void
initplaylist(void)
@@ -17,7 +18,6 @@ Song *
addplaylist(const char *path)
{
Song *s;
- static int rollingid = 0;
s = &playlist.songs[playlist.nsongs];
strncpy(s->path, path, sizeof(s->path));
@@ -69,7 +69,7 @@ putcursong(Song *s)
}
void
-playlistdump(int fd)
+dumpplaylist(int fd)
{
Song *s;
int i;
@@ -79,3 +79,10 @@ playlistdump(int fd)
dprintf(fd, "%d: %s\n", s->id, s->path);
}
}
+
+void
+clearplaylist(void)
+{
+ playlist.nsongs = 0;
+ rollingid = 0;
+}
diff --git a/sad.h b/sad.h
@@ -58,6 +58,8 @@ Song *findsong(const char *);
Song *findsongid(int);
Song *getcursong(void);
void putcursong(Song *);
+void dumpplaylist(int);
+void clearplaylist(void);
/* wav.c */
extern Decoder wavdecoder;