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
016d9961
Commit
016d9961
authored
Oct 28, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: use g_str_has_prefix() instead of prefixcmp()
Remove duplicated code from MPD.
parent
4a71f662
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
28 additions
and
35 deletions
+28
-35
audio.c
src/audio.c
+3
-1
database.c
src/database.c
+2
-2
mp3_plugin.c
src/decoder/mp3_plugin.c
+2
-1
directory_save.c
src/directory_save.c
+6
-6
ls.c
src/ls.c
+1
-2
main.c
src/main.c
+3
-2
playlist.c
src/playlist.c
+8
-8
utils.c
src/utils.c
+0
-10
utils.h
src/utils.h
+0
-2
volume.c
src/volume.c
+3
-1
No files found.
src/audio.c
View file @
016d9961
...
@@ -28,6 +28,8 @@
...
@@ -28,6 +28,8 @@
#include "utils.h"
#include "utils.h"
#include "os_compat.h"
#include "os_compat.h"
#include <glib.h>
#define AUDIO_DEVICE_STATE "audio_device_state:"
#define AUDIO_DEVICE_STATE "audio_device_state:"
#define AUDIO_BUFFER_SIZE 2*MPD_PATH_MAX
#define AUDIO_BUFFER_SIZE 2*MPD_PATH_MAX
...
@@ -434,7 +436,7 @@ void readAudioDevicesState(FILE *fp)
...
@@ -434,7 +436,7 @@ void readAudioDevicesState(FILE *fp)
while
(
myFgets
(
buffer
,
AUDIO_BUFFER_SIZE
,
fp
))
{
while
(
myFgets
(
buffer
,
AUDIO_BUFFER_SIZE
,
fp
))
{
char
*
c
,
*
name
;
char
*
c
,
*
name
;
if
(
prefixcmp
(
buffer
,
AUDIO_DEVICE_STATE
))
if
(
!
g_str_has_prefix
(
buffer
,
AUDIO_DEVICE_STATE
))
continue
;
continue
;
c
=
strchr
(
buffer
,
':'
);
c
=
strchr
(
buffer
,
':'
);
...
...
src/database.c
View file @
016d9961
...
@@ -280,11 +280,11 @@ db_load(void)
...
@@ -280,11 +280,11 @@ db_load(void)
while
(
myFgets
(
buffer
,
sizeof
(
buffer
),
fp
)
&&
while
(
myFgets
(
buffer
,
sizeof
(
buffer
),
fp
)
&&
0
!=
strcmp
(
DIRECTORY_INFO_END
,
buffer
))
{
0
!=
strcmp
(
DIRECTORY_INFO_END
,
buffer
))
{
if
(
!
prefixcmp
(
buffer
,
DIRECTORY_MPD_VERSION
))
{
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_MPD_VERSION
))
{
if
(
foundVersion
)
if
(
foundVersion
)
FATAL
(
"already found version in db
\n
"
);
FATAL
(
"already found version in db
\n
"
);
foundVersion
=
1
;
foundVersion
=
1
;
}
else
if
(
!
prefixcmp
(
buffer
,
DIRECTORY_FS_CHARSET
))
{
}
else
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_FS_CHARSET
))
{
char
*
fsCharset
;
char
*
fsCharset
;
char
*
tempCharset
;
char
*
tempCharset
;
...
...
src/decoder/mp3_plugin.c
View file @
016d9961
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include "../utils.h"
#include "../utils.h"
#include "../conf.h"
#include "../conf.h"
#include <glib.h>
#include <mad.h>
#include <mad.h>
#ifdef HAVE_ID3TAG
#ifdef HAVE_ID3TAG
...
@@ -564,7 +565,7 @@ static int parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
...
@@ -564,7 +565,7 @@ static int parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
/* This is technically incorrect, since the encoder might not be lame.
/* This is technically incorrect, since the encoder might not be lame.
* But there's no other way to determine if this is a lame tag, and we
* But there's no other way to determine if this is a lame tag, and we
* wouldn't want to go reading a tag that's not there. */
* wouldn't want to go reading a tag that's not there. */
if
(
prefixcmp
(
lame
->
encoder
,
"LAME"
))
if
(
!
g_str_has_prefix
(
lame
->
encoder
,
"LAME"
))
return
0
;
return
0
;
if
(
sscanf
(
lame
->
encoder
+
4
,
"%u.%u"
,
if
(
sscanf
(
lame
->
encoder
+
4
,
"%u.%u"
,
...
...
src/directory_save.c
View file @
016d9961
...
@@ -71,22 +71,22 @@ directory_load(FILE *fp, struct directory *directory)
...
@@ -71,22 +71,22 @@ directory_load(FILE *fp, struct directory *directory)
char
*
name
;
char
*
name
;
while
(
myFgets
(
buffer
,
bufferSize
,
fp
)
while
(
myFgets
(
buffer
,
bufferSize
,
fp
)
&&
prefixcmp
(
buffer
,
DIRECTORY_END
))
{
&&
!
g_str_has_prefix
(
buffer
,
DIRECTORY_END
))
{
if
(
!
prefixcmp
(
buffer
,
DIRECTORY_DIR
))
{
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_DIR
))
{
struct
directory
*
subdir
;
struct
directory
*
subdir
;
strcpy
(
key
,
&
(
buffer
[
strlen
(
DIRECTORY_DIR
)]));
strcpy
(
key
,
&
(
buffer
[
strlen
(
DIRECTORY_DIR
)]));
if
(
!
myFgets
(
buffer
,
bufferSize
,
fp
))
if
(
!
myFgets
(
buffer
,
bufferSize
,
fp
))
FATAL
(
"Error reading db, fgets
\n
"
);
FATAL
(
"Error reading db, fgets
\n
"
);
/* for compatibility with db's prior to 0.11 */
/* for compatibility with db's prior to 0.11 */
if
(
!
prefixcmp
(
buffer
,
DIRECTORY_MTIME
))
{
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_MTIME
))
{
if
(
!
myFgets
(
buffer
,
bufferSize
,
fp
))
if
(
!
myFgets
(
buffer
,
bufferSize
,
fp
))
FATAL
(
"Error reading db, fgets
\n
"
);
FATAL
(
"Error reading db, fgets
\n
"
);
}
}
if
(
prefixcmp
(
buffer
,
DIRECTORY_BEGIN
))
if
(
!
g_str_has_prefix
(
buffer
,
DIRECTORY_BEGIN
))
FATAL
(
"Error reading db at line: %s
\n
"
,
buffer
);
FATAL
(
"Error reading db at line: %s
\n
"
,
buffer
);
name
=
&
(
buffer
[
strlen
(
DIRECTORY_BEGIN
)]);
name
=
&
(
buffer
[
strlen
(
DIRECTORY_BEGIN
)]);
if
(
prefixcmp
(
name
,
directory
->
path
)
!=
0
)
if
(
!
g_str_has_prefix
(
name
,
directory
->
path
)
!=
0
)
FATAL
(
"Wrong path in database: '%s' in '%s'
\n
"
,
FATAL
(
"Wrong path in database: '%s' in '%s'
\n
"
,
name
,
directory
->
path
);
name
,
directory
->
path
);
...
@@ -98,7 +98,7 @@ directory_load(FILE *fp, struct directory *directory)
...
@@ -98,7 +98,7 @@ directory_load(FILE *fp, struct directory *directory)
dirvec_add
(
&
directory
->
children
,
subdir
);
dirvec_add
(
&
directory
->
children
,
subdir
);
}
}
directory_load
(
fp
,
subdir
);
directory_load
(
fp
,
subdir
);
}
else
if
(
!
prefixcmp
(
buffer
,
SONG_BEGIN
))
{
}
else
if
(
g_str_has_prefix
(
buffer
,
SONG_BEGIN
))
{
readSongInfoIntoList
(
fp
,
&
directory
->
songs
,
directory
);
readSongInfoIntoList
(
fp
,
&
directory
->
songs
,
directory
);
}
else
{
}
else
{
FATAL
(
"Unknown line in db: %s
\n
"
,
buffer
);
FATAL
(
"Unknown line in db: %s
\n
"
,
buffer
);
...
...
src/ls.c
View file @
016d9961
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#include "path.h"
#include "path.h"
#include "client.h"
#include "client.h"
#include "log.h"
#include "log.h"
#include "utils.h"
#include "list.h"
#include "list.h"
#include "stored_playlist.h"
#include "stored_playlist.h"
#include "os_compat.h"
#include "os_compat.h"
...
@@ -92,7 +91,7 @@ int isRemoteUrl(const char *url)
...
@@ -92,7 +91,7 @@ int isRemoteUrl(const char *url)
while
(
*
urlPrefixes
)
{
while
(
*
urlPrefixes
)
{
count
++
;
count
++
;
if
(
!
prefixcmp
(
url
,
*
urlPrefixes
))
if
(
g_str_has_prefix
(
url
,
*
urlPrefixes
))
return
count
;
return
count
;
urlPrefixes
++
;
urlPrefixes
++
;
}
}
...
...
src/main.c
View file @
016d9961
...
@@ -46,12 +46,13 @@
...
@@ -46,12 +46,13 @@
#include "tag.h"
#include "tag.h"
#include "dbUtils.h"
#include "dbUtils.h"
#include "../config.h"
#include "../config.h"
#include "utils.h"
#include "normalize.h"
#include "normalize.h"
#include "zeroconf.h"
#include "zeroconf.h"
#include "main_notify.h"
#include "main_notify.h"
#include "os_compat.h"
#include "os_compat.h"
#include <glib.h>
#define SYSTEM_CONFIG_FILE_LOCATION "/etc/mpd.conf"
#define SYSTEM_CONFIG_FILE_LOCATION "/etc/mpd.conf"
#define USER_CONFIG_FILE_LOCATION "/.mpdconf"
#define USER_CONFIG_FILE_LOCATION "/.mpdconf"
...
@@ -156,7 +157,7 @@ static void parseOptions(int argc, char **argv, Options * options)
...
@@ -156,7 +157,7 @@ static void parseOptions(int argc, char **argv, Options * options)
if
(
argc
>
1
)
{
if
(
argc
>
1
)
{
int
i
=
1
;
int
i
=
1
;
while
(
i
<
argc
)
{
while
(
i
<
argc
)
{
if
(
!
prefixcmp
(
argv
[
i
],
"--"
))
{
if
(
g_str_has_prefix
(
argv
[
i
],
"--"
))
{
if
(
strcmp
(
argv
[
i
],
"--help"
)
==
0
)
{
if
(
strcmp
(
argv
[
i
],
"--help"
)
==
0
)
{
usage
(
argv
);
usage
(
argv
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
...
...
src/playlist.c
View file @
016d9961
...
@@ -301,7 +301,7 @@ void readPlaylistState(FILE *fp)
...
@@ -301,7 +301,7 @@ void readPlaylistState(FILE *fp)
char
buffer
[
PLAYLIST_BUFFER_SIZE
];
char
buffer
[
PLAYLIST_BUFFER_SIZE
];
while
(
myFgets
(
buffer
,
PLAYLIST_BUFFER_SIZE
,
fp
))
{
while
(
myFgets
(
buffer
,
PLAYLIST_BUFFER_SIZE
,
fp
))
{
if
(
!
prefixcmp
(
buffer
,
PLAYLIST_STATE_FILE_STATE
))
{
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_STATE
))
{
if
(
strcmp
(
&
(
buffer
[
strlen
(
PLAYLIST_STATE_FILE_STATE
)]),
if
(
strcmp
(
&
(
buffer
[
strlen
(
PLAYLIST_STATE_FILE_STATE
)]),
PLAYLIST_STATE_FILE_STATE_PLAY
)
==
0
)
{
PLAYLIST_STATE_FILE_STATE_PLAY
)
==
0
)
{
state
=
PLAYER_STATE_PLAY
;
state
=
PLAYER_STATE_PLAY
;
...
@@ -312,24 +312,24 @@ void readPlaylistState(FILE *fp)
...
@@ -312,24 +312,24 @@ void readPlaylistState(FILE *fp)
==
0
)
{
==
0
)
{
state
=
PLAYER_STATE_PAUSE
;
state
=
PLAYER_STATE_PAUSE
;
}
}
}
else
if
(
!
prefixcmp
(
buffer
,
PLAYLIST_STATE_FILE_TIME
))
{
}
else
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_TIME
))
{
seek_time
=
seek_time
=
atoi
(
&
(
buffer
[
strlen
(
PLAYLIST_STATE_FILE_TIME
)]));
atoi
(
&
(
buffer
[
strlen
(
PLAYLIST_STATE_FILE_TIME
)]));
}
else
}
else
if
(
!
prefixcmp
(
buffer
,
PLAYLIST_STATE_FILE_REPEAT
))
{
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_REPEAT
))
{
if
(
strcmp
if
(
strcmp
(
&
(
buffer
[
strlen
(
PLAYLIST_STATE_FILE_REPEAT
)]),
(
&
(
buffer
[
strlen
(
PLAYLIST_STATE_FILE_REPEAT
)]),
"1"
)
==
0
)
{
"1"
)
==
0
)
{
setPlaylistRepeatStatus
(
true
);
setPlaylistRepeatStatus
(
true
);
}
else
}
else
setPlaylistRepeatStatus
(
false
);
setPlaylistRepeatStatus
(
false
);
}
else
if
(
!
prefixcmp
(
buffer
,
PLAYLIST_STATE_FILE_CROSSFADE
))
{
}
else
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_CROSSFADE
))
{
setPlayerCrossFade
(
atoi
setPlayerCrossFade
(
atoi
(
&
(
&
(
buffer
(
buffer
[
strlen
[
strlen
(
PLAYLIST_STATE_FILE_CROSSFADE
)])));
(
PLAYLIST_STATE_FILE_CROSSFADE
)])));
}
else
if
(
!
prefixcmp
(
buffer
,
PLAYLIST_STATE_FILE_RANDOM
))
{
}
else
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_RANDOM
))
{
if
(
strcmp
if
(
strcmp
(
&
(
&
(
buffer
(
buffer
...
@@ -338,15 +338,15 @@ void readPlaylistState(FILE *fp)
...
@@ -338,15 +338,15 @@ void readPlaylistState(FILE *fp)
setPlaylistRandomStatus
(
true
);
setPlaylistRandomStatus
(
true
);
}
else
}
else
setPlaylistRandomStatus
(
false
);
setPlaylistRandomStatus
(
false
);
}
else
if
(
!
prefixcmp
(
buffer
,
PLAYLIST_STATE_FILE_CURRENT
))
{
}
else
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_CURRENT
))
{
if
(
strlen
(
buffer
)
==
if
(
strlen
(
buffer
)
==
strlen
(
PLAYLIST_STATE_FILE_CURRENT
))
strlen
(
PLAYLIST_STATE_FILE_CURRENT
))
state_file_fatal
();
state_file_fatal
();
current
=
atoi
(
&
(
buffer
current
=
atoi
(
&
(
buffer
[
strlen
[
strlen
(
PLAYLIST_STATE_FILE_CURRENT
)]));
(
PLAYLIST_STATE_FILE_CURRENT
)]));
}
else
if
(
!
prefixcmp
(
buffer
,
}
else
if
(
g_str_has_prefix
(
buffer
,
PLAYLIST_STATE_FILE_PLAYLIST_BEGIN
))
{
PLAYLIST_STATE_FILE_PLAYLIST_BEGIN
))
{
if
(
state
==
PLAYER_STATE_STOP
)
if
(
state
==
PLAYER_STATE_STOP
)
current
=
-
1
;
current
=
-
1
;
loadPlaylistFromStateFile
(
fp
,
buffer
,
state
,
loadPlaylistFromStateFile
(
fp
,
buffer
,
state
,
...
...
src/utils.c
View file @
016d9961
...
@@ -261,13 +261,3 @@ void xpthread_cond_destroy(pthread_cond_t *cond)
...
@@ -261,13 +261,3 @@ void xpthread_cond_destroy(pthread_cond_t *cond)
if
((
err
=
pthread_cond_destroy
(
cond
)))
if
((
err
=
pthread_cond_destroy
(
cond
)))
FATAL
(
"failed to destroy cond: %s
\n
"
,
strerror
(
err
));
FATAL
(
"failed to destroy cond: %s
\n
"
,
strerror
(
err
));
}
}
int
prefixcmp
(
const
char
*
str
,
const
char
*
prefix
)
{
for
(;
;
str
++
,
prefix
++
)
if
(
!*
prefix
)
return
0
;
else
if
(
*
str
!=
*
prefix
)
return
(
unsigned
char
)
*
prefix
-
(
unsigned
char
)
*
str
;
}
src/utils.h
View file @
016d9961
...
@@ -104,6 +104,4 @@ void xpthread_mutex_destroy(pthread_mutex_t *mutex);
...
@@ -104,6 +104,4 @@ void xpthread_mutex_destroy(pthread_mutex_t *mutex);
void
xpthread_cond_destroy
(
pthread_cond_t
*
cond
);
void
xpthread_cond_destroy
(
pthread_cond_t
*
cond
);
int
prefixcmp
(
const
char
*
str
,
const
char
*
prefix
);
#endif
#endif
src/volume.c
View file @
016d9961
...
@@ -26,6 +26,8 @@
...
@@ -26,6 +26,8 @@
#include "../config.h"
#include "../config.h"
#include <glib.h>
#ifdef HAVE_OSS
#ifdef HAVE_OSS
#include <sys/soundcard.h>
#include <sys/soundcard.h>
#endif
#endif
...
@@ -518,7 +520,7 @@ void read_sw_volume_state(FILE *fp)
...
@@ -518,7 +520,7 @@ void read_sw_volume_state(FILE *fp)
if
(
volume_mixerType
!=
VOLUME_MIXER_TYPE_SOFTWARE
)
if
(
volume_mixerType
!=
VOLUME_MIXER_TYPE_SOFTWARE
)
return
;
return
;
while
(
myFgets
(
buf
,
sizeof
(
buf
),
fp
))
{
while
(
myFgets
(
buf
,
sizeof
(
buf
),
fp
))
{
if
(
prefixcmp
(
buf
,
SW_VOLUME_STATE
))
if
(
!
g_str_has_prefix
(
buf
,
SW_VOLUME_STATE
))
continue
;
continue
;
sv
=
strtol
(
buf
+
strlen
(
SW_VOLUME_STATE
),
&
end
,
10
);
sv
=
strtol
(
buf
+
strlen
(
SW_VOLUME_STATE
),
&
end
,
10
);
if
(
mpd_likely
(
!*
end
))
if
(
mpd_likely
(
!*
end
))
...
...
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