changeset 32543:18338ee51c9d

Export mp_basename in a function instead of duplicate macros in various places
author cboesch
date Tue, 16 Nov 2010 21:06:52 +0000
parents 775be5bfdcb3
children 9d5d8c799869
files gui/interface.c libmenu/menu_pt.c mplayer.c path.c path.h
diffstat 5 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/gui/interface.c	Tue Nov 16 19:58:54 2010 +0000
+++ b/gui/interface.c	Tue Nov 16 21:06:52 2010 +0000
@@ -1134,8 +1134,6 @@
  return NULL;
 }
 
-#define mp_basename(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
-
 #include "playtree.h"
 
 //This function adds/inserts one file into the gui playlist
--- a/libmenu/menu_pt.c	Tue Nov 16 19:58:54 2010 +0000
+++ b/libmenu/menu_pt.c	Tue Nov 16 21:06:52 2010 +0000
@@ -24,6 +24,7 @@
 #include "config.h"
 #include "mp_msg.h"
 #include "help_mp.h"
+#include "path.h"
 
 #include "libmpcodecs/img_format.h"
 #include "libmpcodecs/mp_image.h"
@@ -38,8 +39,6 @@
 #include "input/input.h"
 #include "access_mpcontext.h"
 
-#define mp_basename(s) (strrchr((s),'/')==NULL?(char*)(s):(strrchr((s),'/')+1))
-
 struct list_entry_s {
   struct list_entry p;
   play_tree_t* pt;
@@ -156,7 +155,7 @@
   for( ; i != NULL ; i = i->next ) {
     e = calloc(1,sizeof(list_entry_t));
     if(i->files)
-      e->p.txt = mp_basename(i->files[0]);
+      e->p.txt = (char *)mp_basename(i->files[0]);
     else
       e->p.txt = "Group ...";
     e->pt = i;
--- a/mplayer.c	Tue Nov 16 19:58:54 2010 +0000
+++ b/mplayer.c	Tue Nov 16 21:06:52 2010 +0000
@@ -349,8 +349,6 @@
 #include "cfg-mplayer.h"
 
 
-#define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
-
 const void *mpctx_get_video_out(MPContext *mpctx)
 {
     return mpctx->video_out;
@@ -456,7 +454,7 @@
   {
   case META_NAME:
   {
-    return strdup (mp_basename2 (filename));
+    return strdup(mp_basename(filename));
   }
 
   case META_VIDEO_CODEC:
@@ -1046,8 +1044,6 @@
   return eof;
 }
 
-#define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
-
 static int playtree_add_playlist(play_tree_t* entry)
 {
   play_tree_add_bpf(entry,filename);
@@ -3174,7 +3170,7 @@
 	mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing,
 		filename_recode(filename));
         if(use_filename_title && vo_wintitle == NULL)
-            vo_wintitle = strdup ( mp_basename2 (filename));
+            vo_wintitle = strdup(mp_basename(filename));
     }
 
     edl_loadfile();
@@ -3368,7 +3364,8 @@
   current_module="handle_demux_playlist";
   while (ds_get_packet(mpctx->demuxer->video,&playlist_entry)>0)
   {
-    char *temp, *bname;
+    char *temp;
+    const char *bname;
 
     mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n",
 	    filename_recode(playlist_entry));
--- a/path.c	Tue Nov 16 19:58:54 2010 +0000
+++ b/path.c	Tue Nov 16 21:06:52 2010 +0000
@@ -193,3 +193,16 @@
     strcpy(codec_path, path);
     needs_free = 1;
 }
+
+const char *mp_basename(const char *path)
+{
+    char *s;
+
+#if HAVE_DOS_PATHS
+    s = strrchr(path, '\\');
+    if (s)
+        return s + 1;
+#endif
+    s = strrchr(path, '/');
+    return s ? s + 1 : s;
+}
--- a/path.h	Tue Nov 16 19:58:54 2010 +0000
+++ b/path.h	Tue Nov 16 21:06:52 2010 +0000
@@ -26,5 +26,6 @@
 char *get_path(const char *filename);
 void set_path_env(void);
 void set_codec_path(const char *path);
+const char *mp_basename(const char *path);
 
 #endif /* MPLAYER_PATH_H */