Skip to content

Commit

Permalink
Minor code cleanup in ofx importer; improve const-correctness.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20373 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
cstim committed Mar 4, 2011
1 parent 5483672 commit 92e138b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 46 deletions.
12 changes: 7 additions & 5 deletions src/import-export/import-commodity-matcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);


Expand Down
50 changes: 25 additions & 25 deletions src/import-export/import-commodity-matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**@}*/
40 changes: 24 additions & 16 deletions src/import-export/ofx/gnc-ofx-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 92e138b

Please sign in to comment.