[PATCH] Export mp_basename in a function

Clément Bœsch ubitux at gmail.com
Thu Nov 11 17:30:36 CET 2010


---
 gui/interface.c   |    2 --
 libmenu/menu_pt.c |    3 +--
 mplayer.c         |    8 ++------
 path.c            |   13 +++++++++++++
 path.h            |    1 +
 5 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/gui/interface.c b/gui/interface.c
index a03281e..a83aaa2 100644
--- a/gui/interface.c
+++ b/gui/interface.c
@@ -1135,8 +1135,6 @@ void * gtkSet( int cmd,float fparam, void * vparam )
  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
diff --git a/libmenu/menu_pt.c b/libmenu/menu_pt.c
index 80d9cf7..ca7eb9c 100644
--- a/libmenu/menu_pt.c
+++ b/libmenu/menu_pt.c
@@ -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;
diff --git a/mplayer.c b/mplayer.c
index e03bfe4..7adf8be 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -349,8 +349,6 @@ static int crash_debug = 0;
 #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 @@ char *get_metadata (metadata_t type) {
   {
   case META_NAME:
   {
-    return strdup (mp_basename2 (filename));
+    return strdup(mp_basename(filename));
   }
 
   case META_VIDEO_CODEC:
@@ -1046,8 +1044,6 @@ static int libmpdemux_was_interrupted(int eof) {
   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);
@@ -3175,7 +3171,7 @@ while (player_idle_mode && !filename) {
 	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();
diff --git a/path.c b/path.c
index 2a1d504..ce7de5b 100644
--- a/path.c
+++ b/path.c
@@ -193,3 +193,16 @@ void set_codec_path(const char *path)
     strcpy(codec_path, path);
     needs_free = 1;
 }
+
+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;
+}
diff --git a/path.h b/path.h
index 3e71120..3bc03d5 100644
--- a/path.h
+++ b/path.h
@@ -26,5 +26,6 @@ extern char *codec_path;
 char *get_path(const char *filename);
 void set_path_env(void);
 void set_codec_path(const char *path);
+char *mp_basename(const char *path);
 
 #endif /* MPLAYER_PATH_H */
-- 
1.7.3.2


--Y4VYWfdFdHwFhC6D--


More information about the MPlayer-dev-eng mailing list