[plz CC as I'm not subscribed]

Hello,
since mpc no more prints the song position while
mpc play or mpc move still need it there are 2 options.
* Always pipe to nl (or cat -n) the mpc playlist ouput
OR
* let's the song position be printed according to --format.

The problem is that converting int to string would bloat
to much the code IMHO so the patch KISS and does the following :

If the option.formats contains %position% then
- %position% will be removed from the option.formats string
- each line of the playlist output will get its position printed
before pretty_print_song is called.

Raph
diff --git a/src/command.c b/src/command.c
index 44b6d35..a83de5f 100644
--- a/src/command.c
+++ b/src/command.c
@@ -500,11 +500,26 @@ int
 cmd_playlist(mpd_unused int argc, mpd_unused char **argv, struct 
mpd_connection *conn)
 {
        struct mpd_song *song;
+       int count = 1, fmt_count = 0, arg_long = strlen("%position%");
+       char *fmt_pos_pos;
+
+       /* if option.formats contains "%position%", set fmt_count to 1 and
+          translate the format string following */
+       if((fmt_pos_pos = strstr(options.format, "%position%")) != NULL) {
+         fmt_count = 1;
+         while(*(fmt_pos_pos+arg_long) != 0) {
+           *fmt_pos_pos = *(fmt_pos_pos+arg_long);
+           fmt_pos_pos++;
+         }
+         *fmt_pos_pos = 0;
+       }
 
        if (!mpd_send_list_queue_meta(conn))
                printErrorAndExit(conn);
 
        while ((song = mpd_recv_song(conn)) != NULL) {
+               if(fmt_count == 1)
+                 printf("%d-",count++);
                pretty_print_song(song);
                mpd_song_free(song);
                printf("\n");
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to