From 920d0976e7f657b34804b39bfbb4785fd24a76f0 Mon Sep 17 00:00:00 2001 From: cboesch Date: Sat, 4 Dec 2010 10:24:42 +0000 Subject: Change some filename-handling code to use mp_basename() git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32675 b3059339-0415-0410-9bf9-f77b7e298cf2 --- command.c | 11 +++-------- mplayer.c | 25 +++---------------------- vobsub.c | 7 ++----- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/command.c b/command.c index 798842b9cd..6bf4825848 100644 --- a/command.c +++ b/command.c @@ -290,10 +290,8 @@ static int mp_property_filename(m_option_t *prop, int action, void *arg, char *f; if (!mpctx->filename) return M_PROPERTY_UNAVAILABLE; - if (((f = strrchr(mpctx->filename, '/')) - || (f = strrchr(mpctx->filename, '\\'))) && f[1]) - f++; - else + f = (char *)mp_basename(mpctx->filename); + if (!*f) f = mpctx->filename; return m_property_string_ro(prop, action, arg, f); } @@ -1523,10 +1521,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 8386bb1afd..51ce9a8bf1 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1013,7 +1013,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"); @@ -1021,20 +1021,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); @@ -3695,14 +3682,8 @@ if (edl_output_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/vobsub.c b/vobsub.c index e9868b3f2c..08efa3acec 100644 --- a/vobsub.c +++ b/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" @@ -96,11 +97,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 = 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 -- cgit v1.2.3