Added _get_as_int_d function, which is same as _get_as_int but with default value...
authorskeezix <skeezix@flotsam-vm.(none)>
Sat, 6 Mar 2010 04:29:35 +0000 (23:29 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Sat, 6 Mar 2010 04:29:35 +0000 (23:29 -0500)
include/pnd_conf.h
lib/pnd_conf.c

index 8779f17..a522fd7 100644 (file)
@@ -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" */
index e2114a5..5f1901f 100644 (file)
@@ -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 );
+}