remove spectacularly brain-damaged implementation of 'ForEach'

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9097 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-08-16 21:13:31 +00:00
parent 7c57239e84
commit 1752f2c33d
15 changed files with 68 additions and 232 deletions

View File

@ -88,7 +88,7 @@ append_group (xmlNodePtr parent, AccountGroup *grp)
}
}
static gboolean
static int
traverse_txns (Transaction *txn, gpointer data)
{
xmlNodePtr node;
@ -97,7 +97,7 @@ traverse_txns (Transaction *txn, gpointer data)
node = gnc_transaction_dom_tree_create(txn);
xmlAddChild (parent, node);
return TRUE;
return 0;
}
#endif

View File

@ -966,7 +966,7 @@ write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd)
xmlFreeNode(node);
}
static gboolean
static int
xml_add_trn_data(Transaction *t, gpointer data)
{
struct file_backend *be_data = data;
@ -980,7 +980,7 @@ xml_add_trn_data(Transaction *t, gpointer data)
xmlFreeNode(node);
be_data->gd->counter.transactions_loaded++;
run_callback(be_data->gd, "transaction");
return TRUE;
return 0;
}
static void

View File

@ -254,7 +254,7 @@ mark_transaction_commodities(Transaction * t, void *data)
g_hash_table_insert(hash, xaccTransGetCurrency(t), hash);
return TRUE;
return 0;
}
static gboolean

View File

