From 7bae3e09224bf37856e9fd13a0e0dc4865b9a6c1 Mon Sep 17 00:00:00 2001 From: skeezix Date: Fri, 5 Mar 2010 23:29:35 -0500 Subject: [PATCH] Added _get_as_int_d function, which is same as _get_as_int but with default value (instead of returning BADNUM) --- include/pnd_conf.h | 1 + lib/pnd_conf.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/pnd_conf.h b/include/pnd_conf.h index 8779f17..a522fd7 100644 --- a/include/pnd_conf.h +++ b/include/pnd_conf.h @@ -123,6 +123,7 @@ pnd_conf_handle pnd_conf_fetch_by_path ( char *fullpath ); char *pnd_conf_get_as_char ( pnd_conf_handle c, char *key ); #define PND_CONF_BADNUM (-31337) /* really lame hack, I know */ int pnd_conf_get_as_int ( pnd_conf_handle c, char *key ); +int pnd_conf_get_as_int_d ( pnd_conf_handle c, char *key, int def ); // same as _as_int, but returns default instead of BADNUM #ifdef __cplusplus } /* "C" */ diff --git a/lib/pnd_conf.c b/lib/pnd_conf.c index e2114a5..5f1901f 100644 --- a/lib/pnd_conf.c +++ b/lib/pnd_conf.c @@ -257,3 +257,15 @@ int pnd_conf_get_as_int ( pnd_conf_handle c, char *key ) { return ( i ); } + +int pnd_conf_get_as_int_d ( pnd_conf_handle c, char *key, int def ) { + char *t = pnd_box_find_by_key ( c, key ); + + if ( ! t ) { + return ( def ); // non-existant + } + + int i = atoi ( t ); + + return ( i ); +} -- 2.39.5