changeset 32588:aa82dfc7bd49

Make use of mp_basename in a few places.
author cboesch
date Sat, 04 Dec 2010 10:24:42 +0000
parents c878178a05f2
children 23f25ad2c45f
files command.c mplayer.c sub/vobsub.c
diffstat 3 files changed, 9 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/command.c	Sat Dec 04 01:55:18 2010 +0000
+++ b/command.c	Sat Dec 04 10:24:42 2010 +0000
@@ -284,9 +284,8 @@
     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 @@
             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,
--- a/mplayer.c	Sat Dec 04 01:55:18 2010 +0000
+++ b/mplayer.c	Sat Dec 04 10:24:42 2010 +0000
@@ -978,7 +978,7 @@
 {
     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 @@
     }
     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 @@
       (!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 @@
       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);
--- a/sub/vobsub.c	Sat Dec 04 01:55:18 2010 +0000
+++ b/sub/vobsub.c	Sat Dec 04 10:24:42 2010 +0000
@@ -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 @@
             strcat(rar_filename, ".rar");
         }
         /* get rid of the path if there is any */
-        if ((p = strrchr(filename, '/')) == NULL) {
-            p = filename;
-        } else {
-            p++;
-        }
+        p = 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