@ -673,12 +673,11 @@ static gboolean add_to_verslist (struct _listinfo *listinfo,
return TRUE;
}
static gboolean add_txnvers_cb (Transaction *t, void *data)
static gint add_txnvers_cb (Transaction *t, void *data)
{
if (!t || !data)
return FALSE;
return add_to_verslist ((struct _listinfo *)data, &(t->guid), t->version);
if (!t || !data) return 1;
add_to_verslist ((struct _listinfo *)data, &(t->guid), t->version);
return 0;
}
gnc_vers_list * rpcend_build_gncverslist_txn (GList *txnlist,

View File

@ -1,7 +1,7 @@
/********************************************************************\
* Account.c -- Account data structure implementation *
* Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1997-2002 Linas Vepstas <linas@linas.org> *
* Copyright (C) 1997-2003 Linas Vepstas <linas@linas.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -1919,7 +1919,7 @@ xaccAccountGetBalanceAsOfDate (Account *acc, time_t date)
* it doesn't exist yet and I'm uncertain of exactly how
* it would work at this time, since it differs from
* xaccAccountForEachTransaction by using gpointer return
* values rather than gbooleans.
* values rather than gints.
*/
GList *lp;
Timespec ts, trans_ts;
@ -3040,60 +3040,14 @@ xaccAccountGetReconcileChildrenStatus(Account *account)
/********************************************************************\
\********************************************************************/
gboolean
xaccAccountVisitUnvisitedTransactions(Account *acc,
gboolean (*proc)(Transaction *t,
void *data),
void *data,
GHashTable *visited_txns)
{
gboolean keep_going = TRUE;
GList *lp;
if(!acc) return(FALSE);
if(!proc) return(FALSE);
if(!visited_txns) return(FALSE);
for(lp = acc->splits; lp && keep_going; lp = lp->next) {
Split *s = (Split *) lp->data;
Transaction *t = xaccSplitGetParent(s);
if(t) {
const GUID *guid = xaccTransGetGUID(t);
gpointer been_here = g_hash_table_lookup(visited_txns, guid);
if(!GPOINTER_TO_INT(been_here)) {
g_hash_table_insert(visited_txns, (gpointer) guid,
GINT_TO_POINTER(TRUE));
if(!proc(t, data)) {
keep_going = FALSE;
}
}
}
}
return(keep_going);
}
gboolean
gint
xaccAccountForEachTransaction(Account *acc,
gboolean (*proc)(Transaction *t, void *data),
TransactionCallback proc,
void *data)
{
GHashTable *visited_txns = NULL;
gboolean result = FALSE;
if(!acc) return(FALSE);
if(!proc) return(FALSE);
visited_txns = guid_hash_table_new();
if(visited_txns) {
result =
xaccAccountVisitUnvisitedTransactions(acc, proc, data, visited_txns);
}
/* cleanup */
if(visited_txns) g_hash_table_destroy(visited_txns);
return(result);
if(!acc || !proc) return 0;
xaccAccountBeginStagedTransactionTraversals (acc);
return xaccAccountStagedTransactionTraversal(acc, 42, proc, data);
}
/********************************************************************\

View File

@ -453,14 +453,6 @@ gboolean xaccAccountTypesCompatible (GNCAccountType parent_type,
/* ------------------ */
/* Doxygen note: if these typedefs are inside the member group, the
* member group will show up at the top of the documentation, which is
* probably not wanted. */
/** \warning Unimplemented, for xaccAccountForEachSplit() */
typedef gpointer (*SplitCallback)(Split *s, gpointer data);
/** Callback prototype for xaccAccountForEachTransaction() */
typedef gboolean (*TransactionCallback)(Transaction *t, void *data);
/** @name Account split/transaction list management */
/*@{*/
/** The xaccAccountInsertSplit() method will insert the indicated
@ -486,7 +478,7 @@ gpointer xaccAccountForEachSplit(Account *account,
/** The xaccAccountForEachTransaction() routine will traverse all of
the transactions in the given 'account' and call the callback
function 'proc' on each transaction. Processing will continue
if-and-only-if 'proc' does not return FALSE. The user data pointer
if-and-only-if 'proc' returns 0. The user data pointer
'data' will be passed on to the callback function 'proc'.
This function does not descend recursively to traverse transactions
@ -495,12 +487,9 @@ gpointer xaccAccountForEachSplit(Account *account,
'proc' will be called exactly once for each transaction that is
pointed to by at least one split in the given account.
Note too, that if you call this function on two separate accounts
and those accounts share transactions, proc will be called once per
account for the shared transactions.
The result of this function will not be FALSE if-and-only-if
The result of this function will be 0 if-and-only-if
every relevant transaction was traversed exactly once.
Else the return value is the last non-zero value returned by proc.
Note that the traversal occurs only over the transactions that
are locally cached in the local gnucash engine. If the gnucash
@ -510,34 +499,16 @@ gpointer xaccAccountForEachSplit(Account *account,
it will not traverse transactions present only in the remote
database.
*/
gboolean
xaccAccountForEachTransaction(Account *account,
TransactionCallback proc,
void *data);
/** The xaccAccountVisitUnvisitedTransactions() routine will
visit every transaction in the account that hasn't already been
visited exactly once. visited_txns must be a hash table created
via guid_hash_table_new() and is the authority about which
transactions have already been visited. Further, when this
procedure returns visited_txns will have been modified to reflect
all the newly visited transactions.
The result of this function will not be FALSE if-and-only-if
every relevant transaction was traversed exactly once.
*/
gboolean
xaccAccountVisitUnvisitedTransactions(Account *account,
TransactionCallback,
void *data,
GHashTable *visited_txns);
gint xaccAccountForEachTransaction(Account *account,
TransactionCallback proc,
void *data);
/** Returns a pointer to the transaction, not a copy. */
Transaction *
xaccAccountFindTransByDesc(Account *account, const char *description);
Transaction * xaccAccountFindTransByDesc(Account *account,
const char *description);
/** Returns a pointer to the split, not a copy. */
Split *
xaccAccountFindSplitByDesc(Account *account, const char *description);
Split * xaccAccountFindSplitByDesc(Account *account, const char *description);
/** The xaccAccountFixSplitDateOrder() subroutine checks to see if
* a split is in proper sorted date order with respect

View File

@ -1133,90 +1133,15 @@ xaccGroupStagedTransactionTraversal (AccountGroup *grp,
/********************************************************************\
\********************************************************************/
struct group_visit_data
{
gboolean (*proc)(Transaction *t, void *data);
void *up_data;
GHashTable *visit_table;
};
static gboolean
xaccGroupVisitUnvisitedTransactions_thunk(Transaction *trn,
void *data)
{
gpointer test_trn;
struct group_visit_data *grdata = (struct group_visit_data*)data;
gboolean result;
test_trn = g_hash_table_lookup(grdata->visit_table, trn);
if(!test_trn)
{
g_hash_table_insert(grdata->visit_table, trn, "");
result = grdata->proc(trn, grdata->up_data);
}
else
result = TRUE;
return result;
}
gboolean
xaccGroupVisitUnvisitedTransactions (AccountGroup *g,
gboolean (*proc)(Transaction *t,
void *data),
void *data,
GHashTable *visited_txns)
{
gboolean keep_going = TRUE;
GList *list;
GList *node;
struct group_visit_data grdata;
if (!g) return(FALSE);
if (!proc) return(FALSE);
if (!visited_txns) return(FALSE);
list = xaccGroupGetSubAccounts (g);
grdata.proc = proc;
grdata.up_data = data;
grdata.visit_table = visited_txns;
for (node = list; node && keep_going; node = node->next)
{
Account *account = node->data;
keep_going = xaccAccountForEachTransaction(
account, xaccGroupVisitUnvisitedTransactions_thunk, (void*)&grdata);
}
g_list_free (list);
return(keep_going);
}
gboolean
int
xaccGroupForEachTransaction (AccountGroup *g,
gboolean (*proc)(Transaction *t, void *data),
int (*proc)(Transaction *t, void *data),
void *data)
{
GHashTable *visited_txns = NULL;
gboolean result = FALSE;
if (!g || !proc) return 0;
if (!g) return(FALSE);
if (!proc) return(FALSE);
visited_txns = guid_hash_table_new();
if (visited_txns)
result = xaccGroupVisitUnvisitedTransactions(g, proc, data, visited_txns);
/* cleanup */
if (visited_txns)
g_hash_table_destroy(visited_txns);
return(result);
xaccGroupBeginStagedTransactionTraversals (g);
return xaccGroupStagedTransactionTraversal (g, 42, proc, data);
}
/********************************************************************\

View File

@ -300,10 +300,9 @@ gboolean xaccSplitTransactionTraverse(Split *split, int stage);
* a traversal is undefined, so don't do that.
*/
typedef int (*TransactionCallbackInt)(Transaction *t, void *data);
int xaccGroupStagedTransactionTraversal(AccountGroup *grp,
unsigned int stage,
TransactionCallbackInt,
TransactionCallback,
void *data);
/* xaccAccountStagedTransactionTraversal() calls thunk on each
@ -320,11 +319,11 @@ int xaccGroupStagedTransactionTraversal(AccountGroup *grp,
int xaccAccountStagedTransactionTraversal(Account *a,
unsigned int stage,
TransactionCallbackInt,
TransactionCallback,
void *data);
/** Traverse all of the transactions in the given account group.
Continue processing IFF proc does not return FALSE. This function
Continue processing IFF proc returns 0. This function
will descend recursively to traverse transactions in the
children of the accounts in the group.
@ -332,12 +331,9 @@ int xaccAccountStagedTransactionTraversal(Account *a,
pointed to by at least one split in any account in the hierarchy
topped by AccountGroup g.
Note too, that if you call this function on two separate account
groups and those accounts groups share transactions, proc will be
called once per account on the shared transactions.
The result of this function will not be FALSE IFF every relevant
transaction was traversed exactly once.
The result of this function will be 0 IFF every relevant
transaction was traversed exactly once; otherwise, the return
value is the last non-zero value returned by the callback.
Note that the traversal occurs only over the transactions that
are locally cached in the local gnucash engine. If the gnucash
@ -346,26 +342,14 @@ int xaccAccountStagedTransactionTraversal(Account *a,
This routine will not cause an SQL database query to be performed;
it will not traverse transactions present only in the remote
database.
Note that this routine is just a trivial wrapper for
xaccGroupBeginStagedTransactionTraversals(grp);
xaccGroupStagedTransactionTraversal(grp, 42, cb, data);
*/
gboolean
xaccGroupForEachTransaction(AccountGroup *g,
TransactionCallback,
void *data);
/* Visit every transaction in the account that hasn't already been
visited exactly once. visited_txns must be a hash table created
via guid_hash_table_new() and is the authority about which
transactions have already been visited. Further, when this
procedure returns, visited_txns will have been modified to reflect
all the newly visited transactions.
The result of this function will not be FALSE IFF every relevant
transaction was traversed exactly once. */
gboolean
xaccGroupVisitUnvisitedTransactions(AccountGroup *g,
TransactionCallback,
void *data,
GHashTable *visited_txns);
int xaccGroupForEachTransaction(AccountGroup *g,
TransactionCallback, void *data);
#endif /* XACC_ACCOUNT_GROUP_H */

View File

@ -543,11 +543,11 @@ xaccAccountScrubCommodity (Account *account)
/* ================================================================ */
static gboolean
static int
scrub_trans_currency_helper (Transaction *t, gpointer data)
{
xaccTransScrubCurrency (t);
return TRUE;
return 0;
}
static gpointer

View File

@ -3216,11 +3216,11 @@ xaccSplitMakeStockSplit(Split *s)
/* ====================================================================== */
static gboolean
static int
counter_thunk(Transaction *t, void *data)
{
(*((guint*)data))++;
return TRUE;
return 0;
}
guint

View File

@ -153,6 +153,10 @@ typedef GList AccountGUIDList;
/** GList of GUIDs of a GNCBook */
typedef GList BookGUIDList;
typedef gint (*SplitCallback)(Split *s, gpointer data);
typedef gint (*TransactionCallback)(Transaction *t, void *data);
/** Function type for init hooks in the engine. */
typedef void (* gnc_engine_init_hook_t)(int, char **);

View File

@ -684,7 +684,7 @@ make_random_changes_to_transaction_and_splits (QofBook *book,
xaccTransRollbackEdit (trans);
}
static gboolean
static int
add_trans_helper (Transaction *trans, gpointer data)
{
TransInfo *ti;
@ -695,8 +695,7 @@ add_trans_helper (Transaction *trans, gpointer data)
ti->guid = *xaccTransGetGUID (trans);
*list = g_list_prepend (*list, ti);
return TRUE;
return 0;
}
void

View File

@ -11,7 +11,7 @@
#include "test-engine-stuff.h"
#include "test-stuff.h"
static gboolean
static int
test_trans_query (Transaction *trans, gpointer data)
{
QofBook *book = data;
@ -28,21 +28,21 @@ test_trans_query (Transaction *trans, gpointer data)
"number of matching transactions %d not 1",
g_list_length (list));
g_list_free (list);
return FALSE;
return 13;
}
if (list->data != trans)
{
failure ("matching transaction is wrong");
g_list_free (list);
return FALSE;
return 13;
}
success ("found right transaction");
xaccFreeQuery (q);
g_list_free (list);
return TRUE;
return 0;
}
static void

