r14504 - gnucash/branches/2.0 - Allow account-separator character in account names (#347321).

Derek Atkins warlord at cvs.gnucash.org
Sat Jul 15 11:04:19 EDT 2006


Author: warlord
Date: 2006-07-15 11:04:19 -0400 (Sat, 15 Jul 2006)
New Revision: 14504
Trac: http://svn.gnucash.org/trac/changeset/14504

Modified:
   gnucash/branches/2.0/
   gnucash/branches/2.0/ChangeLog
   gnucash/branches/2.0/src/engine/Group.c
Log:
Allow account-separator character in account names (#347321).
Revert to previous behavior of xaccGetAccountFromFullName()
which was changed in r13467 when the function was restructured.
This patch returns to the old behavior (but uses the new
function structure).

Merge from r14488 and r14496



Property changes on: gnucash/branches/2.0
___________________________________________________________________
Name: svk:merge
   + d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/branches/2.0:12847

Modified: gnucash/branches/2.0/ChangeLog
===================================================================
--- gnucash/branches/2.0/ChangeLog	2006-07-15 13:26:48 UTC (rev 14503)
+++ gnucash/branches/2.0/ChangeLog	2006-07-15 15:04:19 UTC (rev 14504)
@@ -1,3 +1,12 @@
+2006-07-12  Derek Atkins  <derek at ihtfp.com>
+
+	* src/engine/Group.c:
+	  Allow account-separator character in account names (#347321).
+	  Revert to previous behavior of xaccGetAccountFromFullName()
+	  which was changed in r13467 when the function was restructured.
+	  This patch returns to the old behavior (but uses the new
+	  function structure).
+
 2006-07-09  Chris Lyttle  <chris at wilddev.net>
 
 	* NEWS: Added some text about the release.

Modified: gnucash/branches/2.0/src/engine/Group.c
===================================================================
--- gnucash/branches/2.0/src/engine/Group.c	2006-07-15 13:26:48 UTC (rev 14503)
+++ gnucash/branches/2.0/src/engine/Group.c	2006-07-15 15:04:19 UTC (rev 14504)
@@ -556,35 +556,79 @@
 xaccGetAccountFromFullNameHelper (const AccountGroup *grp,
 				  gchar **names)
 {
-  Account *found;
+  Account *found = NULL;
   GList *node;
+  gchar *name_str, *temp_str;
+  const gchar *separator;
+  gboolean str_alloced = FALSE;
 
   g_return_val_if_fail(grp, NULL);
   g_return_val_if_fail(names, NULL);
 
-  /* Look for the first name in the children. */
-  for (node = grp->accounts; node; node = node->next) {
-    Account *account = node->data;
+  separator = gnc_get_account_separator_string();
+  /* start with the first name in the list */
+  name_str = names[0];
 
-    if (safe_strcmp(xaccAccountGetName (account), names[0]) == 0) {
-      /* We found an account.  If the next entry is NULL, there is
-       * nothing left in the name, so just return the account. */
-      if (names[1] == NULL)
-	return account;
+  /* Make sure we actually HAVE a string! */
+  if (name_str == NULL)
+    return NULL;
 
-      /* No children?  We're done. */
-      if (!account->children)
-	return NULL;
+  while (1)
+  {
+    /* Look for the first name in the children. */
+    for (node = grp->accounts; node; node = node->next) {
+      Account *account = node->data;
 
-      /* There's stuff left to search for.  Search recursively. */
-      found = xaccGetAccountFromFullNameHelper(account->children, &names[1]);
-      if (found != NULL) {
-	return found;
+      if (safe_strcmp(xaccAccountGetName (account), name_str) == 0) {
+	/* We found an account.  If the next entry is NULL, there is
+	 * nothing left in the name, so just return the account. */
+	if (names[1] == NULL) {
+	  found = account;
+	  goto done;
+	}
+
+	/* No children?  We're done. */
+	if (!account->children) {
+	  found = NULL;
+	  goto done;
+	}
+
+	/* There's stuff left to search for.  Search recursively. */
+	found = xaccGetAccountFromFullNameHelper(account->children, &names[1]);
+	if (found != NULL) {
+	  goto done;
+	}
       }
     }
+
+    /* If we got here then we didn't find a match based on name_str
+     * so build a new name_str using the next token and try again.
+     */
+
+    /* If there's no more names then we're done.  We didn't find anything */
+    if (names[1] == NULL) {
+      found = NULL;
+      break;
+    }
+
+    /* If we are here, we didn't find anything and there
+     * must be more separators. So, continue looking with
+     * a longer name, in case there is a name with the
+     * separator character in it. */ 
+
+    /* Build the new name string */
+    temp_str = g_strconcat(name_str, separator, names[1], NULL);
+    if (str_alloced)
+      g_free(name_str);
+    str_alloced = TRUE;
+    names++;
+    name_str = temp_str;    
   }
 
-  return NULL;
+done:
+  if (str_alloced)
+    g_free(name_str);
+  return found;
 }
 
 



More information about the gnucash-changes mailing list