renamce cstrtok to buffer2array. please don't rename functions; especially to names that look extremely std-lib-ish. also, don't use isspace, apparently it's local dependent and potentially consideres ' ' or '\t' not to be a space, or considers other characters to be a space.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4574 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2006-08-06 13:53:53 +00:00
parent 31de97a42b
commit 8e53406774
6 changed files with 44 additions and 28 deletions

View File

@ -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] );

View File

@ -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

View File

@ -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;

View File

@ -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)

View File

@ -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 "interface.h"
#include "volume.h"
#include "mpd_types.h"
#include "sig_handlers.h"
#include "list.h"
#include "dbUtils.h"
#include "interface.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 "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;
}

View File

@ -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);