From 4a757d939673c8105ad70b22f5e22058caf449cc Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Tue, 11 Sep 2001 07:41:26 +0000 Subject: [PATCH] More module refactoring. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5361 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/gnc-ui-util.c | 8 ++ src/app-utils/gnc-ui-util.h | 2 + src/app-utils/gw-app-utils-spec.scm | 8 ++ src/engine/engine-helpers.c | 93 +++++++++++++++++++ src/engine/engine-helpers.h | 14 +++ src/engine/gw-engine-spec.scm | 68 ++++++++++++++ src/report/report-system/report-system.scm | 4 - src/report/report-system/report-utilities.scm | 26 ------ 8 files changed, 193 insertions(+), 30 deletions(-) diff --git a/src/app-utils/gnc-ui-util.c b/src/app-utils/gnc-ui-util.c index 8ed89d473e..b2543c4003 100644 --- a/src/app-utils/gnc-ui-util.c +++ b/src/app-utils/gnc-ui-util.c @@ -775,6 +775,14 @@ gnc_account_create_opening_balance (Account *account, return TRUE; } +char * +gnc_account_get_full_name (Account *account) +{ + if (!account) return NULL; + + return xaccAccountGetFullName (account, gnc_get_account_separator ()); +} + static void gnc_lconv_set (char **p_value, char *default_value) { diff --git a/src/app-utils/gnc-ui-util.h b/src/app-utils/gnc-ui-util.h index 292b91eec5..14fbd5479d 100644 --- a/src/app-utils/gnc-ui-util.h +++ b/src/app-utils/gnc-ui-util.h @@ -88,6 +88,8 @@ gboolean gnc_account_create_opening_balance (Account *account, gnc_numeric balance, time_t date); +char * gnc_account_get_full_name (Account *account); + /* Price source functions *******************************************/ diff --git a/src/app-utils/gw-app-utils-spec.scm b/src/app-utils/gw-app-utils-spec.scm index 9ae3686d59..da725b496e 100644 --- a/src/app-utils/gw-app-utils-spec.scm +++ b/src/app-utils/gw-app-utils-spec.scm @@ -203,6 +203,14 @@ determines formatting details.") '() "Resume gui refresh events.") + (gw:wrap-function + mod + 'gnc:account-get-full-name + '() + "gnc_account_get_full_name" + '(( account)) + "Return the fully-qualified name of the account.") + (gw:wrap-function mod 'gnc:default-print-info diff --git a/src/engine/engine-helpers.c b/src/engine/engine-helpers.c index 61308fb3d5..659ae4608c 100644 --- a/src/engine/engine-helpers.c +++ b/src/engine/engine-helpers.c @@ -1297,6 +1297,7 @@ gnc_numeric_p(SCM arg) return TRUE; } } + static SCM gnc_glist_account_ptr_to_scm_internal (GList *account_list, gboolean free_list) { @@ -1369,6 +1370,98 @@ gnc_glist_account_ptr_p(SCM list) return gh_list_p(list); } +static SCM +gnc_glist_transaction_ptr_to_scm_internal (GList *trans_list, + gboolean free_list) +{ + static SCM trans_type = SCM_UNDEFINED; + SCM result; + + if (trans_type == SCM_UNDEFINED) + { + trans_type = gh_eval_str(""); + /* don't really need this - types are bound globally anyway. */ + if(trans_type != SCM_UNDEFINED) scm_protect_object(trans_type); + } + + result = gnc_glist_to_scm_list(trans_list, trans_type); + + if (free_list) + g_list_free (trans_list); + + return result; +} + +SCM +gnc_glist_transaction_ptr_to_scm (GList *transaction_list) +{ + return gnc_glist_transaction_ptr_to_scm_internal (transaction_list, TRUE); +} + +SCM +gnc_glist_transaction_ptr_to_scm_no_free (GList *transaction_list) +{ + return gnc_glist_transaction_ptr_to_scm_internal (transaction_list, FALSE); +} + +GList * +gnc_scm_to_glist_transaction_ptr (SCM scm_list) +{ + return gnc_scm_list_to_glist (scm_list); +} + +int +gnc_glist_transaction_ptr_p (SCM list) +{ + return gh_list_p (list); +} + +static SCM +gnc_glist_split_ptr_to_scm_internal (GList *trans_list, + gboolean free_list) +{ + static SCM trans_type = SCM_UNDEFINED; + SCM result; + + if (trans_type == SCM_UNDEFINED) + { + trans_type = gh_eval_str(""); + /* don't really need this - types are bound globally anyway. */ + if(trans_type != SCM_UNDEFINED) scm_protect_object(trans_type); + } + + result = gnc_glist_to_scm_list(trans_list, trans_type); + + if (free_list) + g_list_free (trans_list); + + return result; +} + +SCM +gnc_glist_split_ptr_to_scm (GList *split_list) +{ + return gnc_glist_split_ptr_to_scm_internal (split_list, TRUE); +} + +SCM +gnc_glist_split_ptr_to_scm_no_free (GList *split_list) +{ + return gnc_glist_split_ptr_to_scm_internal (split_list, FALSE); +} + +GList * +gnc_scm_to_glist_split_ptr (SCM scm_list) +{ + return gnc_scm_list_to_glist (scm_list); +} + +int +gnc_glist_split_ptr_p (SCM list) +{ + return gh_list_p (list); +} + /******************************************************************** * gnc_scm_to_commodity ********************************************************************/ diff --git a/src/engine/engine-helpers.h b/src/engine/engine-helpers.h index 1fcb2b7049..556e1d6d78 100644 --- a/src/engine/engine-helpers.h +++ b/src/engine/engine-helpers.h @@ -87,6 +87,20 @@ SCM gnc_glist_account_ptr_to_scm_no_free (GList *account_list); GList * gnc_scm_to_glist_account_ptr(SCM scm_list); int gnc_glist_account_ptr_p(SCM scm_list); +/* The GList is freed */ +SCM gnc_glist_transaction_ptr_to_scm(GList *transaction_list); +/* The GList is not freed */ +SCM gnc_glist_transaction_ptr_to_scm_no_free (GList *transaction_list); +GList * gnc_scm_to_glist_transaction_ptr(SCM scm_list); +int gnc_glist_transaction_ptr_p(SCM scm_list); + +/* The GList is freed */ +SCM gnc_glist_split_ptr_to_scm(GList *split_list); +/* The GList is not freed */ +SCM gnc_glist_split_ptr_to_scm_no_free (GList *split_list); +GList * gnc_scm_to_glist_split_ptr(SCM scm_list); +int gnc_glist_split_ptr_p(SCM scm_list); + /* The GList is freed */ SCM gnc_glist_commodity_ptr_to_scm(GList * list); GList * gnc_scm_to_glist_commodity_ptr(SCM list); diff --git a/src/engine/gw-engine-spec.scm b/src/engine/gw-engine-spec.scm index 7f06461ee5..2d7130af57 100644 --- a/src/engine/gw-engine-spec.scm +++ b/src/engine/gw-engine-spec.scm @@ -155,6 +155,66 @@ (old-func c-name) ";\n"))))) + ;; list of split * + (let ((wt (gw:wrap-type mod ' + "GList *" "const GList *"))) + (gw:type-set-scm-arg-type-test-ccodegen! + wt + (lambda (param) + (let ((old-func + (lambda (x) + (list "gnc_glist_split_ptr_p(" x ")")))) + (old-func (gw:param-get-scm-name param))))) + (gw:type-set-pre-call-arg-ccodegen! + wt + (lambda (param) + (let* ((scm-name (gw:param-get-scm-name param)) + (c-name (gw:param-get-c-name param)) + (old-func + (lambda (x) + (list "gnc_scm_to_glist_split_ptr(" x ")")))) + (list c-name " = " (old-func scm-name) ";\n")))) + + (gw:type-set-call-ccodegen! wt standard-c-call-gen) + + (add-standard-result-handlers! + wt + (lambda (scm-name c-name) + (let ((old-func + (lambda (x) + (list "gnc_glist_split_ptr_to_scm_no_free(" x ")")))) + (list scm-name " = " (old-func c-name) ";\n"))))) + + ;; list of transaction * + (let ((wt (gw:wrap-type mod ' + "GList *" "const GList *"))) + (gw:type-set-scm-arg-type-test-ccodegen! + wt + (lambda (param) + (let ((old-func + (lambda (x) + (list "gnc_glist_transaction_ptr_p(" x ")")))) + (old-func (gw:param-get-scm-name param))))) + (gw:type-set-pre-call-arg-ccodegen! + wt + (lambda (param) + (let* ((scm-name (gw:param-get-scm-name param)) + (c-name (gw:param-get-c-name param)) + (old-func + (lambda (x) + (list "gnc_scm_to_glist_transaction_ptr(" x ")")))) + (list c-name " = " (old-func scm-name) ";\n")))) + + (gw:type-set-call-ccodegen! wt standard-c-call-gen) + + (add-standard-result-handlers! + wt + (lambda (scm-name c-name) + (let ((old-func + (lambda (x) + (list "gnc_glist_transaction_ptr_to_scm_no_free(" x ")")))) + (list scm-name " = " (old-func c-name) ";\n"))))) + ;; list of account * (let ((wt (gw:wrap-type mod ' "GList *" "const GList *"))) @@ -635,6 +695,14 @@ will cause NULL to be returned. A convenient way of cycling through all splits is to start at zero, and kep incrementing until a null pointer is returned.") + (gw:wrap-function + mod + 'gnc:transaction-get-splits + ' + "xaccTransGetSplitList" + '(( t)) + "Returns a list of the splits in t.") + (gw:wrap-function mod 'gnc:transaction-get-num diff --git a/src/report/report-system/report-system.scm b/src/report/report-system/report-system.scm index 9b30bc3a30..34e04cc875 100644 --- a/src/report/report-system/report-system.scm +++ b/src/report/report-system/report-system.scm @@ -130,7 +130,6 @@ (export gnc:report-remove-by-id) (export gnc:find-report) (export gnc:report-generate-restore-forms) -(export gnc:backtrace-if-exception) (export gnc:report-render-html) (export gnc:report-run) @@ -503,8 +502,6 @@ (export gnc:account-get-type-string-plural) (export gnc:accounts-get-commodities) (export gnc:get-current-group-depth) -(export gnc:account-separator-char) -(export gnc:account-get-full-name) (export gnc:split-get-corr-account-full-name) (export gnc:account-get-immediate-subaccounts) (export gnc:account-get-all-subaccounts) @@ -526,7 +523,6 @@ (export gnc:account-get-balance-interval) (export gnc:account-get-comm-balance-interval) (export gnc:group-get-comm-balance-interval) -(export gnc:transaction-get-splits) (load-from-path "commodity-utilities.scm") (load-from-path "html-barchart.scm") diff --git a/src/report/report-system/report-utilities.scm b/src/report/report-system/report-utilities.scm index 7e4d8ac665..6a870feb29 100644 --- a/src/report/report-system/report-utilities.scm +++ b/src/report/report-system/report-utilities.scm @@ -154,22 +154,6 @@ (accounts-get-children-depth (gnc:group-get-account-list (gnc:get-current-group)))) -;; get a full account name -(define (gnc:account-get-full-name account) - (let ((separator (gnc:account-separator-char))) - (if (not account) - "" - (let ((parent-name - (gnc:account-get-full-name - (gnc:group-get-parent - (gnc:account-get-parent account))))) - (if (string=? parent-name "") - (gnc:account-get-name account) - (string-append - parent-name - separator - (gnc:account-get-name account))))))) - (define (gnc:split-get-corr-account-full-name split) (let ((separator (string-ref (gnc:account-separator-char) 0))) (gnc:split-get-corr-account-full-name-internal split separator))) @@ -597,13 +581,3 @@ (gnc:account-get-comm-balance-interval account from to #t)) group)) this-collector)) - -;; FIXME redundant -(define (gnc:transaction-get-splits transaction) - (let* ((num-splits (gnc:transaction-get-split-count transaction))) - (let loop ((index 0)) - (if (= index num-splits) - '() - (cons - (gnc:transaction-get-split transaction index) - (loop (+ index 1)))))))