View File

@ -307,7 +307,7 @@ static void create_transactions_on( SchedXaction *sx,
GDate *gd,
toCreateInstance *tci,
GList **createdGUIDs );
static gboolean create_each_transaction_helper( Transaction *t, void *d );
static gint create_each_transaction_helper( Transaction *t, void *d );
/* External for what reason ... ? */
void sxsl_get_sx_vars( SchedXaction *sx, GHashTable *varHash );
static void hash_to_sorted_list( GHashTable *hashTable, GList **gl );
@ -2364,7 +2364,7 @@ gnc_sxsl_del_vars_table_ea( gpointer key,
g_free( (gnc_numeric*)value );
}
static gboolean
static gint
create_each_transaction_helper( Transaction *t, void *d )
{
Transaction *newT;
@ -2409,7 +2409,7 @@ create_each_transaction_helper( Transaction *t, void *d )
PERR( "\tseen transaction w/o splits. :(" );
xaccTransDestroy( newT );
xaccTransCommitEdit( newT );
return FALSE;
return 13;
}
/* Setup the predefined variables for credit/debit formula
@ -2596,7 +2596,7 @@ create_each_transaction_helper( Transaction *t, void *d )
xaccTransRollbackEdit( newT );
xaccTransDestroy( newT );
xaccTransCommitEdit( newT );
return FALSE;
return 13;
}
xaccTransCommitEdit( newT );
@ -2607,7 +2607,7 @@ create_each_transaction_helper( Transaction *t, void *d )
(gpointer)xaccTransGetGUID(newT) );
}
return TRUE;
return 0;
}
/**

View File

@ -924,10 +924,10 @@ gnc_import_process_trans_clist (GtkCList *clist,
/********************************************************************\
* check_trans_online_id() Callback function to be used by
* gnc_import_exists_online_id. Takes pointers to two transaction and
* returns TRUE if their online_id kvp_frame do NOT match, or if both
* returns 0 if their online_id kvp_frame do NOT match, or if both
* pointers point to the same transaction.
* \********************************************************************/
static gboolean check_trans_online_id(Transaction *trans1, void *user_data)
static gint check_trans_online_id(Transaction *trans1, void *user_data)
{
Transaction *trans2 = user_data;
const gchar *online_id1 = gnc_import_get_trans_online_id(trans1);
@ -936,12 +936,12 @@ static gboolean check_trans_online_id(Transaction *trans1, void *user_data)
if ((trans1 == trans2) || (online_id1 == NULL) ||
(online_id2 == NULL) || (strcmp(online_id1, online_id2) != 0))
{
return TRUE;
return 0;
}
else
{
//printf("test_trans_online_id(): Duplicate found\n");
return FALSE;
return 1;
}
}
@ -963,7 +963,7 @@ gboolean gnc_import_exists_online_id (Transaction *trans)
{
/* DEBUG("%s%d%s","Checking split ",i," for duplicates"); */
dest_acct = xaccSplitGetAccount(source_split);
online_id_exists = !xaccAccountForEachTransaction(dest_acct,
online_id_exists = xaccAccountForEachTransaction(dest_acct,
check_trans_online_id,
trans);
}