add a sort order for accounts

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1318 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-10-18 17:05:10 +00:00
parent 893f6bb8f4
commit 1ed074fddb
2 changed files with 76 additions and 1 deletions

View File

@ -563,6 +563,70 @@ xaccCheckTransDateOrder (Transaction *trans )
/********************************************************************\
\********************************************************************/
/* The sort order is used to implicitly define an
* order for report generation */
static int typeorder[NUM_ACCOUNT_TYPES] = {
BANK, STOCK, MUTUAL, CURRENCY, CASH, ASSET,
CREDIT, LIABILITY, INCOME, EXPENSE, EQUITY };
static int revorder[NUM_ACCOUNT_TYPES] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
int
xaccAccountOrder (Account **aa, Account **ab)
{
char *da, *db;
int ta, tb;
if ( (*aa) && !(*ab) ) return -1;
if ( !(*aa) && (*ab) ) return +1;
if ( !(*aa) && !(*ab) ) return 0;
/* sort on accountCode strings */
da = (*aa)->accountCode;
db = (*ab)->accountCode;
SAFE_STRCMP (da, db);
/* if acccount-type-order array not initialized, initialize it */
/* this will happen at most once during program invocation */
if (-1 == revorder[0]) {
int i;
for (i=0; i<NUM_ACCOUNT_TYPES; i++) {
revorder [typeorder[i]] = i;
}
}
/* otherwise, sort on account type */
ta = (*aa)->type;
tb = (*ab)->type;
ta = revorder[ta];
tb = revorder[tb];
if (ta < tb) return -1;
if (ta > tb) return +1;
/* otherwise, sort on accountName strings */
da = (*aa)->accountName;
db = (*ab)->accountName;
SAFE_STRCMP (da, db);
/* accountName strings should really, really be unique, and so in theory
* we should never ever get here. But just in case theory is broke ... */
da = (*aa)->currency;
db = (*ab)->currency;
SAFE_STRCMP (da, db);
da = (*aa)->security;
db = (*ab)->security;
SAFE_STRCMP (da, db);
return 0;
}
/********************************************************************\
\********************************************************************/
int
xaccIsAccountInList (Account * acc, Account **list)
{

View File

@ -72,10 +72,21 @@ int xaccCheckDateOrder (Account *, Split *);
int xaccCheckTransDateOrder (Transaction *);
/* The xaccIsAccountInList() subroutine returns the number of times
* that an account appears in the account list. */
* that an account appears in the account list.
*/
int xaccIsAccountInList (Account * acc, Account **list);
void xaccZeroRunningBalances (Account **list);
/* The xaccAccountOrder() subroutine defines a sorting order
* on accounts. It takes pointers to two accounts, and
* returns -1 if the first account is "less than" the second,
* returns +1 if the first is "greater than" the second, and
* 0 if they are equal. To determine the sort order, first
* the account codes are compared, and if these are equal, then
* account types, and, if these are queal, the account names.
*/
int xaccAccountOrder (Account**, Account **);
/* The xaccConsolidateTransactions() subroutine scans through
* all of the transactions in an account, and compares them.
* If any of them are exact duplicates, the duplicates are removed.