for improperly config file lines, print the line number
also, in myFgets, chop off '\r' at the end of the line (thanx mr gates) git-svn-id: https://svn.musicpd.org/mpd/trunk@2000 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
ef81001138
commit
ab0b6ce56f
@ -160,6 +160,7 @@ char ** readConf(char * file) {
|
|||||||
int i;
|
int i;
|
||||||
int numberOfArgs;
|
int numberOfArgs;
|
||||||
short allowCat[CONF_NUMBER_OF_PARAMS];
|
short allowCat[CONF_NUMBER_OF_PARAMS];
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
for(i=0;i<CONF_NUMBER_OF_PARAMS;i++) allowCat[i] = 0;
|
for(i=0;i<CONF_NUMBER_OF_PARAMS;i++) allowCat[i] = 0;
|
||||||
|
|
||||||
@ -171,19 +172,22 @@ char ** readConf(char * file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while(myFgets(string,sizeof(string),fp)) {
|
while(myFgets(string,sizeof(string),fp)) {
|
||||||
|
count++;
|
||||||
|
|
||||||
if(string[0]==CONF_COMMENT) continue;
|
if(string[0]==CONF_COMMENT) continue;
|
||||||
numberOfArgs = buffer2array(string,&array);
|
numberOfArgs = buffer2array(string,&array);
|
||||||
if(numberOfArgs==0) continue;
|
if(numberOfArgs==0) continue;
|
||||||
if(2!=numberOfArgs) {
|
if(2!=numberOfArgs) {
|
||||||
ERROR("improperly formated config line: %s\n",string);
|
ERROR("improperly formated config file at line %i: %s\n",count,string);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
while(i<CONF_NUMBER_OF_PARAMS && 0!=strcmp(conf_strings[i],array[0])) i++;
|
while(i<CONF_NUMBER_OF_PARAMS && 0!=strcmp(conf_strings[i],array[0])) i++;
|
||||||
if(i>=CONF_NUMBER_OF_PARAMS) {
|
if(i>=CONF_NUMBER_OF_PARAMS) {
|
||||||
ERROR("unrecognized line in conf: %s\n",string);
|
ERROR("unrecognized paramater in conf at line %i: %s\n",count,string);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(conf_params[i]!=NULL) {
|
if(conf_params[i]!=NULL) {
|
||||||
if(allowCat[i]) {
|
if(allowCat[i]) {
|
||||||
conf_params[i] = realloc(conf_params[i],
|
conf_params[i] = realloc(conf_params[i],
|
||||||
|
@ -32,6 +32,9 @@ char * myFgets(char * buffer, int bufferSize, FILE * fp) {
|
|||||||
if(ret && strlen(buffer)>0 && buffer[strlen(buffer)-1]=='\n') {
|
if(ret && strlen(buffer)>0 && buffer[strlen(buffer)-1]=='\n') {
|
||||||
buffer[strlen(buffer)-1] = '\0';
|
buffer[strlen(buffer)-1] = '\0';
|
||||||
}
|
}
|
||||||
|
if(ret && strlen(buffer)>0 && buffer[strlen(buffer)-1]=='\r') {
|
||||||
|
buffer[strlen(buffer)-1] = '\0';
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user