aboutsummaryrefslogtreecommitdiffstats
path: root/lib/misc.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-07-01 17:52:05 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2006-07-01 17:52:05 +0200
commit5100caa16bb707d89f1873aca99b5f87abc1dd56 (patch)
treecb07ef3e313f9d6f4f5feb2231176c5e9a2a7a2a /lib/misc.c
parent0a3c243b6659dc10efb227e507f324c2711d6dcd (diff)
Added "account set" command.
Diffstat (limited to 'lib/misc.c')
-rw-r--r--lib/misc.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/misc.c b/lib/misc.c
index 784d80d6..17599946 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -485,3 +485,37 @@ void random_bytes( unsigned char *buf, int count )
buf[i] = rand() & 0xff;
}
}
+
+int is_bool( char *value )
+{
+ if( *value == 0 )
+ return 0;
+
+ if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) )
+ return 1;
+ if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) )
+ return 1;
+
+ while( *value )
+ if( !isdigit( *value ) )
+ return 0;
+ else
+ value ++;
+
+ return 1;
+}
+
+int bool2int( char *value )
+{
+ int i;
+
+ if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) )
+ return 1;
+ if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) )
+ return 0;
+
+ if( sscanf( value, "%d", &i ) == 1 )
+ return i;
+
+ return 0;
+}