start using prefixcmp()
LOC reduction and less noise makes things easier for tired old folks to follow.
This commit is contained in:
parent
f5df13f853
commit
27fad52c6b
@ -27,7 +27,6 @@
|
|||||||
#include "os_compat.h"
|
#include "os_compat.h"
|
||||||
|
|
||||||
#define AUDIO_DEVICE_STATE "audio_device_state:"
|
#define AUDIO_DEVICE_STATE "audio_device_state:"
|
||||||
#define AUDIO_DEVICE_STATE_LEN (sizeof(AUDIO_DEVICE_STATE)-1)
|
|
||||||
#define AUDIO_BUFFER_SIZE 2*MPD_PATH_MAX
|
#define AUDIO_BUFFER_SIZE 2*MPD_PATH_MAX
|
||||||
|
|
||||||
static struct audio_format audio_configFormat;
|
static struct audio_format audio_configFormat;
|
||||||
@ -460,7 +459,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 (strncmp(buffer, AUDIO_DEVICE_STATE, AUDIO_DEVICE_STATE_LEN))
|
if (prefixcmp(buffer, AUDIO_DEVICE_STATE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
c = strchr(buffer, ':');
|
c = strchr(buffer, ':');
|
||||||
|
@ -889,22 +889,18 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
|
|||||||
ListNode *nodeTemp;
|
ListNode *nodeTemp;
|
||||||
|
|
||||||
while (myFgets(buffer, bufferSize, fp)
|
while (myFgets(buffer, bufferSize, fp)
|
||||||
&& 0 != strncmp(DIRECTORY_END, buffer, strlen(DIRECTORY_END))) {
|
&& prefixcmp(buffer, DIRECTORY_END)) {
|
||||||
if (0 == strncmp(DIRECTORY_DIR, buffer, strlen(DIRECTORY_DIR))) {
|
if (!prefixcmp(buffer, DIRECTORY_DIR)) {
|
||||||
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 (0 == strncmp(DIRECTORY_MTIME, buffer,
|
if (!prefixcmp(buffer, DIRECTORY_MTIME)) {
|
||||||
strlen(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 (strncmp
|
if (prefixcmp(buffer, DIRECTORY_BEGIN))
|
||||||
(DIRECTORY_BEGIN, buffer,
|
|
||||||
strlen(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)]);
|
||||||
|
|
||||||
while (nextDirNode && (strcmpRet =
|
while (nextDirNode && (strcmpRet =
|
||||||
@ -932,7 +928,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
|
|||||||
}
|
}
|
||||||
|
|
||||||
readDirectoryInfo(fp, subDirectory);
|
readDirectoryInfo(fp, subDirectory);
|
||||||
} else if (0 == strncmp(SONG_BEGIN, buffer, strlen(SONG_BEGIN))) {
|
} else if (!prefixcmp(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);
|
||||||
@ -1086,16 +1082,13 @@ int readDirectoryDB(void)
|
|||||||
if (0 == strcmp(DIRECTORY_INFO_BEGIN, buffer)) {
|
if (0 == strcmp(DIRECTORY_INFO_BEGIN, buffer)) {
|
||||||
while (myFgets(buffer, bufferSize, fp) &&
|
while (myFgets(buffer, bufferSize, fp) &&
|
||||||
0 != strcmp(DIRECTORY_INFO_END, buffer)) {
|
0 != strcmp(DIRECTORY_INFO_END, buffer)) {
|
||||||
if (0 == strncmp(DIRECTORY_MPD_VERSION, buffer,
|
if (!prefixcmp(buffer, DIRECTORY_MPD_VERSION))
|
||||||
strlen(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 (0 ==
|
} else if (!prefixcmp(buffer,
|
||||||
strncmp(DIRECTORY_FS_CHARSET, buffer,
|
DIRECTORY_FS_CHARSET)) {
|
||||||
strlen
|
|
||||||
(DIRECTORY_FS_CHARSET))) {
|
|
||||||
char *fsCharset;
|
char *fsCharset;
|
||||||
char *tempCharset;
|
char *tempCharset;
|
||||||
|
|
||||||
|
@ -613,7 +613,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 (strncmp(lame->encoder, "LAME", 4) != 0)
|
if (prefixcmp(lame->encoder, "LAME"))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (sscanf(lame->encoder+4, "%u.%u",
|
if (sscanf(lame->encoder+4, "%u.%u",
|
||||||
|
3
src/ls.c
3
src/ls.c
@ -89,9 +89,8 @@ int isRemoteUrl(const char *url)
|
|||||||
|
|
||||||
while (*urlPrefixes) {
|
while (*urlPrefixes) {
|
||||||
count++;
|
count++;
|
||||||
if (strncmp(*urlPrefixes, url, strlen(*urlPrefixes)) == 0) {
|
if (!prefixcmp(url, *urlPrefixes))
|
||||||
return count;
|
return count;
|
||||||
}
|
|
||||||
urlPrefixes++;
|
urlPrefixes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,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 (strncmp(argv[i], "--", 2) == 0) {
|
if (!prefixcmp(argv[i], "--")) {
|
||||||
if (strcmp(argv[i], "--help") == 0) {
|
if (strcmp(argv[i], "--help") == 0) {
|
||||||
usage(argv);
|
usage(argv);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
@ -309,8 +309,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 (strncmp(buffer, PLAYLIST_STATE_FILE_STATE,
|
if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_STATE)) {
|
||||||
strlen(PLAYLIST_STATE_FILE_STATE)) == 0) {
|
|
||||||
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;
|
||||||
@ -321,33 +320,24 @@ void readPlaylistState(FILE *fp)
|
|||||||
== 0) {
|
== 0) {
|
||||||
state = PLAYER_STATE_PAUSE;
|
state = PLAYER_STATE_PAUSE;
|
||||||
}
|
}
|
||||||
} else if (strncmp(buffer, PLAYLIST_STATE_FILE_TIME,
|
} else if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_TIME)) {
|
||||||
strlen(PLAYLIST_STATE_FILE_TIME)) == 0) {
|
|
||||||
seek_time =
|
seek_time =
|
||||||
atoi(&(buffer[strlen(PLAYLIST_STATE_FILE_TIME)]));
|
atoi(&(buffer[strlen(PLAYLIST_STATE_FILE_TIME)]));
|
||||||
} else
|
} else
|
||||||
if (strncmp
|
if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_REPEAT)) {
|
||||||
(buffer, PLAYLIST_STATE_FILE_REPEAT,
|
|
||||||
strlen(PLAYLIST_STATE_FILE_REPEAT)) == 0) {
|
|
||||||
if (strcmp
|
if (strcmp
|
||||||
(&(buffer[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
|
(&(buffer[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
|
||||||
"1") == 0) {
|
"1") == 0) {
|
||||||
setPlaylistRepeatStatus(1);
|
setPlaylistRepeatStatus(1);
|
||||||
} else
|
} else
|
||||||
setPlaylistRepeatStatus(0);
|
setPlaylistRepeatStatus(0);
|
||||||
} else
|
} else if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_CROSSFADE)) {
|
||||||
if (strncmp
|
|
||||||
(buffer, PLAYLIST_STATE_FILE_CROSSFADE,
|
|
||||||
strlen(PLAYLIST_STATE_FILE_CROSSFADE)) == 0) {
|
|
||||||
setPlayerCrossFade(atoi
|
setPlayerCrossFade(atoi
|
||||||
(&
|
(&
|
||||||
(buffer
|
(buffer
|
||||||
[strlen
|
[strlen
|
||||||
(PLAYLIST_STATE_FILE_CROSSFADE)])));
|
(PLAYLIST_STATE_FILE_CROSSFADE)])));
|
||||||
} else
|
} else if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_RANDOM)) {
|
||||||
if (strncmp
|
|
||||||
(buffer, PLAYLIST_STATE_FILE_RANDOM,
|
|
||||||
strlen(PLAYLIST_STATE_FILE_RANDOM)) == 0) {
|
|
||||||
if (strcmp
|
if (strcmp
|
||||||
(&
|
(&
|
||||||
(buffer
|
(buffer
|
||||||
@ -356,20 +346,15 @@ void readPlaylistState(FILE *fp)
|
|||||||
setPlaylistRandomStatus(1);
|
setPlaylistRandomStatus(1);
|
||||||
} else
|
} else
|
||||||
setPlaylistRandomStatus(0);
|
setPlaylistRandomStatus(0);
|
||||||
} else if (strncmp(buffer, PLAYLIST_STATE_FILE_CURRENT,
|
} else if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_CURRENT)) {
|
||||||
strlen(PLAYLIST_STATE_FILE_CURRENT))
|
|
||||||
== 0) {
|
|
||||||
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
|
} else if (!prefixcmp(buffer,
|
||||||
if (strncmp
|
PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)) {
|
||||||
(buffer, PLAYLIST_STATE_FILE_PLAYLIST_BEGIN,
|
|
||||||
strlen(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)
|
|
||||||
) == 0) {
|
|
||||||
if (state == PLAYER_STATE_STOP)
|
if (state == PLAYER_STATE_STOP)
|
||||||
current = -1;
|
current = -1;
|
||||||
loadPlaylistFromStateFile(fp, buffer, state,
|
loadPlaylistFromStateFile(fp, buffer, state,
|
||||||
|
12
src/volume.c
12
src/volume.c
@ -508,26 +508,22 @@ int changeVolumeLevel(int change, int rel)
|
|||||||
|
|
||||||
void read_sw_volume_state(FILE *fp)
|
void read_sw_volume_state(FILE *fp)
|
||||||
{
|
{
|
||||||
/* strlen(SW_VOLUME_STATE) + strlen('100') + '\0' */
|
char buf[sizeof(SW_VOLUME_STATE) + sizeof("100") - 1];
|
||||||
#define bufsize 16
|
|
||||||
char buf[bufsize];
|
|
||||||
const size_t len = strlen(SW_VOLUME_STATE);
|
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
long int sv;
|
long int sv;
|
||||||
|
|
||||||
if (volume_mixerType != VOLUME_MIXER_TYPE_SOFTWARE)
|
if (volume_mixerType != VOLUME_MIXER_TYPE_SOFTWARE)
|
||||||
return;
|
return;
|
||||||
while (myFgets(buf, bufsize, fp)) {
|
while (myFgets(buf, sizeof(buf), fp)) {
|
||||||
if (strncmp(buf, SW_VOLUME_STATE, len))
|
if (prefixcmp(buf, SW_VOLUME_STATE))
|
||||||
continue;
|
continue;
|
||||||
sv = strtol(buf + len, &end, 10);
|
sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10);
|
||||||
if (mpd_likely(!*end))
|
if (mpd_likely(!*end))
|
||||||
changeSoftwareVolume(sv, 0);
|
changeSoftwareVolume(sv, 0);
|
||||||
else
|
else
|
||||||
ERROR("Can't parse software volume: %s\n", buf);
|
ERROR("Can't parse software volume: %s\n", buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#undef bufsize
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_sw_volume_state(FILE *fp)
|
void save_sw_volume_state(FILE *fp)
|
||||||
|
Loading…
Reference in New Issue
Block a user