diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index 3aa187491c127ed0f92b1922b0ece81af5a8daa6..3b498b5497624d61ec8e6ca1d14583c7dfb6f7d8 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -65,7 +65,7 @@ static BOOL find_section(FILE* fp, const char* section) rewind(fp); while(!feof(fp)) { - if(fgets(str,sizeof(str)-1,fp)==NULL) + if(fgets(str,sizeof(str),fp)==NULL) break; p=str; while(*p && *p<=' ') p++; @@ -96,7 +96,7 @@ static char* get_value(FILE* fp, const char* section, const char* key) return(NULL); while(!feof(fp)) { - if(fgets(str,sizeof(str)-1,fp)==NULL) + if(fgets(str,sizeof(str),fp)==NULL) break; p=str; while(*p && *p<=' ') p++; @@ -184,6 +184,100 @@ char** iniFreeStringList(char** list) return(NULL); } +char** iniReadSectionList(FILE* fp) +{ + char* p; + char* tp; + char** lp; + char** np; + char str[MAX_LINE_LEN]; + ulong items=0; + + if((lp=malloc(sizeof(char*)))==NULL) + return(NULL); + + *lp=NULL; + + if(fp==NULL) + return(lp); + + rewind(fp); + + while(!feof(fp)) { + if(fgets(str,sizeof(str),fp)==NULL) + break; + p=str; + while(*p && *p<=' ') p++; + if(*p!='[') + continue; + p++; + tp=strchr(p,']'); + if(tp==NULL) + continue; + *tp=0; + if((np=realloc(lp,sizeof(char*)*(items+2)))==NULL) + break; + lp=np; + if((lp[items]=malloc(strlen(p)+1))==NULL) + break; + strcpy(lp[items++],p); + } + + lp[items]=NULL; /* terminate list */ + + return(lp); +} + +char** iniReadKeyList(FILE* fp, const char* section) +{ + + char* p; + char* tp; + char** lp; + char** np; + char str[MAX_LINE_LEN]; + ulong items=0; + + if((lp=malloc(sizeof(char*)))==NULL) + return(NULL); + + *lp=NULL; + + if(fp==NULL) + return(lp); + + rewind(fp); + + if(!find_section(fp,section)) + return(lp); + + while(!feof(fp)) { + if(fgets(str,sizeof(str),fp)==NULL) + break; + p=str; + while(*p && *p<=' ') p++; + if(*p==';') + continue; + if(*p=='[') + break; + tp=strchr(p,'='); + if(tp==NULL) + continue; + *tp=0; + truncsp(p); + if((np=realloc(lp,sizeof(char*)*(items+2)))==NULL) + break; + lp=np; + if((lp[items]=malloc(strlen(p)+1))==NULL) + break; + strcpy(lp[items++],p); + } + + lp[items]=NULL; /* terminate list */ + + return(lp); +} + long iniReadInteger(FILE* fp, const char* section, const char* key, long deflt) { char* value; diff --git a/src/xpdev/ini_file.h b/src/xpdev/ini_file.h index 9e1abb8c4d3f6bd60495c7164061d207e70b446c..90093fd5222d541b8fce0442c1bdbb55c114c4cd 100644 --- a/src/xpdev/ini_file.h +++ b/src/xpdev/ini_file.h @@ -49,6 +49,8 @@ typedef struct { extern "C" { #endif +char** iniReadSectionList(FILE* fp); +char** iniReadKeyList (FILE* fp, const char* section); char* iniReadString (FILE* fp, const char* section, const char* key, const char* deflt); char** iniReadStringList(FILE* fp, const char* section, const char* key