diff --git a/src/gnc-exp-parser.c b/src/gnc-exp-parser.c index 8715174d39..490ababa26 100644 --- a/src/gnc-exp-parser.c +++ b/src/gnc-exp-parser.c @@ -21,9 +21,11 @@ #include "config.h" #include +#include #include "finproto.h" #include "fin_spl_protos.h" +#include "global-options.h" #include "gnc-exp-parser.h" #include "messages.h" #include "util.h" @@ -48,12 +50,37 @@ static gboolean parser_inited = FALSE; void gnc_exp_parser_init (void) { + SCM alist; + if (parser_inited) gnc_exp_parser_shutdown (); variable_bindings = g_hash_table_new (g_str_hash, g_str_equal); + /* This comes after the statics have been initialized. Not at the end! */ parser_inited = TRUE; + + alist = gnc_lookup_option ("__exp_parser", "defined_variables", SCM_EOL); + + while (gh_list_p(alist) && !gh_null_p(alist)) + { + char *name; + double value; + SCM assoc; + + assoc = gh_car (alist); + alist = gh_cdr (alist); + + name = gh_scm2newstr(gh_car (assoc), NULL); + if (name == NULL) + continue; + + value = gh_scm2double(gh_cdr (assoc)); + + gnc_exp_parser_set_value (name, value); + + free(name); + } } static gboolean @@ -65,12 +92,31 @@ remove_binding (gpointer key, gpointer value, gpointer not_used) return TRUE; } +static void +binding_cons (gpointer key, gpointer value, gpointer data) +{ + char *name = key; + ParserNum *pnum = value; + SCM *alist_p = data; + SCM assoc; + + assoc = gh_cons (gh_str02scm (name), gh_double2scm (pnum->value)); + + *alist_p = gh_cons (assoc, *alist_p); +} + void gnc_exp_parser_shutdown (void) { + SCM alist; + if (!parser_inited) return; + alist = SCM_EOL; + g_hash_table_foreach (variable_bindings, binding_cons, &alist); + gnc_set_option ("__exp_parser", "defined_variables", alist); + g_hash_table_foreach_remove (variable_bindings, remove_binding, NULL); g_hash_table_destroy (variable_bindings); variable_bindings = NULL; diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index 9bea66e1df..d4e7feefd0 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -164,8 +164,6 @@ gnucash_ui_init(void) app = gnome_app_new("GnuCash", "GnuCash"); - gnc_options_init(); - gnc_configure_date_format(); date_callback_id = gnc_register_option_change_callback(gnc_configure_date_format_cb, NULL, @@ -294,7 +292,6 @@ gnc_ui_destroy (void) app = NULL; } - gnc_options_shutdown(); gnc_extensions_shutdown(); } diff --git a/src/scm/main.scm b/src/scm/main.scm index 46b869ce66..6739a83777 100644 --- a/src/scm/main.scm +++ b/src/scm/main.scm @@ -53,6 +53,12 @@ (gnc:hook-run-danglers gnc:*startup-hook*) + ;; Initialize the C side options code. Must come after the scheme + ;; options are loaded. + (gnc:c-options-init) + + ;; Initialize the expresion parser. Must come after the C side + ;; options initialization. (gnc:exp-parser-init) (if (gnc:config-var-value-get gnc:*arg-show-version*) @@ -94,7 +100,7 @@ ;; Now the fun begins. (gnc:startup) - + (if (not (= (gnc:lowlev-app-init) 0)) (gnc:shutdown 0)) @@ -104,6 +110,9 @@ ;; add a hook to save the user configs on shutdown (gnc:hook-add-dangler gnc:*shutdown-hook* gnc:save-global-options) + ;; add a hood to shut down the C side options code + (gnc:hook-add-dangler gnc:*shutdown-hook* gnc:c-options-shutdown) + (if (null? gnc:*batch-mode-forms-to-evaluate*) ;; We're not in batch mode; we can go ahead and do the normal thing. (let ((ok (not (gnc:config-var-value-get gnc:*arg-no-file*))) diff --git a/src/scm/prefs.scm b/src/scm/prefs.scm index d007d48bce..5fe1c5d9da 100644 --- a/src/scm/prefs.scm +++ b/src/scm/prefs.scm @@ -579,6 +579,10 @@ the current value of the path." (gnc:make-internal-option "__gui" "reg_column_widths" '())) +(gnc:register-configuration-option + (gnc:make-internal-option + "__exp_parser" "defined_variables" '())) + ;; This needs to be after all the global options definitions (if (gnc:debugging?)