Save named parser variables between sessions.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3012 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-10-03 09:40:53 +00:00
parent 010d59408b
commit a15c41808b
4 changed files with 60 additions and 4 deletions

View File

@ -21,9 +21,11 @@
#include "config.h"
#include <ctype.h>
#include <guile/gh.h>
#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;

View File

@ -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();
}

View File

@ -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*)))

View File

@ -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?)