diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index 66e87b7bd0385f1bc1ad00615ca837039998abf7..c0cf0a1326eaeb5885f5a6a94c1e415acfe00058 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -687,6 +687,30 @@ char* DLLCALL iniSetNamedInt(str_list_t* list, const char* section, const char* return iniSetInteger(list, section, key, value, style); } +char* DLLCALL iniSetNamedHexInt(str_list_t* list, const char* section, const char* key, named_ulong_t* names + ,ulong value, ini_style_t* style) +{ + size_t i; + + for(i=0;names[i].name!=NULL;i++) + if(names[i].value==value) + return iniSetString(list, section, key, names[i].name, style); + + return iniSetHexInt(list, section, key, value, style); +} + +char* DLLCALL iniSetNamedLongInt(str_list_t* list, const char* section, const char* key, named_ulong_t* names + ,ulong value, ini_style_t* style) +{ + size_t i; + + for(i=0;names[i].name!=NULL;i++) + if(names[i].value==value) + return iniSetString(list, section, key, names[i].name, style); + + return iniSetLongInt(list, section, key, value, style); +} + char* DLLCALL iniSetNamedFloat(str_list_t* list, const char* section, const char* key, named_double_t* names ,double value, ini_style_t* style) { @@ -1889,6 +1913,51 @@ long DLLCALL iniGetNamedInt(str_list_t list, const char* section, const char* ke return(parseNamedInt(vp,names)); } +static ulong parseNamedLongInt(const char* value, named_ulong_t* names) +{ + unsigned i; + + /* Look for exact matches first */ + for(i=0; names[i].name!=NULL; i++) + if(stricmp(names[i].name,value)==0) + return(names[i].value); + + /* Look for partial matches second */ + for(i=0; names[i].name!=NULL; i++) + if(strnicmp(names[i].name,value,strlen(value))==0) + return(names[i].value); + + return(parseLongInteger(value)); +} + +ulong DLLCALL iniReadNamedLongInt(FILE* fp, const char* section, const char* key + ,named_ulong_t* names, ulong deflt) +{ + char buf[INI_MAX_VALUE_LEN]; + char* value; + + if((value=read_value(fp,section,key,buf))==NULL) + return(deflt); + + if(*value==0) /* blank value */ + return(deflt); + + return(parseNamedLongInt(value,names)); +} + +ulong DLLCALL iniGetNamedLongInt(str_list_t list, const char* section, const char* key + ,named_ulong_t* names, ulong deflt) +{ + char* vp=NULL; + + get_value(list, section, key, NULL, &vp); + + if(vp==NULL || *vp==0) /* blank value or missing key */ + return(deflt); + + return(parseNamedLongInt(vp,names)); +} + static double parseNamedFloat(const char* value, named_double_t* names) { unsigned i; diff --git a/src/xpdev/ini_file.h b/src/xpdev/ini_file.h index fa09ed04330576e9c9c5a0b7c7e6fe275ce630c6..bfa0cdceee8c3a8cdf5a261f68c29d1df4dd4080 100644 --- a/src/xpdev/ini_file.h +++ b/src/xpdev/ini_file.h @@ -108,6 +108,8 @@ DLLEXPORT unsigned* DLLCALL iniReadEnumList(FILE*, const char* section, const ch ,str_list_t names, unsigned* count, const char* sep, const char* deflt); DLLEXPORT long DLLCALL iniReadNamedInt(FILE*, const char* section, const char* key ,named_long_t*, long deflt); +DLLEXPORT ulong DLLCALL iniReadNamedLongInt(FILE*, const char* section, const char* key + ,named_ulong_t*, ulong deflt); DLLEXPORT double DLLCALL iniReadNamedFloat(FILE*, const char* section, const char* key ,named_double_t*, double deflt); DLLEXPORT ulong DLLCALL iniReadBitField(FILE*, const char* section, const char* key @@ -164,6 +166,8 @@ DLLEXPORT unsigned* DLLCALL iniGetEnumList(str_list_t, const char* section, cons ,str_list_t names, unsigned* count, const char* sep, const char* deflt); DLLEXPORT long DLLCALL iniGetNamedInt(str_list_t, const char* section, const char* key ,named_long_t*, long deflt); +DLLEXPORT ulong DLLCALL iniGetNamedLongInt(str_list_t, const char* section, const char* key + ,named_ulong_t*, ulong deflt); DLLEXPORT double DLLCALL iniGetNamedFloat(str_list_t, const char* section, const char* key ,named_double_t*, double deflt); DLLEXPORT ulong DLLCALL iniGetBitField(str_list_t, const char* section, const char* key @@ -216,6 +220,10 @@ DLLEXPORT char* DLLCALL iniSetEnumList(str_list_t*, const char* section, const ,const char* sep, str_list_t names, unsigned* values, unsigned count, ini_style_t*); DLLEXPORT char* DLLCALL iniSetNamedInt(str_list_t*, const char* section, const char* key, named_long_t* ,long value, ini_style_t*); +DLLEXPORT char* DLLCALL iniSetNamedHexInt(str_list_t*, const char* section, const char* key, named_ulong_t* + ,ulong value, ini_style_t*); +DLLEXPORT char* DLLCALL iniSetNamedLongInt(str_list_t*, const char* section, const char* key, named_ulong_t* + ,ulong value, ini_style_t*); DLLEXPORT char* DLLCALL iniSetNamedFloat(str_list_t*, const char* section, const char* key, named_double_t* ,double value, ini_style_t*); DLLEXPORT char* DLLCALL iniSetBitField(str_list_t*, const char* section, const char* key, ini_bitdesc_t*, ulong value