From c02e5f745c65b70cad0f3ddb70025a8ec8337380 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Wed, 28 Nov 2007 03:41:04 +0000 Subject: [PATCH] Created iniGet/ReadEnumList() functions for Deuce (he did say "please"). Do we need an iniSetEnumList() function too? --- src/xpdev/ini_file.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ src/xpdev/ini_file.h | 4 +++ 2 files changed, 62 insertions(+) diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index 7defaa5e96..11ac697ccc 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -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; diff --git a/src/xpdev/ini_file.h b/src/xpdev/ini_file.h index 58e81ae4b9..93e765ce6b 100644 --- a/src/xpdev/ini_file.h +++ b/src/xpdev/ini_file.h @@ -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 -- GitLab