Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: [PATCH] Relative paths in playlists

[PATCH] Relative paths in playlists

From: Brian King <brking_at_charter.net>
Date: Wed, 31 Jul 2002 21:00:10 -0500

I made a stab at adding support for relative paths in playlists. It
seems to work well on my Jukebox20. Let me know if I overlooked
something or if there is a better way to implement this.

It should handle playlists that contain entries like

./The_London_Howlin_Wolf_Sessions/02-I_Aint_Superstitious.mp3

and

../../Sonic_Youth/A_Thousand_Leaves/02-Sunday.mp3

not sure if there are any other types I should worry about...

The patch is made against the current cvs.

-bk



Index: playlist.c
===================================================================
RCS file: /cvsroot/rockbox/apps/playlist.c,v
retrieving revision 1.23
diff -u -r1.23 playlist.c
--- playlist.c 22 Jul 2002 15:36:39 -0000 1.23
+++ playlist.c 1 Aug 2002 01:50:50 -0000
_at__at_ -42,6 +42,8 _at__at_
     int fd;
     int i;
     char buf[MAX_PATH+1];
+ char dir_buf[MAX_PATH+1];
+ char *dir_end;
 
     playlist.index = (playlist.index+steps) % playlist.amount;
     seek = playlist.indices[playlist.index];
_at__at_ -81,10 +83,32 _at__at_
               strcpy(now_playing, &buf[2]);
               return now_playing;
           }
- else {
- snprintf(now_playing, MAX_PATH+1, "%s/%s", dirname, buf);
+ else if ( '.' == buf[0] && '.' == buf[1] && '/' == buf[2] ) {
+ /* handle relative paths */
+ seek=3;
+ while(buf[seek] == '.' &&
+ buf[seek+1] == '.' &&
+ buf[seek+2] == '/')
+ seek += 3;
+ strcpy(dir_buf, dirname);
+ for (i=0; i<seek/3; i++) {
+ dir_end = strrchr(dir_buf, '/');
+ if (dir_end)
+ *dir_end = '\0';
+ else
+ break;
+ }
+ snprintf(now_playing, MAX_PATH+1, "%s/%s", dir_buf, &buf[seek]);
               return now_playing;
           }
+ else if ( '.' == buf[0] && '/' == buf[1] ) {
+ snprintf(now_playing, MAX_PATH+1, "%s/%s", dirname, &buf[2]);
+ return now_playing;
+ }
+ else {
+ snprintf(now_playing, MAX_PATH+1, "%s/%s", dirname, buf);
+ return now_playing;
+ }
       }
     }
     else
Received on 2002-08-01

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy