aboutsummaryrefslogtreecommitdiffstats
path: root/src/conf.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-07-29 18:55:00 +0000
committerEric Wong <normalperson@yhbt.net>2006-07-29 18:55:00 +0000
commitf08342c11fb7f31b168902b4d89d8e543e03125a (patch)
treee56ebfd5f0b4376d10e4f02dba17f3dfef82b999 /src/conf.c
parentf05166a6a0f39e6c6f8ce9675d7f6f6f58300577 (diff)
downloadmpd-f08342c11fb7f31b168902b4d89d8e543e03125a.tar.gz
mpd-f08342c11fb7f31b168902b4d89d8e543e03125a.tar.xz
mpd-f08342c11fb7f31b168902b4d89d8e543e03125a.zip
replace buffer2array() with cstrtok() from mpd-ke
This modifies the string in place, and does not allocate any memory from the heap. This is considerably smaller than the function it replaces, and will be instrumental in getting the commands/conf malloc reductions done. git-svn-id: https://svn.musicpd.org/mpd/trunk@4481 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/conf.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/conf.c b/src/conf.c
index 5aefa016f..f130334ba 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -41,6 +41,7 @@
#define CONF_REPEATABLE_MASK 0x01
#define CONF_BLOCK_MASK 0x02
+#define CONF_LINE_TOKEN_MAX 3
typedef struct _configEntry {
unsigned char mask;
@@ -193,15 +194,16 @@ static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string)
{
ConfigParam *ret = newConfigParam(NULL, *count);
- char **array;
int i;
int numberOfArgs;
int argsMinusComment;
while (myFgets(string, MAX_STRING_SIZE, fp)) {
+ char *array[CONF_LINE_TOKEN_MAX] = { 0 };
+
(*count)++;
- numberOfArgs = buffer2array(string, &array);
+ numberOfArgs = cstrtok(string, array, CONF_LINE_TOKEN_MAX);
for (i = 0; i < numberOfArgs; i++) {
if (array[i][0] == CONF_COMMENT)
@@ -211,13 +213,11 @@ static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string)
argsMinusComment = i;
if (0 == argsMinusComment) {
- freeArgArray(array, numberOfArgs);
continue;
}
if (1 == argsMinusComment &&
0 == strcmp(array[0], CONF_BLOCK_END)) {
- freeArgArray(array, numberOfArgs);
break;
}
@@ -238,8 +238,6 @@ static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string)
}
addBlockParam(ret, array[0], array[1], *count);
-
- freeArgArray(array, numberOfArgs);
}
return ret;
@@ -249,7 +247,6 @@ void readConf(char *file)
{
FILE *fp;
char string[MAX_STRING_SIZE + 1];
- char **array;
int i;
int numberOfArgs;
int argsMinusComment;
@@ -265,9 +262,10 @@ void readConf(char *file)
}
while (myFgets(string, MAX_STRING_SIZE, fp)) {
+ char *array[CONF_LINE_TOKEN_MAX] = { 0 };
count++;
- numberOfArgs = buffer2array(string, &array);
+ numberOfArgs = cstrtok(string, array, CONF_LINE_TOKEN_MAX);
for (i = 0; i < numberOfArgs; i++) {
if (array[i][0] == CONF_COMMENT)
@@ -277,7 +275,6 @@ void readConf(char *file)
argsMinusComment = i;
if (0 == argsMinusComment) {
- freeArgArray(array, numberOfArgs);
continue;
}
@@ -316,8 +313,6 @@ void readConf(char *file)
param = newConfigParam(array[1], count);
insertInListWithoutKey(entry->configParamList, param);
-
- freeArgArray(array, numberOfArgs);
}
fclose(fp);
}