From 07ed169799877c8fc62f79e41488df8d9288a448 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Wed, 28 Sep 2005 08:25:59 +0000 Subject: [PATCH] Support named integers, floats, and enums when partial value names are used. (e.g. "CRIT" instead of "CRITICAL"). --- src/xpdev/ini_file.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/xpdev/ini_file.c b/src/xpdev/ini_file.c index 66f3d1d515..3a3dd52aa5 100644 --- a/src/xpdev/ini_file.c +++ b/src/xpdev/ini_file.c @@ -61,11 +61,13 @@ void iniSetDefaultStyle(ini_style_t style) default_style = style; } -char* log_levels[] = {"Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Info", "Debug", NULL}; +/* These correlate with the LOG_* definitions in syslog.h/gen_defs.h */ +static char* logLevelStringList[] + = {"Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Informational", "Debugging", NULL}; str_list_t iniLogLevelStringList(void) { - return(log_levels); + return(logLevelStringList); } static char* section_name(char* p) @@ -1329,10 +1331,16 @@ static unsigned parseEnum(const char* value, str_list_t names) { unsigned i; + /* Look for exact matches first */ for(i=0;names[i]!=NULL;i++) if(stricmp(names[i],value)==0) return(i); + /* Look for partial matches second */ + for(i=0;names[i]!=NULL;i++) + if(strnicmp(names[i],value,strlen(value))==0) + return(i); + return(strtoul(value,NULL,0)); } @@ -1366,10 +1374,16 @@ static long parseNamedInt(const char* value, named_long_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(strtol(value,NULL,0)); } @@ -1405,10 +1419,16 @@ static double parseNamedFloat(const char* value, named_double_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(atof(value)); } -- GitLab