1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-06 23:21:54 +00:00

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
This commit is contained in:
cboesch 2010-11-16 21:06:52 +00:00 committed by Uoti Urpala
parent 970d02c791
commit e8757fb883
4 changed files with 23 additions and 10 deletions

View File

@ -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;

View File

@ -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));

16
path.c
View File

@ -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;
}

1
path.h
View File

@ -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 */