Skip to content
Snippets Groups Projects
Commit e74c70e1 authored by rswindell's avatar rswindell
Browse files

Created iniReadSectionList and iniReadKeyList functions to return list of

section names or key names in a .ini file.
parent fd715e0d
No related branches found
No related tags found
No related merge requests found
...@@ -65,7 +65,7 @@ static BOOL find_section(FILE* fp, const char* section) ...@@ -65,7 +65,7 @@ static BOOL find_section(FILE* fp, const char* section)
rewind(fp); rewind(fp);
while(!feof(fp)) { while(!feof(fp)) {
if(fgets(str,sizeof(str)-1,fp)==NULL) if(fgets(str,sizeof(str),fp)==NULL)
break; break;
p=str; p=str;
while(*p && *p<=' ') p++; while(*p && *p<=' ') p++;
...@@ -96,7 +96,7 @@ static char* get_value(FILE* fp, const char* section, const char* key) ...@@ -96,7 +96,7 @@ static char* get_value(FILE* fp, const char* section, const char* key)
return(NULL); return(NULL);
while(!feof(fp)) { while(!feof(fp)) {
if(fgets(str,sizeof(str)-1,fp)==NULL) if(fgets(str,sizeof(str),fp)==NULL)
break; break;
p=str; p=str;
while(*p && *p<=' ') p++; while(*p && *p<=' ') p++;
...@@ -184,6 +184,100 @@ char** iniFreeStringList(char** list) ...@@ -184,6 +184,100 @@ char** iniFreeStringList(char** list)
return(NULL); 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) long iniReadInteger(FILE* fp, const char* section, const char* key, long deflt)
{ {
char* value; char* value;
......
...@@ -49,6 +49,8 @@ typedef struct { ...@@ -49,6 +49,8 @@ typedef struct {
extern "C" { extern "C" {
#endif #endif
char** iniReadSectionList(FILE* fp);
char** iniReadKeyList (FILE* fp, const char* section);
char* iniReadString (FILE* fp, const char* section, const char* key, char* iniReadString (FILE* fp, const char* section, const char* key,
const char* deflt); const char* deflt);
char** iniReadStringList(FILE* fp, const char* section, const char* key char** iniReadStringList(FILE* fp, const char* section, const char* key
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment