changeset 11947:3ccd5dcf447c

m_option_type_double
author michael
date Tue, 10 Feb 2004 14:32:06 +0000
parents 73b7ddcf4cbe
children fe2424e87a1e
files m_option.c m_option.h
diffstat 2 files changed, 32 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/m_option.c	Tue Feb 10 14:12:26 2004 +0000
+++ b/m_option.c	Tue Feb 10 14:32:06 2004 +0000
@@ -179,10 +179,10 @@
 // Float
 
 #undef VAL
-#define VAL(x) (*(float*)(x))
+#define VAL(x) (*(double*)(x))
 
-static int parse_float(m_option_t* opt,char *name, char *param, void* dst, int src) {
-  float tmp_float;
+static int parse_double(m_option_t* opt,char *name, char *param, void* dst, int src) {
+  double tmp_float;
   char* endptr;
   src = 0;
 
@@ -230,6 +230,33 @@
   return 1;
 }
 
+static char* print_double(m_option_t* opt,  void* val) {
+  opt = NULL;
+  return dup_printf("%f",VAL(val));
+}
+
+m_option_type_t m_option_type_double = {
+  "Double",
+  "double precission floating point number or ratio (numerator[:/]denominator)",
+  sizeof(double),
+  0,
+  parse_double,
+  print_double,
+  copy_opt,
+  copy_opt,
+  NULL,
+  NULL
+};
+
+#undef VAL
+#define VAL(x) (*(float*)(x))
+
+static int parse_float(m_option_t* opt,char *name, char *param, void* dst, int src) {
+    double tmp;
+    int r= parse_double(opt, name, param, &tmp, src);
+    if(r==1 && dst) VAL(dst) = tmp;
+}
+
 static char* print_float(m_option_t* opt,  void* val) {
   opt = NULL;
   return dup_printf("%f",VAL(val));
--- a/m_option.h	Tue Feb 10 14:12:26 2004 +0000
+++ b/m_option.h	Tue Feb 10 14:32:06 2004 +0000
@@ -11,6 +11,7 @@
 extern m_option_type_t m_option_type_flag;
 extern m_option_type_t m_option_type_int;
 extern m_option_type_t m_option_type_float;
+extern m_option_type_t m_option_type_double;
 extern m_option_type_t m_option_type_string;
 extern m_option_type_t m_option_type_string_list;
 extern m_option_type_t m_option_type_position;
@@ -78,6 +79,7 @@
 #define CONF_TYPE_FLAG		(&m_option_type_flag)
 #define CONF_TYPE_INT		(&m_option_type_int)
 #define CONF_TYPE_FLOAT		(&m_option_type_float)
+#define CONF_TYPE_DOUBLE	(&m_option_type_double)
 #define CONF_TYPE_STRING	(&m_option_type_string)
 #define CONF_TYPE_FUNC		(&m_option_type_func)
 #define CONF_TYPE_FUNC_PARAM	(&m_option_type_func_param)