Code

libmpdclient update
authorKalle Wallin <kaw@linux.se>
Sun, 5 Jun 2005 21:34:52 +0000 (21:34 +0000)
committerKalle Wallin <kaw@linux.se>
Sun, 5 Jun 2005 21:34:52 +0000 (21:34 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@3320 09075e82-0dd4-0310-85a5-a0d7c8717e4f

src/libmpdclient.c
src/libmpdclient.h

index e93b3947e9e4a5804c090a1f4be5bcd7f948be1a..bc1c1d6e709817eabe932b17672a8a0ff1c5c60a 100644 (file)
@@ -69,25 +69,33 @@ int mpd_ipv6Supported() {
 }                       
 #endif  
 
-
-char * mpd_sanitizeArg(const char * arg) {
+static char * mpd_sanitizeArg(const char * arg) {
        size_t i;
-       int count=0;
        char * ret;
-
-       for(i=0;i<strlen(arg);i++) {
-               if(arg[i]=='"' || arg[i]=='\\') count++;
+       register const char *c;
+       register char *rc;
+       
+       /* 
+       unsigned int count = 0;
+       
+       c = arg;
+       for(i = strlen(arg); i != 0; --i) {
+               if(*c=='"' || *c=='\\') count++;
+               c++;
        }
-
        ret = malloc(strlen(arg)+count+1);
-
-       count = 0;
-       for(i=0;i<strlen(arg)+1;i++) {
-               if(arg[i]=='"' || arg[i]=='\\') {
-                       ret[i+count] = '\\';
-                       count++;
-               }
-               ret[i+count] = arg[i];
+       */
+       /* instead of counting in that loop above, just
+        * use a bit more memory and half running time
+        */
+       ret = malloc(strlen(arg) * 2 + 1);
+
+       c = arg;
+       rc = ret;
+       for(i = strlen(arg)+1; i != 0; --i) {
+               if(*c=='"' || *c=='\\')
+                       *rc++ = '\\';
+               *(rc++) = *(c++);
        }
 
        return ret;
@@ -789,6 +797,10 @@ void mpd_initSong(mpd_Song * song) {
        song->title = NULL;
        song->name = NULL;
        song->date = NULL;
+       /* added by Qball */
+       song->genre = NULL;
+       song->composer = NULL;
+
        song->time = MPD_SONG_NO_TIME;
        song->pos = MPD_SONG_NO_NUM;
        song->id = MPD_SONG_NO_ID;
@@ -802,6 +814,8 @@ void mpd_finishSong(mpd_Song * song) {
        if(song->track) free(song->track);
        if(song->name) free(song->name);
        if(song->date) free(song->date);
+       if(song->genre) free(song->genre);
+       if(song->composer) free(song->composer);
 }
 
 mpd_Song * mpd_newSong() {
@@ -827,6 +841,8 @@ mpd_Song * mpd_songDup(mpd_Song * song) {
        if(song->track) ret->track = strdup(song->track);
        if(song->name) ret->name = strdup(song->name);
        if(song->date) ret->date = strdup(song->date);
+       if(song->genre) ret->genre= strdup(song->genre);
+       if(song->composer) ret->composer= strdup(song->composer);
        ret->time = song->time;
        ret->pos = song->pos;
        ret->id = song->id;
@@ -1016,6 +1032,15 @@ mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection) {
                                        strcmp(re->name, "Date") == 0) {
                                entity->info.song->date = strdup(re->value);
                        }
+                       else if(!entity->info.song->genre &&
+                                       strcmp(re->name, "Genre") == 0) {
+                               entity->info.song->genre = strdup(re->value);
+                       }
+                       else if(!entity->info.song->composer &&
+                                       strcmp(re->name, "Composer") == 0) {
+                               entity->info.song->composer = strdup(re->value);
+                       }                                                                       
+                       
                }
                else if(entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) {
                }
index 9298a09c28ed5e79c6f9c6c305db588caa954cbb..79a94d8ee3ea5ab35945bc56324de332cd5aa46e 100644 (file)
@@ -233,6 +233,11 @@ typedef struct _mpd_Song {
        char * name;
        /* date */
        char *date;
+
+       /* added by qball */
+       char *genre;
+       char *composer;
+
        /* length of song in seconds, check that it is not MPD_SONG_NO_TIME  */
        int time;
        /* if plchanges/playlistinfo/playlistid used, is the position of the 
@@ -356,6 +361,9 @@ void mpd_sendCurrentSongCommand(mpd_Connection * connection);
 /* songNum of -1, means to display the whole list */
 void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songNum);
 
+/* songId of -1, means to display the whole list */
+void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int songId);
+
 /* use this to get the changes in the playlist since version _playlist_ */
 void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist);