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

Support named integers, floats, and enums when partial value names are used.

(e.g. "CRIT" instead of "CRITICAL").
parent b8c1702c
No related branches found
No related tags found
No related merge requests found
......@@ -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));
}
......
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