diff options
author | cboesch <cboesch@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2010-11-16 21:06:52 +0000 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-12-16 03:59:37 +0200 |
commit | e8757fb88311329a35d874b43ff1aaf095ed4147 (patch) | |
tree | d8818a6042537bcc393f368349a2303c6fdcca52 | |
parent | 970d02c79189ce1c0037fac80bde93f0fa0cb693 (diff) | |
download | mpv-e8757fb88311329a35d874b43ff1aaf095ed4147.tar.bz2 mpv-e8757fb88311329a35d874b43ff1aaf095ed4147.tar.xz |
path.c: add function for mp_basename, remove duplicated macros
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32630 b3059339-0415-0410-9bf9-f77b7e298cf2
Fix crash on path without directories.
Regression introduced in r32630. Patch by Yuriy Kaminskiy yumkam at mail ru.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32631 b3059339-0415-0410-9bf9-f77b7e298cf2
Handle correctly paths with mixed '/' and '\' in it.
Patch by Yuriy Kaminskiy (yumkam at mail ru)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32632 b3059339-0415-0410-9bf9-f77b7e298cf2
Handle ':' on systems with DOS paths: it allows paths like C:foo.avi.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32642 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | libmenu/menu_pt.c | 5 | ||||
-rw-r--r-- | mplayer.c | 11 | ||||
-rw-r--r-- | path.c | 16 | ||||
-rw-r--r-- | path.h | 1 |
4 files changed, 23 insertions, 10 deletions
diff --git a/libmenu/menu_pt.c b/libmenu/menu_pt.c index 7008db2896..985066ba7c 100644 --- a/libmenu/menu_pt.c +++ b/libmenu/menu_pt.c @@ -23,6 +23,7 @@ #include "config.h" #include "mp_msg.h" +#include "path.h" #include "libmpcodecs/img_format.h" #include "libmpcodecs/mp_image.h" @@ -37,8 +38,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; @@ -155,7 +154,7 @@ static int op(menu_t* menu, char* args) { 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; @@ -361,8 +361,6 @@ int use_filename_title; #include "metadata.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; @@ -477,7 +475,7 @@ char *get_metadata(struct MPContext *mpctx, metadata_t type) { case META_NAME: { - return strdup (mp_basename2 (mpctx->filename)); + return strdup(mp_basename(mpctx->filename)); } case META_VIDEO_CODEC: @@ -1082,8 +1080,6 @@ static int libmpdemux_was_interrupted(struct MPContext *mpctx, int stop_play) return stop_play; } -#define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1)) - static int playtree_add_playlist(struct MPContext *mpctx, play_tree_t* entry) { play_tree_add_bpf(entry,mpctx->filename); @@ -3661,7 +3657,7 @@ while (opts->player_idle_mode && !mpctx->filename) { mp_tmsg(MSGT_CPLAYER,MSGL_INFO,"\nPlaying %s.\n", filename_recode(mpctx->filename)); if(use_filename_title && opts->vo_wintitle == NULL) - opts->vo_wintitle = strdup(mp_basename2(mpctx->filename)); + opts->vo_wintitle = strdup(mp_basename(mpctx->filename)); } if (edl_filename) { @@ -3857,7 +3853,8 @@ if (mpctx->demuxer && mpctx->demuxer->type==DEMUXER_TYPE_PLAYLIST) 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)); @@ -193,3 +193,19 @@ void set_codec_path(const char *path) 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) + path = s + 1; + s = strrchr(path, ':'); + if (s) + path = s + 1; +#endif + s = strrchr(path, '/'); + return s ? s + 1 : path; +} @@ -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); +const char *mp_basename(const char *path); #endif /* MPLAYER_PATH_H */ |