aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/buffer2array.c28
-rw-r--r--src/buffer2array.h2
-rw-r--r--src/command.c8
-rw-r--r--src/conf.c4
-rw-r--r--src/directory.c24
-rw-r--r--src/player.h2
6 files changed, 42 insertions, 26 deletions
diff --git a/src/buffer2array.c b/src/buffer2array.c
index 3bdb66547..38ced19dc 100644
--- a/src/buffer2array.c
+++ b/src/buffer2array.c
@@ -23,7 +23,15 @@
#include <string.h>
#include <ctype.h>
-int cstrtok(char *buffer, char *array[], const int max)
+
+inline static
+int
+isWhiteSpace(char c)
+{
+ return (c == ' ' || c == '\t');
+}
+
+int buffer2array(char *buffer, char *array[], const int max)
{
int i = 0;
char *c = buffer;
@@ -48,18 +56,18 @@ int cstrtok(char *buffer, char *array[], const int max)
escape = (*(c++) != '\\') ? 0 : !escape;
}
} else {
- while (isspace(*c))
+ while (isWhiteSpace(*c))
++c;
array[i++] = c++;
if (*c == '\0')
return i;
- while (!isspace(*c) && *c != '\0')
+ while (!isWhiteSpace(*c) && *c != '\0')
++c;
}
if (*c == '\0')
return i;
*(c++) = '\0';
- while (isspace(*c))
+ while (isWhiteSpace(*c))
++c;
}
return i;
@@ -78,37 +86,37 @@ int main()
int i, max;
b = strdup("lsinfo \"/some/dir/name \\\"test\\\"\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir/name \"test\"", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir/name \\\"test\\\" something else\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir/name \"test\" something else", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir\\\\name\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir\\name", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"/some/dir name\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("/some/dir name", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"\\\"/some/dir\\\"\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("\"/some/dir\"", a[1]) );
assert( !a[2] );
b = strdup("lsinfo \"\\\"/some/dir\\\" x\"");
- max = cstrtok(b, a, 4);
+ max = buffer2array(b, a, 4);
assert( !strcmp("lsinfo", a[0]) );
assert( !strcmp("\"/some/dir\" x", a[1]) );
assert( !a[2] );
diff --git a/src/buffer2array.h b/src/buffer2array.h
index cecd3b6d3..e12f0ceed 100644
--- a/src/buffer2array.h
+++ b/src/buffer2array.h
@@ -27,6 +27,6 @@
* The arguments buffer and array are modified.
* Returns the number of elements tokenized.
*/
-int cstrtok(char *buffer, char *array[], const int max);
+int buffer2array(char *buffer, char *array[], const int max);
#endif
diff --git a/src/command.c b/src/command.c
index b063f8a0e..10e87bd80 100644
--- a/src/command.c
+++ b/src/command.c
@@ -31,6 +31,7 @@
#include "dbUtils.h"
#include "tag.h"
+#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@@ -164,6 +165,9 @@ static void addCommand(char *name,
cmd->listHandler = listHandler_func;
cmd->reqPermission = reqPermission;
+ assert(minargs <= maxargs);
+ assert(maxargs <= COMMAND_ARGV_MAX);
+
insertInList(commandList, cmd->cmd, cmd);
}
@@ -1142,7 +1146,7 @@ static CommandEntry *getCommandEntryFromString(char *string, int *permission)
{
CommandEntry *cmd = NULL;
char *argv[COMMAND_ARGV_MAX] = { NULL };
- int argc = cstrtok(string, argv, COMMAND_ARGV_MAX);
+ int argc = buffer2array(string, argv, COMMAND_ARGV_MAX);
if (0 == argc)
return NULL;
@@ -1161,7 +1165,7 @@ static int processCommandInternal(int fd, int *permission,
CommandEntry *cmd;
int ret = -1;
- argc = cstrtok(commandString, argv, COMMAND_ARGV_MAX);
+ argc = buffer2array(commandString, argv, COMMAND_ARGV_MAX);
if (argc == 0)
return 0;
diff --git a/src/conf.c b/src/conf.c
index bea4e2c08..54cb560b4 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -203,7 +203,7 @@ static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string)
(*count)++;
- numberOfArgs = cstrtok(string, array, CONF_LINE_TOKEN_MAX);
+ numberOfArgs = buffer2array(string, array, CONF_LINE_TOKEN_MAX);
for (i = 0; i < numberOfArgs; i++) {
if (array[i][0] == CONF_COMMENT)
@@ -265,7 +265,7 @@ void readConf(char *file)
char *array[CONF_LINE_TOKEN_MAX] = { NULL };
count++;
- numberOfArgs = cstrtok(string, array, CONF_LINE_TOKEN_MAX);
+ numberOfArgs = buffer2array(string, array, CONF_LINE_TOKEN_MAX);
for (i = 0; i < numberOfArgs; i++) {
if (array[i][0] == CONF_COMMENT)
diff --git a/src/directory.c b/src/directory.c
index 9b90418f2..73a43d98f 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -18,22 +18,23 @@
#include "directory.h"
-#include "ls.h"
#include "command.h"
-#include "utils.h"
-#include "path.h"
-#include "log.h"
#include "conf.h"
-#include "stats.h"
-#include "playlist.h"
-#include "listen.h"
+#include "dbUtils.h"
#include "interface.h"
-#include "volume.h"
+#include "list.h"
+#include "listen.h"
+#include "log.h"
+#include "ls.h"
#include "mpd_types.h"
+#include "path.h"
+#include "player.h"
+#include "playlist.h"
#include "sig_handlers.h"
-#include "list.h"
-#include "dbUtils.h"
+#include "stats.h"
#include "tagTracker.h"
+#include "utils.h"
+#include "volume.h"
#include <sys/wait.h>
#include <dirent.h>
@@ -732,7 +733,8 @@ static int statDirectory(Directory * dir)
{
struct stat st;
- if (myStat(getDirectoryPath(dir) ? getDirectoryPath(dir) : "", &st) < 0) {
+ if (myStat(getDirectoryPath(dir) ? getDirectoryPath(dir) : "", &st) < 0)
+ {
return -1;
}
diff --git a/src/player.h b/src/player.h
index ac83c9ea5..e414c7c3d 100644
--- a/src/player.h
+++ b/src/player.h
@@ -89,6 +89,8 @@ typedef struct _PlayerControl {
MetadataChunk fileMetadataChunk;
} PlayerControl;
+void clearPlayerPid();
+
void player_sigChldHandler(int pid, int status);
int playerPlay(int fd, Song * song);