r20373 - gnucash/trunk/src/import-export - Minor code cleanup in ofx importer; improve const-correctness.

Christian Stimming cstim at code.gnucash.org
Fri Mar 4 16:02:50 EST 2011


Author: cstim
Date: 2011-03-04 16:02:50 -0500 (Fri, 04 Mar 2011)
New Revision: 20373
Trac: http://svn.gnucash.org/trac/changeset/20373

Modified:
   gnucash/trunk/src/import-export/import-commodity-matcher.c
   gnucash/trunk/src/import-export/import-commodity-matcher.h
   gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
Log:
Minor code cleanup in ofx importer; improve const-correctness.

Modified: gnucash/trunk/src/import-export/import-commodity-matcher.c
===================================================================
--- gnucash/trunk/src/import-export/import-commodity-matcher.c	2011-03-04 20:17:02 UTC (rev 20372)
+++ gnucash/trunk/src/import-export/import-commodity-matcher.c	2011-03-04 21:02:50 UTC (rev 20373)
@@ -51,12 +51,12 @@
 
 
 
-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 @@
     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);
 
 

Modified: gnucash/trunk/src/import-export/import-commodity-matcher.h
===================================================================
--- gnucash/trunk/src/import-export/import-commodity-matcher.h	2011-03-04 20:17:02 UTC (rev 20372)
+++ gnucash/trunk/src/import-export/import-commodity-matcher.h	2011-03-04 21:02:50 UTC (rev 20373)
@@ -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
 /**@}*/

Modified: gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
===================================================================
--- gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c	2011-03-04 20:17:02 UTC (rev 20372)
+++ gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c	2011-03-04 21:02:50 UTC (rev 20373)
@@ -75,21 +75,21 @@
 
 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 @@
                                             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 @@
             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 @@
             {
                 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 @@
                                                         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 @@
                          && 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 @@
                                                                 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 @@
                                                                 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 @@
                                                                 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);



More information about the gnucash-changes mailing list