[Gnucash-changes] r14426 - gnucash/branches/register-rewrite/src - Two changes to the gnc_commodity API:
Chris Shoemaker
chris at cvs.gnucash.org
Sat Jun 24 12:12:22 EDT 2006
Author: chris
Date: 2006-06-24 12:12:18 -0400 (Sat, 24 Jun 2006)
New Revision: 14426
Trac: http://svn.gnucash.org/trac/changeset/14426
Modified:
gnucash/branches/register-rewrite/src/backend/file/gnc-commodity-xml-v2.c
gnucash/branches/register-rewrite/src/backend/file/gnc-schedxaction-xml-v2.c
gnucash/branches/register-rewrite/src/backend/file/io-gncbin-r.c
gnucash/branches/register-rewrite/src/backend/file/io-gncxml-v1.c
gnucash/branches/register-rewrite/src/backend/file/sixtp-dom-parsers.c
gnucash/branches/register-rewrite/src/backend/file/test/test-dom-converters1.c
gnucash/branches/register-rewrite/src/backend/file/test/test-file-stuff.c
gnucash/branches/register-rewrite/src/backend/file/test/test-xml-commodity.c
gnucash/branches/register-rewrite/src/backend/postgres/price.c
gnucash/branches/register-rewrite/src/engine/SchedXaction.c
gnucash/branches/register-rewrite/src/engine/gnc-commodity.c
gnucash/branches/register-rewrite/src/engine/gnc-commodity.h
gnucash/branches/register-rewrite/src/engine/gw-engine-spec.scm
gnucash/branches/register-rewrite/src/engine/iso-currencies-to-c
gnucash/branches/register-rewrite/src/engine/test-core/test-engine-stuff.c
gnucash/branches/register-rewrite/src/engine/test/test-commodities.c
gnucash/branches/register-rewrite/src/gnome-utils/dialog-commodity.c
gnucash/branches/register-rewrite/src/import-export/binary-import/druid-commodity.c
gnucash/branches/register-rewrite/src/import-export/qif-import/druid-qif-import.c
gnucash/branches/register-rewrite/src/import-export/qif-import/qif-dialog-utils.scm
Log:
Two changes to the gnc_commodity API:
1. Pass only the namespace and mnemonic strings to
gnc_commodity_new(). This separates construction from the setters and
simplifies callers.
2. Combine gnc_commodity_set_mnemonic() and gnc_commodity_set_namespace()
into one function: gnc_commodity_set_namespace_and_mnemonic().
This allows callers to safely ignore the possibility of an accidental
hash collision when setting these key-parts non-atomically.
These changes result in some simplifications of gnc_commodity's life-cycle.
Modified: gnucash/branches/register-rewrite/src/backend/file/gnc-commodity-xml-v2.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/file/gnc-commodity-xml-v2.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/file/gnc-commodity-xml-v2.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -126,8 +126,6 @@
};
struct com_char_handler com_handlers[] = {
- { cmdty_namespace, gnc_commodity_set_namespace },
- { cmdty_id, gnc_commodity_set_mnemonic },
{ cmdty_name, gnc_commodity_set_fullname },
{ cmdty_xcode, gnc_commodity_set_cusip },
{ cmdty_quote_tz, gnc_commodity_set_quote_tz },
@@ -186,17 +184,21 @@
static gboolean
valid_commodity(gnc_commodity *com)
{
- if(gnc_commodity_get_namespace(com) == NULL)
+ const char *str;
+
+ str = gnc_commodity_get_namespace(com);
+ if (!str || *str == '\0')
{
PWARN("Invalid commodity: no namespace");
return FALSE;
}
- if(gnc_commodity_get_mnemonic(com) == NULL)
+ str = gnc_commodity_get_mnemonic(com);
+ if (!str || *str == '\0')
{
PWARN("Invalid commodity: no mnemonic");
return FALSE;
}
- if(gnc_commodity_get_fraction(com) == 0)
+ if (gnc_commodity_get_fraction(com) == 0)
{
PWARN("Invalid commodity: 0 fraction");
return FALSE;
@@ -205,9 +207,8 @@
}
static gnc_commodity *
-gnc_commodity_find_currency (QofBook *book, xmlNodePtr tree)
+gnc_commodity_find_or_make_currency (QofBook *book, xmlNodePtr tree)
{
- gnc_commodity_table * table;
gchar *namespace = NULL, *mnemonic = NULL;
xmlNodePtr node;
@@ -222,11 +223,7 @@
if (!namespace || !mnemonic)
return NULL;
- if (!gnc_commodity_namespace_is_iso(namespace))
- return NULL;
-
- table = gnc_commodity_table_get_table(book);
- return gnc_commodity_table_lookup(table, namespace, mnemonic);
+ return gnc_commodity_new(book, namespace, mnemonic);
}
static gboolean
@@ -255,9 +252,11 @@
g_return_val_if_fail(tree, FALSE);
- com = gnc_commodity_find_currency(book, tree);
- if (!com)
- com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0);
+ com = gnc_commodity_find_or_make_currency(book, tree);
+ if (!com) {
+ PWARN("Invalid commodity");
+ return FALSE;
+ }
for(achild = tree->xmlChildrenNode; achild; achild = achild->next)
{
Modified: gnucash/branches/register-rewrite/src/backend/file/gnc-schedxaction-xml-v2.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/file/gnc-schedxaction-xml-v2.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/file/gnc-schedxaction-xml-v2.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -713,9 +713,7 @@
applies for
SchedXaction.c:xaccSchedXactionInit... */
com = gnc_commodity_new( txd->book,
- "template", "template",
- "template", "template",
- 1 );
+ "template", "template");
xaccAccountSetCommodity( acc, com );
}
Modified: gnucash/branches/register-rewrite/src/backend/file/io-gncbin-r.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/file/io-gncbin-r.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/file/io-gncbin-r.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -382,9 +382,7 @@
currency_name);
if(!old) {
- old = gnc_commodity_new(book, currency_name,
- GNC_COMMODITY_NS_LEGACY, currency_name,
- 0, 100000);
+ old = gnc_commodity_new(book, GNC_COMMODITY_NS_LEGACY, currency_name);
}
return old;
}
Modified: gnucash/branches/register-rewrite/src/backend/file/io-gncxml-v1.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/file/io-gncxml-v1.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/file/io-gncxml-v1.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -1929,12 +1929,10 @@
if(!cpi->name) cpi->name = g_strdup("");
if(!cpi->xcode) cpi->xcode = g_strdup("");
- comm = gnc_commodity_new(pstatus->book,
- cpi->name,
- cpi->space,
- cpi->id,
- cpi->xcode,
- cpi->fraction);
+ comm = gnc_commodity_new(pstatus->book, cpi->space, cpi->id);
+ gnc_commodity_set_fullname(comm, cpi->name);
+ gnc_commodity_set_cusip(comm, cpi->xcode);
+ gnc_commodity_set_fraction(comm, cpi->fraction);
if(comm)
{
gnc_commodity_table *ctab;
Modified: gnucash/branches/register-rewrite/src/backend/file/sixtp-dom-parsers.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/file/sixtp-dom-parsers.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/file/sixtp-dom-parsers.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -733,7 +733,7 @@
} else {
g_strstrip(space_str);
g_strstrip(id_str);
- c = gnc_commodity_new(book, NULL, space_str, id_str, NULL, 0);
+ c = gnc_commodity_new(book, space_str, id_str);
}
g_free(space_str);
@@ -759,8 +759,6 @@
gnc_commodity_get_namespace(daref),
gnc_commodity_get_mnemonic(daref));
- gnc_commodity_destroy(daref);
-
g_return_val_if_fail (ret != NULL, NULL);
return ret;
Modified: gnucash/branches/register-rewrite/src/backend/file/test/test-dom-converters1.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/file/test/test-dom-converters1.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/file/test/test-dom-converters1.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -61,17 +61,18 @@
test_str1 = get_random_string();
test_str2 = get_random_string();
- test_com1 = gnc_commodity_new(book, NULL, test_str1, test_str2, NULL, 0);
+ test_com1 = gnc_commodity_new(book, test_str1, test_str2);
test_node = commodity_ref_to_dom_tree("test-com", test_com1);
test_com2 = dom_tree_to_commodity_ref_no_engine(test_node, book);
+ do_test((test_com1 == test_com2),
+ "gnc_commodity identity");
do_test(gnc_commodity_equiv(test_com1, test_com2),
"dom_tree_to_commodity_ref_no_engine");
xmlFreeNode(test_node);
gnc_commodity_destroy(test_com1);
- gnc_commodity_destroy(test_com2);
g_free(test_str1);
g_free(test_str2);
Modified: gnucash/branches/register-rewrite/src/backend/file/test/test-file-stuff.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/file/test/test-file-stuff.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/file/test/test-file-stuff.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -215,16 +215,11 @@
g_return_val_if_fail(cmpcom, FALSE);
- if(gnc_commodity_equiv(com, cmpcom))
- {
- gnc_commodity_destroy(cmpcom);
- return TRUE;
- }
- else
- {
- gnc_commodity_destroy(cmpcom);
- return TRUE;
- }
+ /* It's incorrect to always free cmpcom, since it may have been a
+ valid, in-use commodity, even if it's not equal to com.
+ Instead, we allow the potential leak of cmpcom. In practice,
+ this only happens when there is a test failure. */
+ return gnc_commodity_equiv(com, cmpcom);
}
gboolean
Modified: gnucash/branches/register-rewrite/src/backend/file/test/test-xml-commodity.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/file/test/test-xml-commodity.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/file/test/test-xml-commodity.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -131,10 +131,8 @@
do_test_args(gnc_commodity_equiv((gnc_commodity*)data, gdata->com),
"gnc_commodity_sixtp_parser_create",
__FILE__, __LINE__, "%d", gdata->value );
- gnc_commodity_destroy((gnc_commodity*)data);
return TRUE;
-
}
static void
Modified: gnucash/branches/register-rewrite/src/backend/postgres/price.c
===================================================================
--- gnucash/branches/register-rewrite/src/backend/postgres/price.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/backend/postgres/price.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -73,11 +73,11 @@
/* no we don't ... restore it */
com = gnc_commodity_new (book,
- DB_GET_VAL("fullname",j),
DB_GET_VAL("namespace",j),
- DB_GET_VAL("mnemonic",j),
- DB_GET_VAL("code",j),
- atoi(DB_GET_VAL("fraction",j)));
+ DB_GET_VAL("mnemonic",j));
+ gnc_commodity_set_fullname(com, DB_GET_VAL("fullname",j));
+ gnc_commodity_set_cusip(com, DB_GET_VAL("code",j));
+ gnc_commodity_set_fraction(com, atoi(DB_GET_VAL("fraction",j)));
}
return NULL;
}
Modified: gnucash/branches/register-rewrite/src/engine/SchedXaction.c
===================================================================
--- gnucash/branches/register-rewrite/src/engine/SchedXaction.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/engine/SchedXaction.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -76,8 +76,7 @@
xaccAccountSetCommodity(
sx->template_acct,
gnc_commodity_new( book,
- "template", "template",
- "template", "template", 1 ) );
+ "template", "template") );
xaccAccountSetType( sx->template_acct, BANK );
ag = gnc_book_get_template_group( book );
xaccGroupInsertAccount( ag, sx->template_acct );
Modified: gnucash/branches/register-rewrite/src/engine/gnc-commodity.c
===================================================================
--- gnucash/branches/register-rewrite/src/engine/gnc-commodity.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/engine/gnc-commodity.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -526,9 +526,8 @@
}
gnc_commodity *
-gnc_commodity_new(QofBook *book, const char * fullname,
- const char * namespace, const char * mnemonic,
- const char * cusip, int fraction)
+gnc_commodity_new(QofBook *book, const char * namespace,
+ const char * mnemonic)
{
gnc_commodity * retval = g_new0(gnc_commodity, 1);
gnc_commodity_table *table;
@@ -536,10 +535,10 @@
qof_instance_init (&retval->inst, GNC_ID_COMMODITY, book);
table = gnc_commodity_table_get_table(book);
retval->namespace = gnc_commodity_table_add_namespace(table, namespace, book);
- retval->fullname = CACHE_INSERT(fullname);
+ retval->fullname = CACHE_INSERT("");
retval->mnemonic = CACHE_INSERT(mnemonic);
- retval->cusip = CACHE_INSERT(cusip);
- retval->fraction = fraction;
+ retval->cusip = CACHE_INSERT("");
+ retval->fraction = 0;
retval->mark = 0;
retval->quote_flag = 0;
retval->quote_source = NULL;
@@ -565,11 +564,15 @@
{
QofBook *book;
gnc_commodity_table *table;
+ const char *ns_name;
if(!cm) return;
book = qof_instance_get_book(&cm->inst);
table = gnc_commodity_table_get_table(book);
- gnc_commodity_table_remove(table, cm);
+ /* only remove from the table if this exact commodity is there */
+ ns_name = gnc_commodity_namespace_get_name(cm->namespace);
+ if (gnc_commodity_table_lookup (table, ns_name, cm->mnemonic) == cm)
+ gnc_commodity_table_remove(table, cm);
qof_event_gen (&cm->inst.entity, QOF_EVENT_DESTROY, NULL);
@@ -596,18 +599,6 @@
g_free(cm);
}
-static void
-gnc_commodity_copy(gnc_commodity * dest, gnc_commodity *src)
-{
- gnc_commodity_set_fullname (dest, src->fullname);
- dest->namespace = src->namespace;
- gnc_commodity_set_fraction (dest, src->fraction);
- gnc_commodity_set_cusip (dest, src->cusip);
- gnc_commodity_set_quote_flag (dest, src->quote_flag);
- gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
- gnc_commodity_set_quote_tz (dest, src->quote_tz);
-}
-
static gnc_commodity *
gnc_commodity_clone(gnc_commodity *src)
{
@@ -774,58 +765,33 @@
return cm ? cm->quote_tz : NULL;
}
-/********************************************************************
- * gnc_commodity_set_mnemonic
- ********************************************************************/
-
void
-gnc_commodity_set_mnemonic(gnc_commodity * cm, const char * mnemonic)
+gnc_commodity_set_namespace_and_mnemonic(
+ gnc_commodity *cm, const gchar *namespace, const gchar *mnemonic)
{
- gnc_commodity_table *table;
- if (!cm) return;
- if (cm->mnemonic == mnemonic) return;
-
- gnc_commodity_begin_edit(cm);
- table = gnc_commodity_table_get_table(qof_instance_get_book(&cm->inst));
- gnc_commodity_table_remove(table, cm);
- CACHE_REPLACE(cm->mnemonic, mnemonic);
-
- mark_commodity_dirty (cm);
- reset_printname(cm);
- reset_unique_name(cm);
- {
- gnc_commodity *same = gnc_commodity_table_insert(table, cm);
- g_assert(same == cm);
- }
- gnc_commodity_commit_edit(cm);
-}
-
-/********************************************************************
- * gnc_commodity_set_namespace
- ********************************************************************/
-
-void
-gnc_commodity_set_namespace(gnc_commodity * cm, const char * namespace)
-{
QofBook *book;
+ gnc_commodity *found;
gnc_commodity_table *table;
gnc_commodity_namespace *nsp;
if (!cm) return;
book = qof_instance_get_book (&cm->inst);
table = gnc_commodity_table_get_table(book);
+ found = gnc_commodity_table_lookup(table, namespace, mnemonic);
+
+ if (found == cm) return;
gnc_commodity_table_remove(table, cm);
nsp = gnc_commodity_table_add_namespace(table, namespace, book);
- if (cm->namespace == nsp)
- return;
gnc_commodity_begin_edit(cm);
+ CACHE_REPLACE(cm->mnemonic, mnemonic);
cm->namespace = nsp;
if (nsp->iso4217)
cm->quote_source = gnc_quote_source_lookup_by_internal("currency");
mark_commodity_dirty(cm);
reset_printname(cm);
reset_unique_name(cm);
+ gnc_commodity_table_remove(table, cm);
{
gnc_commodity *same = gnc_commodity_table_insert(table, cm);
g_assert(same == cm);
@@ -1260,12 +1226,8 @@
if (c)
{
- if (c == comm)
- {
- return c;
- }
- gnc_commodity_copy (c, comm);
- gnc_commodity_destroy (comm);
+ if (c != comm)
+ gnc_commodity_destroy (comm);
return c;
}
@@ -1303,7 +1265,8 @@
ns_name = gnc_commodity_namespace_get_name(comm->namespace);
c = gnc_commodity_table_lookup (table, ns_name, comm->mnemonic);
- if (c != comm) return;
+ if (c)
+ comm = c;
qof_event_gen (&comm->inst.entity, QOF_EVENT_REMOVE, NULL);
Modified: gnucash/branches/register-rewrite/src/engine/gnc-commodity.h
===================================================================
--- gnucash/branches/register-rewrite/src/engine/gnc-commodity.h 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/engine/gnc-commodity.h 2006-06-24 16:12:18 UTC (rev 14426)
@@ -238,14 +238,11 @@
* data structure, populates it with the data provided, and then
* generates the dynamic names that exist as part of a commodity.
*
- * @note This function does not check to see if the commodity exists
- * before adding a new commodity.
+ * @note If the commodity already exists, this function will return
+ * the existing commodity.
*
* @param book The book that the new commodity will belong to.
*
- * @param fullname The complete name of this commodity. E.G. "Acme
- * Systems, Inc."
- *
* @param namespace An aggregation of commodities. E.G. ISO4217,
* Nasdaq, Downbelow, etc.
*
@@ -255,23 +252,11 @@
* match the stock ticker symbol used by the exchange where you want
* to get automatic stock quote updates. E.G. ACME, ACME.US, etc.
*
- * @param cusip A string containing the CUSIP code or similar
- * UNIQUE code for this commodity. The stock ticker is NOT
- * appropriate as that goes in the mnemonic field.
- *
- * @param fraction The smallest division of this commodity
- * allowed. I.E. If this is 1, then the commodity must be traded in
- * whole units; if 100 then the commodity may be traded in 0.01
- * units, etc.
- *
- * @return A pointer to the new commodity.
+ * @return A pointer to the new (or existing) commodity.
*/
gnc_commodity * gnc_commodity_new(QofBook *book,
- const char * fullname,
const char * namespace,
- const char * mnemonic,
- const char * cusip,
- int fraction);
+ const char * mnemonic);
/** Destroy a commodity. Release all memory attached to this data structure.
* @note This function does not (can not) check to see if the
@@ -450,29 +435,27 @@
@{
*/
-/** Set the mnemonic for the specified commodity. This should be a
- * pointer to a null terminated string of the form "ACME", "QWER",
- * etc.
+/** Set both the namespace and mnemonic for the specified commodity.
+ * The namespace should be a pointer to a null terminated string of
+ * the form "AMEX", "NASDAQ", etc. The mnemonic should be a pointer
+ * to a null terminated string of the form "ACME", "QWER", etc.
*
* @param cm A pointer to a commodity data structure.
*
- * @param mnemonic A pointer to the mnemonic for this commodity.
+ * @param namespace A pointer to the namespace for this commodity.
* This string belongs to the caller and will be duplicated by the
* engine.
- */
-void gnc_commodity_set_mnemonic(gnc_commodity * cm, const char * mnemonic);
-
-/** Set the namespace for the specified commodity. This should be a
- * pointer to a null terminated string of the form "AMEX", "NASDAQ",
- * etc.
*
- * @param cm A pointer to a commodity data structure.
- *
- * @param namespace A pointer to the namespace for this commodity.
+ * @param mnemonic A pointer to the mnemonic for this commodity.
* This string belongs to the caller and will be duplicated by the
* engine.
+ *
+ * Note: Caller should check for a mnemonic/namespace collision with
+ * an existing commodity before calling this function. If a collision
+ * occurs, this commodity will replace the previous one.
*/
-void gnc_commodity_set_namespace(gnc_commodity * cm, const char * namespace);
+void gnc_commodity_set_namespace_and_mnemonic(
+ gnc_commodity * cm, const gchar * namespace, const gchar *mnemonic);
/** Set the full name for the specified commodity. This should be
* a pointer to a null terminated string of the form "Acme Systems,
Modified: gnucash/branches/register-rewrite/src/engine/gw-engine-spec.scm
===================================================================
--- gnucash/branches/register-rewrite/src/engine/gw-engine-spec.scm 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/engine/gw-engine-spec.scm 2006-06-24 16:12:18 UTC (rev 14426)
@@ -2040,11 +2040,8 @@
'<gnc:commodity*>
"gnc_commodity_new"
'((<gnc:Book*> book)
- ((<gw:mchars> caller-owned const) fullname)
((<gw:mchars> caller-owned const) namespace)
- ((<gw:mchars> caller-owned const) mnemonic)
- ((<gw:mchars> caller-owned const) exchange-code)
- (<gw:int> smallest-fraction) )
+ ((<gw:mchars> caller-owned const) mnemonic))
"Create a new gnc_commodity object.")
(gw:wrap-function
@@ -2089,6 +2086,14 @@
(gw:wrap-function
ws
+ 'gnc:commodity-set-fullname
+ '<gw:void>
+ "gnc_commodity_set_fullname"
+ '((<gnc:commodity*> comm) ((<gw:mchars> caller-owned const) fullname))
+ "Set the currency's full name (US Dollars).")
+
+(gw:wrap-function
+ ws
'gnc:commodity-get-exchange-code
'(<gw:mchars> callee-owned const)
"gnc_commodity_get_cusip"
@@ -2097,6 +2102,14 @@
(gw:wrap-function
ws
+ 'gnc:commodity-set-cusip
+ '<gw:void>
+ "gnc_commodity_set_cusip"
+ '((<gnc:commodity*> comm) ((<gw:mchars> caller-owned const) cusip))
+ "Set the cusip (exchange specific data, not the stock ticker)")
+
+(gw:wrap-function
+ ws
'gnc:commodity-get-fraction
'<gw:int>
"gnc_commodity_get_fraction"
@@ -2105,6 +2118,14 @@
(gw:wrap-function
ws
+ 'gnc:commodity-set-fraction
+ '<gw:void>
+ "gnc_commodity_set_fraction"
+ '((<gnc:commodity*> comm) (<gw:int> frac))
+ "Set the number of smallest transactional units per unit of the currency")
+
+(gw:wrap-function
+ ws
'gnc:commodity-is-currency?
'<gw:bool>
"gnc_commodity_is_currency"
Modified: gnucash/branches/register-rewrite/src/engine/iso-currencies-to-c
===================================================================
--- gnucash/branches/register-rewrite/src/engine/iso-currencies-to-c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/engine/iso-currencies-to-c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -38,12 +38,12 @@
output-port "
{
const char *fullname = ~S;
- gnc_commodity *c = gnc_commodity_new(book,
- _(fullname),
- ~S,
- ~S,
- ~S,
+ gnc_commodity *c = gnc_commodity_new(book,
+ ~S,
~S);\n
+ gnc_commodity_set_fullname(c, _(fullname));\n
+ gnc_commodity_set_cusip(c, ~S);\n
+ gnc_commodity_set_fraction(c, ~S);\n
if(!c) {
PWARN(\"failed to create commodity for currency %s\", fullname);
}
Modified: gnucash/branches/register-rewrite/src/engine/test/test-commodities.c
===================================================================
--- gnucash/branches/register-rewrite/src/engine/test/test-commodities.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/engine/test/test-commodities.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -39,7 +39,7 @@
QofBook *book;
book = qof_book_new ();
- com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0);
+ com = gnc_commodity_new(book, NULL, NULL);
gnc_commodity_destroy(com);
qof_book_destroy (book);
@@ -63,12 +63,12 @@
cusip = get_random_string();
fraction = get_random_int_in_range(0, 10000);
- com = gnc_commodity_new(book, fullname, namespace, mnemonic,
- cusip, fraction);
+ com = gnc_commodity_new(book, namespace, mnemonic);
do_test(
com != NULL, "commodity with data new and destroy");
+ gnc_commodity_set_fullname(com, fullname);
do_test(
safe_strcmp(fullname, gnc_commodity_get_fullname(com)) == 0,
"fullnames equal test");
@@ -81,10 +81,12 @@
safe_strcmp(mnemonic, gnc_commodity_get_mnemonic(com)) == 0,
"mnemonic equal test");
+ gnc_commodity_set_cusip(com, cusip);
do_test(
safe_strcmp(cusip, gnc_commodity_get_cusip(com)) == 0,
"cusip equal test");
+ gnc_commodity_set_fraction(com, fraction);
do_test(
gnc_commodity_get_fraction(com) == fraction,
"fraction code equal test");
@@ -96,13 +98,12 @@
"reset fullnames equal test");
namespace = get_random_commodity_namespace();
- gnc_commodity_set_namespace(com, namespace);
+ mnemonic = get_random_string();
+ gnc_commodity_set_namespace_and_mnemonic(com, namespace, mnemonic);
do_test(
safe_strcmp(namespace, gnc_commodity_get_namespace(com)) == 0,
"reset namespace equal test");
- mnemonic = get_random_string();
- gnc_commodity_set_mnemonic(com, mnemonic);
do_test(
safe_strcmp(mnemonic, gnc_commodity_get_mnemonic(com)) == 0,
"reset mnemonic equal test");
@@ -119,8 +120,7 @@
gnc_commodity_get_fraction(com) == fraction,
"reset fraction code equal test");
- com2 = gnc_commodity_new(book, fullname, namespace, mnemonic,
- cusip, fraction);
+ com2 = gnc_commodity_new(book, namespace, mnemonic);
do_test(
gnc_commodity_equiv(com, com2), "commodity equiv");
Modified: gnucash/branches/register-rewrite/src/engine/test-core/test-engine-stuff.c
===================================================================
--- gnucash/branches/register-rewrite/src/engine/test-core/test-engine-stuff.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/engine/test-core/test-engine-stuff.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -559,7 +559,10 @@
ran_int = get_random_int_in_range(min_scu, max_scu);
- ret = gnc_commodity_new(book, name, space, mn, cusip, ran_int);
+ ret = gnc_commodity_new(book, space, mn);
+ gnc_commodity_set_fullname(ret, name);
+ gnc_commodity_set_cusip(ret, cusip);
+ gnc_commodity_set_fraction(ret, ran_int);
g_free(mn);
g_free(name);
@@ -571,19 +574,17 @@
void
make_random_changes_to_commodity (gnc_commodity *com)
{
- char *str;
+ char *str, *str2;
g_return_if_fail (com);
str = get_random_string ();
- gnc_commodity_set_namespace (com, str);
+ str2 = get_random_string ();
+ gnc_commodity_set_namespace_and_mnemonic(com, str, str2);
g_free (str);
+ g_free (str2);
str = get_random_string ();
- gnc_commodity_set_mnemonic (com, str);
- g_free (str);
-
- str = get_random_string ();
gnc_commodity_set_fullname (com, str);
g_free (str);
Modified: gnucash/branches/register-rewrite/src/gnome-utils/dialog-commodity.c
===================================================================
--- gnucash/branches/register-rewrite/src/gnome-utils/dialog-commodity.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/gnome-utils/dialog-commodity.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -1198,18 +1198,17 @@
}
if (!w->edit_commodity) {
- c = gnc_commodity_new(book, fullname, namespace, mnemonic, code, fraction);
+ c = gnc_commodity_new(book, namespace, mnemonic);
w->edit_commodity = c;
gnc_commodity_begin_edit(c);
} else {
c = w->edit_commodity;
gnc_commodity_begin_edit(c);
- gnc_commodity_set_fullname (c, fullname);
- gnc_commodity_set_mnemonic (c, mnemonic);
- gnc_commodity_set_namespace (c, namespace);
- gnc_commodity_set_cusip (c, code);
- gnc_commodity_set_fraction (c, fraction);
+ gnc_commodity_set_namespace_and_mnemonic(c, namespace, mnemonic);
}
+ gnc_commodity_set_fullname (c, fullname);
+ gnc_commodity_set_cusip (c, code);
+ gnc_commodity_set_fraction (c, fraction);
gnc_commodity_set_quote_flag (c, gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (w->get_quote_check)));
Modified: gnucash/branches/register-rewrite/src/import-export/binary-import/druid-commodity.c
===================================================================
--- gnucash/branches/register-rewrite/src/import-export/binary-import/druid-commodity.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/import-export/binary-import/druid-commodity.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -179,10 +179,10 @@
/* otherwise, guess that it's a NASDAQ security. */
if (!found) {
- found = gnc_commodity_new(book, gnc_commodity_get_mnemonic(lost),
- GNC_COMMODITY_NS_NASDAQ,
- gnc_commodity_get_mnemonic(lost),
- NULL, 100000);
+ found = gnc_commodity_new(book, GNC_COMMODITY_NS_NASDAQ,
+ gnc_commodity_get_mnemonic(lost));
+ gnc_commodity_set_fullname(found, gnc_commodity_get_mnemonic(lost));
+ gnc_commodity_set_fraction(found, 100000);
}
g_hash_table_insert(d->new_map, (gpointer)gnc_commodity_get_mnemonic(lost),
@@ -426,8 +426,7 @@
/* fill in the commodity structure info */
gnc_commodity_set_fullname(new_comm, new_name);
- gnc_commodity_set_namespace(new_comm, new_type);
- gnc_commodity_set_mnemonic(new_comm, new_mnemonic);
+ gnc_commodity_set_namespace_and_mnemonic(new_comm, new_type, new_mnemonic);
return FALSE;
}
Modified: gnucash/branches/register-rewrite/src/import-export/qif-import/druid-qif-import.c
===================================================================
--- gnucash/branches/register-rewrite/src/import-export/qif-import/druid-qif-import.c 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/import-export/qif-import/druid-qif-import.c 2006-06-24 16:12:18 UTC (rev 14426)
@@ -1136,7 +1136,7 @@
gnc_set_busy_cursor(NULL, TRUE);
/* get any changes to the imported stocks */
- for(pageptr = wind->commodity_pages; pageptr; pageptr=pageptr->next) {
+ for(pageptr = wind->commodity_pages; pageptr; pageptr = pageptr->next) {
gtkpage = GNOME_DRUID_PAGE(pageptr->data);
page = g_object_get_data(G_OBJECT(gtkpage), "page_struct");
@@ -1144,9 +1144,9 @@
namespace = gnc_ui_namespace_picker_ns((page->new_type_combo));
fullname = gtk_entry_get_text(GTK_ENTRY(page->new_name_entry));
- gnc_commodity_set_namespace(page->commodity, namespace);
+ gnc_commodity_set_namespace_and_mnemonic(page->commodity,
+ namespace, mnemonic);
gnc_commodity_set_fullname(page->commodity, fullname);
- gnc_commodity_set_mnemonic(page->commodity, mnemonic);
}
/* call a scheme function to do the work. The return value is an
Modified: gnucash/branches/register-rewrite/src/import-export/qif-import/qif-dialog-utils.scm
===================================================================
--- gnucash/branches/register-rewrite/src/import-export/qif-import/qif-dialog-utils.scm 2006-06-24 03:52:16 UTC (rev 14425)
+++ gnucash/branches/register-rewrite/src/import-export/qif-import/qif-dialog-utils.scm 2006-06-24 16:12:18 UTC (rev 14426)
@@ -623,18 +623,18 @@
;; we know nothing about this security.. we need to
;; ask about it
- (let ((ticker-symbol (qif-ticker-map:lookup-ticker ticker-map stock-name)))
+ (let ((ticker-symbol (qif-ticker-map:lookup-ticker ticker-map stock-name))
+ (c #f))
(if (not ticker-symbol)
(set! ticker-symbol stock-name))
(set! names (cons stock-name names))
- (hash-set!
- stock-hash stock-name
- (gnc:commodity-create book
- stock-name
+ (set! c (gnc:commodity-create book
GNC_COMMODITY_NS_NYSE
- ticker-symbol
- ""
- 100000))))))
+ ticker-symbol))
+ (gnc:commodity-set-fullname c stock-name)
+ (gnc:commodity-set-cusip c "")
+ (gnc:commodity-set-fraction c 100000)
+ (hash-set! stock-hash stock-name c)))))
#f))
#f acct-hash)
More information about the gnucash-changes
mailing list