[PATCH] Make use of mp_basename in a few places.

Clément Bœsch ubitux at gmail.com
Fri Dec 3 22:56:35 CET 2010


---
 command.c    |   10 +++-------
 mplayer.c    |   34 ++++------------------------------
 sub/vobsub.c |    7 ++-----
 3 files changed, 9 insertions(+), 42 deletions(-)

diff --git a/command.c b/command.c
index 0d5247d..41b611e 100644
--- a/command.c
+++ b/command.c
@@ -284,9 +284,8 @@ static int mp_property_filename(m_option_t *prop, int action, void *arg,
     char *f;
     if (!filename)
         return M_PROPERTY_UNAVAILABLE;
-    if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
-        f++;
-    else
+    f = (char *)mp_basename(filename);
+    if (!*f)
         f = filename;
     return m_property_string_ro(prop, action, arg, f);
 }
@@ -1467,10 +1466,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
             sub_name = ass_track->name;
 #endif
         if (sub_name) {
-            char *tmp, *tmp2;
-            tmp = sub_name;
-            if ((tmp2 = strrchr(tmp, '/')))
-                tmp = tmp2 + 1;
+            const char *tmp = mp_basename(sub_name);
 
             snprintf(*(char **) arg, 63, "(%d) %s%s",
                      mpctx->set_of_sub_pos + 1,
diff --git a/mplayer.c b/mplayer.c
index dbe68eb..6fdf3ef 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -978,7 +978,7 @@ static void load_per_file_config (m_config_t* conf, const char *const file)
 {
     char *confpath;
     char cfg[PATH_MAX];
-    char *name;
+    const char *name;
 
     if (strlen(file) > PATH_MAX - 14) {
         mp_msg(MSGT_CPLAYER, MSGL_WARN, "Filename is too long, can not load file or directory specific config files\n");
@@ -986,20 +986,7 @@ static void load_per_file_config (m_config_t* conf, const char *const file)
     }
     sprintf (cfg, "%s.conf", file);
 
-    name = strrchr(cfg, '/');
-    if (HAVE_DOS_PATHS) {
-        char *tmp = strrchr(cfg, '\\');
-        if (!name || tmp > name)
-            name = tmp;
-        tmp = strrchr(cfg, ':');
-        if (!name || tmp > name)
-            name = tmp;
-    }
-    if (!name)
-	name = cfg;
-    else
-	name++;
-
+    name = mp_basename(cfg);
     if (use_filedir_conf) {
         char dircfg[PATH_MAX];
         strcpy(dircfg, cfg);
@@ -2755,14 +2742,7 @@ int gui_no_filename=0;
       (!strcmp(argv[1], "-gui") || !strcmp(argv[1], "-nogui"))) {
     use_gui = !strcmp(argv[1], "-gui");
   } else
-  if ( argv[0] )
-  {
-    char *base = strrchr(argv[0], '/');
-    if (!base)
-      base = strrchr(argv[0], '\\');
-    if (!base)
-      base = argv[0];
-    if(strstr(base, "gmplayer"))
+  if (argv[0] && strstr(mp_basename(argv[0]), "gmplayer")) {
           use_gui=1;
   }
 
@@ -3205,14 +3185,8 @@ while (player_idle_mode && !filename) {
       vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec);
       /* try from ~/.mplayer/sub */
       if(!vo_vobsub && (psub = get_path( "sub/" ))) {
-          char *bname;
+          const char *bname = mp_basename(buf);
           int l;
-          bname = strrchr(buf,'/');
-#if defined(__MINGW32__) || defined(__CYGWIN__)
-          if(!bname) bname = strrchr(buf,'\\');
-#endif
-          if(bname) bname++;
-          else bname = buf;
           l = strlen(psub) + strlen(bname) + 1;
           psub = realloc(psub,l);
           strcat(psub,bname);
diff --git a/sub/vobsub.c b/sub/vobsub.c
index 9416adb..1239dd8 100644
--- a/sub/vobsub.c
+++ b/sub/vobsub.c
@@ -36,6 +36,7 @@
 #include "vobsub.h"
 #include "spudec.h"
 #include "mp_msg.h"
+#include "path.h"
 #include "unrar_exec.h"
 #include "libavutil/common.h"
 
@@ -95,11 +96,7 @@ static rar_stream_t *rar_open(const char *const filename,
             strcat(rar_filename, ".rar");
         }
         /* get rid of the path if there is any */
-        if ((p = strrchr(filename, '/')) == NULL) {
-            p = filename;
-        } else {
-            p++;
-        }
+        p = (char *)mp_basename(filename);
         rc = unrar_exec_get(&stream->data, &stream->size, p, rar_filename);
         if (!rc) {
             /* There is no matching filename in the archive. However, sometimes
-- 
1.7.3.2


--MW5yreqqjyrRcusr--


More information about the MPlayer-dev-eng mailing list