From b81b256508c6f7a6503e578adce2c4044b9e529d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Mon, 19 Oct 1998 06:17:23 +0000 Subject: [PATCH] oops, we need another routine to do the right thing ... git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1328 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Group.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ src/engine/Group.h | 6 ++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/engine/Group.c b/src/engine/Group.c index 68d1f7e1a2..c6fd72c233 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -513,6 +513,66 @@ xaccGroupGetNextFreeCode (AccountGroup *grp, int digits) return retval; } +/********************************************************************\ +\********************************************************************/ +/* almost identical code to above, but altered to deal with + * specified account */ + +char * +xaccAccountGetNextChildCode (Account *parent_acc, int digits) +{ + Account *acc; + int i, maxcode = 0; + char * retval; + AccountGroup *grp; + + if (!parent_acc) return NULL; + + /* count levels to top */ + acc = parent_acc; + while (acc) { + digits --; + assert (acc->parent); /* all acounts must be in a group */ + 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 = parent_acc; + if (acc) { + if (acc->accountCode) { + maxcode = strtol (acc->accountCode, NULL, BASE); + } + } + grp = parent_acc->children; + if (grp) { + 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