Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
dc229fda
Commit
dc229fda
authored
Mar 27, 2006
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Use utf_8scandir() and some cleanup
- Fix double free()
parent
8f390d8e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
44 deletions
+32
-44
src/input/subtitles.c
src/input/subtitles.c
+32
-44
No files found.
src/input/subtitles.c
View file @
dc229fda
/*****************************************************************************
* subtitles.c
*****************************************************************************
* Copyright (C) 2003-200
4
the VideoLAN team
* Copyright (C) 2003-200
6
the VideoLAN team
* $Id$
*
* Authors: Derk-Jan Hartman <hartman at videolan.org>
...
...
@@ -162,29 +162,22 @@ static int compare_sub_priority( const void *a, const void *b )
}
/* Utility function for scandir */
static
int
Filter
(
const
struct
dirent
*
p
_dir_content
)
static
int
Filter
(
const
char
*
psz
_dir_content
)
{
int
i
;
char
*
tmp
=
NULL
;
if
(
p_dir_content
==
NULL
||
p_dir_content
->
d_name
==
NULL
)
return
VLC_FALSE
;
/* does it end with a subtitle extension? */
tmp
=
strrchr
(
p_dir_content
->
d_name
,
'.'
);
if
(
!
tmp
)
{
return
VLC_FALSE
;
}
const
char
*
tmp
=
strrchr
(
psz_dir_content
,
'.'
);
if
(
tmp
==
NULL
)
return
0
;
else
{
int
i
;
tmp
++
;
for
(
i
=
0
;
sub_exts
[
i
];
i
++
)
{
if
(
strcmp
(
sub_exts
[
i
],
tmp
+
1
)
==
0
)
{
return
VLC_TRUE
;
}
}
if
(
strcmp
(
sub_exts
[
i
],
tmp
)
==
0
)
return
1
;
}
return
VLC_FALSE
;
return
0
;
}
...
...
@@ -275,7 +268,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
char
*
psz_name
)
{
vlc_value_t
fuzzy
;
int
j
,
i_result2
,
i_
dir_content
,
i_
sub_count
=
0
,
i_fname_len
=
0
;
int
j
,
i_result2
,
i_sub_count
=
0
,
i_fname_len
=
0
;
char
*
f_dir
=
NULL
,
*
f_fname
=
NULL
,
*
f_fname_noext
=
NULL
,
*
f_fname_trim
=
NULL
;
char
*
tmp
=
NULL
;
...
...
@@ -283,7 +276,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
char
tmp_fname_trim
[
PATH_MAX
];
char
tmp_fname_ext
[
PATH_MAX
];
struct
dirent
**
pp_dir_content
;
char
**
tmp_subdirs
,
**
subdirs
;
/* list of subdirectories to look in */
subfn
*
result
=
NULL
;
/* unsorted results */
...
...
@@ -354,36 +346,33 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
for
(
j
=
-
1
;
(
j
==
-
1
)
||
(
(
j
>=
0
)
&&
(
subdirs
!=
NULL
)
&&
(
*
subdirs
!=
NULL
)
);
j
++
)
{
char
*
psz_locale_dir
;
pp_dir_content
=
NULL
;
i_dir_content
=
0
;
const
char
*
psz_dir
=
j
<
0
?
f_dir
:
*
subdirs
;
char
**
ppsz_dir_content
;
int
i_dir_content
;
if
(
j
<
0
&&
f
_dir
==
NULL
)
if
(
psz
_dir
==
NULL
)
continue
;
/* parse psz_src dir */
psz_locale_dir
=
ToLocale
(
j
<
0
?
f_dir
:
*
subdirs
);
i_dir_content
=
scandir
(
psz_locale_dir
,
&
pp_dir_content
,
Filter
,
NULL
);
LocaleFree
(
psz_locale_dir
);
i_dir_content
=
utf8_scandir
(
psz_dir
,
&
ppsz_dir_content
,
Filter
,
NULL
);
if
(
i_dir_content
!=
-
1
)
{
int
a
;
msg_Dbg
(
p_this
,
"looking for a subtitle file in %s"
,
j
<
0
?
f_dir
:
*
subdirs
);
msg_Dbg
(
p_this
,
"looking for a subtitle file in %s"
,
psz_dir
);
for
(
a
=
0
;
a
<
i_dir_content
;
a
++
)
{
char
*
psz_name
=
vlc_fix_readdir_charset
(
p_this
,
ppsz_dir_content
[
a
]
);
int
i_prio
=
0
;
struct
dirent
*
p_dir_content
=
pp_dir_content
[
a
];
char
*
psz_inUTF8
=
FromLocale
(
p_dir_content
->
d_name
);
char
*
p_fixed_name
=
vlc_fix_readdir_charset
(
p_this
,
psz_inUTF8
);
LocaleFree
(
psz_inUTF8
);
if
(
psz_name
==
NULL
)
continue
;
/* retrieve various parts of the filename */
strcpy_strip_ext
(
tmp_fname_noext
,
p
_fixed
_name
);
strcpy_get_ext
(
tmp_fname_ext
,
p
_fixed
_name
);
strcpy_strip_ext
(
tmp_fname_noext
,
p
sz
_name
);
strcpy_get_ext
(
tmp_fname_ext
,
p
sz
_name
);
strcpy_trim
(
tmp_fname_trim
,
tmp_fname_noext
);
if
(
!
i_prio
&&
!
strcmp
(
tmp_fname_trim
,
f_fname_trim
)
)
...
...
@@ -416,15 +405,15 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
if
(
i_prio
>=
fuzzy
.
i_int
)
{
FILE
*
f
;
char
*
psz_path
;
char
psz_path
[
strlen
(
psz_dir
)
+
strlen
(
psz_name
)
+
1
]
;
asprintf
(
&
psz_path
,
"%s%s"
,
j
<
0
?
f_dir
:
*
subdirs
,
p_fixed
_name
);
msg_Dbg
(
p_this
,
"autodetected subtitle: %s with priority %d"
,
p
_fixed_name
,
i_prio
);
sprintf
(
psz_path
,
"%s%s"
,
psz_dir
,
psz
_name
);
msg_Dbg
(
p_this
,
"autodetected subtitle: %s with priority %d"
,
p
sz_path
,
i_prio
);
/* FIXME: a portable wrapper for stat() or access() would be more suited */
if
(
(
f
=
utf8_fopen
(
psz_path
,
"rt"
)
)
)
{
fclose
(
f
);
msg_Dbg
(
p_this
,
"autodetected subtitle: %s with priority %d"
,
p
_fixed_name
,
i_prio
);
msg_Dbg
(
p_this
,
"autodetected subtitle: %s with priority %d"
,
p
sz_path
,
i_prio
);
result
[
i_sub_count
].
priority
=
i_prio
;
result
[
i_sub_count
].
psz_fname
=
psz_path
;
result
[
i_sub_count
].
psz_ext
=
strdup
(
tmp_fname_ext
);
...
...
@@ -433,16 +422,15 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
else
{
msg_Dbg
(
p_this
,
"fopen failed"
);
if
(
psz_path
)
free
(
psz_path
);
LocaleFree
(
psz_path
);
free
(
psz_path
);
}
}
if
(
i_sub_count
>=
MAX_SUBTITLE_FILES
)
break
;
if
(
p_fixed_name
)
free
(
p_fixed
_name
);
free
(
psz
_name
);
}
for
(
a
=
0
;
a
<
i_dir_content
;
a
++
)
if
(
pp_dir_content
[
a
]
)
free
(
pp
_dir_content
[
a
]
);
if
(
pp
_dir_content
)
free
(
pp
_dir_content
);
free
(
ppsz
_dir_content
[
a
]
);
if
(
pp
sz_dir_content
)
free
(
ppsz
_dir_content
);
}
if
(
j
>=
0
)
if
(
*
subdirs
)
free
(
*
subdirs
++
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment