Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
5899a272
Commit
5899a272
authored
Dec 02, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/gme: simplify ParseContainerPath()
Use simple string and path parsing functions instead of GLib's g_pattern_match(), which was used in a very clumsy way.
parent
27b4c62b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
34 deletions
+27
-34
configure.ac
configure.ac
+0
-2
GmeDecoderPlugin.cxx
src/decoder/plugins/GmeDecoderPlugin.cxx
+27
-32
No files found.
configure.ac
View file @
5899a272
...
...
@@ -341,8 +341,6 @@ AC_ARG_ENABLE(gme,
AS_HELP_STRING([--enable-gme],
[enable Blargg's game music emulator plugin]),,
enable_gme=auto)
MPD_DEPENDS([enable_gme], [enable_glib],
[Cannot use --enable-gme with --disable-glib])
AC_ARG_ENABLE(httpd-output,
AS_HELP_STRING([--enable-httpd-output],
...
...
src/decoder/plugins/GmeDecoderPlugin.cxx
View file @
5899a272
...
...
@@ -23,6 +23,7 @@
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
#include "fs/Path.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/Alloc.hxx"
#include "util/FormatString.hxx"
#include "util/UriUtil.hxx"
...
...
@@ -30,7 +31,6 @@
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -48,10 +48,27 @@ static constexpr unsigned GME_BUFFER_SAMPLES =
GME_BUFFER_FRAMES
*
GME_CHANNELS
;
struct
GmeContainerPath
{
char
*
path
;
AllocatedPath
path
;
unsigned
track
;
};
gcc_pure
static
unsigned
ParseSubtuneName
(
const
char
*
base
)
{
if
(
memcmp
(
base
,
SUBTUNE_PREFIX
,
sizeof
(
SUBTUNE_PREFIX
)
-
1
)
!=
0
)
return
0
;
base
+=
sizeof
(
SUBTUNE_PREFIX
)
-
1
;
char
*
endptr
;
auto
track
=
strtoul
(
base
,
&
endptr
,
10
);
if
(
endptr
==
base
||
*
endptr
!=
'.'
)
return
0
;
return
track
;
}
/**
* returns the file path stripped of any /tune_xxx.* subtune suffix
* and the track number (or 0 if no "tune_xxx" suffix is present).
...
...
@@ -59,33 +76,13 @@ struct GmeContainerPath {
static
GmeContainerPath
ParseContainerPath
(
Path
path_fs
)
{
const
char
*
subtune_suffix
=
uri_get_suffix
(
path_fs
.
c_str
());
char
*
path_container
=
xstrdup
(
path_fs
.
c_str
());
char
pat
[
64
];
snprintf
(
pat
,
sizeof
(
pat
),
"%s%s"
,
"*/"
SUBTUNE_PREFIX
"???."
,
subtune_suffix
);
GPatternSpec
*
path_with_subtune
=
g_pattern_spec_new
(
pat
);
if
(
!
g_pattern_match
(
path_with_subtune
,
strlen
(
path_container
),
path_container
,
nullptr
))
{
g_pattern_spec_free
(
path_with_subtune
);
return
{
path_container
,
0
};
}
unsigned
track
=
0
;
char
*
sub
=
g_strrstr
(
path_container
,
"/"
SUBTUNE_PREFIX
);
if
(
sub
!=
nullptr
)
{
*
sub
=
'\0'
;
sub
+=
strlen
(
"/"
SUBTUNE_PREFIX
);
int
song_num
=
strtol
(
sub
,
nullptr
,
10
);
if
(
song_num
>=
1
)
track
=
song_num
-
1
;
}
const
Path
base
=
path_fs
.
GetBase
();
unsigned
track
;
if
(
base
.
IsNull
()
||
(
track
=
ParseSubtuneName
(
base
.
c_str
()))
<
1
)
return
{
AllocatedPath
(
path_fs
),
0
};
g_pattern_spec_free
(
path_with_subtune
);
return
{
path_container
,
track
};
return
{
path_fs
.
GetDirectoryName
(),
track
-
1
};
}
static
char
*
...
...
@@ -120,8 +117,7 @@ gme_file_decode(Decoder &decoder, Path path_fs)
Music_Emu
*
emu
;
const
char
*
gme_err
=
gme_open_file
(
container
.
path
,
&
emu
,
GME_SAMPLE_RATE
);
free
(
container
.
path
);
gme_open_file
(
container
.
path
.
c_str
(),
&
emu
,
GME_SAMPLE_RATE
);
if
(
gme_err
!=
nullptr
)
{
LogWarning
(
gme_domain
,
gme_err
);
return
;
...
...
@@ -256,8 +252,7 @@ gme_scan_file(Path path_fs,
Music_Emu
*
emu
;
const
char
*
gme_err
=
gme_open_file
(
container
.
path
,
&
emu
,
GME_SAMPLE_RATE
);
free
(
container
.
path
);
gme_open_file
(
container
.
path
.
c_str
(),
&
emu
,
GME_SAMPLE_RATE
);
if
(
gme_err
!=
nullptr
)
{
LogWarning
(
gme_domain
,
gme_err
);
return
false
;
...
...
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