From c5310c33f54603d623b76fa5eb4f19edeb25be77 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Wed, 27 Oct 2004 20:39:02 +0000 Subject: more config rewrite progress git-svn-id: https://svn.musicpd.org/mpd/branches/shank-rewrite-config@2360 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/conf.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/conf.h | 2 +- 2 files changed, 106 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/conf.c b/src/conf.c index 2ea161061..a00a02caa 100644 --- a/src/conf.c +++ b/src/conf.c @@ -35,6 +35,8 @@ #define MAX_STRING_SIZE MAXPATHLEN+80 #define CONF_COMMENT '#' +#define CONF_BLOCK_BEGIN "{" +#define CONF_BLOCK_END "}" #define CONF_REPEATABLE_MASK 0x01 #define CONF_BLOCK_MASK 0x02 @@ -153,23 +155,124 @@ void initConf() { registerConfigParam(CONF_ID3V1_ENCODING, 0, 0); } -int readConf(char * file) { +ConfigParam * readConfigBlock(FILE * fp, int * count, char * string, + char * name, char * value) +{ + char ** array; + int i; + int numberOfArgs; + int argsMinusComment; + + while(myFgets(string,sizeof(MAX_STRING_SIZE),fp)) { + (*count)++; + + numberOfArgs = buffer2array(string, &array); + + for(i=0; imask & CONF_REPEATABLE_MASK) && + entry->configParamList->numberOfNodes) + { + param = entry->configParamList->firstNode->data; + ERROR("config paramter \"%s\" is first defined on line " + "%i and redefined on line %i\n", + array[0], param->line, count); + exit(EXIT_FAILURE); + } + + if(entry->mask & CONF_BLOCK_MASK) { + param = readConfigBlock(fp, &count, string, array[0], array[1]); + } + else param = newConfigParam(array[1]); + + addConfigParamToEntry(entry, param); + + freeArgArray(&array, numberOfArgs); + } +} + +void readConf(char * file) { FILE * fp; char string[MAX_STRING_SIZE+1]; char ** array; int i; int numberOfArgs; + int argsMinusComment; int count = 0; + ConfigEntry * entry; + void * voidPtr; + ConfigParam * param; if(!(fp=fopen(file,"r"))) { ERROR("problems opening file %s for reading\n",file); exit(EXIT_FAILURE); } - while(myFgets(string,sizeof(string),fp)) { + while(myFgets(string,sizeof(MAX_STRING_SIZE),fp)) { count++; numberOfArgs = buffer2array(string, &array); + + for(i=0; imask & CONF_REPEATABLE_MASK) && + entry->configParamList->numberOfNodes) + { + param = entry->configParamList->firstNode->data; + ERROR("config paramter \"%s\" is first defined on line " + "%i and redefined on line %i\n", + array[0], param->line, count); + exit(EXIT_FAILURE); + } + + if(entry->mask & CONF_BLOCK_MASK) { + param = readConfigBlock(fp, &count, string, array[0], array[1]); + } + else { + } + + freeArgArray(&array, numberOfArgs); + } } diff --git a/src/conf.h b/src/conf.h index 9dbdc86d1..eba5e47da 100644 --- a/src/conf.h +++ b/src/conf.h @@ -71,7 +71,7 @@ typedef struct _ConfigParam { void initConf(); -int readConf(char * file); +void readConf(char * file); /* don't free the returned value set _last_ to NULL to get first entry */ -- cgit v1.2.3