[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3316 - in GNUnet: contrib src/include src/setup src/setup/
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3316 - in GNUnet: contrib src/include src/setup src/setup/lib src/setup/text src/util/config_impl |
Date: |
Fri, 25 Aug 2006 21:01:46 -0700 (PDT) |
Author: grothoff
Date: 2006-08-25 21:01:40 -0700 (Fri, 25 Aug 2006)
New Revision: 3316
Modified:
GNUnet/contrib/config-daemon.scm
GNUnet/src/include/gnunet_setup_lib.h
GNUnet/src/setup/Makefile.am
GNUnet/src/setup/gnunet-setup.c
GNUnet/src/setup/lib/gns.c
GNUnet/src/setup/lib/tree.c
GNUnet/src/setup/text/conf.c
GNUnet/src/setup/text/conf.h
GNUnet/src/util/config_impl/impl.c
Log:
setup works
Modified: GNUnet/contrib/config-daemon.scm
===================================================================
--- GNUnet/contrib/config-daemon.scm 2006-08-26 02:09:12 UTC (rev 3315)
+++ GNUnet/contrib/config-daemon.scm 2006-08-26 04:01:40 UTC (rev 3316)
@@ -17,10 +17,10 @@
;;
;;
;; GNUnet setup requires two functions from this script.
-;; First, a function "setup" which constructs the
+;; First, a function "gnunet-config-setup" which constructs the
;; configuration tree.
;;
-;; Second, a function "change" which is notified whenever
+;; Second, a function "gnunet-config-change" which is notified whenever
;; configuration options are changed; the script can then
;; change the visibility of other options.
;;
@@ -83,8 +83,8 @@
(define (meta-adv builder)
(builder
(_ "Meta")
- (_ "EXPERIMENTAL")
- (_ "Prompt for development and/or incomplete code")
+ (_ "ADVANCED")
+ (_ "Show options for advanced users")
(_
"These are options that maybe difficult to understand for the beginner.
These options typically refer to features that allow tweaking of the
@@ -130,7 +130,7 @@
;; first main method: build tree using build-tree-node
;; The lambda expression is used to throw away the last argument,
;; which we use internally and which is not used by build-tree-node!
-(define (setup)
+(define (gnunet-config-setup)
(main
(lambda (a b c d e f g h i) (build-tree-node a b c d e f g h) ) ) )
@@ -139,7 +139,9 @@
;; the tree builder but this time scan use the "i" tags to determine
;; how the visibility needs to change
-(define (change ctx root changed)
- (0))
+(define (gnunet-config-change ctx root changed)
+ 0)
+;; Example: (change-visible ctx "FOO" "BAR" #t)
+
;; (setup)
\ No newline at end of file
Modified: GNUnet/src/include/gnunet_setup_lib.h
===================================================================
--- GNUnet/src/include/gnunet_setup_lib.h 2006-08-26 02:09:12 UTC (rev
3315)
+++ GNUnet/src/include/gnunet_setup_lib.h 2006-08-26 04:01:40 UTC (rev
3316)
@@ -57,6 +57,7 @@
GNS_String = 8,
GNS_Double = 16,
GNS_UInt64 = 32,
+ GNS_TypeMask = 60,
} GNS_Type;
/**
Modified: GNUnet/src/setup/Makefile.am
===================================================================
--- GNUnet/src/setup/Makefile.am 2006-08-26 02:09:12 UTC (rev 3315)
+++ GNUnet/src/setup/Makefile.am 2006-08-26 04:01:40 UTC (rev 3316)
@@ -7,8 +7,8 @@
curses_dir = ncurses
endif
-SUBDIRS = lib
-# text $(curses_dir) $(gtk_dir) .
+SUBDIRS = lib text .
+# $(curses_dir) $(gtk_dir) .
plugindir = $(libdir)/GNUnet
Modified: GNUnet/src/setup/gnunet-setup.c
===================================================================
--- GNUnet/src/setup/gnunet-setup.c 2006-08-26 02:09:12 UTC (rev 3315)
+++ GNUnet/src/setup/gnunet-setup.c 2006-08-26 04:01:40 UTC (rev 3316)
@@ -113,7 +113,7 @@
static const char * modules[] = {
"gconfig", "setup_gtk", "gconf_main" ,
"menuconfig", "setup_curses", "mconf_main" ,
- "config", "setup_text", "conf_main" ,
+ "config", "setup_text", "main_" ,
"wizard-curses", "setup_curses", "wizard_curs_main",
"wizard-gtk", "setup_gtk", "gtk_wizard_main",
NULL,
@@ -168,8 +168,8 @@
if (cfgFilename == NULL)
cfgFilename = config_daemon
- ? DEFAULT_DAEMON_CONFIG_FILE
- : DEFAULT_CLIENT_CONFIG_FILE;
+ ? STRDUP(DEFAULT_DAEMON_CONFIG_FILE)
+ : STRDUP(DEFAULT_CLIENT_CONFIG_FILE);
dirname = STRDUP(cfgFilename);
i = strlen(dirname) - 1;
while (i > -1) {
@@ -181,16 +181,16 @@
i--;
}
disk_directory_create(ectx, dirname);
- if ( ( (0 == ACCESS(cfgFilename, W_OK)) ||
- ( (errno == ENOENT) &&
- (0 == ACCESS(dirname, W_OK))) ) )
+ if ( ( (0 != ACCESS(cfgFilename, W_OK)) &&
+ ( (errno != ENOENT) ||
+ (0 != ACCESS(dirname, W_OK))) ) )
GE_DIE_STRERROR_FILE(ectx,
GE_FATAL | GE_USER | GE_ADMIN | GE_IMMEDIATE,
"access",
dirname);
FREE(dirname);
- if(0 == ACCESS(cfgFilename, F_OK))
+ if (0 == ACCESS(cfgFilename, F_OK))
GC_parse_configuration(cfg,
cfgFilename);
dirname = os_get_installation_path(IPK_DATADIR);
Modified: GNUnet/src/setup/lib/gns.c
===================================================================
--- GNUnet/src/setup/lib/gns.c 2006-08-26 02:09:12 UTC (rev 3315)
+++ GNUnet/src/setup/lib/gns.c 2006-08-26 04:01:40 UTC (rev 3316)
@@ -105,7 +105,7 @@
section);
return 0;
}
- switch (pos->type & (-1 ^ GNS_KindMask)) {
+ switch (pos->type & GNS_TypeMask) {
case GNS_Boolean: {
int val;
@@ -208,7 +208,7 @@
free_tree(t->children[i]);
i++;
}
- switch (t->type & (-1 ^ GNS_KindMask) ) {
+ switch (t->type & GNS_TypeMask) {
case 0:
break; /* no value */
case GNS_Boolean:
Modified: GNUnet/src/setup/lib/tree.c
===================================================================
--- GNUnet/src/setup/lib/tree.c 2006-08-26 02:09:12 UTC (rev 3315)
+++ GNUnet/src/setup/lib/tree.c 2006-08-26 04:01:40 UTC (rev 3316)
@@ -130,7 +130,7 @@
opt);
if (t == NULL)
return SCM_EOL;
- switch (t->type & (-1 ^ GNS_KindMask) ) {
+ switch (t->type & GNS_TypeMask) {
case 0:
return SCM_EOL; /* no value */
case GNS_Boolean:
@@ -168,13 +168,24 @@
tc = (TC *) SCM_SMOB_DATA(smob);
opt = scm_to_locale_string(option);
sec = scm_to_locale_string(section);
- val = SCM_INUM(yesno);
+ val = scm_is_true(scm_boolean_p(yesno)) ? 1 : 0;
t = tree_lookup(tc->root,
sec,
opt);
- t->visible = val;
- tc->vcl(tc->ctx,
- t);
+ if (t != NULL) {
+ t->visible = val;
+ tc->vcl(tc->ctx,
+ t);
+ fprintf(stderr,
+ "Changing visibility of entry `%s' in section `%s'\n",
+ opt,
+ sec);
+ } else {
+ fprintf(stderr,
+ _("Internal error: entry `%s' in section `%s' not found for
visibility change!\n"),
+ opt,
+ sec);
+ }
return SCM_EOL;
}
@@ -214,18 +225,18 @@
}
SCM_ASSERT(scm_boolean_p(visible), visible, SCM_ARG6, "build_tree_node");
if (scm_is_string(value)) {
- SCM_ASSERT(scm_list_p(range), range, 8, "build_tree_node");
+ SCM_ASSERT(scm_list_p(range), range, SCM_ARGn, "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");
+ range, SCM_ARGn, "build_tree_node");
} else if (scm_is_integer(value)) {
SCM_ASSERT(scm_pair_p(range),
- range, 8, "build_tree_node");
+ range, SCM_ARGn, "build_tree_node");
SCM_ASSERT(scm_is_integer(SCM_CAR(range)),
- range, 8, "build_tree_node");
+ range, SCM_ARGn, "build_tree_node");
SCM_ASSERT(scm_is_integer(SCM_CDR(range)),
- range, 8, "build_tree_node");
+ range, SCM_ARGn, "build_tree_node");
} else if (scm_is_true(scm_real_p(value))) {
/* no checks */
} else if (scm_is_true(scm_boolean_p(value))) {
@@ -247,7 +258,7 @@
tree->children[i] = (struct GNS_Tree*) SCM_SMOB_DATA(child);
}
tree->children[clen] = NULL;
- tree->type = clen == 0 ? GNS_Leaf : GNS_Node;
+ tree->type = (clen == 0) ? GNS_Leaf : GNS_Node;
tree->visible = scm_is_true(visible);
if (scm_is_string(value)) {
@@ -260,17 +271,21 @@
= scm_to_locale_string(scm_list_ref(range,
scm_from_signed_integer(i)));
tree->value.String.legalRange[len] = NULL;
+ tree->type |= GNS_String;
} 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));
+ tree->type |= GNS_UInt64;
} else if (scm_is_true(scm_real_p(value))) {
tree->value.Double.val = scm_to_double(value);
tree->value.Double.def = scm_to_double(value);
+ tree->type |= GNS_Double;
} else if (scm_is_true(scm_boolean_p(value))) {
tree->value.Boolean.val = scm_is_true(value);
tree->value.Boolean.def = scm_is_true(value);
+ tree->type |= GNS_Boolean;
}
/* box and return */
return box_tree(tree);
@@ -287,7 +302,7 @@
SCM smob;
scm_c_primitive_load(specification);
- proc = scm_variable_ref(scm_c_lookup("setup"));
+ proc = scm_variable_ref(scm_c_lookup("gnunet-config-setup"));
smob = scm_apply_0(proc, SCM_EOL);
return (void*) SCM_SMOB_DATA(smob);
}
@@ -296,8 +311,12 @@
struct GNS_Tree *
tree_parse(struct GE_Context * ectx,
const char * specification) {
- return scm_with_guile(parse_internal,
- (void*) specification);
+ struct GNS_Tree * ret;
+
+ ret = scm_with_guile(parse_internal,
+ (void*) specification);
+ ret->type = GNS_Root;
+ return ret;
}
struct NCI {
@@ -317,7 +336,8 @@
/* I hope that loading of "specification" from
tree_parse is preserved by guile.
Otherwise we have to re-do this here */
- proc = scm_variable_ref(scm_c_lookup("change"));
+ scm_c_primitive_load("/home/grothoff/share/GNUnet/config-daemon.scm");
+ proc = scm_variable_ref(scm_c_lookup("gnunet-config-change"));
smob_ctx = box_tc(n->tc);
smob_root = box_tree(n->root);
smob_chng = box_tree(n->change);
@@ -339,7 +359,7 @@
struct GNS_Tree * change) {
TC tc;
struct NCI n;
-
+
tc.vcl = vcl;
tc.ctx = ctx;
tc.root = root;
@@ -349,14 +369,8 @@
scm_with_guile(¬ify_change_internal, &n);
}
-/**
- * Hopefully this initialization can be done
- * once and for all outside of a guile context.
- * If not, we'll have to move it into the
- * _internal methods.
- */
-void __attribute__ ((constructor)) gns_scheme_init() {
- tc_tag = scm_make_smob_type ("tc", sizeof (TC));
+static void * init_helper(void * unused) {
+ tc_tag = scm_make_smob_type ("tc", 0);
scm_set_smob_mark (tc_tag, NULL);
scm_set_smob_free (tc_tag, free_box);
scm_set_smob_print (tc_tag, print_tc);
@@ -374,7 +388,18 @@
scm_c_define_gsubr("get-option",
3, 0, 0,
&get_option);
+ return NULL;
}
+/**
+ * Hopefully this initialization can be done
+ * once and for all outside of a guile context.
+ * If not, we'll have to move it into the
+ * _internal methods.
+ */
+void __attribute__ ((constructor)) gns_scheme_init() {
+ scm_with_guile(&init_helper, NULL);
+}
+
/* end of tree.c */
Modified: GNUnet/src/setup/text/conf.c
===================================================================
--- GNUnet/src/setup/text/conf.c 2006-08-26 02:09:12 UTC (rev 3315)
+++ GNUnet/src/setup/text/conf.c 2006-08-26 04:01:40 UTC (rev 3316)
@@ -32,7 +32,18 @@
#include "gnunet_setup_lib.h"
#include "conf.h"
#include "platform.h"
+#include <term.h>
+static char rd() {
+ size_t ret;
+ char c;
+
+ ret = fread(&c, 1, 1, stdin);
+ if (ret == 1)
+ return c;
+ return '\x1b'; /* escape */
+}
+
/**
* printf with indentation
*/
@@ -53,9 +64,9 @@
GNS_Value * val) {
char buf[92];
- switch (type & (~ GNS_KindMask)) {
+ switch (type & GNS_TypeMask) {
case GNS_Boolean:
- if (val->Boolean.def)
+ if (val->Boolean.val)
return STRDUP(_("yes"));
return STRDUP(_("no"));
case GNS_String:
@@ -80,10 +91,10 @@
int i;
char defLet;
- switch (type & (~ GNS_KindMask)) {
+ switch (type & GNS_TypeMask) {
case GNS_Boolean:
iprintf(indent,
- _("\tEnter yes (%s) / no (%s) or help (%s): "),
+ _("\tEnter yes (%s), no (%s) or help (%s): "),
val->Boolean.def ? "Y" : "y",
val->Boolean.def ? "n" : "N",
"?");
@@ -127,7 +138,7 @@
val->UInt64.def);
break;
default:
- GE_ASSERT(NULL, 0);
+ return;
}
}
@@ -142,10 +153,10 @@
int j;
unsigned long long l;
- switch (type & (~ GNS_KindMask)) {
+ switch (type & GNS_TypeMask) {
case GNS_Boolean:
while (1) {
- c = fgetc(stdin);
+ c = rd();
switch (c) {
case 'y':
case 'Y':
@@ -185,7 +196,7 @@
return OK;
} else {
while (1) {
- c = fgetc(stdin);
+ c = rd();
if (c == '?') {
printf(_("Help\n"));
return NO;
@@ -261,7 +272,10 @@
}
break;
default:
- GE_ASSERT(NULL, 0);
+ fprintf(stderr,
+ _("Unknown kind %x (internal error). Skipping option.\n"),
+ type & GNS_TypeMask);
+ return OK;
}
return OK;
}
@@ -289,7 +303,7 @@
ovalue);
iprintf(indent,
"%s\n",
- tree->description);
+ gettext(tree->description));
printChoice(indent,
tree->type,
&tree->value);
@@ -304,7 +318,7 @@
printf("\n\n");
iprintf(0,
"%s\n",
- tree->help);
+ gettext(tree->help));
printf("\n");
}
value = getValueAsString(tree->type,
@@ -334,12 +348,13 @@
iprintf(indent,
_(/* do not translate y/n/? */
"\tDescend? (y/n/?) "));
- choice = fgetc(stdin);
+ choice = rd();
switch(choice) {
case 'N':
case 'n':
iprintf(indent,
- "%c\n", choice);
+ "%c\n",
+ choice);
return OK;
case '\x1b':
iprintf(indent,
@@ -349,19 +364,23 @@
case 'h':
case 'H':
iprintf(indent,
- "%c\n", choice);
+ "%c\n",
+ choice);
iprintf(indent,
+ "%s\n",
gettext(tree->help));
choice = '\0';
break;
case 'Y':
case 'y':
iprintf(indent,
- "%c\n", choice);
+ "%c\n",
+ choice);
break;
default:
iprintf(indent,
- "%c\n", choice);
+ "%c\n",
+ choice);
iprintf(indent,
_("Invalid entry.\n"));
choice = '\0';
@@ -379,32 +398,72 @@
return SYSERR;
i++;
}
+ return OK;
default:
- GE_ASSERT(NULL, 0);
+ fprintf(stderr,
+ _("Unknown kind %x (internal error). Aborting.\n"),
+ tree->type & GNS_KindMask);
return SYSERR;
}
+ return SYSERR;
}
-int conf_main(int argc,
- const char **argv,
- struct PluginHandle * self,
- struct GE_Context * ectx,
- struct GC_Configuration * cfg,
- struct GNS_Context * gns,
- const char * filename,
- int is_daemon) {
+int main_setup_text(int argc,
+ const char **argv,
+ struct PluginHandle * self,
+ struct GE_Context * ectx,
+ struct GC_Configuration * cfg,
+ struct GNS_Context * gns,
+ const char * filename,
+ int is_daemon) {
struct GNS_Tree * root;
+ struct termios oldT;
+ struct termios newT;
+ char c;
+ int ret;
+ ioctl(0, TCGETS, &oldT);
+ newT = oldT;
+ newT.c_lflag &= ~ECHO;
+ newT.c_lflag &= ~ICANON;
+ ioctl(0, TCSETS, &newT);
+
root = GNS_get_tree(gns);
- if (OK != conf(-1,
- cfg,
- ectx,
- root))
- return 1;
- if (-1 == GC_write_configuration(cfg,
- filename))
- return 1;
- printf(_("Configuration file `%s' created.\n"),
- filename);
+ c = 'r';
+ while (c == 'r') {
+ if (OK != conf(-1,
+ cfg,
+ ectx,
+ root)) {
+ ioctl(0, TCSETS, &oldT);
+ return 1;
+ }
+ if ( (0 == GC_test_dirty(cfg)) &&
+ (0 == ACCESS(filename, R_OK)) ) {
+ printf(_("Configuration unchanged, no need to save.\n"));
+ ioctl(0, TCSETS, &oldT);
+ return 0;
+ }
+ printf("\n");
+ printf(_("Save configuration? Answer 'y' for yes, 'n' for no, 'r' to
repeat configuration. "));
+ do {
+ c = rd();
+ } while ( (c != 'y') && (c != 'n') && (c != 'r') );
+ printf("%c\n", c);
+ }
+ if (c == 'y') {
+ ret = GC_write_configuration(cfg,
+ filename);
+ if (ret == 1) {
+ printf(_("Configuration was unchanged, no need to save.\n"));
+ } else if (ret == -1) { /* error */
+ ioctl(0, TCSETS, &oldT);
+ return 1;
+ } else {
+ printf(_("Configuration file `%s' created.\n"),
+ filename);
+ }
+ }
+ ioctl(0, TCSETS, &oldT);
return 0;
}
Modified: GNUnet/src/setup/text/conf.h
===================================================================
--- GNUnet/src/setup/text/conf.h 2006-08-26 02:09:12 UTC (rev 3315)
+++ GNUnet/src/setup/text/conf.h 2006-08-26 04:01:40 UTC (rev 3316)
@@ -31,13 +31,13 @@
#include "gnunet_util.h"
#include "gnunet_setup_lib.h"
-int conf_main(int argc,
- const char ** argv,
- struct PluginHandle * self,
- struct GE_Context * ectx,
- struct GC_Configuration * cfg,
- struct GNS_Context * gns,
- const char * filename,
- int is_daemon);
+int main_setup_text(int argc,
+ const char ** argv,
+ struct PluginHandle * self,
+ struct GE_Context * ectx,
+ struct GC_Configuration * cfg,
+ struct GNS_Context * gns,
+ const char * filename,
+ int is_daemon);
#endif
Modified: GNUnet/src/util/config_impl/impl.c
===================================================================
--- GNUnet/src/util/config_impl/impl.c 2006-08-26 02:09:12 UTC (rev 3315)
+++ GNUnet/src/util/config_impl/impl.c 2006-08-26 04:01:40 UTC (rev 3316)
@@ -294,11 +294,14 @@
int error;
int ret;
- if (! GC_test_dirty(cfg))
- return 0; /* success: nothing to do! */
- if (NULL == (fp = FOPEN(filename, "w")))
+ data = cfg->data;
+ if (NULL == (fp = FOPEN(filename, "w"))) {
+ GE_LOG_STRERROR_FILE(data->ectx,
+ GE_ERROR | GE_USER | GE_IMMEDIATE,
+ "fopen",
+ filename);
return -1;
- data = cfg->data;
+ }
error = 0;
ret = 0;
MUTEX_LOCK(data->lock);
@@ -598,6 +601,10 @@
ret = -1; /* error -- update refused */
} else {
/* all confirmed, commit! */
+ if ( (e->val == NULL) ||
+ (0 != strcmp(e->val,
+ e->dirty_val)) )
+ data->dirty = 1;
FREENONNULL(e->val);
e->val = e->dirty_val;
e->dirty_val = NULL;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3316 - in GNUnet: contrib src/include src/setup src/setup/lib src/setup/text src/util/config_impl,
grothoff <=