From 079754e1c86c5ddeaa6a67823efa544791f20eea Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Mon, 19 Oct 1998 04:13:07 +0000 Subject: [PATCH] move account code tools to different file git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1327 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Account.c | 47 ++---------------------------------- src/engine/Group.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/engine/Group.h | 8 +++++-- 3 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/engine/Account.c b/src/engine/Account.c index adaf92f274..b48be6fa1d 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -630,55 +630,12 @@ xaccAccountOrder (Account **aa, Account **ab) void xaccAccountAutoCode (Account *acc, int digits) { - Account *rent; - int maxcode = 0; - AccountGroup *top = acc->parent; - int i; - if (!acc) return; if (acc->accountCode) return; /* no-op if code already assinged */ if (!(acc->parent)) return; - /* count levels to top */ - rent = acc->parent->parent; - while (rent) { - digits --; - assert (rent->parent); - rent = rent->parent->parent; - } - - /* if (0>digits) we could insert a decimal place, but I am too lazy - * to write this code. It doesn't seem important at the moment ... */ - - /* find the largest used code */ - rent = acc->parent->parent; - if (rent) { - if (rent->accountCode) { - maxcode = strtol (rent->accountCode, NULL, BASE); - } - } - for (i=0; inumAcc; i++) { - Account *acnt = top->account[i]; - if (acnt->accountCode) { - int code = strtol (acnt->accountCode, NULL, BASE); - if (code > maxcode) maxcode = code; - } - } - - /* right-shift */ - for (i=1; iaccountCode = ultostr ((unsigned long) maxcode, BASE); - top->saved = FALSE; + acc->accountCode = xaccGroupGetNextFreeCode (acc->parent, digits); + acc->parent->saved = FALSE; } /********************************************************************\ diff --git a/src/engine/Group.c b/src/engine/Group.c index 3b0fd39764..68d1f7e1a2 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -456,6 +456,63 @@ xaccRecomputeGroupBalance (AccountGroup *grp) } } +/********************************************************************\ +\********************************************************************/ +/* account codes will be assigned base-36, with three digits */ + +#define BASE 36 + +char * +xaccGroupGetNextFreeCode (AccountGroup *grp, int digits) +{ + Account *acc; + int i, maxcode = 0; + char * retval; + + if (!grp) return NULL; + + /* count levels to top */ + acc = grp->parent; + while (acc) { + digits --; + assert (acc->parent); + acc = acc->parent->parent; + } + + /* if (0>digits) we could insert a decimal place, but I am too lazy + * to write this code. It doesn't seem important at the moment ... */ + + /* find the largest used code */ + acc = grp->parent; + if (acc) { + if (acc->accountCode) { + maxcode = strtol (acc->accountCode, NULL, BASE); + } + } + for (i=0; inumAcc; i++) { + Account *acnt = grp->account[i]; + if (acnt->accountCode) { + int code = strtol (acnt->accountCode, NULL, BASE); + if (code > maxcode) maxcode = code; + } + } + + /* right-shift */ + for (i=1; i