gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3631 - in GNUnet/src: include setup setup/lib


From: grothoff
Subject: [GNUnet-SVN] r3631 - in GNUnet/src: include setup setup/lib
Date: Fri, 3 Nov 2006 11:15:18 -0800 (PST)

Author: grothoff
Date: 2006-11-03 11:15:15 -0800 (Fri, 03 Nov 2006)
New Revision: 3631

Modified:
   GNUnet/src/include/gnunet_setup_lib.h
   GNUnet/src/setup/gnunet-setup.c
   GNUnet/src/setup/lib/gns.c
Log:
dump default options in gnunet-setup

Modified: GNUnet/src/include/gnunet_setup_lib.h
===================================================================
--- GNUnet/src/include/gnunet_setup_lib.h       2006-11-03 18:54:27 UTC (rev 
3630)
+++ GNUnet/src/include/gnunet_setup_lib.h       2006-11-03 19:15:15 UTC (rev 
3631)
@@ -225,4 +225,14 @@
                                    GNS_TreeChangeListener listener,
                                    void * cls);
 
+/**
+ * Convert the default value of the given tree entry to
+ * a string.
+ *
+ * @return NULL on error
+ */
+char *
+GNS_get_default_value_as_string(GNS_Type type,
+                               const GNS_Value * value);
+
 #endif

Modified: GNUnet/src/setup/gnunet-setup.c
===================================================================
--- GNUnet/src/setup/gnunet-setup.c     2006-11-03 18:54:27 UTC (rev 3630)
+++ GNUnet/src/setup/gnunet-setup.c     2006-11-03 19:15:15 UTC (rev 3631)
@@ -65,6 +65,44 @@
   COMMAND_LINE_OPTION_END,
 };
 
+static void gns2cfg(struct GNS_Tree * pos) {
+  int i;
+  char * val;
+  
+  if (pos == NULL)
+    return;
+  i = 0;
+  while (pos->children[i] != NULL) {
+    gns2cfg(pos->children[i]);
+    i++;
+  }
+  if (i != 0)
+    return;
+  if ( (pos->section == NULL) ||
+       (pos->option == NULL) )
+    return;
+  val = NULL;
+  if (0 == GC_get_configuration_value_string(cfg,
+                                            pos->section,
+                                            pos->option,
+                                            "",
+                                            &val)) {
+    FREE(val);
+    return;
+  }
+  FREE(val);
+  val = GNS_get_default_value_as_string(pos->type,
+                                       &pos->value);
+  if (val != NULL) {
+    GC_set_configuration_value_string(cfg,
+                                     ectx,
+                                     pos->section,
+                                     pos->option,
+                                     val);
+    FREE(val);
+  }
+}
+
 static int dyn_config(const char * module,
                      const char * mainfunc,
                      int argc,
@@ -215,6 +253,7 @@
     FREE(cfgFilename);
     return -1;
   }
+  gns2cfg(GNS_get_tree(gns));
 
   done = NO;
   i = 0;

Modified: GNUnet/src/setup/lib/gns.c
===================================================================
--- GNUnet/src/setup/lib/gns.c  2006-11-03 18:54:27 UTC (rev 3630)
+++ GNUnet/src/setup/lib/gns.c  2006-11-03 19:15:15 UTC (rev 3631)
@@ -351,3 +351,36 @@
     pos = pos->next;
   }
 }
+
+/**
+ * Convert the default value of the given tree entry to
+ * a string.
+ *
+ * @return NULL on error
+ */
+char *
+GNS_get_default_value_as_string(GNS_Type type,
+                               const GNS_Value * value) {
+  char buf[48];
+
+  if (value == NULL)
+    return NULL;
+  switch (type & GNS_TypeMask) {
+  case GNS_Boolean:
+    if (value->Boolean.def)
+      return STRDUP("YES");
+    return STRDUP("NO");
+  case GNS_String:
+    if (value->String.def == NULL)
+      return NULL;
+    return STRDUP(value->String.def);
+  case GNS_Double:
+    SNPRINTF(buf, 48, "%f", value->Double.def);
+    return STRDUP(buf);
+  case GNS_UInt64:
+    SNPRINTF(buf, 48, "%llu", value->UInt64.def);
+    return STRDUP(buf);
+  default:
+    return NULL;
+  }
+}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]