From a699183ae5a79ebde1964079d69e7f17bda618bb Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Fri, 4 Dec 2009 20:26:48 +0000 Subject: [PATCH] Bug #537476: Fix currency trading account preference lookup Patch by Mike Alexander: There are a few values related to the trading accounts preference that are needed in both Scheme and C code. Since one of them was already defined in Scheme before I started, I defined all of them there and tried to import them to C. This is obviously not a good idea, especially since the make check tests don't even fire up Guile so Scheme code isn't available. This patch changes things around to define the values in C and import them to Scheme. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18464 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/app-utils.scm | 2 +- .../business-utils/business-utils.scm | 4 +-- src/engine/engine.i | 5 +++ src/libqof/qof/Makefile.am | 3 +- src/libqof/qof/qofbook.c | 33 +++---------------- src/libqof/qof/qofbookslots.h | 33 +++++++++++++++++++ 6 files changed, 47 insertions(+), 33 deletions(-) create mode 100644 src/libqof/qof/qofbookslots.h diff --git a/src/app-utils/app-utils.scm b/src/app-utils/app-utils.scm index 295e19efc1..7126f9626d 100644 --- a/src/app-utils/app-utils.scm +++ b/src/app-utils/app-utils.scm @@ -257,7 +257,7 @@ (export simple-obj-from-list) (export make-simple-obj) -(define gnc:*kvp-option-path* '("options")) +(define gnc:*kvp-option-path* (list BOOK-OPTIONS-NAME)) (export gnc:*kvp-option-path*) (load-from-path "c-interface.scm") diff --git a/src/business/business-utils/business-utils.scm b/src/business/business-utils/business-utils.scm index 281b151054..9263e45f7f 100644 --- a/src/business/business-utils/business-utils.scm +++ b/src/business/business-utils/business-utils.scm @@ -18,8 +18,8 @@ gnc:*company-phone* gnc:*company-fax* gnc:*company-url* gnc:*company-email* gnc:*company-contact*) -(define gnc:*book-label* (N_ "Accounts")) -(define gnc:*trading-accounts* (N_ "Trading Accounts")) +(define gnc:*book-label* ACCOUNT-OPTIONS-SECTION) +(define gnc:*trading-accounts* TRADING-ACCOUNTS-OPTION) (export gnc:*book-label* gnc:*trading-accounts*) diff --git a/src/engine/engine.i b/src/engine/engine.i index df3b93d790..988bf4ec79 100644 --- a/src/engine/engine.i +++ b/src/engine/engine.i @@ -114,6 +114,7 @@ SplitList * qof_query_run (QofQuery *q); %ignore qof_query_run; %include %include +%include gnc_numeric gnc_numeric_create(gint64 num, gint64 denom); gnc_numeric gnc_numeric_zero(void); @@ -297,6 +298,10 @@ static KvpFrame * gnc_book_get_slots(QofBook *book) { SET_ENUM("TRANS-DATE-POSTED"); SET_ENUM("TRANS-DESCRIPTION"); SET_ENUM("TRANS-NUM"); + + SET_ENUM("BOOK-OPTIONS-NAME"); + SET_ENUM("ACCOUNT-OPTIONS-SECTION"); + SET_ENUM("TRADING-ACCOUNTS-OPTION"); SET_ENUM("ACCOUNT-CODE-"); /* sic */ diff --git a/src/libqof/qof/Makefile.am b/src/libqof/qof/Makefile.am index 0131468d40..901eba3b3c 100644 --- a/src/libqof/qof/Makefile.am +++ b/src/libqof/qof/Makefile.am @@ -2,14 +2,12 @@ lib_LTLIBRARIES = libgnc-qof.la libgnc_qof_la_LDFLAGS= -version-info $(LIBQOF_LIBRARY_VERSION) libgnc_qof_la_LIBADD= \ - $(GUILE_LIBS) \ $(GLIB_LIBS) \ $(REGEX_LIBS) \ $(top_builddir)/lib/libc/libc-missing.la AM_CPPFLAGS = \ -I$(top_srcdir)/lib/libc \ - $(GUILE_INCS) \ $(GLIB_CFLAGS) libgnc_qof_la_SOURCES = \ @@ -58,6 +56,7 @@ qofinclude_HEADERS = \ qofinstance.h \ qofquery.h \ qofbook.h \ + qofbookslots.h \ qoflog.h \ qofobject.h \ qofquerycore.h \ diff --git a/src/libqof/qof/qofbook.c b/src/libqof/qof/qofbook.c index 32a26383c0..9621e86453 100644 --- a/src/libqof/qof/qofbook.c +++ b/src/libqof/qof/qofbook.c @@ -39,7 +39,6 @@ #include #include -#include #include "qof.h" #include "qofevent-p.h" @@ -47,6 +46,7 @@ #include "qofbook-p.h" #include "qofid-p.h" #include "qofobject-p.h" +#include "qofbookslots.h" static QofLogModule log_module = QOF_MOD_ENGINE; @@ -440,39 +440,17 @@ qof_book_get_counter (const QofBook *book, const char *counter_name) return counter; } -static char *get_scm_string(const char *str_name) -{ - SCM scm_string = scm_c_eval_string (str_name); - if (! SCM_STRINGP(scm_string)) - return NULL; - - return g_strdup(SCM_STRING_CHARS(scm_string)); -} - /* Determine whether this book uses trading accounts */ gboolean qof_book_use_trading_accounts (const QofBook *book) { -#if 0 - static char *options_name = NULL; - static char *acct_section = NULL; - static char *trading_opt = NULL; - const char *opt; kvp_value *kvp_val; - if (options_name == NULL) - { - options_name = get_scm_string ("(car gnc:*kvp-option-path*)"); - //acct_section = get_scm_string ("gnc:*book-label*"); - //trading_opt = get_scm_string ("gnc:*trading-accounts*"); - if (options_name == NULL || acct_section == NULL || trading_opt == NULL) - { - PWARN ("Unable to find trading account preference"); - } - } - kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book), options_name, acct_section, - trading_opt, NULL); + kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book), + BOOK_OPTIONS_NAME, + ACCOUNT_OPTIONS_SECTION, + TRADING_ACCOUNTS_OPTION, NULL); if (kvp_val == NULL) return FALSE; @@ -480,7 +458,6 @@ gboolean qof_book_use_trading_accounts (const QofBook *book) if (opt && opt[0] == 't' && opt[1] == 0) return TRUE; -#endif return FALSE; } diff --git a/src/libqof/qof/qofbookslots.h b/src/libqof/qof/qofbookslots.h new file mode 100644 index 0000000000..894b62e7b5 --- /dev/null +++ b/src/libqof/qof/qofbookslots.h @@ -0,0 +1,33 @@ +/********************************************************************\ + * qofbookslots.h -- Defines the names of slots used in the book. * + * This program 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 of * + * the License, or (at your option) any later version. * + * * + * This program 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 this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * + * Boston, MA 02110-1301, USA gnu@gnu.org * + * * +\********************************************************************/ + +/** @name Book parameter names + + * These define the names used for the slots used to store book level parameters. + * They are defined here so swig will find them since they need to be available to + * Scheme code too. + @{ +*/ +#define BOOK_OPTIONS_NAME "options" +#define ACCOUNT_OPTIONS_SECTION "Accounts" +#define TRADING_ACCOUNTS_OPTION "Trading Accounts" + +/** @} */