From 52b6a93f9773256f6d5a0efbd420fac83b3ed10b Mon Sep 17 00:00:00 2001
From: Kalle Wallin <kaw@linux.se>
Date: Sun, 5 Jun 2005 21:34:52 +0000
Subject: libmpdclient update

git-svn-id: https://svn.musicpd.org/ncmpc/trunk@3320 09075e82-0dd4-0310-85a5-a0d7c8717e4f
---
 src/libmpdclient.c | 55 +++++++++++++++++++++++++++++++++++++++---------------
 src/libmpdclient.h |  8 ++++++++
 2 files changed, 48 insertions(+), 15 deletions(-)

(limited to 'src')

diff --git a/src/libmpdclient.c b/src/libmpdclient.c
index e93b3947e..bc1c1d6e7 100644
--- a/src/libmpdclient.c
+++ b/src/libmpdclient.c
@@ -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) {
 		}
diff --git a/src/libmpdclient.h b/src/libmpdclient.h
index 9298a09c2..79a94d8ee 100644
--- a/src/libmpdclient.h
+++ b/src/libmpdclient.h
@@ -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);
 
-- 
cgit v1.2.3