From 92e138b06b7e5e290e64ab740cfffe67cbb3828d Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Fri, 4 Mar 2011 21:02:50 +0000 Subject: [PATCH] Minor code cleanup in ofx importer; improve const-correctness. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20373 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/import-export/import-commodity-matcher.c | 12 +++-- src/import-export/import-commodity-matcher.h | 50 ++++++++++---------- src/import-export/ofx/gnc-ofx-import.c | 40 +++++++++------- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/src/import-export/import-commodity-matcher.c b/src/import-export/import-commodity-matcher.c index 0e0ab5222f..1780b4c410 100644 --- a/src/import-export/import-commodity-matcher.c +++ b/src/import-export/import-commodity-matcher.c @@ -51,12 +51,12 @@ static QofLogModule log_module = GNC_MOD_IMPORT; -gnc_commodity * gnc_import_select_commodity(char * cusip, - char auto_create, - char * default_fullname, - char * default_mnemonic) +gnc_commodity * gnc_import_select_commodity(const char * cusip, + gboolean auto_create, + const char * default_fullname, + const char * default_mnemonic) { - gnc_commodity_table * commodity_table = gnc_get_current_commodities (); + const gnc_commodity_table * commodity_table = gnc_get_current_commodities (); gnc_commodity * retval = NULL; gnc_commodity * tmp_commodity = NULL; char * tmp_namespace = NULL; @@ -67,8 +67,10 @@ gnc_commodity * gnc_import_select_commodity(char * cusip, DEBUG("Default mnemonic received: %s", default_mnemonic ? default_mnemonic : "(null)"); + g_return_val_if_fail(cusip, NULL); DEBUG("Looking for commodity with exchange_code: %s", cusip); + g_assert(commodity_table); namespace_list = gnc_commodity_table_get_namespaces(commodity_table); diff --git a/src/import-export/import-commodity-matcher.h b/src/import-export/import-commodity-matcher.h index 28a0dce1d3..22e7797b11 100644 --- a/src/import-export/import-commodity-matcher.h +++ b/src/import-export/import-commodity-matcher.h @@ -29,39 +29,39 @@ /** Must be called with a string containing a unique identifier for the - commodity. If an commodity with a matching cusip is - found, the function immediately returns with a pointer to that - commodity. Otherwise, the user may be prompted to select a GnuCash - account or create a new one (in both cases, the cusip is - written to the commodity's cusip field, overwriting anything that - was there before. + commodity. If an commodity with a matching cusip is found, the + function immediately returns with a pointer to that commodity. + Otherwise, the user may be prompted to select a GnuCash commodity or + create a new one (in both cases, the cusip is written to the + commodity's cusip field, overwriting anything that was there before. - @param cusip The string containing the code for which you - want a matching commodity. A CUISP code or similar UNIQUE code. - The stock ticker is NOT appropriate, unless you have no other option. + @param cusip The string containing the code for which you want a + matching commodity. A CUISP code or similar UNIQUE code. The stock + ticker is NOT appropriate, unless you have no other option. Must be + non-NULL. - @param auto_create If 0, if the cusip value in unknown, - the function returns NULL, otherwise, the user will be asked to - create a new account. + @param auto_create If the cusip value is unknown and this parameter + is false (zero), the function returns NULL. Otherwise the user will + be asked to select an existing or create a new commodity. - @param default_fullname A human-readable description of the commodity, such - as the stock name. Can be NULL. If it is not NULL, it will be shown - to the user when selecting a commodity. It will also be used as - the default if a new commodity is created. + @param default_fullname A human-readable description of the + commodity, such as the stock name. Can be NULL. If it is not NULL, + it will be shown to the user when selecting a commodity. It will + also be used as the default if a new commodity is created. - @param default_mnemonic Usually the stock ticker or similar. Can be NULL. - If it is not NULL, it will be shown - to the user when selecting a commodity. It will also be used as - the default if a new commodity is created. + @param default_mnemonic Usually the stock ticker or similar. Can be + NULL. If it is not NULL, it will be shown to the user when + selecting a commodity. It will also be used as the default if a new + commodity is created. @return A pointer to the found or created commodity, or NULL if no - account was found or created. + commodity was found or created. */ -gnc_commodity * gnc_import_select_commodity(char * cusip, - char auto_create, - char * default_fullname, - char * default_mnemonic); +gnc_commodity * gnc_import_select_commodity(const char * cusip, + gboolean auto_create, + const char * default_fullname, + const char * default_mnemonic); #endif /**@}*/ diff --git a/src/import-export/ofx/gnc-ofx-import.c b/src/import-export/ofx/gnc-ofx-import.c index 9a42c4b5a5..cef8dd8b29 100644 --- a/src/import-export/ofx/gnc-ofx-import.c +++ b/src/import-export/ofx/gnc-ofx-import.c @@ -75,21 +75,21 @@ double ofx_get_investment_amount(struct OfxTransactionData data); int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data) { - char * tmp_cusip = NULL; - char * tmp_default_fullname = NULL; - char * tmp_default_mnemonic = NULL; + const char* tmp_cusip = NULL; + const char* tmp_default_fullname = NULL; + const char* tmp_default_mnemonic = NULL; if (data.unique_id_valid == true) { - tmp_cusip = (char *)data.unique_id; + tmp_cusip = data.unique_id; } if (data.secname_valid == true) { - tmp_default_fullname = (char *)data.secname; + tmp_default_fullname = data.secname; } if (data.ticker_valid == true) { - tmp_default_mnemonic = (char *)data.ticker; + tmp_default_mnemonic = data.ticker; } gnc_import_select_commodity(tmp_cusip, @@ -126,7 +126,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u ACCT_TYPE_NONE, NULL, NULL); if (account != NULL) { - /********** Validate the input strings to ensure utf8 ********************/ + /***** Validate the input strings to ensure utf8 *****/ if (data.name_valid) gnc_utf8_strip_invalid(data.name); if (data.memo_valid) @@ -136,7 +136,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u if (data.reference_number_valid) gnc_utf8_strip_invalid(data.reference_number); - /********** Create the transaction and setup transaction data ************/ + /***** Create the transaction and setup transaction data *******/ book = gnc_account_get_book(account); transaction = xaccMallocTransaction(book); xaccTransBeginEdit(transaction); @@ -377,7 +377,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u { if (data.invtransactiontype_valid == false) { - /*************Process a normal transaction ***************************/ + /***** Process a normal transaction ******/ DEBUG("Adding split; Ordinary banking transaction, money flows from or into the source account"); split = xaccMallocSplit(book); xaccTransAppendSplit(transaction, split); @@ -388,7 +388,8 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); - /* Also put the ofx transaction's memo in the split's memo field */ + /* Also put the ofx transaction's memo in the + * split's memo field */ if (data.memo_valid == true) { xaccSplitSetMemo(split, data.memo); @@ -403,9 +404,10 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u && data.security_data_ptr != NULL && data.security_data_ptr->secname_valid == true) { - /************************ Process an investment transaction ******************************/ - /* Note that the ACCT_TYPE_STOCK account type should be replaced with something - derived from data.invtranstype*/ + /********* Process an investment transaction **********/ + /* Note that the ACCT_TYPE_STOCK account type + should be replaced with something derived from + data.invtranstype*/ investment_commodity = gnc_import_select_commodity(data.unique_id, 0, NULL, @@ -526,7 +528,9 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); - /* Also put the ofx transaction name in the splits memo field, or ofx memo if name is unavailable */ + /* Also put the ofx transaction name in + * the splits memo field, or ofx memo if + * name is unavailable */ if (data.name_valid == true) { xaccSplitSetMemo(split, data.name); @@ -549,7 +553,9 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); - /* Also put the ofx transaction name in the splits memo field, or ofx memo if name is unavailable */ + /* Also put the ofx transaction name in + * the splits memo field, or ofx memo if + * name is unavailable */ if (data.name_valid == true) { xaccSplitSetMemo(split, data.name); @@ -573,7 +579,9 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); - /* Also put the ofx transaction name in the splits memo field, or ofx memo if name is unavailable */ + /* Also put the ofx transaction name in + * the splits memo field, or ofx memo if + * name is unavailable */ if (data.name_valid == true) { xaccSplitSetMemo(split, data.name);