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

Created iniGet/ReadEnumList() functions for Deuce (he did say "please").

Do we need an iniSetEnumList() function too?
parent 45a55fce
No related branches found
No related tags found
No related merge requests found
......@@ -1523,6 +1523,36 @@ static unsigned parseEnum(const char* value, str_list_t names)
return(strtoul(value,NULL,0));
}
static unsigned* parseEnumList(const char* values, const char* sep, str_list_t names)
{
char* vals;
str_list_t list;
unsigned* enum_list;
size_t i,count;
if(values==NULL)
return NULL;
if((vals=strdup(values)) == NULL)
return NULL;
list=splitList(vals, sep);
free(vals);
if((count=strListCount(list)) < 1)
return NULL;
if((enum_list=(unsigned *)malloc(count*sizeof(unsigned)))!=NULL) {
for(i=0;i<count;i++)
enum_list[i]=parseEnum(list[i], names);
}
strListFree(&list);
return enum_list;
}
unsigned iniReadEnum(FILE* fp, const char* section, const char* key, str_list_t names, unsigned deflt)
{
char buf[INI_MAX_VALUE_LEN];
......@@ -1537,6 +1567,19 @@ unsigned iniReadEnum(FILE* fp, const char* section, const char* key, str_list_t
return(parseEnum(value,names));
}
unsigned* iniReadEnumList(FILE* fp, const char* section, const char* key
,str_list_t names
,const char* sep, const char* deflt)
{
char* value;
char buf[INI_MAX_VALUE_LEN];
if((value=read_value(fp,section,key,buf))==NULL || *value==0 /* blank */)
value=(char*)deflt;
return(parseEnumList(value, sep, names));
}
unsigned iniGetEnum(str_list_t list, const char* section, const char* key, str_list_t names, unsigned deflt)
{
char value[INI_MAX_VALUE_LEN];
......@@ -1549,6 +1592,21 @@ unsigned iniGetEnum(str_list_t list, const char* section, const char* key, str_l
return(parseEnum(value,names));
}
unsigned* iniGetEnumList(str_list_t list, const char* section, const char* key
,str_list_t names, const char* sep, const char* deflt)
{
char value[INI_MAX_VALUE_LEN];
get_value(list, section, key, value);
if(*value==0 /* blank value or missing key */) {
if(deflt==NULL)
return(NULL);
SAFECOPY(value,deflt);
}
return(parseEnumList(value, sep, names));
}
static long parseNamedInt(const char* value, named_long_t* names)
{
unsigned i;
......
......@@ -100,6 +100,8 @@ time_t iniReadDateTime(FILE*, const char* section, const char* key
,time_t deflt);
unsigned iniReadEnum(FILE*, const char* section, const char* key
,str_list_t names, unsigned deflt);
unsigned* iniReadEnumList(FILE*, const char* section, const char* key
,str_list_t names, const char* sep, const char* deflt);
long iniReadNamedInt(FILE*, const char* section, const char* key
,named_long_t*, long deflt);
double iniReadNamedFloat(FILE*, const char* section, const char* key
......@@ -152,6 +154,8 @@ time_t iniGetDateTime(str_list_t, const char* section, const char* key
,time_t deflt);
unsigned iniGetEnum(str_list_t, const char* section, const char* key
,str_list_t names, unsigned deflt);
unsigned* iniGetEnumList(str_list_t, const char* section, const char* key
,str_list_t names, const char* sep, const char* deflt);
long iniGetNamedInt(str_list_t, const char* section, const char* key
,named_long_t*, long deflt);
double iniGetNamedFloat(str_list_t, 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