[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3260 - in GNUnet: . contrib m4 src/include src/setup src/s
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3260 - in GNUnet: . contrib m4 src/include src/setup src/setup/lib |
Date: |
Sat, 19 Aug 2006 20:00:20 -0700 (PDT) |
Author: grothoff
Date: 2006-08-19 20:00:12 -0700 (Sat, 19 Aug 2006)
New Revision: 3260
Added:
GNUnet/src/setup/lib/tree.c
Modified:
GNUnet/README.debian
GNUnet/configure.ac
GNUnet/contrib/Makefile.am
GNUnet/m4/Makefile.in
GNUnet/src/include/gnunet_setup_lib.h
GNUnet/src/setup/Makefile.am
GNUnet/src/setup/gnunet-setup.c
GNUnet/src/setup/lib/Makefile.am
GNUnet/src/setup/lib/gns.c
GNUnet/src/setup/lib/tree.h
Log:
guilerry
Modified: GNUnet/README.debian
===================================================================
--- GNUnet/README.debian 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/README.debian 2006-08-20 03:00:12 UTC (rev 3260)
@@ -26,8 +26,10 @@
libmysqlclient14-dev
libncurses5-dev
libcurl3-gnutls-dev
+guile-1.8-dev (out since Feb 2006 - still no debian package!)
libextractor-dev (unstable required!)
+
Additional libextractor dependencies:
libvorbis-dev
@@ -48,11 +50,6 @@
mysql-client-5.0 (for administration)
-For gnunet-download-manager (probably no longer needed):
-
-guile-1.6
-
-
For Subversion access and compilation:
subversion
Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/configure.ac 2006-08-20 03:00:12 UTC (rev 3260)
@@ -439,83 +439,8 @@
AC_DEFINE_UNQUOTED(USE_IPV6, $ipv6, [IPV6 available])
# check for guile
+GUILE_FLAGS
-AC_ARG_ENABLE(guile,
- [AC_HELP_STRING([--enable-guile],
- [Install Guile scripts.])],
- enable_guile=$enableval)
-
-# By default, enable Guile
-if test -z $enable_guile
-then
- enable_guile="yes"
-fi
-
-guile=0
-if test "$enable_guile" = "yes"
-then
- AC_PATH_PROG([guile_available], [guile])
- if test -z "$guile_available"
- then
- AC_MSG_WARN([Guile not available, so `gnunet-download-manager' won't be
installed.])
- else
- # Perform the whole Guile feature tests
- GUILE_PROGS
- guile=1
- GUILE_MODULE_AVAILABLE(module_available,[(ice-9 format)])
- if test "$module_available" = "no";
- then
- AC_MSG_WARN([required guile module not available])
- guile=0
- fi
- GUILE_MODULE_AVAILABLE(module_available,[(ice-9 regex)])
- if test "$module_available" = "no";
- then
- AC_MSG_WARN([required guile module not available])
- guile=0
- fi
- GUILE_MODULE_AVAILABLE(module_available,[(ice-9 and-let-star)])
- if test "$module_available" = "no";
- then
- AC_MSG_WARN([required guile module not available])
- guile=0
- fi
- GUILE_MODULE_AVAILABLE(module_available,[(ice-9 pretty-print)])
- if test "$module_available" = "no";
- then
- AC_MSG_WARN([required guile module not available])
- guile=0
- fi
- GUILE_MODULE_AVAILABLE(module_available,[(ice-9 documentation)])
- if test "$module_available" = "no";
- then
- AC_MSG_WARN([required guile module not available])
- guile=0
- fi
- GUILE_MODULE_AVAILABLE(module_available,[(ice-9 optargs)])
- if test "$module_available" = "no";
- then
- AC_MSG_WARN([required guile module not available])
- guile=0
- fi
-
- # Check that the keywork syntax used by (ice-9 optargs) is `#:keywork'
- # (as in Guile 1.6) and not `#!' (as in Guile 1.4)
- GUILE_MODULE_CHECK([guile_pound_colon_keywords],
- [(ice-9 optargs)],
- [(lambda* (foo [#]:optional (o [#t])) o)],
- [Guile 1.6's optarg keyword style is supported])
- if test $guile_pound_colon_keywords != "yes"
- then
- AC_MSG_WARN([`(ice-9 optargs)' doesn't support the `[#:]' keyword
syntax. Upgrade to Guile 1.6 or later.]);
- guile=0
- else
- guile=1
- fi
- fi
-fi # enable_guile
-AM_CONDITIONAL(HAVE_GUILE, test x$guile != x0)
-
AC_CONFIG_FILES([ po/Makefile.in m4/Makefile
Makefile
contrib/Makefile
@@ -562,6 +487,10 @@
src/applications/transport/Makefile
src/applications/vpn/Makefile
src/setup/Makefile
+src/setup/lib/Makefile
+src/setup/gtk/Makefile
+src/setup/ncurses/Makefile
+src/setup/text/Makefile
src/server/Makefile
src/transports/Makefile
src/util/Makefile
Modified: GNUnet/contrib/Makefile.am
===================================================================
--- GNUnet/contrib/Makefile.am 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/contrib/Makefile.am 2006-08-20 03:00:12 UTC (rev 3260)
@@ -1,6 +1,4 @@
-if HAVE_GUILE
- bin_SCRIPTS = gnunet-download-manager.scm
-endif
+bin_SCRIPTS = gnunet-download-manager.scm
pkgdata_DATA = \
config-client.in \
Modified: GNUnet/m4/Makefile.in
===================================================================
--- GNUnet/m4/Makefile.in 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/m4/Makefile.in 2006-08-20 03:00:12 UTC (rev 3260)
@@ -41,10 +41,10 @@
$(top_srcdir)/m4/gtk-2.0.m4 $(top_srcdir)/m4/guile.m4 \
$(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
- $(top_srcdir)/m4/libgcrypt.m4 $(top_srcdir)/m4/nls.m4 \
- $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/po.m4 \
- $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/acinclude.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/libcurl.m4 $(top_srcdir)/m4/libgcrypt.m4 \
+ $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/pkg.m4 \
+ $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \
+ $(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -97,14 +97,14 @@
GTK_CFLAGS = @GTK_CFLAGS@
GTK_LIBS = @GTK_LIBS@
GUILE = @GUILE@
+GUILE_CFLAGS = @GUILE_CFLAGS@
GUILE_CONFIG = @GUILE_CONFIG@
+GUILE_LDFLAGS = @GUILE_LDFLAGS@
GUILE_TOOLS = @GUILE_TOOLS@
HAVE_CURSES_FALSE = @HAVE_CURSES_FALSE@
HAVE_CURSES_TRUE = @HAVE_CURSES_TRUE@
HAVE_GTK_FALSE = @HAVE_GTK_FALSE@
HAVE_GTK_TRUE = @HAVE_GTK_TRUE@
-HAVE_GUILE_FALSE = @HAVE_GUILE_FALSE@
-HAVE_GUILE_TRUE = @HAVE_GUILE_TRUE@
HAVE_IPV6_FALSE = @HAVE_IPV6_FALSE@
HAVE_IPV6_TRUE = @HAVE_IPV6_TRUE@
HAVE_MYSQL_FALSE = @HAVE_MYSQL_FALSE@
@@ -194,7 +194,6 @@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
-guile_available = @guile_available@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
Modified: GNUnet/src/include/gnunet_setup_lib.h
===================================================================
--- GNUnet/src/include/gnunet_setup_lib.h 2006-08-19 22:42:46 UTC (rev
3259)
+++ GNUnet/src/include/gnunet_setup_lib.h 2006-08-20 03:00:12 UTC (rev
3260)
@@ -43,7 +43,14 @@
#ifndef GNUNET_SETUP_LIB_H
#define GNUNET_SETUP_LIB_H
+#include "gnunet_util.h"
+
/**
+ * Register GNUnet setup functions with scheme (call only once).
+ */
+void gns_scheme_register(void);
+
+/**
* Types of nodes and values in the configuration tree.
*/
typedef enum {
@@ -52,10 +59,9 @@
GNS_Leaf = 2,
GNS_KindMask = 3,
GNS_Boolean = 4,
- GNS_Float = 8,
+ GNS_String = 8,
GNS_Double = 16,
GNS_UInt64 = 32,
- GNS_String = 64,
} GNS_Type;
/**
@@ -73,11 +79,6 @@
} Boolean;
struct {
- float val;
- float def;
- } Float;
-
- struct {
unsigned long long val;
unsigned long long min;
unsigned long long max;
@@ -217,7 +218,7 @@
void
GNS_register_tree_change_listener(struct GNS_Context * ctx,
GNS_TreeChangeListener listener,
- void * ctx);
+ void * cls);
/**
* Release a tree change listener from GNS (do not call the listener
@@ -226,6 +227,6 @@
void
GNS_unregister_tree_change_listener(struct GNS_Context * ctx,
GNS_TreeChangeListener listener,
- void * ctx);
+ void * cls);
#endif
Modified: GNUnet/src/setup/Makefile.am
===================================================================
--- GNUnet/src/setup/Makefile.am 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/src/setup/Makefile.am 2006-08-20 03:00:12 UTC (rev 3260)
@@ -25,12 +25,15 @@
gnunet_setup_SOURCES = \
gnunet-setup.c
-gnunet_setup_LDADD = \
+gnunet_setup_LDADD = @GUILE_LDFLAGS@ \
$(top_builddir)/src/setup/lib/libgnunetsetup.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
$(top_builddir)/src/util/config_impl/libgnunetutil_config.la
+gnunet_setup_CFLAGS = \
+ @GUILE_CFLAGS@ -I$(top_scrdir)/include
+
gnunet_win_tool_SOURCE = \
gnunet-win-tool.c
Modified: GNUnet/src/setup/gnunet-setup.c
===================================================================
--- GNUnet/src/setup/gnunet-setup.c 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/src/setup/gnunet-setup.c 2006-08-20 03:00:12 UTC (rev 3260)
@@ -24,14 +24,15 @@
* @author Nils Durner
* @author Christian Grothoff
*/
-
-#include "platform.h"
#include "gnunet_util.h"
#include "gnunet_directories.h"
#include "gnunet_setup_lib.h"
#include "gnunet_util_config_impl.h"
#include "gnunet_util_error_loggers.h"
+#include "platform.h"
+#include <libguile.h>
+
typedef int (*ConfigurationPluginMain)(int argc,
const char ** argv,
struct PluginHandle * self,
@@ -116,15 +117,17 @@
};
-int main(int argc,
- const char *argv[]) {
+int real_main(void * unused,
+ int argc,
+ const char *argv[]) {
const char * operation;
int done;
char * filename;
char * dirname;
char * specname;
int i;
-
+
+ gns_scheme_register();
ectx = GE_create_context_stderr(NO,
GE_WARNING | GE_ERROR | GE_FATAL |
GE_USER | GE_ADMIN | GE_DEVELOPER |
@@ -205,9 +208,9 @@
strcpy(specname, dirname);
FREE(dirname);
if (config_daemon)
- strcat(specname, "/config-daemon.in");
+ strcat(specname, "/config-daemon.scm");
else
- strcat(specname, "/config-client.in");
+ strcat(specname, "/config-client.scm");
gns = GNS_load_specification(ectx,
cfg,
specname);
@@ -260,3 +263,12 @@
GE_free_context(ectx);
return 0;
}
+
+/**
+ * Guile's gh_enter sucks.
+ */
+int main(int argc,
+ const char *argv[]) {
+ scm_boot_guile(argc, argv, real_main, NULL);
+ return 0; /* never reached */
+}
Modified: GNUnet/src/setup/lib/Makefile.am
===================================================================
--- GNUnet/src/setup/lib/Makefile.am 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/src/setup/lib/Makefile.am 2006-08-20 03:00:12 UTC (rev 3260)
@@ -10,13 +10,18 @@
lib_LTLIBRARIES = libgnunetsetup.la
libgnunetsetup_la_SOURCES = \
- gns.c
+ gns.c \
+ tree.c tree.h
-libgnunetsetup_la_LIBADD = \
+libgnunetsetup_la_LIBADD = @GUILE_LDFLAGS@ \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/util/loggers/libgnunetutil_logging.la \
- $(top_builddir)/src/util/config_impl/libgnunetutil_config.la
+ $(top_builddir)/src/util/config_impl/libgnunetutil_config.la
libgnunetsetup_la_LDFLAGS = \
-export-dynamic
+libgnunetsetup_la_CFLAGS = @GUILE_CFLAGS@ \
+ -I$(top_scrdir)/include
+
+
Modified: GNUnet/src/setup/lib/gns.c
===================================================================
--- GNUnet/src/setup/lib/gns.c 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/src/setup/lib/gns.c 2006-08-20 03:00:12 UTC (rev 3260)
@@ -55,14 +55,14 @@
};
-static void notfiy_listeners(void * ctx,
+static void notify_listeners(void * ctx,
struct GNS_Tree * tree) {
struct GNS_Context * g = ctx;
GNS_TCL * lpos;
lpos = g->listeners;
while (lpos != NULL) {
- lpos->l(pos, lpos->c);
+ lpos->l(tree, lpos->c);
lpos = lpos->next;
}
}
@@ -85,7 +85,9 @@
struct GNS_Context * g = ctx;
struct GNS_Tree * pos;
- pos = tree_lookup(section, option);
+ pos = tree_lookup(g->root,
+ section,
+ option);
if (pos == NULL) {
GE_LOG(g->ectx,
GE_DEVELOPER | GE_BULK | GE_ERROR,
@@ -95,7 +97,7 @@
return 0; /* or refuse? */
}
/* first, check if value is valid */
- if (pos->type & GNS_KindMask != GNS_Leaf) {
+ if ((pos->type & GNS_KindMask) != GNS_Leaf) {
GE_LOG(g->ectx,
GE_DEVELOPER | GE_BULK | GE_ERROR,
"Tree value change for non-leaf option `%s' in section `%s'!\n",
@@ -116,32 +118,6 @@
pos->value.Boolean.val = val;
break;
}
- case GNS_Float: {
- char * s;
- float f;
-
- s = NULL;
- GC_get_configuration_value_string(cfg,
- section,
- option,
- NULL,
- &s);
- if (s == NULL) {
- pos->value.Float.val = pos->value.Float.def;
- } else {
- if (1 != sscanf(s, "%f", &f)) {
- GE_LOG(ectx,
- GE_USER | GE_ERROR | GE_IMMEDIATE,
- "`%s' is not a valid floating point number.\n",
- s);
- FREE(s);
- return SYSERR;
- }
- pos->value.Float.val = f;
- FREE(s);
- }
- break;
- }
case GNS_UInt64: {
unsigned long long val;
@@ -190,7 +166,7 @@
if (SYSERR == GC_get_configuration_value_choice(cfg,
section,
option,
-
pos->value.String.legalRange,
+ (const char**)
pos->value.String.legalRange,
pos->value.String.def,
&ival))
return SYSERR;
@@ -221,6 +197,41 @@
return 0;
}
+static void free_tree(struct GNS_Tree * t) {
+ int i;
+
+ i = 0;
+ while (t->children[i] != NULL) {
+ free_tree(t->children[i]);
+ i++;
+ }
+ switch (t->type & (-1 ^ GNS_KindMask) ) {
+ case 0:
+ break; /* no value */
+ case GNS_Boolean:
+ case GNS_UInt64:
+ case GNS_Double:
+ break; /* nothing to free */
+ case GNS_String:
+ i = 0;
+ while (t->value.String.legalRange[i] != NULL) {
+ FREE(t->value.String.legalRange[i]);
+ i++;
+ }
+ FREE(t->value.String.legalRange);
+ FREE(t->value.String.val);
+ break;
+ default:
+ GE_BREAK(NULL, 0);
+ break;
+ }
+ FREE(t->description);
+ FREE(t->help);
+ FREE(t->children);
+ FREE(t);
+}
+
+
/**
* Start the setup process by loading a scheme file that
* contains the configuration specification.
@@ -240,7 +251,7 @@
root = tree_parse(ectx, specification);
if (root == NULL)
return NULL;
- ctx = MALLOC(sizeof(GNS_Context));
+ ctx = MALLOC(sizeof(struct GNS_Context));
ctx->ectx = ectx;
ctx->cfg = cfg;
ctx->root = root;
@@ -271,41 +282,6 @@
return ctx->root;
}
-static void free_tree(struct GNS_Tree * t) {
- int i;
-
- i = 0;
- while (t->children[i] != NULL) {
- free_tree(t->children[i]);
- i++;
- }
- switch (t->type & (-1 ^ GNS_KindMask) ) {
- case 0:
- break; /* no value */
- case GNS_Boolean:
- case GNS_Float:
- case GNS_UInt64:
- case GNS_Double:
- break; /* nothing to free */
- case GNS_String:
- i = 0;
- while (t->value.String.legalRange[i] != NULL) {
- FREE(t->value.String.legalRange[i]);
- i++;
- }
- FREE(t->value.String.legalRange);
- FREE(t->value.String.val);
- break;
- default:
- GE_BREAK(NULL, 0);
- break;
- }
- FREE(t->description);
- FREE(t->help);
- FREE(t->children);
- FREE(t);
-}
-
/**
* Free resources associated with the GNS context.
*/
@@ -327,12 +303,12 @@
void
GNS_register_tree_change_listener(struct GNS_Context * ctx,
GNS_TreeChangeListener listener,
- void * ctx) {
+ void * cls) {
GNS_TCL * n;
n = MALLOC(sizeof(GNS_TCL));
n->l = listener;
- n->c = ctx;
+ n->c = cls;
n->next = ctx->listeners;
ctx->listeners = n;
}
@@ -344,7 +320,7 @@
void
GNS_unregister_tree_change_listener(struct GNS_Context * ctx,
GNS_TreeChangeListener listener,
- void * ctx) {
+ void * cls) {
GNS_TCL * pos;
GNS_TCL * prev;
@@ -352,7 +328,7 @@
pos = ctx->listeners;
while (pos != NULL) {
if ( (pos->l == listener) &&
- (pos->c == ctx)) {
+ (pos->c == cls)) {
if (prev == NULL)
ctx->listeners = pos->next;
else
Added: GNUnet/src/setup/lib/tree.c
===================================================================
--- GNUnet/src/setup/lib/tree.c 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/src/setup/lib/tree.c 2006-08-20 03:00:12 UTC (rev 3260)
@@ -0,0 +1,301 @@
+/*
+ This file is part of GNUnet.
+ (C) 2006 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/setup/tree.c
+ * @brief tree API (guile integration)
+ * @author Christian Grothoff
+ */
+
+#include "gnunet_util.h"
+#include "gnunet_setup_lib.h"
+#include "tree.h"
+#include "platform.h"
+
+#include <libguile.h>
+
+typedef struct {
+ VisibilityChangeListener vcl;
+ void * ctx;
+ struct GNS_Tree * root;
+} TC;
+
+/* ********************** scheme smob boxing ***************** */
+
+static scm_t_bits tc_tag;
+
+static scm_t_bits tree_tag;
+
+static SCM
+box_tc(TC * tc) {
+ SCM smob;
+
+ SCM_NEWSMOB (smob, tc_tag, tc);
+ return smob;
+}
+
+static SCM
+box_tree(struct GNS_Tree * tree) {
+ SCM smob;
+
+ SCM_NEWSMOB (smob, tree_tag, tree);
+ return smob;
+}
+
+static size_t
+free_box(SCM smob) {
+ return 0;
+}
+
+static int
+print_tc(SCM tc_smob,
+ SCM port,
+ scm_print_state *pstate) {
+ /* TC * tc = (TC *) SCM_SMOB_DATA (tc_smob); */
+ scm_puts ("TC", port);
+ /* non-zero means success */
+ return 1;
+}
+
+static int
+print_tree(SCM tree_smob,
+ SCM port,
+ scm_print_state *pstate) {
+ /* struct GNS_Tree * tree = (struct GNS_Tree *) SCM_SMOB_DATA (tree_smob); */
+
+ scm_puts ("Tree", port);
+ /* non-zero means success */
+ return 1;
+}
+
+/* **************************** tree API ****************** */
+
+struct GNS_Tree *
+tree_lookup(struct GNS_Tree * root,
+ const char * section,
+ const char * option) {
+ int i;
+ struct GNS_Tree * ret;
+
+ if ( (root->section != NULL) &&
+ (root->option != NULL) &&
+ (0 == strcmp(section, root->section)) &&
+ (0 == strcmp(option, root->option)) )
+ return root;
+ i = 0;
+ while (root->children[i] != NULL) {
+ ret = tree_lookup(root->children[i],
+ section,
+ option);
+ if (ret != NULL)
+ return ret;
+ i++;
+ }
+ return NULL;
+}
+
+/**
+ * Change the visibility of an entry in the
+ * tree (and notify listeners about change).
+ */
+SCM change_visible(SCM smob,
+ SCM option,
+ SCM section,
+ SCM yesno) {
+ TC * tc;
+ char * opt;
+ char * sec;
+ int val;
+ struct GNS_Tree * t;
+
+ SCM_ASSERT(SCM_SMOB_PREDICATE(tc_tag, smob), smob, SCM_ARG1,
"change_visible");
+ SCM_ASSERT(scm_string_p(option), option, SCM_ARG2, "change_visible");
+ SCM_ASSERT(scm_string_p(section), section, SCM_ARG3, "change_visible");
+ SCM_ASSERT(scm_boolean_p(yesno), yesno, SCM_ARG4, "change_visible");
+
+ tc = (TC *) SCM_SMOB_DATA(smob);
+ opt = scm_to_locale_string(option);
+ sec = scm_to_locale_string(section);
+ val = SCM_INUM(yesno);
+ t = tree_lookup(tc->root,
+ sec,
+ opt);
+ t->visible = val;
+ tc->vcl(tc->ctx,
+ t);
+ return SCM_EOL;
+}
+
+/**
+ * Create a node in the tree.
+ *
+ * @param value the current value (must also be default value)
+ * @param range information about the legal range of values;
+ * maybe list of strings for string values or pair
+ * min/max for integers
+ */
+SCM build_tree_node(SCM section,
+ SCM option,
+ SCM description,
+ SCM help,
+ SCM children,
+ SCM visible,
+ SCM value,
+ SCM range) {
+ struct GNS_Tree * tree;
+ SCM child;
+ int i;
+ int clen;
+ int len;
+
+ /* verify arguments */
+ SCM_ASSERT(scm_string_p(section), section, SCM_ARG1, "build_tree_node");
+ SCM_ASSERT(scm_string_p(option), option, SCM_ARG2, "build_tree_node");
+ SCM_ASSERT(scm_string_p(description), description, SCM_ARG3,
"build_tree_node");
+ SCM_ASSERT(scm_string_p(help), help, SCM_ARG4, "build_tree_node");
+ SCM_ASSERT(scm_list_p(children), children, SCM_ARG5, "build_tree_node");
+ clen = scm_to_int(scm_length(children));
+ for (i=0;i<clen;i++) {
+ child = scm_list_ref(children, scm_from_signed_integer(i));
+ SCM_ASSERT(SCM_SMOB_PREDICATE(tree_tag, child),
+ children, SCM_ARG5, "build_tree_node");
+ }
+ SCM_ASSERT(scm_boolean_p(visible), visible, SCM_ARG6, "build_tree_node");
+ if (scm_string_p(value)) {
+ SCM_ASSERT(scm_list_p(range), range, 8, "build_tree_node");
+ len = scm_to_int(scm_length(range));
+ for (i=0;i<len;i++)
+ SCM_ASSERT(scm_string_p(scm_list_ref(range, scm_from_signed_integer(i))),
+ range, 8, "build_tree_node");
+ } else if (scm_is_integer(value)) {
+ SCM_ASSERT(scm_pair_p(range),
+ range, 8, "build_tree_node");
+ SCM_ASSERT(scm_is_integer(SCM_CAR(range)),
+ range, 8, "build_tree_node");
+ SCM_ASSERT(scm_is_integer(SCM_CDR(range)),
+ range, 8, "build_tree_node");
+ } else if (scm_real_p(value)) {
+ /* no checks */
+ } else if (scm_boolean_p(value)) {
+ /* no checks */
+ } else {
+ SCM_ASSERT(0,
+ range, SCM_ARG7, "build_tree_node"); /* invalid type */
+ }
+
+ /* construct C object */
+ tree = MALLOC(sizeof(struct GNS_Tree));
+ tree->section = scm_to_locale_string(section);
+ tree->option = scm_to_locale_string(option);
+ tree->description = scm_to_locale_string(description);
+ tree->help = scm_to_locale_string(help);
+ tree->children = MALLOC(sizeof(struct GNS_Tree*) * (clen + 1));
+ for (i=0;i<clen;i++) {
+ child = scm_list_ref(children, scm_from_signed_integer(i));
+ tree->children[i] = (struct GNS_Tree*) SCM_SMOB_DATA(child);
+ }
+ tree->children[clen] = NULL;
+ tree->type = clen == 0 ? GNS_Leaf : GNS_Node;
+ tree->visible = scm_is_true(visible);
+
+ if (scm_string_p(value)) {
+ tree->value.String.val = scm_to_locale_string(value);
+ tree->value.String.def = scm_to_locale_string(value);
+ len = scm_to_int32(range);
+ tree->value.String.legalRange = MALLOC(sizeof(char*) * (len + 1));
+ for (i=0;i<len;i++)
+ tree->value.String.legalRange[i]
+ = scm_to_locale_string(scm_list_ref(range,
+ scm_from_signed_integer(i)));
+ tree->value.String.legalRange[len] = NULL;
+ } else if (scm_is_integer(value)) {
+ tree->value.UInt64.val = scm_to_uint64(value);
+ tree->value.UInt64.def = scm_to_uint64(value);
+ tree->value.UInt64.min = scm_to_uint64(SCM_CAR(range));
+ tree->value.UInt64.max = scm_to_uint64(SCM_CDR(range));
+ } else if (scm_real_p(value)) {
+ tree->value.Double.val = scm_to_double(value);
+ tree->value.Double.def = scm_to_double(value);
+ } else if (scm_boolean_p(value)) {
+ tree->value.Boolean.val = scm_is_true(value);
+ tree->value.Boolean.def = scm_is_true(value);
+ }
+
+ /* box and return */
+ return box_tree(tree);
+}
+
+void gns_scheme_register() {
+ tc_tag = scm_make_smob_type ("tc", sizeof (TC));
+ scm_set_smob_mark (tc_tag, NULL);
+ scm_set_smob_free (tc_tag, free_box);
+ scm_set_smob_print (tc_tag, print_tc);
+
+ tree_tag = scm_make_smob_type ("tc", sizeof (struct GNS_Tree));
+ scm_set_smob_mark (tree_tag, NULL);
+ scm_set_smob_free (tree_tag, free_box);
+ scm_set_smob_print (tree_tag, print_tree);
+ scm_c_define_gsubr("change-visible",
+ 4, 0, 0,
+ &change_visible);
+ scm_c_define_gsubr("build-tree-node",
+ 8, 0, 0,
+ &build_tree_node);
+}
+
+/**
+ * Parse the specification file and create the tree.
+ * Set all values to defaults.
+ */
+struct GNS_Tree *
+tree_parse(struct GE_Context * ectx,
+ const char * specification) {
+ SCM proc;
+ SCM smob;
+ struct GNS_Tree * tree;
+ proc = scm_variable_ref(scm_c_lookup("setup"));
+ smob = scm_apply_0(proc, SCM_EOL);
+ tree = (struct GNS_Tree*) SCM_SMOB_DATA(smob);
+ return tree;
+}
+
+/**
+ * A value in the tree has been changed.
+ * Update visibility (and notify about changes).
+ */
+void tree_notify_change(VisibilityChangeListener vcl,
+ void * ctx,
+ struct GE_Context * ectx,
+ struct GNS_Tree * root,
+ struct GNS_Tree * change) {
+ TC tc;
+ SCM smob_ctx;
+ SCM smob_root;
+ SCM smob_chng;
+ SCM proc;
+
+ proc = scm_variable_ref(scm_c_lookup("change"));
+ smob_ctx = box_tc(&tc);
+ smob_root = box_tree(root);
+ smob_chng = box_tree(change);
+ scm_apply_3(proc, smob_ctx, smob_root, smob_chng, SCM_EOL);
+}
+
+/* end of tree.c */
Property changes on: GNUnet/src/setup/lib/tree.c
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: GNUnet/src/setup/lib/tree.h
===================================================================
--- GNUnet/src/setup/lib/tree.h 2006-08-19 22:42:46 UTC (rev 3259)
+++ GNUnet/src/setup/lib/tree.h 2006-08-20 03:00:12 UTC (rev 3260)
@@ -32,6 +32,11 @@
tree_parse(struct GE_Context * ectx,
const char * specification);
+struct GNS_Tree *
+tree_lookup(struct GNS_Tree * root,
+ const char * section,
+ const char * option);
+
typedef void (*VisibilityChangeListener)(void * ctx,
struct GNS_Tree * tree);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3260 - in GNUnet: . contrib m4 src/include src/setup src/setup/lib,
grothoff <=