commit c9682aa045b8f0125d72d0e3842195bb2a956676 sin <sin@2f30.org> 2014-12-28 15:44:53 +0000 Only allow one instance of each file to be added to the library
library.c | 18 ++++++++++++++++++ sad.h | 1 + 2 files changed, 19 insertions(+)
diff --git a/library.c b/library.c index dca2a2a..ab18912 100644 --- a/library.c +++ b/library.c @@ -19,6 +19,10 @@ addlibrary(const char *path) Decoder *d; Song *s; + s = findsong(path); + if (s) + return NULL; + d = matchdecoder(path); if (!d) return NULL; @@ -43,6 +47,20 @@ addlibrary(const char *path) return s; } +Song * +findsong(const char *path) +{ + Song *s; + int i; + + for (i = 0; i < library.nsongs; i++) { + s = library.songs[i]; + if (!strcmp(s->path, path)) + return s; + } + return NULL; +} + Song * findsongid(int id) { diff --git a/sad.h b/sad.h index 22fb2bf..e993f74 100644 --- a/sad.h +++ b/sad.h @@ -75,6 +75,7 @@ void stopsong(Song *); /* library.c */ Song *addlibrary(const char *); +Song *findsong(const char *); Song *findsongid(int); void dumplibrary(int); int searchlibrary(int, const char *);