[Gnucash-changes] Convert the expression parser over from saving
persistent data as a
David Hampton
hampton at cvs.gnucash.org
Fri Oct 7 18:14:15 EDT 2005
Log Message:
-----------
Convert the expression parser over from saving persistent data as a
scheme fragments to saving it in a glib key/value file.
Tags:
----
gnucash-gnome2-dev
Modified Files:
--------------
gnucash:
ChangeLog
gnucash/src/app-utils:
Makefile.am
gnc-exp-parser.c
Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.311
retrieving revision 1.1487.2.312
diff -LChangeLog -LChangeLog -u -r1.1487.2.311 -r1.1487.2.312
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,19 @@
+2005-10-07 David Hampton <hampton at employees.org>
+
+ * src/app-utils/Makefile.am:
+ * src/app-utils/gnc-exp-parser.c: Convert the expression parser
+ over from saving persistent data as a scheme fragments to saving
+ it in a glib key/value file.
+
+ * src/core-utils/Makefile.am:
+ * src/core-utils/gnc-gkeyfile-utils.[ch]: Add some helper
+ functions for reading/writing glib key/value data structures.
+
+ * configure.in:
+ * lib/Makefile.am:
+ * lib/glib26: Add glib key-value support for systems running
+ glib24.
+
2005-10-07 Joshua Sled <jsled at asynchronous.org>
* src/register/register-gnome/gnucash-sheet.c
Index: Makefile.am
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-utils/Makefile.am,v
retrieving revision 1.29.4.12
retrieving revision 1.29.4.13
diff -Lsrc/app-utils/Makefile.am -Lsrc/app-utils/Makefile.am -u -r1.29.4.12 -r1.29.4.13
--- src/app-utils/Makefile.am
+++ src/app-utils/Makefile.am
@@ -9,6 +9,7 @@
-I${top_srcdir}/src/calculation \
-I${top_srcdir}/src/core-utils \
-I${top_srcdir}/src/engine \
+ -I${top_srcdir}/lib/glib26 \
${GUILE_INCS} \
${G_WRAP_COMPILE_ARGS} \
${GLIB_CFLAGS} \
@@ -75,6 +76,7 @@
${top_builddir}/src/engine/libgncmod-engine.la \
${top_builddir}/src/calculation/libgncmod-calculation.la \
${top_builddir}/src/core-utils/libcore-utils.la \
+ ${top_builddir}/lib/glib26/libgncglib.la \
${GUILE_LIBS} \
${GLIB_LIBS}
Index: gnc-exp-parser.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-utils/gnc-exp-parser.c,v
retrieving revision 1.6.4.3
retrieving revision 1.6.4.4
diff -Lsrc/app-utils/gnc-exp-parser.c -Lsrc/app-utils/gnc-exp-parser.c -u -r1.6.4.3 -r1.6.4.4
--- src/app-utils/gnc-exp-parser.c
+++ src/app-utils/gnc-exp-parser.c
@@ -30,11 +30,13 @@
#include "finproto.h"
#include "fin_spl_protos.h"
#include "global-options.h"
+#include "gnc-gkeyfile-utils.h"
#include "gnc-exp-parser.h"
#include "messages.h"
#include "gnc-ui-util.h"
#include "guile-mappings.h"
+#define GROUP_NAME "Variables"
/** Data Types *****************************************************/
@@ -53,6 +55,12 @@
/** Implementations ************************************************/
+static gchar *
+gnc_exp_parser_filname (void)
+{
+ return g_build_filename(g_get_home_dir(), ".gnucash", "expressions-2.0", NULL);
+}
+
void
gnc_exp_parser_init ( void )
{
@@ -62,7 +70,9 @@
void
gnc_exp_parser_real_init ( gboolean addPredefined )
{
- SCM alist;
+ gchar *filename, **keys, **key, *str_value;
+ GKeyFile *key_file;
+ gnc_numeric value;
if (parser_inited)
gnc_exp_parser_shutdown ();
@@ -73,55 +83,20 @@
parser_inited = TRUE;
if ( addPredefined ) {
- alist = gnc_lookup_option ("__exp_parser", "defined_variables", SCM_EOL);
-
- while (SCM_LISTP(alist) && !SCM_NULLP(alist))
- {
- const gchar *name;
- SCM assoc;
- SCM val_scm;
- gnc_numeric value;
- gboolean good;
-
- assoc = SCM_CAR (alist);
- alist = SCM_CDR (alist);
-
- if (!SCM_CONSP (assoc))
- continue;
-
- name = SCM_STRING_CHARS (SCM_CAR (assoc));
- if (name == NULL)
- continue;
-
- val_scm = SCM_CDR (assoc);
- good = TRUE;
-
- if (SCM_NUMBERP (val_scm))
- {
- double dvalue;
-
- dvalue = scm_num2dbl (val_scm, __FUNCTION__);
- value = double_to_gnc_numeric (dvalue, GNC_DENOM_AUTO,
- GNC_DENOM_SIGFIGS(6)
- | GNC_RND_ROUND);
- }
- else if (SCM_STRINGP (val_scm))
- {
- const gchar *s;
- gboolean err;
-
- s = SCM_STRING_CHARS (val_scm);
-
- err = string_to_gnc_numeric (s, &value);
- if (err == FALSE)
- good = FALSE;
- }
- else
- good = FALSE;
-
- if (good)
- gnc_exp_parser_set_value (name, gnc_numeric_reduce (value));
- }
+ filename = gnc_exp_parser_filname();
+ key_file = gnc_key_file_load_from_file(filename, FALSE);
+ if (key_file) {
+ keys = g_key_file_get_keys(key_file, GROUP_NAME, NULL, NULL);
+ for (key = keys; key && *key; key++) {
+ str_value = g_key_file_get_string(key_file, GROUP_NAME, *key, NULL);
+ if (str_value && string_to_gnc_numeric(str_value, &value)) {
+ gnc_exp_parser_set_value (*key, gnc_numeric_reduce (value));
+ }
+ }
+ g_strfreev(keys);
+ g_key_file_free(key_file);
+ }
+ g_free(filename);
}
}
@@ -135,32 +110,35 @@
}
static void
-binding_cons (gpointer key, gpointer value, gpointer data)
+set_one_key (gpointer key, gpointer value, gpointer data)
{
char *name = key;
ParserNum *pnum = value;
- SCM *alist_p = data;
char *num_str;
- SCM assoc;
num_str = gnc_numeric_to_string (gnc_numeric_reduce (pnum->value));
- assoc = scm_cons (scm_makfrom0str (name), scm_makfrom0str (num_str));
+ g_key_file_set_string ((GKeyFile *)data, GROUP_NAME, name, num_str);
g_free (num_str);
-
- *alist_p = scm_cons (assoc, *alist_p);
}
void
gnc_exp_parser_shutdown (void)
{
- SCM alist;
+ GKeyFile* key_file;
+ gchar *filename;
if (!parser_inited)
return;
- alist = SCM_EOL;
- g_hash_table_foreach (variable_bindings, binding_cons, &alist);
- gnc_set_option ("__exp_parser", "defined_variables", alist);
+ filename = gnc_exp_parser_filname();
+ key_file = g_key_file_new();
+ g_hash_table_foreach (variable_bindings, set_one_key, key_file);
+ g_key_file_set_comment(key_file, GROUP_NAME, NULL,
+ _(" Variables are in the form 'name=value'"),
+ NULL);
+ gnc_key_file_save_to_file(filename, key_file);
+ g_key_file_free(key_file);
+ g_free(filename);
g_hash_table_foreach_remove (variable_bindings, remove_binding, NULL);
g_hash_table_destroy (variable_bindings);
More information about the gnucash-changes
mailing list